API  0.9.7
 All Classes Files Functions Variables Macros Groups Pages
CPCheckBox.j
Go to the documentation of this file.
1 /*
2  * CPCheckBox.j
3  * AppKit
4  *
5  * Created by Francisco Tolmasky.
6  * Copyright 2009, 280 North, Inc.
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 
23 
24 
26 @implementation CPCheckBox : CPButton
27 {
28  id __doxygen__;
29 }
30 
31 + (id)checkBoxWithTitle:(CPString)aTitle theme:(CPTheme)aTheme
32 {
33  return [self buttonWithTitle:aTitle theme:aTheme];
34 }
35 
36 + (id)checkBoxWithTitle:(CPString)aTitle
37 {
38  return [self buttonWithTitle:aTitle];
39 }
40 
41 + (CPString)defaultThemeClass
42 {
43  return @"check-box";
44 }
45 
46 + (Class)_binderClassForBinding:(CPString)aBinding
47 {
48  if (aBinding === CPValueBinding)
49  return [_CPCheckBoxValueBinder class];
50 
51  return [super _binderClassForBinding:aBinding];
52 }
53 
54 - (id)initWithFrame:(CGRect)aFrame
55 {
56  self = [super initWithFrame:aFrame];
57 
58  if (self)
59  {
60  [self setHighlightsBy:CPContentsCellMask];
61  [self setShowsStateBy:CPContentsCellMask];
62 
63  // Defaults?
64  [self setImagePosition:CPImageLeft];
65  [self setAlignment:CPLeftTextAlignment];
66 
67  [self setBordered:NO];
68  }
69 
70  return self;
71 }
72 
73 - (void)takeStateFromKeyPath:(CPString)aKeyPath ofObjects:(CPArray)objects
74 {
75  var count = objects.length,
76  value = [objects[0] valueForKeyPath:aKeyPath] ? CPOnState : CPOffState;
77 
78  [self setAllowsMixedState:NO];
79  [self setState:value];
80 
81  while (count-- > 1)
82  {
83  if (value !== ([objects[count] valueForKeyPath:aKeyPath] ? CPOnState : CPOffState))
84  {
85  [self setAllowsMixedState:YES];
86  [self setState:CPMixedState];
87  }
88  }
89 }
90 
91 - (void)takeValueFromKeyPath:(CPString)aKeyPath ofObjects:(CPArray)objects
92 {
93  [self takeStateFromKeyPath:aKeyPath ofObjects:objects];
94 }
95 
96 - (CPImage)image
97 {
98  return [self currentValueForThemeAttribute:@"image"];
99 }
100 
101 - (CPImage)alternateImage
102 {
103  return [self currentValueForThemeAttribute:@"image"];
104 }
105 
106 - (BOOL)startTrackingAt:(CGPoint)aPoint
107 {
108  var startedTracking = [super startTrackingAt:aPoint];
109  [self highlight:YES];
110  return startedTracking;
111 }
112 
113 @end
114 @implementation _CPCheckBoxValueBinder : CPBinder
115 {
116  id __doxygen__;
117 }
118 
119 - (void)_updatePlaceholdersWithOptions:(CPDictionary)options
120 {
121  [super _updatePlaceholdersWithOptions:options];
122 
123  [self _setPlaceholder:CPMixedState forMarker:CPMultipleValuesMarker isDefault:YES];
124  [self _setPlaceholder:CPOffState forMarker:CPNoSelectionMarker isDefault:YES];
125  [self _setPlaceholder:CPOffState forMarker:CPNotApplicableMarker isDefault:YES];
126  [self _setPlaceholder:CPOffState forMarker:CPNullMarker isDefault:YES];
127 }
128 
129 - (void)setPlaceholderValue:(id)aValue withMarker:(CPString)aMarker forBinding:(CPString)aBinding
130 {
131  [_source setAllowsMixedState:(aValue === CPMixedState)];
132  [_source setState:aValue];
133 }
134 
135 - (void)setValue:(id)aValue forBinding:(CPString)aBinding
136 {
137  [_source setState:aValue];
138 }
139 
140 @end