1// 2// NumberOptionUI.mm 3// LDView 4// 5// Created by Travis Cobbs on 6/17/08. 6// Copyright 2008 __MyCompanyName__. All rights reserved. 7// 8 9#import "NumberOptionUI.h" 10#import "LDViewCategories.h" 11 12#include <LDExporter/LDExporterSetting.h> 13 14 15@implementation NumberOptionUI 16 17- (id)initWithOptions:(Options *)theOptions setting:(LDExporterSetting &)theSetting 18{ 19 self = [super initWithOptions:theOptions setting:theSetting]; 20 if (self != nil) 21 { 22 NSRect frame; 23 24 textFieldWidth = 72.0f; 25 label = [self newLabel]; 26 [label setAlignment:NSRightTextAlignment]; 27 textField = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]; 28 [textField setStringValue:[NSString stringWithUCString:setting->getStringValue()]]; 29 [textField sizeToFit]; 30 frame = [textField frame]; 31 frame.size.width = textFieldWidth; 32 [textField setFrame:frame]; 33 [[textField cell] setRepresentedObject:self]; 34 } 35 return self; 36} 37 38- (void)dealloc 39{ 40 if (!shown) 41 { 42 [label release]; 43 } 44 [super dealloc]; 45} 46 47- (CGFloat)updateLayoutX:(CGFloat)x y:(CGFloat)y width:(CGFloat)width update:(bool)update optimalWidth:(CGFloat &)optimalWidth 48{ 49 CGFloat delta = textFieldWidth + 6.0f; 50 NSRect labelBounds = { { x, y }, { width, 1024.0f } }; 51 NSRect textFieldBounds = [textField frame]; 52 53 labelBounds = [self calcLabelLayout:label inRect:labelBounds optimalWidth:optimalWidth delta:delta]; 54 if (update) 55 { 56 57 textFieldBounds.origin.x = x + optimalWidth - textFieldWidth; 58 textFieldBounds.origin.y = y; 59 if (textFieldBounds.size.height > labelBounds.size.height) 60 { 61 labelBounds.origin.y += (CGFloat)(int)((textFieldBounds.size.height - labelBounds.size.height) / 2.0f); 62 } 63 else 64 { 65 textFieldBounds.origin.y += (CGFloat)(int)((labelBounds.size.height - textFieldBounds.size.height) / 2.0f); 66 } 67 labelBounds.size.width = optimalWidth - textFieldWidth - 6.0f; 68 [label setFrame:labelBounds]; 69 [textField setFrame:textFieldBounds]; 70 if (!shown) 71 { 72 shown = true; 73 [docView addSubview:label]; 74 [docView addSubview:textField]; 75 [label release]; 76 } 77 [self addTooltip:textField]; 78 } 79 return std::max(textFieldBounds.size.height, labelBounds.size.height); 80} 81 82- (void)setEnabled:(BOOL)enabled 83{ 84 [label setEnabled:enabled]; 85 [textField setEnabled:enabled]; 86} 87 88- (NSRect)frame 89{ 90 NSRect frame = [label frame]; 91 92 frame.origin.y -= 7.0f; 93 frame.size.height += 14.0f; 94 return frame; 95} 96 97- (NSView *)firstKeyView 98{ 99 return textField; 100} 101 102@end 103