1 /* Copyright (c) 2006-2007 Christopher J. W. Lloyd
3 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
9 #import <AppKit/NSForm.h>
10 #import <AppKit/NSFormCell.h>
11 #import <AppKit/NSTextView.h>
12 #import <AppKit/NSWindow.h>
13 #import <AppKit/NSStringDrawing.h>
14 #import <AppKit/NSRaise.h>
16 @implementation NSForm
18 -(void)resizeWithOldSuperviewSize:(NSSize)oldSize {
19 [super resizeWithOldSuperviewSize:oldSize];
21 _cellSize.width=[self bounds].size.width;
25 NSArray *cells=[self cells];
26 int i,count=[cells count];
27 float maxTitleWidth=0;
30 NSFormCell *cell=[cells objectAtIndex:i];
31 NSAttributedString *title=[cell attributedTitle];
32 float width=[title size].width;
34 if(width>maxTitleWidth)
38 maxTitleWidth=ceil(maxTitleWidth);
42 NSFormCell *cell=[cells objectAtIndex:i];
43 [cell setTitleWidth:maxTitleWidth];
47 -cellAtIndex:(int)index {
48 return [[self cells] objectAtIndex:index];
51 -(int)indexOfCellWithTag:(int)tag {
52 NSArray *cells=[self cells];
53 int i,count=[cells count];
56 if([[cells objectAtIndex:i] tag]==tag)
62 -(int)indexOfSelectedItem {
63 return [self selectedRow];
67 -(void)setBordered:(BOOL)value {
68 NSArray *cells=[self cells];
69 int i,count=[cells count];
72 [[cells objectAtIndex:i] setBordered:value];
74 [self setNeedsDisplay:YES];
77 -(void)setBezeled:(BOOL)value {
78 NSArray *cells=[self cells];
79 int i,count=[cells count];
82 [[cells objectAtIndex:i] setBezeled:value];
84 [self setNeedsDisplay:YES];
87 -(void)setEntryWidth:(float)value {
88 NSSize size=[self cellSize];
91 [self setCellSize:size];
94 -(void)setInterlineSpacing:(float)value {
95 [self setIntercellSpacing:NSMakeSize(0,value)];
98 -(void)setTitleAlignment:(NSTextAlignment)value {
99 NSArray *cells=[self cells];
100 int i,count=[cells count];
103 [[cells objectAtIndex:i] setTitleAlignment:value];
105 [self setNeedsDisplay:YES];
108 -(void)setTitleFont:(NSFont *)value {
109 NSArray *cells=[self cells];
110 int i,count=[cells count];
113 [[cells objectAtIndex:i] setTitleFont:value];
115 [self setNeedsDisplay:YES];
118 -(void)setTitleBaseWritingDirection:(NSWritingDirection)value {
119 NSArray *cells=[self cells];
120 int i,count=[cells count];
123 [[cells objectAtIndex:i] setTitleBaseWritingDirection:value];
125 [self setNeedsDisplay:YES];
128 -(void)setTextAlignment:(NSTextAlignment)value {
129 NSArray *cells=[self cells];
130 int i,count=[cells count];
133 [[cells objectAtIndex:i] setAlignment:value];
135 [self setNeedsDisplay:YES];
138 -(void)setTextFont:(NSFont *)value {
139 NSArray *cells=[self cells];
140 int i,count=[cells count];
143 [[cells objectAtIndex:i] setFont:value];
145 [self setNeedsDisplay:YES];
148 -(void)setTextBaseWritingDirection:(NSWritingDirection)value {
149 NSArray *cells=[self cells];
150 int i,count=[cells count];
153 [[cells objectAtIndex:i] setBaseWritingDirection:value];
155 [self setNeedsDisplay:YES];
158 -(NSFormCell *)addEntry:(NSString *)title {
160 [[[self cells] lastObject] setTitle:title];
162 return [[self cells] lastObject];
165 -(NSFormCell *)insertEntry:(NSString *)title atIndex:(int)index {
166 [self insertRow:index];
167 [[self cellAtRow:index column:0] setTitle:title];
169 return [self cellAtRow:index column:0];
172 -(void)removeEntryAtIndex:(int)index {
173 [self removeRow:index];
176 -(void)selectTextAtIndex:(int)index {
177 NSUnimplementedMethod();
180 -(void)drawCellAtIndex:(int)index {
181 [self drawCellAtRow:index column:0];