trunk/src/osd/modules/debugger/osx/deviceinfoviewer.m
| r0 | r243617 | |
| 1 | // license:BSD-3-Clause |
| 2 | // copyright-holders:Vas Crabb |
| 3 | //============================================================ |
| 4 | // |
| 5 | // deviceinfoviewer.m - MacOS X Cocoa debug window handling |
| 6 | // |
| 7 | // Copyright (c) 1996-2015, Nicola Salmoria and the MAME Team. |
| 8 | // Visit http://mamedev.org for licensing and usage restrictions. |
| 9 | // |
| 10 | //============================================================ |
| 11 | |
| 12 | #import "deviceinfoviewer.h" |
| 13 | |
| 14 | |
| 15 | @implementation MAMEDeviceInfoViewer |
| 16 | |
| 17 | - (NSTextField *)makeLabel:(NSString *)text { |
| 18 | NSTextField *const result = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 100, 14)]; |
| 19 | [result setAutoresizingMask:NSViewMinYMargin]; |
| 20 | [[result cell] setControlSize:NSSmallControlSize]; |
| 21 | [result setEditable:NO]; |
| 22 | [result setSelectable:NO]; |
| 23 | [result setBezeled:NO]; |
| 24 | [result setBordered:NO]; |
| 25 | [result setDrawsBackground:NO]; |
| 26 | [result setAlignment:NSRightTextAlignment]; |
| 27 | [result setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]]]; |
| 28 | [result setStringValue:text]; |
| 29 | [result sizeToFit]; |
| 30 | return result; |
| 31 | } |
| 32 | |
| 33 | |
| 34 | - (NSTextField *)makeField:(NSString *)text { |
| 35 | NSTextField *const result = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 100, 14)]; |
| 36 | [result setAutoresizingMask:(NSViewWidthSizable | NSViewMinYMargin)]; |
| 37 | [[result cell] setControlSize:NSSmallControlSize]; |
| 38 | [result setEditable:NO]; |
| 39 | [result setSelectable:YES]; |
| 40 | [result setBezeled:NO]; |
| 41 | [result setBordered:NO]; |
| 42 | [result setDrawsBackground:NO]; |
| 43 | [result setAlignment:NSLeftTextAlignment]; |
| 44 | [result setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]]]; |
| 45 | [result setStringValue:text]; |
| 46 | [result sizeToFit]; |
| 47 | return result; |
| 48 | } |
| 49 | |
| 50 | |
| 51 | - (NSBox *)makeBox:(NSString *)t toFit:(NSView *)v { |
| 52 | NSBox *const result = [[NSBox alloc] initWithFrame:NSMakeRect(0, 0, [v frame].size.width - 34, 32)]; |
| 53 | [result setAutoresizingMask:(NSViewWidthSizable | NSViewMinYMargin)]; |
| 54 | [result setTitle:t]; |
| 55 | [result setBoxType:NSBoxPrimary]; |
| 56 | [result setBorderType:NSLineBorder]; |
| 57 | [result setContentViewMargins:NSMakeSize(0, 0)]; |
| 58 | [result setAutoresizesSubviews:YES]; |
| 59 | return result; |
| 60 | } |
| 61 | |
| 62 | |
| 63 | - (void)addLabel:(NSString *)l withWidth:(CGFloat)w andField:(NSString *)f toView:(NSView *)v { |
| 64 | NSTextField *const label = [self makeLabel:l]; |
| 65 | NSTextField *const field = [self makeField:f]; |
| 66 | CGFloat const height = MAX([label frame].size.height, [field frame].size.height); |
| 67 | NSSize space = [v bounds].size; |
| 68 | space.width = MAX(space.width, [field frame].size.width + w + 52); |
| 69 | space.height += height + 8; |
| 70 | [label setFrame:NSMakeRect(25, 20, w, height)]; |
| 71 | [field setFrame:NSMakeRect(w + 27, 20, space.width - w - 52, height)]; |
| 72 | [v setFrameSize:space]; |
| 73 | [v addSubview:label]; |
| 74 | [v addSubview:field]; |
| 75 | [label release]; |
| 76 | [field release]; |
| 77 | } |
| 78 | |
| 79 | |
| 80 | - (void)addField:(NSString *)f toBox:(NSBox *)b { |
| 81 | NSTextField *const field = [self makeField:f]; |
| 82 | NSSize space = [b frame].size; |
| 83 | space.width = MAX(space.width, [field frame].size.width + 32); |
| 84 | space.height += [field frame].size.height + 8; |
| 85 | [field setFrame:NSMakeRect(15, 14, space.width - 32, [field frame].size.height)]; |
| 86 | [b setFrameSize:space]; |
| 87 | [[b contentView] addSubview:field]; |
| 88 | [field release]; |
| 89 | } |
| 90 | |
| 91 | |
| 92 | - (void)addBox:(NSBox *)b toView:(NSView *)v { |
| 93 | [b setFrameOrigin:NSMakePoint(17, 16)]; |
| 94 | NSSize space = [v frame].size; |
| 95 | space.width = MAX(space.width, [b frame].size.width + 34); |
| 96 | space.height += [b frame].size.height + 4; |
| 97 | [v setFrameSize:space]; |
| 98 | [v addSubview:b]; |
| 99 | } |
| 100 | |
| 101 | |
| 102 | - (id)initWithDevice:(device_t &)d machine:(running_machine &)m console:(MAMEDebugConsole *)c { |
| 103 | NSView *contentView; |
| 104 | NSScrollView *contentScroll; |
| 105 | |
| 106 | if (!(self = [super initWithMachine:m |
| 107 | title:[NSString stringWithFormat:@"Device %s", d.tag()] |
| 108 | console:c])) |
| 109 | { |
| 110 | return nil; |
| 111 | } |
| 112 | device = &d; |
| 113 | |
| 114 | // Create a view to hold everything |
| 115 | contentView = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 320, 32)]; |
| 116 | [contentView setAutoresizingMask:(NSViewMaxXMargin | NSViewMinYMargin)]; |
| 117 | [contentView setAutoresizesSubviews:YES]; |
| 118 | |
| 119 | // add the stuff that's always present |
| 120 | [self addLabel:@"Tag:" |
| 121 | withWidth:100 |
| 122 | andField:[NSString stringWithUTF8String:device->tag()] |
| 123 | toView:contentView]; |
| 124 | [self addLabel:@"Name:" |
| 125 | withWidth:100 |
| 126 | andField:[NSString stringWithUTF8String:device->name()] |
| 127 | toView:contentView]; |
| 128 | [self addLabel:@"Shortname:" |
| 129 | withWidth:100 |
| 130 | andField:[NSString stringWithUTF8String:device->shortname()] |
| 131 | toView:contentView]; |
| 132 | |
| 133 | // add interfaces if present |
| 134 | device_interface *interface = device->first_interface(); |
| 135 | if (interface != NULL) |
| 136 | { |
| 137 | NSBox *const interfacesBox = [self makeBox:@"Interfaces" toFit:contentView]; |
| 138 | while (interface != NULL) |
| 139 | { |
| 140 | [self addField:[NSString stringWithUTF8String:interface->interface_type()] |
| 141 | toBox:interfacesBox]; |
| 142 | interface = interface->interface_next(); |
| 143 | } |
| 144 | [self addBox:interfacesBox toView:contentView]; |
| 145 | [interfacesBox release]; |
| 146 | } |
| 147 | |
| 148 | // add memory maps if present |
| 149 | device_memory_interface *memory; |
| 150 | if (device->interface(memory)) |
| 151 | { |
| 152 | NSBox *memoryBox = nil; |
| 153 | for (address_spacenum i = AS_0; i < ADDRESS_SPACES; i++) |
| 154 | { |
| 155 | if (memory->has_space(i)) |
| 156 | { |
| 157 | if (memoryBox == nil) |
| 158 | memoryBox = [self makeBox:@"Memory maps" toFit:contentView]; |
| 159 | [self addField:[NSString stringWithUTF8String:memory->space_config(i)->name()] |
| 160 | toBox:memoryBox]; |
| 161 | } |
| 162 | } |
| 163 | if (memoryBox != nil) |
| 164 | { |
| 165 | [self addBox:memoryBox toView:contentView]; |
| 166 | [memoryBox release]; |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | // create a scroll view for holding everything |
| 171 | NSSize desired = [NSScrollView frameSizeForContentSize:[contentView frame].size |
| 172 | hasHorizontalScroller:YES |
| 173 | hasVerticalScroller:YES |
| 174 | borderType:NSNoBorder]; |
| 175 | [window setContentSize:desired]; |
| 176 | contentScroll = [[NSScrollView alloc] initWithFrame:[[window contentView] bounds]]; |
| 177 | [contentScroll setDrawsBackground:NO]; |
| 178 | [contentScroll setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)]; |
| 179 | [contentScroll setHasHorizontalScroller:YES]; |
| 180 | [contentScroll setHasVerticalScroller:YES]; |
| 181 | [contentScroll setAutohidesScrollers:YES]; |
| 182 | [contentScroll setBorderType:NSNoBorder]; |
| 183 | [contentScroll setDocumentView:contentView]; |
| 184 | [contentView release]; |
| 185 | [[window contentView] addSubview:contentScroll]; |
| 186 | [contentScroll release]; |
| 187 | |
| 188 | // calculate the optimal size for everything |
| 189 | [self cascadeWindowWithDesiredSize:NSMakeSize(320, 240) forView:contentScroll]; |
| 190 | |
| 191 | // don't forget the result |
| 192 | return self; |
| 193 | } |
| 194 | |
| 195 | @end |
| | No newline at end of file |