1// license:BSD-3-Clause
2// copyright-holders:Vas Crabb
3//============================================================
4//
5//  errorlogviewer.m - MacOS X Cocoa debug window handling
6//
7//============================================================
8
9#include "emu.h"
10#import "errorlogviewer.h"
11
12#import "errorlogview.h"
13
14#include "util/xmlfile.h"
15
16
17@implementation MAMEErrorLogViewer
18
19- (id)initWithMachine:(running_machine &)m console:(MAMEDebugConsole *)c {
20	NSScrollView    *logScroll;
21	NSString        *title;
22
23	title = [NSString stringWithFormat:@"Error Log: %@ [%@]",
24									   [NSString stringWithUTF8String:m.system().type.fullname()],
25									   [NSString stringWithUTF8String:m.system().name]];
26	if (!(self = [super initWithMachine:m title:title console:c]))
27		return nil;
28
29	// create the error log view
30	logView = [[MAMEErrorLogView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100) machine:*machine];
31	logScroll = [[NSScrollView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)];
32	[logScroll setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)];
33	[logScroll setHasHorizontalScroller:YES];
34	[logScroll setHasVerticalScroller:YES];
35	[logScroll setAutohidesScrollers:YES];
36	[logScroll setBorderType:NSNoBorder];
37	[logScroll setDrawsBackground:NO];
38	[logScroll setDocumentView:logView];
39	[logView release];
40	[window setContentView:logScroll];
41	[logScroll release];
42
43	// calculate the optimal size for everything
44	{
45		NSSize  desired = [NSScrollView frameSizeForContentSize:[logView maximumFrameSize]
46										  hasHorizontalScroller:YES
47											hasVerticalScroller:YES
48													 borderType:[logScroll borderType]];
49
50		// this thing starts with no content, so its prefered height may be very small
51		desired.height = std::max(desired.height, CGFloat(240));
52		[self cascadeWindowWithDesiredSize:desired forView:logScroll];
53	}
54
55	// don't forget the result
56	return self;
57}
58
59
60- (void)dealloc {
61	[super dealloc];
62}
63
64
65- (void)saveConfigurationToNode:(util::xml::data_node *)node {
66	[super saveConfigurationToNode:node];
67	node->set_attribute_int("type", MAME_DEBUGGER_WINDOW_TYPE_ERROR_LOG_VIEWER);
68}
69
70@end
71