-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathSSYLabelledTextField.h
executable file
·103 lines (88 loc) · 5.04 KB
/
SSYLabelledTextField.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#import <Cocoa/Cocoa.h>
/*!
@brief This class provides a control which consists of two text fields,
a non-editable <i>key</i> field and, below it, an editable <i>value</i> field.
@details May be used, for example for a user to fill in a <i>Name</i>, <i>Password</i>
<i>Favorite Animal</i>, etc. etc. Any single line of text.
*/
@interface SSYLabelledTextField : NSControl
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)
<NSTextFieldDelegate>
#endif
{
NSTextField* keyField ;
NSTextField* valueField ;
SEL validationSelector ;
NSWindowController* windowController ; // Documentation explains why this kludge is necessary
id validationObject ;
NSString* errorMessage ;
NSInteger m_tag ;
}
@property (retain) NSTextField* keyField ;
@property (retain) NSTextField* valueField ;
@property (assign) SEL validationSelector ;
@property (retain) id windowController ;
@property (retain) id validationObject ;
@property (retain) NSString* errorMessage ;
@property (assign) NSInteger tag ;
/*!
@brief Convenience method for getting an autoreleased instance of this class.
@details You can implement the validationSelector method in an NSString category.
If a validationSelector is provided, the value entered by the user is continuously
validated (using -controlTextDidChange:). After validation, the instance's "window
controller" (see below) is tested to see if it responds to setEnabled:, or setIsEnabled:,
and setWhyDisabled:. If they respond, and the entry is valid, these two messages
are sent with arguments YES and nil, respectively. If they respond, and the entry
is not valid, these two messages are sent with arguments NO and errorMessage, respectively.
The instance's "window controller" is normally obtained by sending -window.windowController,
but in some cases, such as when this control is used in an SSYAlert, the initial validation
performed by this class' initializer is executed before being the receiver is added to its
window's contentView, and in this case -window.windowController, will return nil. The
two validation (or more likely, invalidation) messages described above will then be sent to
nil and thus not have the intended effect. The fix implemented for this is that if
-window.windowController returns nil, the two messages are sent to the windowController
ivar instead.
The reason the ivar is not used all the time is because when an SSYLabelledTextField object is
unarchived after a -deepCopy of it is stored in SSYAlertView's configurations stack, the
windowController ivar will be the old window controller (which is the old SSYAlertView).
The old SSYAlertView was retained, so it won't crash, but the message goes to a defunct,
no-longer-visible SSYAlertView and thus, again, has no effect.
Code implementing this detection and switching is in -validate.
@param secure YES if the <i>value</i> field should be an NSSecureTextField,
NO for a plain NSTextField
@param validationSelector Either NULL, or a selector to which NSString must respond and
return an NSNumber. The -boolValue of the NSNumber should indicate whether
or not its receiver is a <i>valid</i> entry for the returned SSYLabelledTextField instance.
This selector may take 0 or 1 argument of type id. If this parameter is NULL, no
validation will be performed.
@param validationObject An optional argument to the validationSelector. If the
validationSelector takes no arguments, pass nil.
@param windowController The receiver's window controller to which validation
messages will be sent. If the receiver is being installed into an SSYAlert,
this would be that SSYAlert object. See method details for explanation of why this is needed.
@param displayedKey The string to be set in the <i>key</i> or <i>label</i> field.
@param displayedValue The initial string to be set in the <i>value</i> field, or nil to
set an empty string.
@param editable YES if the <i>value</i> field should be editable, NO otherwise.
@param errorMessage An error message which will be sent as the argument of
a message -setWhyDisabled:to the returned instance's window's window controller, if it responds.
@result The instance, autoreleased.
*/
+ (SSYLabelledTextField*)labelledTextFieldSecure:(BOOL)secure
validationSelector:(SEL)validationSelector
validationObject:(id)validationObject
windowController:(id)windowController
displayedKey:(NSString*)displayedKey
displayedValue:(NSString*)displayedValue
editable:(BOOL)editable
tag:(NSInteger)tag
errorMessage:(NSString*)errorMessage ;
/*!
@brief Resizes the height of the receiver to accomodate the current text values,
subject to allowsShrinking
@param allowShrinking YES if the height is allowed to be reduced. If this parameter
is NO, and less height than the current height is required, this invocation will not reduce
the height but will instead leave empty space.
*/
- (void)sizeHeightToFitAllowShrinking:(BOOL)allowShrinking ;
@end