trunk/src/osd/modules/debugger/osx/deviceinfoviewer.m
| r243617 | r243618 | |
| 12 | 12 | #import "deviceinfoviewer.h" |
| 13 | 13 | |
| 14 | 14 | |
| 15 | @interface MAMEDeviceInfoView : NSView |
| 16 | { |
| 17 | CGFloat minWidth; |
| 18 | } |
| 19 | |
| 20 | - (id)initWithFrame:(NSRect)frame; |
| 21 | |
| 22 | - (void)setMinWidth:(CGFloat)aWidth; |
| 23 | |
| 24 | @end |
| 25 | |
| 26 | |
| 27 | @implementation MAMEDeviceInfoView |
| 28 | |
| 29 | - (id)initWithFrame:(NSRect)frame { |
| 30 | if (!(self = [super initWithFrame:frame])) |
| 31 | return nil; |
| 32 | minWidth = 0; |
| 33 | return self; |
| 34 | } |
| 35 | |
| 36 | - (void)setMinWidth:(CGFloat)aWidth { |
| 37 | minWidth = aWidth; |
| 38 | } |
| 39 | |
| 40 | - (BOOL)isFlipped { |
| 41 | return YES; |
| 42 | } |
| 43 | |
| 44 | - (void)resizeWithOldSuperviewSize:(NSSize)oldBoundsSize { |
| 45 | NSSize const newBoundsSize = [[self superview] bounds].size; |
| 46 | [self setFrameSize:NSMakeSize(MAX(newBoundsSize.width, minWidth), [self frame].size.height)]; |
| 47 | } |
| 48 | |
| 49 | @end |
| 50 | |
| 51 | |
| 15 | 52 | @implementation MAMEDeviceInfoViewer |
| 16 | 53 | |
| 17 | 54 | - (NSTextField *)makeLabel:(NSString *)text { |
| 18 | 55 | NSTextField *const result = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 100, 14)]; |
| 19 | | [result setAutoresizingMask:NSViewMinYMargin]; |
| 56 | [result setAutoresizingMask:(NSViewMaxYMargin | NSViewMaxXMargin)]; |
| 20 | 57 | [[result cell] setControlSize:NSSmallControlSize]; |
| 21 | 58 | [result setEditable:NO]; |
| 22 | 59 | [result setSelectable:NO]; |
| r243617 | r243618 | |
| 33 | 70 | |
| 34 | 71 | - (NSTextField *)makeField:(NSString *)text { |
| 35 | 72 | NSTextField *const result = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 100, 14)]; |
| 36 | | [result setAutoresizingMask:(NSViewWidthSizable | NSViewMinYMargin)]; |
| 73 | [result setAutoresizingMask:(NSViewWidthSizable | NSViewMaxYMargin)]; |
| 37 | 74 | [[result cell] setControlSize:NSSmallControlSize]; |
| 38 | 75 | [result setEditable:NO]; |
| 39 | 76 | [result setSelectable:YES]; |
| r243617 | r243618 | |
| 50 | 87 | |
| 51 | 88 | - (NSBox *)makeBox:(NSString *)t toFit:(NSView *)v { |
| 52 | 89 | NSBox *const result = [[NSBox alloc] initWithFrame:NSMakeRect(0, 0, [v frame].size.width - 34, 32)]; |
| 53 | | [result setAutoresizingMask:(NSViewWidthSizable | NSViewMinYMargin)]; |
| 90 | [result setAutoresizingMask:(NSViewWidthSizable | NSViewMaxYMargin)]; |
| 54 | 91 | [result setTitle:t]; |
| 55 | 92 | [result setBoxType:NSBoxPrimary]; |
| 56 | 93 | [result setBorderType:NSLineBorder]; |
| r243617 | r243618 | |
| 67 | 104 | NSSize space = [v bounds].size; |
| 68 | 105 | space.width = MAX(space.width, [field frame].size.width + w + 52); |
| 69 | 106 | space.height += height + 8; |
| 70 | | [label setFrame:NSMakeRect(25, 20, w, height)]; |
| 71 | | [field setFrame:NSMakeRect(w + 27, 20, space.width - w - 52, height)]; |
| 107 | [label setFrame:NSMakeRect(25, space.height - height - 20, w, height)]; |
| 108 | [field setFrame:NSMakeRect(w + 27, space.height - height - 20, space.width - w - 52, height)]; |
| 72 | 109 | [v setFrameSize:space]; |
| 73 | 110 | [v addSubview:label]; |
| 74 | 111 | [v addSubview:field]; |
| r243617 | r243618 | |
| 79 | 116 | |
| 80 | 117 | - (void)addField:(NSString *)f toBox:(NSBox *)b { |
| 81 | 118 | NSTextField *const field = [self makeField:f]; |
| 119 | [field setAutoresizingMask:(NSViewWidthSizable | NSViewMinYMargin)]; |
| 82 | 120 | NSSize space = [b frame].size; |
| 83 | 121 | space.width = MAX(space.width, [field frame].size.width + 32); |
| 84 | 122 | space.height += [field frame].size.height + 8; |
| r243617 | r243618 | |
| 90 | 128 | |
| 91 | 129 | |
| 92 | 130 | - (void)addBox:(NSBox *)b toView:(NSView *)v { |
| 93 | | [b setFrameOrigin:NSMakePoint(17, 16)]; |
| 94 | 131 | NSSize space = [v frame].size; |
| 95 | 132 | space.width = MAX(space.width, [b frame].size.width + 34); |
| 96 | 133 | space.height += [b frame].size.height + 4; |
| 134 | [b setFrameOrigin:NSMakePoint(17, space.height - [b frame].size.height - 16)]; |
| 97 | 135 | [v setFrameSize:space]; |
| 98 | 136 | [v addSubview:b]; |
| 99 | 137 | } |
| 100 | 138 | |
| 101 | 139 | |
| 102 | 140 | - (id)initWithDevice:(device_t &)d machine:(running_machine &)m console:(MAMEDebugConsole *)c { |
| 103 | | NSView *contentView; |
| 104 | | NSScrollView *contentScroll; |
| 141 | MAMEDeviceInfoView *contentView; |
| 142 | NSScrollView *contentScroll; |
| 105 | 143 | |
| 106 | 144 | if (!(self = [super initWithMachine:m |
| 107 | 145 | title:[NSString stringWithFormat:@"Device %s", d.tag()] |
| r243617 | r243618 | |
| 112 | 150 | device = &d; |
| 113 | 151 | |
| 114 | 152 | // Create a view to hold everything |
| 115 | | contentView = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 320, 32)]; |
| 116 | | [contentView setAutoresizingMask:(NSViewMaxXMargin | NSViewMinYMargin)]; |
| 153 | contentView = [[MAMEDeviceInfoView alloc] initWithFrame:NSMakeRect(0, 0, 320, 32)]; |
| 117 | 154 | [contentView setAutoresizesSubviews:YES]; |
| 118 | 155 | |
| 119 | 156 | // add the stuff that's always present |
| r243617 | r243618 | |
| 167 | 204 | } |
| 168 | 205 | } |
| 169 | 206 | |
| 207 | // lock minimum content size |
| 208 | [contentView setMinWidth:[contentView frame].size.width]; |
| 209 | [contentView setAutoresizingMask:NSViewWidthSizable]; |
| 210 | |
| 170 | 211 | // create a scroll view for holding everything |
| 171 | 212 | NSSize desired = [NSScrollView frameSizeForContentSize:[contentView frame].size |
| 172 | 213 | hasHorizontalScroller:YES |
| r243617 | r243618 | |
| 186 | 227 | [contentScroll release]; |
| 187 | 228 | |
| 188 | 229 | // calculate the optimal size for everything |
| 189 | | [self cascadeWindowWithDesiredSize:NSMakeSize(320, 240) forView:contentScroll]; |
| 230 | [self cascadeWindowWithDesiredSize:[contentScroll frame].size forView:contentScroll]; |
| 190 | 231 | |
| 191 | 232 | // don't forget the result |
| 192 | 233 | return self; |