Merge pull request #10 from gunyarakun/fix-invalid-return
[cocotron.git] / AppKit / NSForm.m
blob62c8b487b1453bd94adb57348855b8e8092131ee
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;
24 -(void)calcSize {
25    NSArray *cells=[self cells];
26    int      i,count=[cells count];
27    float    maxTitleWidth=0;
29    for(i=0;i<count;i++){
30     NSFormCell         *cell=[cells objectAtIndex:i];
31     NSAttributedString *title=[cell attributedTitle];
32     float               width=[title size].width;
34     if(width>maxTitleWidth)
35      maxTitleWidth=width;
36    }
38    maxTitleWidth=ceil(maxTitleWidth);
39    maxTitleWidth+=1;
41    for(i=0;i<count;i++){
42     NSFormCell *cell=[cells objectAtIndex:i];
43     [cell setTitleWidth:maxTitleWidth];
44    }
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];
54    
55    for(i=0;i<count;i++)
56     if([[cells objectAtIndex:i] tag]==tag)
57      return i;
58    
59    return -1;
62 -(int)indexOfSelectedItem {
63    return [self selectedRow];
67 -(void)setBordered:(BOOL)value {
68    NSArray *cells=[self cells];
69    int      i,count=[cells count];
70    
71    for(i=0;i<count;i++)
72     [[cells objectAtIndex:i] setBordered:value];
73     
74    [self setNeedsDisplay:YES];
77 -(void)setBezeled:(BOOL)value {
78    NSArray *cells=[self cells];
79    int      i,count=[cells count];
80    
81    for(i=0;i<count;i++)
82     [[cells objectAtIndex:i] setBezeled:value];
84    [self setNeedsDisplay:YES];
87 -(void)setEntryWidth:(float)value {
88    NSSize size=[self cellSize];
89    
90    size.width=value;
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];
101    
102    for(i=0;i<count;i++)
103     [[cells objectAtIndex:i] setTitleAlignment:value];
104     
105    [self setNeedsDisplay:YES];
108 -(void)setTitleFont:(NSFont *)value {
109    NSArray *cells=[self cells];
110    int      i,count=[cells count];
111    
112    for(i=0;i<count;i++)
113     [[cells objectAtIndex:i] setTitleFont:value];
114     
115    [self setNeedsDisplay:YES];
118 -(void)setTitleBaseWritingDirection:(NSWritingDirection)value {
119    NSArray *cells=[self cells];
120    int      i,count=[cells count];
121    
122    for(i=0;i<count;i++)
123     [[cells objectAtIndex:i] setTitleBaseWritingDirection:value];
124     
125    [self setNeedsDisplay:YES];
128 -(void)setTextAlignment:(NSTextAlignment)value {
129    NSArray *cells=[self cells];
130    int      i,count=[cells count];
131    
132    for(i=0;i<count;i++)
133     [[cells objectAtIndex:i] setAlignment:value];
134     
135    [self setNeedsDisplay:YES];
138 -(void)setTextFont:(NSFont *)value {
139    NSArray *cells=[self cells];
140    int      i,count=[cells count];
141    
142    for(i=0;i<count;i++)
143     [[cells objectAtIndex:i] setFont:value];
144     
145    [self setNeedsDisplay:YES];
148 -(void)setTextBaseWritingDirection:(NSWritingDirection)value {
149    NSArray *cells=[self cells];
150    int      i,count=[cells count];
151    
152    for(i=0;i<count;i++)
153     [[cells objectAtIndex:i] setBaseWritingDirection:value];
154     
155    [self setNeedsDisplay:YES];
158 -(NSFormCell *)addEntry:(NSString *)title {   
159    [self addRow];
160    [[[self cells] lastObject] setTitle:title];
161    
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];
168    
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];
184 @end