summaryrefslogtreecommitdiff
path: root/frontends/cocoa/gui.m
diff options
context:
space:
mode:
authorSven Weidauer <sven@5sw.de>2017-06-05 11:20:56 +0200
committerSven Weidauer <sven@5sw.de>2017-06-05 11:20:56 +0200
commit2ba97ae0dbd01a4f46c543ae025249e5349e0585 (patch)
tree5028ee570078f80f98049bd5a68b209ecfdaca59 /frontends/cocoa/gui.m
parent3ee40a10b123c36be3e29602767840a7a71aaafa (diff)
downloadnetsurf-2ba97ae0dbd01a4f46c543ae025249e5349e0585.tar.gz
netsurf-2ba97ae0dbd01a4f46c543ae025249e5349e0585.tar.bz2
Reformat code using clang-format.
Diffstat (limited to 'frontends/cocoa/gui.m')
-rw-r--r--frontends/cocoa/gui.m340
1 files changed, 166 insertions, 174 deletions
diff --git a/frontends/cocoa/gui.m b/frontends/cocoa/gui.m
index 72f8e7afb..68411c98c 100644
--- a/frontends/cocoa/gui.m
+++ b/frontends/cocoa/gui.m
@@ -38,101 +38,96 @@
#import "cocoa/fetch.h"
#import "cocoa/schedule.h"
+NSString *const kCookiesFileOption = @"CookiesFile";
+NSString *const kURLsFileOption = @"URLsFile";
+NSString *const kHotlistFileOption = @"Hotlist";
+NSString *const kHomepageURLOption = @"HomepageURL";
+NSString *const kOptionsFileOption = @"ClassicOptionsFile";
+NSString *const kAlwaysCancelDownload = @"AlwaysCancelDownload";
+NSString *const kAlwaysCloseMultipleTabs = @"AlwaysCloseMultipleTabs";
-NSString * const kCookiesFileOption = @"CookiesFile";
-NSString * const kURLsFileOption = @"URLsFile";
-NSString * const kHotlistFileOption = @"Hotlist";
-NSString * const kHomepageURLOption = @"HomepageURL";
-NSString * const kOptionsFileOption = @"ClassicOptionsFile";
-NSString * const kAlwaysCancelDownload = @"AlwaysCancelDownload";
-NSString * const kAlwaysCloseMultipleTabs = @"AlwaysCloseMultipleTabs";
-
-#define UNIMPL() NSLog( @"Function '%s' unimplemented", __func__ )
+#define UNIMPL() NSLog(@"Function '%s' unimplemented", __func__)
struct browser_window;
/* 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 : "" );
- return NSERROR_OK;
+ 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;
}
-
static struct gui_window *
gui_window_create(struct browser_window *bw,
- struct gui_window *existing,
- gui_window_create_flags flags)
+ struct gui_window *existing,
+ 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 = [(__bridge BrowserViewController *)(existing) windowController];
- }
-
- result = [[BrowserViewController alloc] initWithBrowser: bw];
-
- if (!(flags & GW_CREATE_TAB) || nil == window) {
- window = [[BrowserWindowController alloc] init] ;
- [[window window] makeKeyAndOrderFront: nil];
- }
- [window addTab: result];
-
- return (__bridge_retained struct gui_window *)result;
+ BrowserWindowController *window = nil;
+ BrowserViewController *result;
+
+ browser_window_set_scale(bw, (float)nsoption_int(scale) / 100, false);
+ if (existing != NULL) {
+ window = [(__bridge BrowserViewController *)(existing)windowController];
+ }
+
+ result = [[BrowserViewController alloc] initWithBrowser:bw];
+
+ if (!(flags & GW_CREATE_TAB) || nil == window) {
+ window = [[BrowserWindowController alloc] init];
+ [[window window] makeKeyAndOrderFront:nil];
+ }
+ [window addTab:result];
+
+ return (__bridge_retained struct gui_window *)result;
}
static void gui_window_destroy(struct gui_window *g)
{
- BrowserViewController *vc = (__bridge_transfer BrowserViewController *)g;
+ BrowserViewController *vc = (__bridge_transfer BrowserViewController *)g;
vc = nil;
}
static void gui_window_set_title(struct gui_window *g, const char *title)
{
- [(__bridge BrowserViewController *)g setTitle: [NSString stringWithUTF8String: title]];
+ [(__bridge BrowserViewController *)g setTitle:[NSString stringWithUTF8String:title]];
}
static nserror gui_window_update_box(struct gui_window *g, const struct rect *rect)
{
if (rect == NULL) {
- [[(__bridge BrowserViewController *)g browserView] setNeedsDisplay: YES];
+ [[(__bridge BrowserViewController *)g browserView] setNeedsDisplay:YES];
return NSERROR_OK;
-
}
- const NSRect nsrect = cocoa_scaled_rect_wh(
- browser_window_get_scale([(__bridge BrowserViewController *)g browser]),
- rect->x0, rect->y0,
- rect->x1 - rect->x0, rect->y1 - rect->y0 );
- [[(__bridge BrowserViewController *)g browserView] setNeedsDisplayInRect: nsrect];
- return NSERROR_OK;
+ const NSRect nsrect = cocoa_scaled_rect_wh(
+ browser_window_get_scale([(__bridge BrowserViewController *)g browser]),
+ rect->x0, rect->y0,
+ rect->x1 - rect->x0, rect->y1 - rect->y0);
+ [[(__bridge BrowserViewController *)g browserView] setNeedsDisplayInRect:nsrect];
+ return NSERROR_OK;
}
static bool gui_window_get_scroll(struct gui_window *g, int *sx, int *sy)
{
- NSCParameterAssert( g != NULL && sx != NULL && sy != NULL );
-
- NSRect visible = [[(__bridge BrowserViewController *)g browserView] visibleRect];
- *sx = cocoa_pt_to_px( NSMinX( visible ) );
- *sy = cocoa_pt_to_px( NSMinY( visible ) );
- return true;
+ NSCParameterAssert(g != NULL && sx != NULL && sy != NULL);
+
+ NSRect visible = [[(__bridge BrowserViewController *)g browserView] visibleRect];
+ *sx = cocoa_pt_to_px(NSMinX(visible));
+ *sy = cocoa_pt_to_px(NSMinY(visible));
+ return true;
}
static nserror gui_window_set_scroll(struct gui_window *g, const struct rect *rect)
{
- [[(__bridge BrowserViewController *)g browserView] scrollPoint: cocoa_point( rect->x0, rect->y0 )];
- return 0;
+ [[(__bridge BrowserViewController *)g browserView] scrollPoint:cocoa_point(rect->x0, rect->y0)];
+ return 0;
}
-
-
/**
* Find the current dimensions of a cocoa browser window content area.
*
@@ -144,145 +139,144 @@ static nserror gui_window_set_scroll(struct gui_window *g, const struct rect *re
* else error code.
*/
static nserror gui_window_get_dimensions(struct gui_window *g,
- int *width, int *height,
- bool scaled)
+ int *width, int *height,
+ bool scaled)
{
- NSCParameterAssert( width != NULL && height != NULL );
-
- NSRect frame = [[[(__bridge BrowserViewController *)g browserView] superview] frame];
- if (scaled) {
- const CGFloat scale = browser_window_get_scale([(__bridge BrowserViewController *)g browser]);
- frame.size.width /= scale;
- frame.size.height /= scale;
- }
- *width = cocoa_pt_to_px( NSWidth( frame ) );
- *height = cocoa_pt_to_px( NSHeight( frame ) );
+ NSCParameterAssert(width != NULL && height != NULL);
- return NSERROR_OK;
+ NSRect frame = [[[(__bridge BrowserViewController *)g browserView] superview] frame];
+ if (scaled) {
+ const CGFloat scale = browser_window_get_scale([(__bridge BrowserViewController *)g browser]);
+ frame.size.width /= scale;
+ frame.size.height /= scale;
+ }
+ *width = cocoa_pt_to_px(NSWidth(frame));
+ *height = cocoa_pt_to_px(NSHeight(frame));
+
+ return NSERROR_OK;
}
static void gui_window_update_extent(struct gui_window *g)
{
- BrowserViewController * const window = (__bridge BrowserViewController *)g;
- int width;
- int height;
- struct browser_window *browser = [window browser];
-
- browser_window_get_extents(browser, false, &width, &height);
-
- [[window browserView] setMinimumSize:
- cocoa_scaled_size( browser_window_get_scale(browser), width, height )];
+ BrowserViewController *const window = (__bridge BrowserViewController *)g;
+ int width;
+ int height;
+ struct browser_window *browser = [window browser];
+
+ browser_window_get_extents(browser, false, &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)
{
- [(__bridge BrowserViewController *)g setStatus: [NSString stringWithUTF8String: text]];
+ [(__bridge BrowserViewController *)g setStatus:[NSString stringWithUTF8String:text]];
}
static void gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape)
{
- switch (shape) {
- case GUI_POINTER_DEFAULT:
- case GUI_POINTER_WAIT:
- case GUI_POINTER_PROGRESS:
- [[NSCursor arrowCursor] set];
- break;
-
- case GUI_POINTER_CROSS:
- [[NSCursor crosshairCursor] set];
- break;
-
- case GUI_POINTER_POINT:
- case GUI_POINTER_MENU:
- [[NSCursor pointingHandCursor] set];
- break;
-
- case GUI_POINTER_CARET:
- [[NSCursor IBeamCursor] set];
- break;
-
- case GUI_POINTER_MOVE:
- [[NSCursor closedHandCursor] set];
- break;
-
- default:
- NSLog( @"Other cursor %d requested", shape );
- [[NSCursor arrowCursor] set];
- break;
- }
+ switch (shape) {
+ case GUI_POINTER_DEFAULT:
+ case GUI_POINTER_WAIT:
+ case GUI_POINTER_PROGRESS:
+ [[NSCursor arrowCursor] set];
+ break;
+
+ case GUI_POINTER_CROSS:
+ [[NSCursor crosshairCursor] set];
+ break;
+
+ case GUI_POINTER_POINT:
+ case GUI_POINTER_MENU:
+ [[NSCursor pointingHandCursor] set];
+ break;
+
+ case GUI_POINTER_CARET:
+ [[NSCursor IBeamCursor] set];
+ break;
+
+ case GUI_POINTER_MOVE:
+ [[NSCursor closedHandCursor] set];
+ break;
+
+ default:
+ NSLog(@"Other cursor %d requested", shape);
+ [[NSCursor arrowCursor] set];
+ break;
+ }
}
static nserror gui_window_set_url(struct gui_window *g, struct nsurl *url)
{
- [(__bridge BrowserViewController *)g setUrl: [NSString stringWithUTF8String: nsurl_access(url)]];
- return NSERROR_OK;
+ [(__bridge BrowserViewController *)g setUrl:[NSString stringWithUTF8String:nsurl_access(url)]];
+ return NSERROR_OK;
}
static void gui_window_start_throbber(struct gui_window *g)
{
- [(__bridge BrowserViewController *)g setIsProcessing: YES];
- [(__bridge BrowserViewController *)g updateBackForward];
+ [(__bridge BrowserViewController *)g setIsProcessing:YES];
+ [(__bridge BrowserViewController *)g updateBackForward];
}
static void gui_window_stop_throbber(struct gui_window *g)
{
- [(__bridge BrowserViewController *)g setIsProcessing: NO];
- [(__bridge BrowserViewController *)g updateBackForward];
+ [(__bridge BrowserViewController *)g setIsProcessing:NO];
+ [(__bridge BrowserViewController *)g updateBackForward];
}
static void gui_window_set_icon(struct gui_window *g, struct hlcache_handle *icon)
{
- NSBitmapImageRep *bmp = NULL;
- NSImage *image = nil;
-
- if (icon != NULL) {
- bmp = (__bridge NSBitmapImageRep *)content_get_bitmap( icon );
- }
-
- if (bmp != nil) {
- image = [[NSImage alloc] initWithSize: NSMakeSize( 32, 32 )];
- [image addRepresentation: bmp];
- } else {
- image = [[NSImage imageNamed: @"NetSurf"] copy];
- }
- [image setFlipped: YES];
-
- [(__bridge BrowserViewController *)g setFavicon: image];
+ NSBitmapImageRep *bmp = NULL;
+ NSImage *image = nil;
+
+ if (icon != NULL) {
+ bmp = (__bridge NSBitmapImageRep *)content_get_bitmap(icon);
+ }
+
+ if (bmp != nil) {
+ image = [[NSImage alloc] initWithSize:NSMakeSize(32, 32)];
+ [image addRepresentation:bmp];
+ } else {
+ image = [[NSImage imageNamed:@"NetSurf"] copy];
+ }
+ [image setFlipped:YES];
+
+ [(__bridge BrowserViewController *)g setFavicon:image];
}
static void
gui_window_place_caret(struct gui_window *g, int x, int y, int height,
- const struct rect *clip)
+ const struct rect *clip)
{
- [[(__bridge BrowserViewController *)g browserView]
- addCaretAt: cocoa_point( x, y )
- height: cocoa_px_to_pt( height )];
+ [[(__bridge BrowserViewController *)g browserView]
+ addCaretAt:cocoa_point(x, y)
+ height:cocoa_px_to_pt(height)];
}
static void gui_window_remove_caret(struct gui_window *g)
{
- [[(__bridge BrowserViewController *)g browserView] removeCaret];
+ [[(__bridge BrowserViewController *)g browserView] removeCaret];
}
static void gui_window_new_content(struct gui_window *g)
{
- [(__bridge BrowserViewController *)g contentUpdated];
+ [(__bridge BrowserViewController *)g contentUpdated];
}
-
static void gui_create_form_select_menu(struct gui_window *g,
- struct form_control *control)
+ struct form_control *control)
{
- BrowserViewController * const window = (__bridge BrowserViewController *)g;
- FormSelectMenu *menu = [[FormSelectMenu alloc]
- initWithControl: control
- forWindow: [window browser]];
- [menu runInView: [window browserView]];
+ BrowserViewController *const window = (__bridge BrowserViewController *)g;
+ FormSelectMenu *menu = [[FormSelectMenu alloc]
+ initWithControl:control
+ forWindow:[window browser]];
+ [menu runInView:[window browserView]];
}
static nserror gui_launch_url(nsurl *url)
{
- [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: [NSString stringWithUTF8String: nsurl_access(url)]]];
+ [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:[NSString stringWithUTF8String:nsurl_access(url)]]];
return NSERROR_OK;
}
@@ -290,45 +284,43 @@ struct ssl_cert_info;
static nserror
gui_cert_verify(nsurl *url,
- const struct ssl_cert_info *certs,
- unsigned long num,
- nserror (*cb)(bool proceed,void *pw), void *cbpw)
+ const struct ssl_cert_info *certs,
+ unsigned long num,
+ nserror (*cb)(bool proceed, void *pw), void *cbpw)
{
- return NSERROR_NOT_IMPLEMENTED;
+ return NSERROR_NOT_IMPLEMENTED;
}
-
static struct gui_window_table window_table = {
- .create = gui_window_create,
- .destroy = gui_window_destroy,
- .invalidate = gui_window_update_box,
- .get_scroll = gui_window_get_scroll,
- .set_scroll = gui_window_set_scroll,
- .get_dimensions = gui_window_get_dimensions,
- .update_extent = gui_window_update_extent,
-
- .set_title = gui_window_set_title,
- .set_url = gui_window_set_url,
- .set_icon = gui_window_set_icon,
- .set_status = gui_window_set_status,
- .set_pointer = gui_window_set_pointer,
- .place_caret = gui_window_place_caret,
- .remove_caret = gui_window_remove_caret,
- .new_content = gui_window_new_content,
- .start_throbber = gui_window_start_throbber,
- .stop_throbber = gui_window_stop_throbber,
- .create_form_select_menu = gui_create_form_select_menu,
+ .create = gui_window_create,
+ .destroy = gui_window_destroy,
+ .invalidate = gui_window_update_box,
+ .get_scroll = gui_window_get_scroll,
+ .set_scroll = gui_window_set_scroll,
+ .get_dimensions = gui_window_get_dimensions,
+ .update_extent = gui_window_update_extent,
+
+ .set_title = gui_window_set_title,
+ .set_url = gui_window_set_url,
+ .set_icon = gui_window_set_icon,
+ .set_status = gui_window_set_status,
+ .set_pointer = gui_window_set_pointer,
+ .place_caret = gui_window_place_caret,
+ .remove_caret = gui_window_remove_caret,
+ .new_content = gui_window_new_content,
+ .start_throbber = gui_window_start_throbber,
+ .stop_throbber = gui_window_stop_throbber,
+ .create_form_select_menu = gui_create_form_select_menu,
};
struct gui_window_table *cocoa_window_table = &window_table;
-
static struct gui_misc_table browser_table = {
- .schedule = cocoa_schedule,
- .warning = cocoa_warning,
+ .schedule = cocoa_schedule,
+ .warning = cocoa_warning,
- .launch_url = gui_launch_url,
- .cert_verify = gui_cert_verify,
+ .launch_url = gui_launch_url,
+ .cert_verify = gui_cert_verify,
};
struct gui_misc_table *cocoa_misc_table = &browser_table;