API  0.9.10
CPFormatter.j
Go to the documentation of this file.
1 /*
2  * CPFormatter.j
3  * Foundation
4  *
5  * Created by Randall Luecke
6  * Copyright 2010, RCLConcepts, LLC.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
34 @implementation CPFormatter : CPObject
35 {
36  id __doxygen__;
37 }
38 
51 - (CPString)stringForObjectValue:(id)anObject
52 {
53  _CPRaiseInvalidAbstractInvocation(self, _cmd);
54  return nil;
55 }
56 
57 /*- (CPAttributedString)attributedStringForObjectValue:(id)anObject withDefaultAttributes:(CPDictionary)attributes
58 {
59 
60 }*/
61 
73 - (CPString)editingStringForObjectValue:(id)anObject
74 {
75  return [self stringForObjectValue:anObject];
76 }
77 
93 - (BOOL)getObjectValue:(idRef)anObject forString:(CPString)aString errorDescription:(CPStringRef)anError
94 {
95  _CPRaiseInvalidAbstractInvocation(self, _cmd);
96  return NO;
97 }
98 
121 - (BOOL)isPartialStringValid:(CPString)aPartialString newEditingString:(CPStringRef)aNewString errorDescription:(CPStringRef)anError
122 {
123  @deref(aPartialString) = nil;
124 
125  if (anError)
126  @deref(anError) = nil;
127 
128  return YES;
129 }
130 
150 - (BOOL)isPartialStringValid:(CPStringRef)aPartialStringRef proposedSelectedRange:(CPRangeRef)aProposedSelectedRangeRef originalString:(CPString)originalString originalSelectedRange:(CPRange)originalSelectedRange errorDescription:(CPStringRef)anError
151 {
152  var newString = nil,
153  valid = [self isPartialStringValid:aPartialStringRef newEditingString:@ref(newString) errorDescription:anError];
154 
155  if (!valid)
156  {
157  @deref(aPartialStringRef) = newString;
158 
159  // If a new string is passed back, the selection is always put at the end
160  if (newString !== nil)
161  @deref(aProposedSelectedRangeRef) = CPMakeRange(newString.length, 0);
162  }
163 
164  return valid;
165 }
166 
167 - (id)initWithCoder:(CPCoder)aCoder
168 {
169  return [self init];
170 }
171 
172 - (void)encodeWithCoder:(CPCoder)aCoder
173 {
174 }
175 
176 @end
An immutable string (collection of characters).
Definition: CPString.h:2
CPFormatter is an abstract class that declares an interface for objects that create, interpret, and validate the textual representation of cell contents. The Foundation framework provides two concrete subclasses of CPFormatter to generate these objects: CPNumberFormatter and CPDateFormatter.
Definition: CPFormatter.h:2
Defines methods for use when archiving & restoring (enc/decoding).
Definition: CPCoder.h:2
id init()
Definition: CPObject.j:145
BOOL isPartialStringValid:newEditingString:errorDescription:(CPString aPartialString, [newEditingString] CPStringRef aNewString, [errorDescription] CPStringRef anError)
Definition: CPFormatter.j:121
CPString stringForObjectValue:(id anObject)
Definition: CPFormatter.j:51
CPRange function CPMakeRange(location, length)
Definition: CPRange.j:37