Previous 199869 Revisions Next

r35106 Wednesday 18th February, 2015 at 14:36:11 UTC by Vasantha Crabb
Make resizing the device info windows work nicely
[src/osd/modules/debugger/osx]deviceinfoviewer.m

trunk/src/osd/modules/debugger/osx/deviceinfoviewer.m
r243617r243618
1212#import "deviceinfoviewer.h"
1313
1414
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
1552@implementation MAMEDeviceInfoViewer
1653
1754- (NSTextField *)makeLabel:(NSString *)text {
1855   NSTextField *const result = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 100, 14)];
19   [result setAutoresizingMask:NSViewMinYMargin];
56   [result setAutoresizingMask:(NSViewMaxYMargin | NSViewMaxXMargin)];
2057   [[result cell] setControlSize:NSSmallControlSize];
2158   [result setEditable:NO];
2259   [result setSelectable:NO];
r243617r243618
3370
3471- (NSTextField *)makeField:(NSString *)text {
3572   NSTextField *const result = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 100, 14)];
36   [result setAutoresizingMask:(NSViewWidthSizable | NSViewMinYMargin)];
73   [result setAutoresizingMask:(NSViewWidthSizable | NSViewMaxYMargin)];
3774   [[result cell] setControlSize:NSSmallControlSize];
3875   [result setEditable:NO];
3976   [result setSelectable:YES];
r243617r243618
5087
5188- (NSBox *)makeBox:(NSString *)t toFit:(NSView *)v {
5289   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)];
5491   [result setTitle:t];
5592   [result setBoxType:NSBoxPrimary];
5693   [result setBorderType:NSLineBorder];
r243617r243618
67104   NSSize space = [v bounds].size;
68105   space.width = MAX(space.width, [field frame].size.width + w + 52);
69106   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)];
72109   [v setFrameSize:space];
73110   [v addSubview:label];
74111   [v addSubview:field];
r243617r243618
79116
80117- (void)addField:(NSString *)f toBox:(NSBox *)b {
81118   NSTextField *const field = [self makeField:f];
119   [field setAutoresizingMask:(NSViewWidthSizable | NSViewMinYMargin)];
82120   NSSize space = [b frame].size;
83121   space.width = MAX(space.width, [field frame].size.width + 32);
84122   space.height += [field frame].size.height + 8;
r243617r243618
90128
91129
92130- (void)addBox:(NSBox *)b toView:(NSView *)v {
93   [b setFrameOrigin:NSMakePoint(17, 16)];
94131   NSSize space = [v frame].size;
95132   space.width = MAX(space.width, [b frame].size.width + 34);
96133   space.height += [b frame].size.height + 4;
134   [b setFrameOrigin:NSMakePoint(17, space.height - [b frame].size.height - 16)];
97135   [v setFrameSize:space];
98136   [v addSubview:b];
99137}
100138
101139
102140- (id)initWithDevice:(device_t &)d machine:(running_machine &)m console:(MAMEDebugConsole *)c {
103   NSView         *contentView;
104   NSScrollView   *contentScroll;
141   MAMEDeviceInfoView   *contentView;
142   NSScrollView      *contentScroll;
105143
106144   if (!(self = [super initWithMachine:m
107145                          title:[NSString stringWithFormat:@"Device %s", d.tag()]
r243617r243618
112150   device = &d;
113151
114152   // 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)];
117154   [contentView setAutoresizesSubviews:YES];
118155
119156   // add the stuff that's always present
r243617r243618
167204      }
168205   }
169206
207   // lock minimum content size
208   [contentView setMinWidth:[contentView frame].size.width];
209   [contentView setAutoresizingMask:NSViewWidthSizable];
210
170211   // create a scroll view for holding everything
171212   NSSize desired = [NSScrollView frameSizeForContentSize:[contentView frame].size
172213                            hasHorizontalScroller:YES
r243617r243618
186227   [contentScroll release];
187228
188229   // calculate the optimal size for everything
189   [self cascadeWindowWithDesiredSize:NSMakeSize(320, 240) forView:contentScroll];
230   [self cascadeWindowWithDesiredSize:[contentScroll frame].size forView:contentScroll];
190231
191232   // don't forget the result
192233   return self;


Previous 199869 Revisions Next


© 1997-2024 The MAME Team