From c423411639555525dbd2a60fe2e3cc21d0896074 Mon Sep 17 00:00:00 2001 From: Klaas Pieter Annema Date: Fri, 29 Jan 2010 12:14:08 +0100 Subject: [PATCH 01/16] made sure CPControl's trackMouse: doesn't eat mouse events when the tableview is in a drag session #431 --- AppKit/CPTableView.j | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/AppKit/CPTableView.j b/AppKit/CPTableView.j index ff105e47a..de4397fc3 100644 --- a/AppKit/CPTableView.j +++ b/AppKit/CPTableView.j @@ -2160,6 +2160,15 @@ window.setTimeout(function(){ return YES; } +- (void)trackMouse:(CPEvent)anEvent +{ + // Prevent CPControl from eating the mouse events when we are in a drag session + if (![_draggedRowIndexes count]) + [super trackMouse:anEvent]; + else + [CPApp sendEvent:anEvent]; +} + /* ignore */ - (BOOL)continueTracking:(CGPoint)lastPoint at:(CGPoint)aPoint { From 90d24fd6bf467ee2f46e03d5030a8f517c1c0da0 Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Fri, 29 Jan 2010 15:17:21 -0800 Subject: [PATCH 02/16] Temporary update for progress indicators for 0.8 --- AppKit/CPProgressIndicator.j | 53 +++++++----------- .../CPProgressIndicatorBarBarRegular0.png | Bin 0 -> 259 bytes .../CPProgressIndicatorBarBarRegular1.png | Bin 0 -> 164 bytes .../CPProgressIndicatorBarBarRegular2.png | Bin 0 -> 252 bytes .../CPProgressIndicatorBarHUDBarRegular0.png | Bin 0 -> 246 bytes .../CPProgressIndicatorBarHUDBarRegular1.png | Bin 0 -> 178 bytes .../CPProgressIndicatorBarHUDBarRegular2.png | Bin 0 -> 244 bytes ...rogressIndicatorBezelBorderBarRegular0.png | Bin 139 -> 222 bytes ...rogressIndicatorBezelBorderBarRegular1.png | Bin 122 -> 169 bytes ...rogressIndicatorBezelBorderBarRegular2.png | Bin 141 -> 220 bytes ...ressIndicatorBezelBorderHUDBarRegular0.png | Bin 0 -> 220 bytes ...ressIndicatorBezelBorderHUDBarRegular1.png | Bin 0 -> 141 bytes ...ressIndicatorBezelBorderHUDBarRegular2.png | Bin 0 -> 222 bytes 13 files changed, 19 insertions(+), 34 deletions(-) create mode 100644 AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBarBarRegular0.png create mode 100644 AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBarBarRegular1.png create mode 100644 AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBarBarRegular2.png create mode 100644 AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBarHUDBarRegular0.png create mode 100644 AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBarHUDBarRegular1.png create mode 100644 AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBarHUDBarRegular2.png create mode 100644 AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBezelBorderHUDBarRegular0.png create mode 100644 AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBezelBorderHUDBarRegular1.png create mode 100644 AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBezelBorderHUDBarRegular2.png diff --git a/AppKit/CPProgressIndicator.j b/AppKit/CPProgressIndicator.j index 663da8450..e44159e3f 100644 --- a/AppKit/CPProgressIndicator.j +++ b/AppKit/CPProgressIndicator.j @@ -104,17 +104,14 @@ var CPProgressIndicatorSpinningStyleColors = nil, for (; start <= end; ++start) { CPProgressIndicatorBezelBorderViewPool[start] = []; - CPProgressIndicatorBezelBorderViewPool[start][CPMiniControlSize] = []; CPProgressIndicatorBezelBorderViewPool[start][CPSmallControlSize] = []; CPProgressIndicatorBezelBorderViewPool[start][CPRegularControlSize] = []; } CPProgressIndicatorClassName = [self className]; - - CPProgressIndicatorStyleIdentifiers = []; - + CPProgressIndicatorStyleIdentifiers[CPProgressIndicatorBarStyle] = @"Bar"; CPProgressIndicatorStyleIdentifiers[CPProgressIndicatorSpinningStyle] = @"Spinny"; CPProgressIndicatorStyleIdentifiers[CPProgressIndicatorHUDBarStyle] = @"HUDBar"; @@ -126,30 +123,20 @@ var CPProgressIndicatorSpinningStyleColors = nil, CPProgressIndicatorStyleSizes = []; // Bar Sttyle - var prefix = CPProgressIndicatorClassName + @"BezelBorder" + CPProgressIndicatorStyleIdentifiers[CPProgressIndicatorBarStyle]; + var prefixes = [ + CPProgressIndicatorClassName + @"BezelBorder" + CPProgressIndicatorStyleIdentifiers[CPProgressIndicatorBarStyle], + CPProgressIndicatorClassName + @"Bar" + CPProgressIndicatorStyleIdentifiers[CPProgressIndicatorBarStyle], + CPProgressIndicatorClassName + @"BezelBorder" + CPProgressIndicatorStyleIdentifiers[CPProgressIndicatorHUDBarStyle], + CPProgressIndicatorClassName + @"Bar" + CPProgressIndicatorStyleIdentifiers[CPProgressIndicatorHUDBarStyle] + ]; - CPProgressIndicatorStyleSizes[prefix + regularIdentifier] = [_CGSizeMake(3.0, 15.0), _CGSizeMake(1.0, 15.0), _CGSizeMake(3.0, 15.0)]; - CPProgressIndicatorStyleSizes[prefix + smallIdentifier] = [_CGSizeMake(3.0, 15.0), _CGSizeMake(1.0, 15.0), _CGSizeMake(3.0, 15.0)]; - CPProgressIndicatorStyleSizes[prefix + miniIdentifier] = [_CGSizeMake(3.0, 15.0), _CGSizeMake(1.0, 15.0), _CGSizeMake(3.0, 15.0)]; - - prefix = CPProgressIndicatorClassName + @"Bar" + CPProgressIndicatorStyleIdentifiers[CPProgressIndicatorBarStyle]; - - CPProgressIndicatorStyleSizes[prefix + regularIdentifier] = _CGSizeMake(1.0, 9.0); - CPProgressIndicatorStyleSizes[prefix + smallIdentifier] = _CGSizeMake(1.0, 9.0); - CPProgressIndicatorStyleSizes[prefix + miniIdentifier] = _CGSizeMake(1.0, 9.0); - - // HUD Bar Style - prefix = CPProgressIndicatorClassName + @"BezelBorder" + CPProgressIndicatorStyleIdentifiers[CPProgressIndicatorHUDBarStyle]; - - CPProgressIndicatorStyleSizes[prefix + regularIdentifier] = [_CGSizeMake(3.0, 15.0), _CGSizeMake(1.0, 15.0), _CGSizeMake(3.0, 15.0)]; - CPProgressIndicatorStyleSizes[prefix + smallIdentifier] = [_CGSizeMake(3.0, 15.0), _CGSizeMake(1.0, 15.0), _CGSizeMake(3.0, 15.0)]; - CPProgressIndicatorStyleSizes[prefix + miniIdentifier] = [_CGSizeMake(3.0, 15.0), _CGSizeMake(1.0, 15.0), _CGSizeMake(3.0, 15.0)]; - - prefix = CPProgressIndicatorClassName + @"Bar" + CPProgressIndicatorStyleIdentifiers[CPProgressIndicatorHUDBarStyle]; - - CPProgressIndicatorStyleSizes[prefix + regularIdentifier] = _CGSizeMake(1.0, 9.0); - CPProgressIndicatorStyleSizes[prefix + smallIdentifier] = _CGSizeMake(1.0, 9.0); - CPProgressIndicatorStyleSizes[prefix + miniIdentifier] = _CGSizeMake(1.0, 9.0); + for (var i = 0, count = prefixes.length; i8U}fi7AzZCsS>Jik5o1IEGZ*N=o5am!6i8uz@W}maXl8RePWAa`X6#e@~T# zxi8lXbIX<<54V^68S(GWzr%ljUa!w%YqRIk;raj1=>N~(?TjoD694|E{`<>*?C0<4 zPrtw4A8^iIfnD$Od;Wl%`6@H-*9*+CuNSC#u*`6yvGKoOzy99lpAhS_%j?qhzWF-~ zexAObe_!&wU9F~gn6cuMS9{f^dj9|apU$E+oh?bR0q8TH_|UTkoFR=s2QzrO`njxg HN@xNAyb5Ze literal 0 HcmV?d00001 diff --git a/AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBarBarRegular1.png b/AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBarBarRegular1.png new file mode 100644 index 0000000000000000000000000000000000000000..31bf729e19c7c850b35030b32ce0efbf49c5e207 GIT binary patch literal 164 zcmeAS@N?(olHy`uVBq!ia0vp^j6f{F!3HF+&llYeq$EpRBT9nv(@M${i&7aJQ}UBi z6+Ckj(^G>|6H_V+Po~-c6}fr3IEGZ*N=o2Zr=Py#^TY4;%c9@c85#Wj`+0if%k%f` zd3^T&Z|JyRpSZ?;zhjKT>+|w6BqC%xPVaetFg>*G|NsBe%q$WNDzo)`9>hOy0-DI+ M>FVdQ&MBb@0PAHvm;e9( literal 0 HcmV?d00001 diff --git a/AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBarBarRegular2.png b/AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBarBarRegular2.png new file mode 100644 index 0000000000000000000000000000000000000000..1a8da63e76ac6dc27c5c59c6af85c9ec343efed7 GIT binary patch literal 252 zcmVnp|FYMd8 zM?qXjX3x2sPnll*WaP8ZQFmlv`ftMW^Vc7Sp9~D#e}4brX8H5?4+9wd`^(Jo`wx`! zAH@0n7sC1bmjxm756t-u<@^CDLz4OP=P$A{B%?w0{QULn2Rk$4FP1M~zkNS*@yZol zCFyI-r(XS*=VtkTU{!Pe28RFt|LXy<3=lH{1Q-DBeO!=JAyz*C00008U}fi7AzZCsS>Jie`AaIEGZ*O1iRrLuy(=!Unb^S+?3@>Gr9w&2#I1emm?g zrk18AEG->Vr~Eb&;0-I=V=Beo&Sw|6H_V+Po~-c6@_@ZIEGZ*O1iLpgKqktPmizHA4`94_dmVn%df-r$9|u` z|1W*d*C$Wwk7e`E12QXqKdfJ7U;od*;4hnCz_oa`W&0D}-QUl{v+C9_Z;Ai^|L5}v aBrvdSHB>q)I9Uy7K7*&LpUXO@geCw$4@o5e literal 0 HcmV?d00001 diff --git a/AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBarHUDBarRegular2.png b/AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBarHUDBarRegular2.png new file mode 100644 index 0000000000000000000000000000000000000000..81691a35590447635c2d92d70a96185bd410a1ae GIT binary patch literal 244 zcmVnp|FI~K} zM^;uw=J1iDPnrHPvGCd0*g7&XGnugb{__W@f|2{rpFi9zfB*bt0E7SknOT1S{R3qK zIe-4ZIV>!{eD0000002ovPDHLkV1hQ3Mil@6 delta 87 zcmV-d0I2`o0gC~U7YYvu1^@s6A?kI+ks&BTElET{R0vyRV1NLw^78Wk$P9N7M-Ixd t1#vW>91VJM6?l!0>*ljQYIRNJKBcVzC>I(n>002ovPDHLkV1h}%AYuRj diff --git a/AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBezelBorderBarRegular1.png b/AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBezelBorderBarRegular1.png index f555903ebe22bce76815622cf3cf34574834c2c7..f3e7717c4d5b5c5d169882b93f595d03c3dcfb29 100644 GIT binary patch delta 116 zcmV-)0E_>6sR57|3J?ee0002jpB1-}At+!=Nkl_0zsuMEeIp z1VIpC7({Q>`8Z}~x7J!{&WR!dxjPzTpx!%bt)W^gDy5*DGfF9O?7i*p^PIr-3NQd$ WG&8b57r&DL0000zopr0Jg3bo&W#< diff --git a/AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBezelBorderBarRegular2.png b/AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBezelBorderBarRegular2.png index 81e575fbd4999165d683fb9916f82ff754e4c020..075026cb307977067915eebe296f38f3c244d724 100644 GIT binary patch delta 169 zcmV;a09OBv0o(zQ7YYyv1^@s6(`v+8LH z_f7>eg&BVT{{0^)@PUJa!-nbKzkduYEG+y#e*EBK0db&!iRJI#zc3CXP8l?1C^Gm> z`}OPBCmtT2|4iS$efzL~|Nix^uC8wx`1$!mf`fzI-@bh-!0`Y7e=Q*92Vw?*00RIN X<|#`-{iTO{00000NkvXXu0mjf8U}fi7AzZCsS>Jit0RF978H@C8ablC@O>{vIrfTH*cPAQc_Z)j*N`VEC)9e zVPRqW%l-29I~q3q`Ty^4ass2#3 RHUM41;OXk;vd$@?2>?9gR9gT5 literal 0 HcmV?d00001 diff --git a/AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBezelBorderHUDBarRegular1.png b/AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBezelBorderHUDBarRegular1.png new file mode 100644 index 0000000000000000000000000000000000000000..e4d1fc5d5c595b81dbdc936f5d85e3134285360f GIT binary patch literal 141 zcmeAS@N?(olHy`uVBq!ia0vp^j6f{F!3HF+&llYeq$EpRBT9nv(@M${i&7aJQ}UBi z6+Ckj(^G>|6H_V+Po~-c73q7rIEGZ*N=isbC`j}1^7?iD%m4rNY|HBZ|8wlzU;jU; n;Np=7EF3My%)Ad6I1Ct43N$CjK1_%PYGv?r^>bP0l+XkKBF8Sr literal 0 HcmV?d00001 diff --git a/AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBezelBorderHUDBarRegular2.png b/AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBezelBorderHUDBarRegular2.png new file mode 100644 index 0000000000000000000000000000000000000000..b6d88f15a82e24d470c66ab4a1a4d047affc2cb6 GIT binary patch literal 222 zcmeAS@N?(olHy`uVBq!ia0vp^%s?!_!3HERXC3VVQj#UE5hcO-X(i=}MX3yqDfvmM z3ZA)%>8U}fi7AzZCsS>JiW)p!978H@B_$*z7%(R(Dx@X!_4n^rP*qi}dwy>2WFH3w zB{em%vj-0@Jo)AQeftSq|K#oK3N|`eDjYcS>HGV5iFUzIw(UkLe8PUVJqh0b|NQ*i z+1~!#{_^|#`|bBsea+gtdiCpQwz|516CONB_`W^=K9|9t|NrB;JAO9KU{pB3U_IY? Vf2I8I$3V9*c)I$ztaD0e0ss<;S(yL; literal 0 HcmV?d00001 From 9db0694677a6c77b2bb96ebc58cb5ea5b6ad7bfc Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Fri, 29 Jan 2010 21:45:03 -0800 Subject: [PATCH 03/16] Remove unused images. --- .../CPProgressIndicatorBarBarRegular.png | Bin 135 -> 0 bytes .../CPProgressIndicatorBarHUDBarSmall.png | Bin 123 -> 0 bytes ...CPProgressIndicatorBezelBorderHUDBarSmall0.png | Bin 138 -> 0 bytes ...CPProgressIndicatorBezelBorderHUDBarSmall1.png | Bin 118 -> 0 bytes ...CPProgressIndicatorBezelBorderHUDBarSmall2.png | Bin 139 -> 0 bytes 5 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBarBarRegular.png delete mode 100644 AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBarHUDBarSmall.png delete mode 100644 AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBezelBorderHUDBarSmall0.png delete mode 100644 AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBezelBorderHUDBarSmall1.png delete mode 100644 AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBezelBorderHUDBarSmall2.png diff --git a/AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBarBarRegular.png b/AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBarBarRegular.png deleted file mode 100644 index 5a4719080e2e4b8ea26c72143b4e05e687b1f4e1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 135 zcmeAS@N?(olHy`uVBq!ia0vp^j6lrI!3HGv^*w(Nq$EpRBT9nv(@M${i&7aJQ}UBi z6+Ckj(^G>|6H_V+Po~-c6={09IEHY@CUbD={W;H|@~^SuzQQBxjvpLKaZMf73XhaJ gELfDx8agZ)V%kOf`Bt0118QRMboFyt=akR{0DLGYIsgCw diff --git a/AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBarHUDBarSmall.png b/AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBarHUDBarSmall.png deleted file mode 100644 index 5bc78a08a68a0433061d3d52e32b15b7a37e73ca..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 123 zcmeAS@N?(olHy`uVBq!ia0vp^j6lrE!3HEhySY69Qj#UE5hcO-X(i=}MX3yqDfvmM z3ZA)%>8U}fi7AzZCsS>Jiex=q978ywlYjmHU#}y~%zQZA;v=hH4Xfb&he!As8U}fi7AzZCsS>JigY|(978ywlM@;k*8O*AI8(r0_+)`hw17MFsf!EL-T6B1 jKFn+GYP!oNJb{_vT9ZZOZN3BYKz$6Ju6{1-oD!M<=zS__ diff --git a/AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBezelBorderHUDBarSmall1.png b/AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBezelBorderHUDBarSmall1.png deleted file mode 100644 index 5f8f753b66a021cb6be160441ae570610edae4dd..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 118 zcmeAS@N?(olHy`uVBq!ia0vp^j6lrK!3HE%<(K{hQj#UE5hcO-X(i=}MX3yqDfvmM z3ZA)%>8U}fi7AzZCsS>JiX=Q;978x{lYj8D@Hhx?D49qcuo2==*~?J4L-~T)6TiJc OH4L7velF{r5}E)fG#)+x diff --git a/AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBezelBorderHUDBarSmall2.png b/AppKit/Resources/CPProgressIndicator/CPProgressIndicatorBezelBorderHUDBarSmall2.png deleted file mode 100644 index 612a5ac4a8c91a2ff8c304dfc397cd13a631fc5b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 139 zcmeAS@N?(olHy`uVBq!ia0vp^%s|Y~!3HE1UzHvKQj#UE5hcO-X(i=}MX3yqDfvmM z3ZA)%>8U}fi7AzZCsS>JigZ0)978ywlYj8D@bK`&@B}>Q(@EfddZN)nDxi<;u0=qb k^%>T80jdexPac$Dke0NFe9^Cv2-L{n>FVdQ&MBb@0F!zs00000 From ac68d670a2eecea5e65d5278bcef0be0a9786b68 Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Fri, 29 Jan 2010 22:11:43 -0800 Subject: [PATCH 04/16] Slight error in the sizing for the previous progress bar commit --- AppKit/CPProgressIndicator.j | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/AppKit/CPProgressIndicator.j b/AppKit/CPProgressIndicator.j index e44159e3f..a9502c418 100644 --- a/AppKit/CPProgressIndicator.j +++ b/AppKit/CPProgressIndicator.j @@ -427,7 +427,13 @@ var CPProgressIndicatorSpinningStyleColors = nil, CPProgressIndicatorStyleIdentifiers[_style], _CPControlIdentifierForControlSize(_controlSize))]; - [_barView setFrameSize:CGSizeMake(CGRectGetWidth([self bounds]) * (_doubleValue - _minValue) / (_maxValue - _minValue) - 4.0, 16.0)]; + var width = CGRectGetWidth([self bounds]), + barWidth = width * ((_doubleValue - _minValue) / (_maxValue - _minValue)); + + if (barWidth > 0.0 && barWidth < 4.0) + barWidth = 4.0; + + [_barView setFrameSize:CGSizeMake(barWidth, 16.0)]; } /* @ignore */ From 86fa759f9fa49facedbdc2099f937c51ee3b274a Mon Sep 17 00:00:00 2001 From: cacaodev Date: Fri, 29 Jan 2010 18:20:26 +0100 Subject: [PATCH 05/16] CPTableHeaderView.j: Gradient headers for canvas capable browsers | Bg images for others. Column selection with pressed state. AppController.j: Modified left table in TestTable to test column selection. CPTableView.j: Added missing ivar; Fixed -deselectRow|Column: --- AppKit/CPTableColumn.j | 3 +- AppKit/CPTableHeaderView.j | 303 ++++++++++++++++++++++--- AppKit/CPTableView.j | 9 +- Tests/Manual/TableTest/AppController.j | 5 +- 4 files changed, 284 insertions(+), 36 deletions(-) diff --git a/AppKit/CPTableColumn.j b/AppKit/CPTableColumn.j index 993acd22d..4b7f9a03f 100644 --- a/AppKit/CPTableColumn.j +++ b/AppKit/CPTableColumn.j @@ -71,8 +71,7 @@ CPTableColumnUserResizingMask = 2; [self setIdentifier:anIdentifier]; - var header = [CPTextField new]; - [header setBackgroundColor:[CPColor colorWithPatternImage:CPAppKitImage("tableview-headerview.png", CGSizeMake(1.0, 23.0))]]; + var header = [[_CPTableColumnHeaderView alloc] initWithFrame:CGRectMakeZero()]; [self setHeaderView:header]; var textDataView = [CPTextField new]; diff --git a/AppKit/CPTableHeaderView.j b/AppKit/CPTableHeaderView.j index 061a3b2eb..62ba593ce 100644 --- a/AppKit/CPTableHeaderView.j +++ b/AppKit/CPTableHeaderView.j @@ -23,12 +23,150 @@ @import "CPTableColumn.j" @import "CPTableView.j" @import "CPView.j" +@import +var _headerGradient = nil, + _selectedHeaderGradient = nil, + _pressedHeaderGradient = nil, + _selectedPressedHeaderGradient = nil, + + supportsCanvasGradient = NO; + +@implementation _CPTableColumnHeaderView : CPView +{ + BOOL _isPressed; + CPTextField _textField; +} + ++ (void)initialize +{ + supportsCanvasGradient = CPFeatureIsCompatible(CPHTMLCanvasFeature); +} + ++ (CGGradient)headerGradient +{ + if (!_headerGradient) + _headerGradient = CGGradientCreateWithColorComponents(CGColorSpaceCreateDeviceRGB(),[1.0,1.0,1.0,1.0,0.929,0.929,0.929,1.0], [0.3,1], 2); + + return _headerGradient; +} + ++ (CGGradient)selectedHeaderGradient +{ + if (!_selectedHeaderGradient) + _selectedHeaderGradient = CGGradientCreateWithColorComponents(CGColorSpaceCreateDeviceRGB(), [0.804,0.851,0.918,1.0,0.655,0.718,0.8,1.0], [0.3,1], 2); + + return _selectedHeaderGradient; +} + ++ (CGGradient)pressedHeaderGradient +{ + if (!_pressedHeaderGradient) + _pressedHeaderGradient = CGGradientCreateWithColorComponents(CGColorSpaceCreateDeviceRGB(),[0.929,0.929,0.929,1.0,1.0,1.0,1.0,1.0], [0.3,1], 2); + + return _pressedHeaderGradient; +} + ++ (CGGradient)selectedPressedHeaderGradient +{ + if (!_selectedPressedHeaderGradient) + _selectedPressedHeaderGradient = CGGradientCreateWithColorComponents(CGColorSpaceCreateDeviceRGB(), [0.655,0.718,0.8,1.0,0.804,0.851,0.918,1.0], [0.3,1], 2); + + return _selectedPressedHeaderGradient; +} + +- (void)initWithFrame:(CGRect)frame +{ + self = [super initWithFrame:frame]; + if (self) + { + _isPressed = NO; + _textField = [[CPTextField alloc] initWithFrame:[self bounds]]; + [_textField setAutoresizingMask:CPViewWidthSizable|CPViewHeightSizable]; + [self addSubview:_textField]; + + if (!supportsCanvasGradient) + [self setBackgroundColor:[CPColor colorWithPatternImage:CPAppKitImage("tableview-headerview.png", CGSizeMake(1.0, 22.0))]]; + + //[self setValue:headerColor forThemeAttribute:@"background-color" inState:CPThemeStateNormal]; + //[self setValue:headerHighlightedColor forThemeAttribute:@"background-color" inState:CPThemeStateHighlighted]; + } + + return self; +} + +- (void)setPressed:(BOOL)flag +{ + _isPressed = flag; + [self setNeedsDisplay:YES]; +} + +- (BOOL)setThemeState:(CPThemeState)aState +{ + if (supportsCanvasGradient) + [super setThemeState:aState]; + else if (aState & CPThemeStateHighlighted) + [self setBackgroundColor:[CPColor colorWithPatternImage:CPAppKitImage("tableview-headerview-highlighted.png", CGSizeMake(1.0, 22.0))]]; +} + +- (BOOL)unsetThemeState:(CPThemeState)aState +{ + if (supportsCanvasGradient) + [super unsetThemeState:aState]; + else if (aState & CPThemeStateHighlighted) + [self setBackgroundColor:[CPColor colorWithPatternImage:CPAppKitImage("tableview-headerview.png", CGSizeMake(1.0, 22.0))]]; +} + +- (void)setStringValue:(CPString)string +{ + [_textField setStringValue:string]; +} + +- (CPString)stringValue +{ + return [_textField stringValue]; +} + +- (void)textField +{ + return _textField; +} + +- (void)sizeToFit +{ +} + +- (void)drawRect:(CGRect)rect +{ + if (!supportsCanvasGradient) + return; + + var context = [[CPGraphicsContext currentContext] graphicsPort], + bounds = [self bounds], + isSelected = ([self themeState] & CPThemeStateSelected); + + if (_isPressed && isSelected) + gradient = [_CPTableColumnHeaderView selectedPressedHeaderGradient]; + else if (isSelected) + gradient = [_CPTableColumnHeaderView selectedHeaderGradient]; + else if (_isPressed) + gradient = [_CPTableColumnHeaderView pressedHeaderGradient]; + else + gradient = [_CPTableColumnHeaderView headerGradient]; + + CGContextBeginPath(context); + CGContextAddRect(context, bounds); + CGContextDrawLinearGradient(context, gradient, CGPointMakeZero(), CGPointMake(0, CGRectGetHeight(bounds)), 0); + CGContextClosePath(context); +} + +@end @implementation CPTableHeaderView : CPView { int _resizedColumn @accessors(readonly, property=resizedColumn); int _draggedColumn @accessors(readonly, property=draggedColumn); + int _pressedColumn @accessors(readonly, property=pressedColumn); float _draggedDistance @accessors(readonly, property=draggedDistance); @@ -43,6 +181,7 @@ { _resizedColumn = CPNotFound; _draggedColumn = CPNotFound; + _pressedColumn = CPNotFound; _draggedDistance = 0.0; } @@ -94,52 +233,156 @@ return bounds; } +- (CPRect)_resizeRectBeforeColumn:(CPInteger)column +{ + var rect = [self headerRectOfColumn:column]; + + rect.origin.x -= 10; + rect.size.width = 20; + + return rect; +} + +- (void)_updatePressed:(BOOL)flag +{ + var headerView = [_tableView._tableColumns[_pressedColumn] headerView]; + if ([headerView respondsToSelector:@selector(setPressed:)]) + [headerView setPressed:flag]; +} + +- (void)mouseDown:(CPEvent)theEvent +{ + var location = [self convertPoint:[theEvent locationInWindow] fromView:nil], + aPoint = CGPointMakeCopy(location), + clickedColumn = [self columnAtPoint:aPoint]; + + if (clickedColumn == -1) + return; + + // Error, can't find var CPTableViewDelegate_tableView_mouseDownInHeaderOfTableColumn_ !? + if (_tableView._implementedDelegateMethods & (1 << 6)) + [[_tableView delegate] tableView:_tableView + mouseDownInHeaderOfTableColumn:[[_tableView tableColumns] objectAtIndex:clickedColumn]]; + + _pressedColumn = clickedColumn; + [self _updatePressed:YES]; +} + +- (void)mouseUp:(CPEvent)theEvent +{ + var location = [self convertPoint:[theEvent locationInWindow] fromView:nil], + clickedColumn = [self columnAtPoint:location]; + + if (clickedColumn == -1) + return; + + if (_pressedColumn != CPNotFound) + { + [self _updatePressed:NO]; + _pressedColumn = CPNotFound; + } + + if ([_tableView allowsColumnSelection]) + { + if ([theEvent modifierFlags] & CPCommandKeyMask) + { + if ([_tableView isColumnSelected:clickedColumn]) + [_tableView deselectColumn:clickedColumn]; + else if ([_tableView allowsMultipleSelection] == YES) + [_tableView selectColumnIndexes:[CPIndexSet indexSetWithIndex:clickedColumn] byExtendingSelection:YES]; + } + else if ([theEvent modifierFlags] & CPShiftKeyMask) + { + // should be from clickedColumn to lastClickedColum with extending:(direction == previous selection) + var selectedIndexes = [_tableView selectedColumnIndexes], + startColumn = MIN(clickedColumn, [selectedIndexes lastIndex]), + endColumn = MAX(clickedColumn, [selectedIndexes firstIndex]); + + [_tableView selectColumnIndexes:[CPIndexSet indexSetWithIndexesInRange:CPMakeRange(startColumn, endColumn - startColumn + 1)] byExtendingSelection:YES]; + } + else + [_tableView selectColumnIndexes:[CPIndexSet indexSetWithIndex:clickedColumn] byExtendingSelection:NO]; + } +} + - (void)layoutSubviews { - var tableColumns = [_tableView tableColumns], - count = [tableColumns count], - columnRect = [self bounds], - spacing = [_tableView intercellSpacing]; - - for (i = 0; i < count; ++i) + var tableColumns = [_tableView tableColumns], + count = [tableColumns count]; + + for (var i = 0; i < count; i++) { var column = [tableColumns objectAtIndex:i], headerView = [column headerView]; - - columnRect.size.width = [column width] + spacing.width; - - [headerView setFrame:columnRect]; - - columnRect.origin.x += [column width] + spacing.width; - - [self addSubview:headerView]; + + var frame = [self headerRectOfColumn:i]; + frame.size.height -= 0.5; + if (i > 0) + { + frame.origin.x += 0.5; + frame.size.width -= 1; + } + + [headerView setFrame:frame]; + + if([headerView superview] != self) + [self addSubview:headerView]; } } - (void)drawRect:(CGRect)aRect { - [[_tableView gridColor] setStroke]; - var context = [[CPGraphicsContext currentContext] graphicsPort], - exposedColumnIndexes = exposedColumnIndexes = [_tableView columnIndexesInRect:aRect], - columnsArray = []; + exposedColumnIndexes = [_tableView columnIndexesInRect:aRect], + columnsArray = [], + tableColumns = [_tableView tableColumns], + exposedTableColumns = _tableView._exposedColumns, + firstIndex = [exposedTableColumns firstIndex], + exposedRange = CPMakeRange(firstIndex, [exposedTableColumns lastIndex] - firstIndex + 1); - [exposedColumnIndexes getIndexes:columnsArray maxCount:-1 inIndexRange:nil]; + CGContextSetLineWidth(context, 1); + CGContextSetStrokeColor(context, [_tableView gridColor]); + + [exposedColumnIndexes getIndexes:columnsArray maxCount:-1 inIndexRange:exposedRange]; var columnArrayIndex = 0, - columnArrayCount = columnsArray.length; - - for(; columnArrayIndex < columnArrayCount; ++columnArrayIndex) + columnArrayCount = columnsArray.length, + columnMaxX; + + CGContextBeginPath(context); + for(; columnArrayIndex < columnArrayCount; columnArrayIndex++) { - // grab each column rect and add horizontal lines - var columnToStroke = [self headerRectOfColumn:columnArrayIndex]; - - CGContextBeginPath(context); - CGContextMoveToPoint(context, ROUND(columnToStroke.origin.x + columnToStroke.size.width) + 0.5, ROUND(columnToStroke.origin.y) + 0.5); - CGContextAddLineToPoint(context, ROUND(columnToStroke.origin.x + columnToStroke.size.width) + 0.5, ROUND(columnToStroke.origin.y + columnToStroke.size.height) + 0.5); - CGContextSetLineWidth(context, 1); - CGContextStrokePath(context); + // grab each column rect and add vertical lines + var columnIndex = columnsArray[columnArrayIndex], + columnToStroke = [self headerRectOfColumn:columnIndex]; + + columnMaxX = CGRectGetMaxX(columnToStroke); + + CGContextMoveToPoint(context, ROUND(columnMaxX) + 0.5, ROUND(CGRectGetMinY(columnToStroke))); + CGContextAddLineToPoint(context, ROUND(columnMaxX) + 0.5, ROUND(CGRectGetMaxY(columnToStroke)) - 1); } + + CGContextClosePath(context); + CGContextStrokePath(context); + + var maxY = CGRectGetMaxY([self bounds]); + // draw normal gradient for remaining space + if (supportsCanvasGradient) + { + aRect.origin.x = columnMaxX - 0.5; + aRect.size.width -= columnMaxX; + CGContextBeginPath(context); + CGContextAddRect(context, CGRectMake(columnMaxX + 1, 0, CGRectGetMaxX([self bounds]) - columnMaxX, CGRectGetHeight([self bounds]))); + CGContextClosePath(context); + CGContextDrawLinearGradient(context, [_CPTableColumnHeaderView headerGradient], CGPointMake(0,0), CGPointMake(0, maxY - 1),0); + } + + // Draw bottom line + CGContextBeginPath(context); + CGContextMoveToPoint(context, 0, maxY - 0.5); + CGContextAddLineToPoint(context, CGRectGetMaxX([self bounds]), maxY - 0.5); + CGContextClosePath(context); + CGContextStrokePath(context); } @end diff --git a/AppKit/CPTableView.j b/AppKit/CPTableView.j index de4397fc3..176166f80 100644 --- a/AppKit/CPTableView.j +++ b/AppKit/CPTableView.j @@ -146,6 +146,7 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5; //Configuring Behavior BOOL _allowsColumnReordering; BOOL _allowsColumnResizing; + BOOL _allowsColumnSelection; BOOL _allowsMultipleSelection; BOOL _allowsEmptySelection; @@ -766,13 +767,17 @@ window.setTimeout(function(){ - (void)deselectColumn:(CPInteger)aColumn { - [_selectedColumnIndexes removeIndex:aColumn]; + var selectedColumnIndexes = [_selectedColumnIndexes copy]; + [selectedColumnIndexes removeIndex:aColumn]; + [self selectColumnIndexes:selectedColumnIndexes byExtendingSelection:NO]; [self _noteSelectionDidChange]; } - (void)deselectRow:(CPInteger)aRow { - [_selectedRowIndexes removeIndex:aRow]; + var selectedRowIndexes = [_selectedRowIndexes copy]; + [selectedRowIndexes removeIndex:aRow]; + [self selectColumnIndexes:selectedRowIndexes byExtendingSelection:NO]; [self _noteSelectionDidChange]; } diff --git a/Tests/Manual/TableTest/AppController.j b/Tests/Manual/TableTest/AppController.j index f9fbb76bd..eb4b7830a 100644 --- a/Tests/Manual/TableTest/AppController.j +++ b/Tests/Manual/TableTest/AppController.j @@ -37,6 +37,7 @@ CPLogRegister(CPLogConsole); tableView = [[CPTableView alloc] initWithFrame:CGRectMake(0.0, 0.0, 500.0, 500.0)];//[view bounds]]; [tableView setAllowsMultipleSelection:YES]; + [tableView setAllowsColumnSelection:YES]; [tableView setUsesAlternatingRowBackgroundColors:YES]; [tableView setGridStyleMask:CPTableViewSolidHorizontalGridLineMask | CPTableViewSolidVerticalGridLineMask]; @@ -68,7 +69,7 @@ CPLogRegister(CPLogConsole); // [textDataView setBackgroundColor:[[CPColor redColor] colorWithAlphaComponent:0.5]]; - for (var i = 1; i <= 3; i++) + for (var i = 1; i <= 2; i++) { var column = [[CPTableColumn alloc] initWithIdentifier:String(i)]; @@ -85,7 +86,7 @@ CPLogRegister(CPLogConsole); //[tableView selectColumnIndexes:[CPIndexSet indexSetWithIndexesInRange:CPMakeRange(0,2)] byExtendingSelection:YES]; - [tableView setColumnAutoresizingStyle:CPTableViewUniformColumnAutoresizingStyle]; + // [tableView setColumnAutoresizingStyle:CPTableViewUniformColumnAutoresizingStyle]; var scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth([view bounds]), CGRectGetHeight([view bounds]))]; [tableView setRowHeight:22.0]; From 1d9e2f81699966fea79f2e94e1dc143d39fcf38a Mon Sep 17 00:00:00 2001 From: Randall Luecke Date: Sun, 31 Jan 2010 01:55:45 -0500 Subject: [PATCH 06/16] Changed drawn gradients to aristo art. --- AppKit/CPTableHeaderView.j | 22 ++++++++++++++++-- ...bleview-headerview-highlighted-pressed.png | Bin 0 -> 133 bytes .../tableview-headerview-pressed.png | Bin 0 -> 136 bytes 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 AppKit/Resources/tableview-headerview-highlighted-pressed.png create mode 100644 AppKit/Resources/tableview-headerview-pressed.png diff --git a/AppKit/CPTableHeaderView.j b/AppKit/CPTableHeaderView.j index 62ba593ce..9b298b812 100644 --- a/AppKit/CPTableHeaderView.j +++ b/AppKit/CPTableHeaderView.j @@ -32,6 +32,8 @@ var _headerGradient = nil, supportsCanvasGradient = NO; +// FIX ME: _CPTableColumnHeaderView has code for drawn gradients. +// We need to decide if we're going to draw it or just use images throughout. @implementation _CPTableColumnHeaderView : CPView { BOOL _isPressed; @@ -40,7 +42,7 @@ var _headerGradient = nil, + (void)initialize { - supportsCanvasGradient = CPFeatureIsCompatible(CPHTMLCanvasFeature); + supportsCanvasGradient = NO;//CPFeatureIsCompatible(CPHTMLCanvasFeature); } + (CGGradient)headerGradient @@ -98,6 +100,18 @@ var _headerGradient = nil, - (void)setPressed:(BOOL)flag { _isPressed = flag; + var isSelected = ([self themeState] & CPThemeStateSelected); + + if(_isPressed && isSelected) + [self setBackgroundColor:[CPColor colorWithPatternImage:CPAppKitImage("tableview-headerview-highlighted-pressed.png", CGSizeMake(1.0, 22.0))]]; + else if (isSelected) + [self setBackgroundColor:[CPColor colorWithPatternImage:CPAppKitImage("tableview-headerview-highlighted.png", CGSizeMake(1.0, 22.0))]]; + else if (_isPressed) + [self setBackgroundColor:[CPColor colorWithPatternImage:CPAppKitImage("tableview-headerview-pressed.png", CGSizeMake(1.0, 22.0))]]; + else + [self setBackgroundColor:[CPColor colorWithPatternImage:CPAppKitImage("tableview-headerview.png", CGSizeMake(1.0, 22.0))]]; + + [self setNeedsDisplay:YES]; } @@ -183,6 +197,7 @@ var _headerGradient = nil, _draggedColumn = CPNotFound; _pressedColumn = CPNotFound; _draggedDistance = 0.0; + [self setBackgroundColor:[CPColor colorWithPatternImage:CPAppKitImage("tableview-headerview.png", CGSizeMake(1.0, 22.0))]]; } return self; @@ -365,6 +380,9 @@ var _headerGradient = nil, CGContextClosePath(context); CGContextStrokePath(context); + return; + + /* var maxY = CGRectGetMaxY([self bounds]); // draw normal gradient for remaining space if (supportsCanvasGradient) @@ -382,7 +400,7 @@ var _headerGradient = nil, CGContextMoveToPoint(context, 0, maxY - 0.5); CGContextAddLineToPoint(context, CGRectGetMaxX([self bounds]), maxY - 0.5); CGContextClosePath(context); - CGContextStrokePath(context); + CGContextStrokePath(context);*/ } @end diff --git a/AppKit/Resources/tableview-headerview-highlighted-pressed.png b/AppKit/Resources/tableview-headerview-highlighted-pressed.png new file mode 100644 index 0000000000000000000000000000000000000000..cd4464d36692ff7a9eb40de496c2264f30bde8af GIT binary patch literal 133 zcmeAS@N?(olHy`uVBq!ia0vp^j6f{L!2~4xmL&cKQj#UE5hcO-X(i=}MX3yqDfvmM z3ZA)%>8U}fi7AzZCsS>Jiqt(_978H@B~|@=WqNtJ|NNN}l9C5!G&VAxJ9aERC555O eP$-CBAc5hD4(oflT*V@w76wmOKbLh*2~7ZGq9~UD literal 0 HcmV?d00001 diff --git a/AppKit/Resources/tableview-headerview-pressed.png b/AppKit/Resources/tableview-headerview-pressed.png new file mode 100644 index 0000000000000000000000000000000000000000..e79e7253901680bf786dd33639a0dcf2c2231dc5 GIT binary patch literal 136 zcmeAS@N?(olHy`uVBq!ia0vp^j6f{L!2~4xmL&cKQj#UE5hcO-X(i=}MX3yqDfvmM z3ZA)%>8U}fi7AzZCsS>JinKgk978H@CDr`@XDiIi%q*;|tSq6tdE>{6hLda_@2~&w iP;>16|NqP^5)8`UIVGge_Pqk?V(@hJb6Mw<&;$U@zAGO9 literal 0 HcmV?d00001 From 840e9c7671c5e7d95cdbf173bae4bbb46192a933 Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Sun, 31 Jan 2010 12:29:38 -0800 Subject: [PATCH 07/16] When removing an item from the collection view, we now unconditionally unhighlight it. We also reapply highlights after reloading finishes. Closes #248. --- AppKit/CPCollectionView.j | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/AppKit/CPCollectionView.j b/AppKit/CPCollectionView.j index 4a9ddecba..7558eb64f 100644 --- a/AppKit/CPCollectionView.j +++ b/AppKit/CPCollectionView.j @@ -333,6 +333,8 @@ while (count--) { [[_items[count] view] removeFromSuperview]; + [_items[count] setSelected:NO]; + _cachedItems.push(_items[count]); } @@ -351,7 +353,11 @@ [self addSubview:[_items[index] view]]; } - + + index = CPNotFound; + while ((index = [_selectionIndexes indexGreaterThanIndex:index]) != CPNotFound) + [_items[index] setSelected:YES]; + [self tile]; } From 11d30566bfc71a6c152880fffb3d43c17d74c51d Mon Sep 17 00:00:00 2001 From: cacaodev Date: Sun, 31 Jan 2010 22:12:37 +0100 Subject: [PATCH 08/16] CPTableHeaderView: change background in -layoutSubviews instead of -setThemeState: ; Added a CPThemeStatePressed used privately, makes things easier for custom headers --- AppKit/CPTableHeaderView.j | 108 +++++++++++++++---------------------- 1 file changed, 44 insertions(+), 64 deletions(-) diff --git a/AppKit/CPTableHeaderView.j b/AppKit/CPTableHeaderView.j index 9b298b812..12eb5294b 100644 --- a/AppKit/CPTableHeaderView.j +++ b/AppKit/CPTableHeaderView.j @@ -23,26 +23,27 @@ @import "CPTableColumn.j" @import "CPTableView.j" @import "CPView.j" -@import +/*@import var _headerGradient = nil, _selectedHeaderGradient = nil, _pressedHeaderGradient = nil, - _selectedPressedHeaderGradient = nil, - - supportsCanvasGradient = NO; + _selectedPressedHeaderGradient = nil, + supportsCanvasGradient = NO;*/ + +var CPThemeStatePressed = CPThemeState("pressed"); // FIX ME: _CPTableColumnHeaderView has code for drawn gradients. // We need to decide if we're going to draw it or just use images throughout. @implementation _CPTableColumnHeaderView : CPView { - BOOL _isPressed; CPTextField _textField; } +/* + (void)initialize { - supportsCanvasGradient = NO;//CPFeatureIsCompatible(CPHTMLCanvasFeature); + supportsCanvasGradient = CPFeatureIsCompatible(CPHTMLCanvasFeature); } + (CGGradient)headerGradient @@ -76,59 +77,36 @@ var _headerGradient = nil, return _selectedPressedHeaderGradient; } +*/ - (void)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { - _isPressed = NO; _textField = [[CPTextField alloc] initWithFrame:[self bounds]]; [_textField setAutoresizingMask:CPViewWidthSizable|CPViewHeightSizable]; [self addSubview:_textField]; - - if (!supportsCanvasGradient) - [self setBackgroundColor:[CPColor colorWithPatternImage:CPAppKitImage("tableview-headerview.png", CGSizeMake(1.0, 22.0))]]; - + //[self setValue:headerColor forThemeAttribute:@"background-color" inState:CPThemeStateNormal]; - //[self setValue:headerHighlightedColor forThemeAttribute:@"background-color" inState:CPThemeStateHighlighted]; + //[self setValue:headerHighlightedColor forThemeAttribute:@"background-color" inState:CPThemeStateSelected]; } return self; } -- (void)setPressed:(BOOL)flag +- (void)layoutSubviews { - _isPressed = flag; - var isSelected = ([self themeState] & CPThemeStateSelected); - - if(_isPressed && isSelected) + var themeState = [self themeState]; + + if((themeState & CPThemeStateSelected) && (themeState & CPThemeStatePressed)) [self setBackgroundColor:[CPColor colorWithPatternImage:CPAppKitImage("tableview-headerview-highlighted-pressed.png", CGSizeMake(1.0, 22.0))]]; - else if (isSelected) + else if (themeState == CPThemeStateSelected) [self setBackgroundColor:[CPColor colorWithPatternImage:CPAppKitImage("tableview-headerview-highlighted.png", CGSizeMake(1.0, 22.0))]]; - else if (_isPressed) + else if (themeState == CPThemeStatePressed) [self setBackgroundColor:[CPColor colorWithPatternImage:CPAppKitImage("tableview-headerview-pressed.png", CGSizeMake(1.0, 22.0))]]; else [self setBackgroundColor:[CPColor colorWithPatternImage:CPAppKitImage("tableview-headerview.png", CGSizeMake(1.0, 22.0))]]; - - - [self setNeedsDisplay:YES]; -} - -- (BOOL)setThemeState:(CPThemeState)aState -{ - if (supportsCanvasGradient) - [super setThemeState:aState]; - else if (aState & CPThemeStateHighlighted) - [self setBackgroundColor:[CPColor colorWithPatternImage:CPAppKitImage("tableview-headerview-highlighted.png", CGSizeMake(1.0, 22.0))]]; -} - -- (BOOL)unsetThemeState:(CPThemeState)aState -{ - if (supportsCanvasGradient) - [super unsetThemeState:aState]; - else if (aState & CPThemeStateHighlighted) - [self setBackgroundColor:[CPColor colorWithPatternImage:CPAppKitImage("tableview-headerview.png", CGSizeMake(1.0, 22.0))]]; } - (void)setStringValue:(CPString)string @@ -148,22 +126,20 @@ var _headerGradient = nil, - (void)sizeToFit { + [_textField sizeToFit]; } - +/* - (void)drawRect:(CGRect)rect { - if (!supportsCanvasGradient) - return; - var context = [[CPGraphicsContext currentContext] graphicsPort], bounds = [self bounds], - isSelected = ([self themeState] & CPThemeStateSelected); + themeState = [self themeState]; - if (_isPressed && isSelected) + if((themeState & CPThemeStateSelected) && (themeState & CPThemeStatePressed)) gradient = [_CPTableColumnHeaderView selectedPressedHeaderGradient]; - else if (isSelected) + else if (themeState == CPThemeStateSelected) gradient = [_CPTableColumnHeaderView selectedHeaderGradient]; - else if (_isPressed) + else if (themeState == CPThemeStatePressed) gradient = [_CPTableColumnHeaderView pressedHeaderGradient]; else gradient = [_CPTableColumnHeaderView headerGradient]; @@ -173,7 +149,7 @@ var _headerGradient = nil, CGContextDrawLinearGradient(context, gradient, CGPointMakeZero(), CGPointMake(0, CGRectGetHeight(bounds)), 0); CGContextClosePath(context); } - +*/ @end @implementation CPTableHeaderView : CPView @@ -258,11 +234,21 @@ var _headerGradient = nil, return rect; } -- (void)_updatePressed:(BOOL)flag +- (void)_setPressedColumn:(CPInteger)column { - var headerView = [_tableView._tableColumns[_pressedColumn] headerView]; - if ([headerView respondsToSelector:@selector(setPressed:)]) - [headerView setPressed:flag]; + if (_pressedColumn != CPNotFound) + { + var headerView = [_tableView._tableColumns[_pressedColumn] headerView]; + [headerView unsetThemeState:CPThemeStatePressed]; + } + + if (column != CPNotFound) + { + var headerView = [_tableView._tableColumns[column] headerView]; + [headerView setThemeState:CPThemeStatePressed]; + } + + _pressedColumn = column; } - (void)mouseDown:(CPEvent)theEvent @@ -279,8 +265,7 @@ var _headerGradient = nil, [[_tableView delegate] tableView:_tableView mouseDownInHeaderOfTableColumn:[[_tableView tableColumns] objectAtIndex:clickedColumn]]; - _pressedColumn = clickedColumn; - [self _updatePressed:YES]; + [self _setPressedColumn:clickedColumn]; } - (void)mouseUp:(CPEvent)theEvent @@ -291,11 +276,7 @@ var _headerGradient = nil, if (clickedColumn == -1) return; - if (_pressedColumn != CPNotFound) - { - [self _updatePressed:NO]; - _pressedColumn = CPNotFound; - } + [self _setPressedColumn:CPNotFound]; if ([_tableView allowsColumnSelection]) { @@ -374,15 +355,13 @@ var _headerGradient = nil, columnMaxX = CGRectGetMaxX(columnToStroke); CGContextMoveToPoint(context, ROUND(columnMaxX) + 0.5, ROUND(CGRectGetMinY(columnToStroke))); - CGContextAddLineToPoint(context, ROUND(columnMaxX) + 0.5, ROUND(CGRectGetMaxY(columnToStroke)) - 1); + CGContextAddLineToPoint(context, ROUND(columnMaxX) + 0.5, ROUND(CGRectGetMaxY(columnToStroke))); } CGContextClosePath(context); CGContextStrokePath(context); - - return; - - /* + +/* var maxY = CGRectGetMaxY([self bounds]); // draw normal gradient for remaining space if (supportsCanvasGradient) @@ -400,7 +379,8 @@ var _headerGradient = nil, CGContextMoveToPoint(context, 0, maxY - 0.5); CGContextAddLineToPoint(context, CGRectGetMaxX([self bounds]), maxY - 0.5); CGContextClosePath(context); - CGContextStrokePath(context);*/ + CGContextStrokePath(context); +*/ } @end From 1c81e0eee05dbe7a2080e6f3318db2445acd4904 Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Sun, 31 Jan 2010 15:07:23 -0800 Subject: [PATCH 09/16] Closes #429. Doesn't necessarily address the root cause however. The problem stems from a bug in Safari which is allowing callbacks to interrupt running code (which should be impossible in JavaScript). The change essentially makes it so that in the case where this happens, which is rare, we'll end up accidentally creating an extra iframe. This isn't ideal, but it also isn't harmful, versus the current situation where code will simply break. --- AppKit/Platform/DOM/CPPlatform.j | 5 +++ AppKit/Platform/DOM/CPPlatformString.j | 52 ++++++++++++++++++-------- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/AppKit/Platform/DOM/CPPlatform.j b/AppKit/Platform/DOM/CPPlatform.j index 47af4b175..60ac59129 100644 --- a/AppKit/Platform/DOM/CPPlatform.j +++ b/AppKit/Platform/DOM/CPPlatform.j @@ -21,6 +21,7 @@ */ CPPlatformDidClearBodyElementNotification = @"CPPlatformDidClearBodyElementNotification"; +CPPlatformWillClearBodyElementNotification = @"CPPlatformWillClearBodyElementNotification"; var screenNeedsInitialization = NO, mainBodyElement = nil; @@ -91,6 +92,10 @@ var screenNeedsInitialization = NO, screenNeedsInitialization = NO; + [[CPNotificationCenter defaultCenter] + postNotificationName:CPPlatformWillClearBodyElementNotification + object:self]; + var bodyElement = [self mainBodyElement]; // Get rid of any of the original contents of the page. diff --git a/AppKit/Platform/DOM/CPPlatformString.j b/AppKit/Platform/DOM/CPPlatformString.j index e0431b0d4..1beb80c6f 100644 --- a/AppKit/Platform/DOM/CPPlatformString.j +++ b/AppKit/Platform/DOM/CPPlatformString.j @@ -22,8 +22,8 @@ #include "../CoreGraphics/CGGeometry.h" - var DOMSpanElement = nil, + DOMIFrameElement = nil, DefaultFont = nil; @implementation CPPlatformString : CPBasePlatformString @@ -39,11 +39,20 @@ var DOMSpanElement = nil, selector:@selector(platformDidClearBodyElement:) name:CPPlatformDidClearBodyElementNotification object:CPPlatform]; + + [[CPNotificationCenter defaultCenter] + addObserver:self + selector:@selector(platformWillClearBodyElement:) + name:CPPlatformWillClearBodyElementNotification + object:CPPlatform]; } + (void)createDOMElements { - var DOMIFrameElement = document.createElement("iframe"); + if (DOMIFrameElement) + return; + + DOMIFrameElement = document.createElement("iframe"); // necessary for Safari caching bug: DOMIFrameElement.name = "iframe_" + FLOOR(RAND() * 10000); DOMIFrameElement.style.position = "absolute"; @@ -80,11 +89,27 @@ var DOMSpanElement = nil, DOMDivElement.appendChild(DOMSpanElement); } ++ (void)removeDOMElements +{ + var iframe = DOMIFrameElement, + bodyElement = [CPPlatform mainBodyElement]; + + DOMSpanElement = nil; + DOMIFrameElement = nil; + + bodyElement.removeChild(iframe); +} + + (void)platformDidClearBodyElement:(CPNotification)aNotification { [self createDOMElements]; } ++ (void)platformWillClearBodyElement:(CPNotification)aNotification +{ + [self removeDOMElements]; +} + + (CGSize)sizeOfString:(CPString)aString withFont:(CPFont)aFont forWidth:(float)aWidth { if (!aFont) @@ -95,35 +120,30 @@ var DOMSpanElement = nil, aFont = DefaultFont; } + if (!DOMIFrameElement) + [self createDOMElements]; + var style = DOMSpanElement.style; - if (aWidth === NULL) + if (!aWidth) { style.width = ""; style.whiteSpace = "pre"; } - else { style.width = ROUND(aWidth) + "px"; - - if (document.attachEvent) - style.wordWrap = "break-word"; - - else - { - style.whiteSpace = "-o-pre-wrap"; - style.whiteSpace = "-pre-wrap"; - style.whiteSpace = "-moz-pre-wrap"; - style.whiteSpace = "pre-wrap"; - } + style.wordWrap = "break-word"; + style.whiteSpace = "-o-pre-wrap"; + style.whiteSpace = "-pre-wrap"; + style.whiteSpace = "-moz-pre-wrap"; + style.whiteSpace = "pre-wrap"; } style.font = [aFont cssString]; if (CPFeatureIsCompatible(CPJavascriptInnerTextFeature)) DOMSpanElement.innerText = aString; - else if (CPFeatureIsCompatible(CPJavascriptTextContentFeature)) DOMSpanElement.textContent = aString; From c911dd8aa62307404112f49355f97e382d62e544 Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Sun, 31 Jan 2010 15:37:06 -0800 Subject: [PATCH 10/16] Slight order change. This really should not matter. --- AppKit/Platform/DOM/CPPlatformString.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AppKit/Platform/DOM/CPPlatformString.j b/AppKit/Platform/DOM/CPPlatformString.j index 1beb80c6f..371e41a0c 100644 --- a/AppKit/Platform/DOM/CPPlatformString.j +++ b/AppKit/Platform/DOM/CPPlatformString.j @@ -94,8 +94,8 @@ var DOMSpanElement = nil, var iframe = DOMIFrameElement, bodyElement = [CPPlatform mainBodyElement]; - DOMSpanElement = nil; DOMIFrameElement = nil; + DOMSpanElement = nil; bodyElement.removeChild(iframe); } From 26945bde4223518e15f13217d9932ccc70f9aa2f Mon Sep 17 00:00:00 2001 From: Randall Luecke Date: Sun, 31 Jan 2010 18:58:32 -0500 Subject: [PATCH 11/16] Removed commented out code and fixed a bug where the pressed state was still set when you drag the mouse from outside the bounds of the header and let go. --- AppKit/CPTableHeaderView.j | 79 ++------------------------------------ 1 file changed, 3 insertions(+), 76 deletions(-) diff --git a/AppKit/CPTableHeaderView.j b/AppKit/CPTableHeaderView.j index 12eb5294b..30edea8a0 100644 --- a/AppKit/CPTableHeaderView.j +++ b/AppKit/CPTableHeaderView.j @@ -23,62 +23,14 @@ @import "CPTableColumn.j" @import "CPTableView.j" @import "CPView.j" -/*@import - -var _headerGradient = nil, - _selectedHeaderGradient = nil, - _pressedHeaderGradient = nil, - _selectedPressedHeaderGradient = nil, - supportsCanvasGradient = NO;*/ var CPThemeStatePressed = CPThemeState("pressed"); -// FIX ME: _CPTableColumnHeaderView has code for drawn gradients. -// We need to decide if we're going to draw it or just use images throughout. @implementation _CPTableColumnHeaderView : CPView { CPTextField _textField; } -/* -+ (void)initialize -{ - supportsCanvasGradient = CPFeatureIsCompatible(CPHTMLCanvasFeature); -} - -+ (CGGradient)headerGradient -{ - if (!_headerGradient) - _headerGradient = CGGradientCreateWithColorComponents(CGColorSpaceCreateDeviceRGB(),[1.0,1.0,1.0,1.0,0.929,0.929,0.929,1.0], [0.3,1], 2); - - return _headerGradient; -} - -+ (CGGradient)selectedHeaderGradient -{ - if (!_selectedHeaderGradient) - _selectedHeaderGradient = CGGradientCreateWithColorComponents(CGColorSpaceCreateDeviceRGB(), [0.804,0.851,0.918,1.0,0.655,0.718,0.8,1.0], [0.3,1], 2); - - return _selectedHeaderGradient; -} - -+ (CGGradient)pressedHeaderGradient -{ - if (!_pressedHeaderGradient) - _pressedHeaderGradient = CGGradientCreateWithColorComponents(CGColorSpaceCreateDeviceRGB(),[0.929,0.929,0.929,1.0,1.0,1.0,1.0,1.0], [0.3,1], 2); - - return _pressedHeaderGradient; -} - -+ (CGGradient)selectedPressedHeaderGradient -{ - if (!_selectedPressedHeaderGradient) - _selectedPressedHeaderGradient = CGGradientCreateWithColorComponents(CGColorSpaceCreateDeviceRGB(), [0.655,0.718,0.8,1.0,0.804,0.851,0.918,1.0], [0.3,1], 2); - - return _selectedPressedHeaderGradient; -} -*/ - - (void)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; @@ -87,9 +39,6 @@ var CPThemeStatePressed = CPThemeState("pressed"); _textField = [[CPTextField alloc] initWithFrame:[self bounds]]; [_textField setAutoresizingMask:CPViewWidthSizable|CPViewHeightSizable]; [self addSubview:_textField]; - - //[self setValue:headerColor forThemeAttribute:@"background-color" inState:CPThemeStateNormal]; - //[self setValue:headerHighlightedColor forThemeAttribute:@"background-color" inState:CPThemeStateSelected]; } return self; @@ -128,28 +77,6 @@ var CPThemeStatePressed = CPThemeState("pressed"); { [_textField sizeToFit]; } -/* -- (void)drawRect:(CGRect)rect -{ - var context = [[CPGraphicsContext currentContext] graphicsPort], - bounds = [self bounds], - themeState = [self themeState]; - - if((themeState & CPThemeStateSelected) && (themeState & CPThemeStatePressed)) - gradient = [_CPTableColumnHeaderView selectedPressedHeaderGradient]; - else if (themeState == CPThemeStateSelected) - gradient = [_CPTableColumnHeaderView selectedHeaderGradient]; - else if (themeState == CPThemeStatePressed) - gradient = [_CPTableColumnHeaderView pressedHeaderGradient]; - else - gradient = [_CPTableColumnHeaderView headerGradient]; - - CGContextBeginPath(context); - CGContextAddRect(context, bounds); - CGContextDrawLinearGradient(context, gradient, CGPointMakeZero(), CGPointMake(0, CGRectGetHeight(bounds)), 0); - CGContextClosePath(context); -} -*/ @end @implementation CPTableHeaderView : CPView @@ -273,11 +200,11 @@ var CPThemeStatePressed = CPThemeState("pressed"); var location = [self convertPoint:[theEvent locationInWindow] fromView:nil], clickedColumn = [self columnAtPoint:location]; - if (clickedColumn == -1) - return; - [self _setPressedColumn:CPNotFound]; + if (clickedColumn == -1) + return; + if ([_tableView allowsColumnSelection]) { if ([theEvent modifierFlags] & CPCommandKeyMask) From 2dc0839d368f88ad3b2b9b37a2c017e29444b4c0 Mon Sep 17 00:00:00 2001 From: Randall Luecke Date: Mon, 1 Feb 2010 00:58:30 -0500 Subject: [PATCH 12/16] Fixed bug where CPButtonBar would not display anything until resized. Closes issue #151. --- AppKit/CPButtonBar.j | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/AppKit/CPButtonBar.j b/AppKit/CPButtonBar.j index e0d66f78f..a66fb7b86 100644 --- a/AppKit/CPButtonBar.j +++ b/AppKit/CPButtonBar.j @@ -8,6 +8,16 @@ { } +- (id)initWithFrame:(CGRect)aFrame +{ + self = [super initWithFrame:aFrame]; + + if (self) + [self setNeedsLayout]; + + return self; +} + + (CPString)themeClass { return @"button-bar"; From c2223e3942a463e9ec97d37b74096e4e691e996b Mon Sep 17 00:00:00 2001 From: Ross Boucher Date: Sun, 31 Jan 2010 23:06:23 -0800 Subject: [PATCH 13/16] Closes #429. This should actually resolve the issue by simply removing the potential race condition entirely. --- AppKit/Platform/DOM/CPPlatform.j | 14 ++++++-- AppKit/Platform/DOM/CPPlatformString.j | 40 +--------------------- AppKit/Platform/DOM/CPPlatformWindow+DOM.j | 15 ++------ 3 files changed, 15 insertions(+), 54 deletions(-) diff --git a/AppKit/Platform/DOM/CPPlatform.j b/AppKit/Platform/DOM/CPPlatform.j index 60ac59129..e3a621fb8 100644 --- a/AppKit/Platform/DOM/CPPlatform.j +++ b/AppKit/Platform/DOM/CPPlatform.j @@ -24,7 +24,8 @@ CPPlatformDidClearBodyElementNotification = @"CPPlatformDidClearBodyElementNot CPPlatformWillClearBodyElementNotification = @"CPPlatformWillClearBodyElementNotification"; var screenNeedsInitialization = NO, - mainBodyElement = nil; + mainBodyElement = nil, + elementRemovalTest = new RegExp("\\bcpdontremove\\b", "g"); @implementation CPPlatform : CPBasePlatform { @@ -99,7 +100,16 @@ var screenNeedsInitialization = NO, var bodyElement = [self mainBodyElement]; // Get rid of any of the original contents of the page. - bodyElement.innerHTML = ""; + var children = bodyElement.childNodes, + length = children.length; + + while (length--) + { + var element = children[length]; + if (!element.className || element.className.match(elementRemovalTest) === null) + bodyElement.removeChild(element); + } + bodyElement.style.overflow = "hidden"; if (document.documentElement) diff --git a/AppKit/Platform/DOM/CPPlatformString.j b/AppKit/Platform/DOM/CPPlatformString.j index 371e41a0c..1cbe99477 100644 --- a/AppKit/Platform/DOM/CPPlatformString.j +++ b/AppKit/Platform/DOM/CPPlatformString.j @@ -33,25 +33,10 @@ var DOMSpanElement = nil, + (void)bootstrap { [self createDOMElements]; - - [[CPNotificationCenter defaultCenter] - addObserver:self - selector:@selector(platformDidClearBodyElement:) - name:CPPlatformDidClearBodyElementNotification - object:CPPlatform]; - - [[CPNotificationCenter defaultCenter] - addObserver:self - selector:@selector(platformWillClearBodyElement:) - name:CPPlatformWillClearBodyElementNotification - object:CPPlatform]; } + (void)createDOMElements { - if (DOMIFrameElement) - return; - DOMIFrameElement = document.createElement("iframe"); // necessary for Safari caching bug: DOMIFrameElement.name = "iframe_" + FLOOR(RAND() * 10000); @@ -63,6 +48,7 @@ var DOMSpanElement = nil, DOMIFrameElement.style.borderWidth = "0px"; DOMIFrameElement.style.overflow = "hidden"; DOMIFrameElement.style.zIndex = 100000000000; + DOMIFrameElement.className = "cpdontremove"; var bodyElement = [CPPlatform mainBodyElement]; @@ -89,27 +75,6 @@ var DOMSpanElement = nil, DOMDivElement.appendChild(DOMSpanElement); } -+ (void)removeDOMElements -{ - var iframe = DOMIFrameElement, - bodyElement = [CPPlatform mainBodyElement]; - - DOMIFrameElement = nil; - DOMSpanElement = nil; - - bodyElement.removeChild(iframe); -} - -+ (void)platformDidClearBodyElement:(CPNotification)aNotification -{ - [self createDOMElements]; -} - -+ (void)platformWillClearBodyElement:(CPNotification)aNotification -{ - [self removeDOMElements]; -} - + (CGSize)sizeOfString:(CPString)aString withFont:(CPFont)aFont forWidth:(float)aWidth { if (!aFont) @@ -120,9 +85,6 @@ var DOMSpanElement = nil, aFont = DefaultFont; } - if (!DOMIFrameElement) - [self createDOMElements]; - var style = DOMSpanElement.style; if (!aWidth) diff --git a/AppKit/Platform/DOM/CPPlatformWindow+DOM.j b/AppKit/Platform/DOM/CPPlatformWindow+DOM.j index 5c73c69cc..e6cff4912 100644 --- a/AppKit/Platform/DOM/CPPlatformWindow+DOM.j +++ b/AppKit/Platform/DOM/CPPlatformWindow+DOM.j @@ -239,6 +239,7 @@ var supportsNativeDragAndDrop = [CPPlatform supportsDragAndDrop]; _DOMFocusElement.style.zIndex = "-1000"; _DOMFocusElement.style.opacity = "0"; _DOMFocusElement.style.filter = "alpha(opacity=0)"; + _DOMFocusElement.className = "cpdontremove"; _DOMBodyElement.appendChild(_DOMFocusElement); @@ -248,6 +249,7 @@ var supportsNativeDragAndDrop = [CPPlatform supportsDragAndDrop]; _DOMPasteboardElement.style.position = "absolute"; _DOMPasteboardElement.style.top = "-10000px"; _DOMPasteboardElement.style.zIndex = "999"; + _DOMPasteboardElement.className = "cpdontremove"; _DOMBodyElement.appendChild(_DOMPasteboardElement); @@ -255,11 +257,6 @@ var supportsNativeDragAndDrop = [CPPlatform supportsDragAndDrop]; _DOMPasteboardElement.blur(); } -- (void)platformDidClearBodyElement:(CPNotification)aNotification -{ - [self createDOMElements]; -} - - (void)registerDOMWindow { var theDocument = _DOMWindow.document; @@ -273,14 +270,6 @@ var supportsNativeDragAndDrop = [CPPlatform supportsDragAndDrop]; _DOMBodyElement.webkitTouchCallout = "none"; [self createDOMElements]; - - if (window === _DOMWindow) - [[CPNotificationCenter defaultCenter] - addObserver:self - selector:@selector(platformDidClearBodyElement:) - name:CPPlatformDidClearBodyElementNotification - object:CPPlatform]; - [self _addLayers]; var theClass = [self class], From ecb88a87ad8a174dffcd415f2b48989f2ecd8cd1 Mon Sep 17 00:00:00 2001 From: Randall Luecke Date: Mon, 1 Feb 2010 02:33:04 -0500 Subject: [PATCH 14/16] Added proper grid drawing for highlighted rows. Closing issues #369 Also fixing bug where top row would not draw its background when clipped --- AppKit/CPTableView.j | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/AppKit/CPTableView.j b/AppKit/CPTableView.j index 176166f80..5f787e0e8 100644 --- a/AppKit/CPTableView.j +++ b/AppKit/CPTableView.j @@ -1823,7 +1823,10 @@ window.setTimeout(function(){ } - (void)_drawRect:(CGRect)aRect -{ +{ + // FIX ME: All three of these methods will likely need to be rewritten for 1.0 + // We've got grid drawing in highlightSelection and crap everywhere. + var exposedRect = [self _exposedRect]; [self drawBackgroundInClipRect:exposedRect]; @@ -1859,7 +1862,7 @@ window.setTimeout(function(){ // CGContextFillRect(context, CGRectIntersection(aRect, fillRect)); // console.profile("row-paint"); var exposedRows = [self rowsInRect:aRect], - firstRow = exposedRows.location, + firstRow = exposedRows.location -1, lastRow = CPMaxRange(exposedRows) - 1, colorIndex = MIN(exposedRows.length, colorCount), heightFilled = 0.0; @@ -2027,33 +2030,34 @@ window.setTimeout(function(){ CGContextBeginPath(context); gridStyleMask = [self gridStyleMask]; - for(var i=0; i < count2-1; i++) + for(var i=0; i < count2; i++) { - var rect = [self rectOfRow:indexes[i]], - minX = _CGRectGetMinX(rect) - 0.5, - maxX = _CGRectGetMaxX(rect) - 0.5, - minY = _CGRectGetMinY(rect) - 0.5, - maxY = _CGRectGetMaxY(rect) - 0.5; + var rect = objj_msgSend(self, rectSelector, indexes[i]), + minX = CGRectGetMinX(rect) - 0.5, + maxX = CGRectGetMaxX(rect) - 0.5, + minY = CGRectGetMinY(rect) - 0.5, + maxY = CGRectGetMaxY(rect) - 0.5; - //FIX ME: if there are vertical lines we need to make them white too... - /*if (gridStyleMask & CPTableViewSolidVerticalGridLineMask) + if ([_selectedRowIndexes count] >= 1 && gridStyleMask & CPTableViewSolidVerticalGridLineMask) { var exposedColumns = [self columnIndexesInRect:aRect], - columnIndexes = [], - exposedColumns2 = CPMakeRange([exposedColumns firstIndex], [exposedColumns lastIndex] - firstColumn + 1); - [exposedColumns getIndexes:columnIndexes maxCount:-1 inIndexRange:exposedColumns2], - columnCount = [exposedColumns count]; - - for(var c = 0; c < columnCount - 1; c++) + exposedColumnIndexes = [], + firstExposedColumn = [exposedColumns firstIndex], + exposedRange = CPMakeRange(firstExposedColumn, [exposedColumns lastIndex] - firstExposedColumn + 1); + [exposedColumns getIndexes:exposedColumnIndexes maxCount:-1 inIndexRange:exposedRange]; + var exposedColumnCount = [exposedColumnIndexes count]; + + for(var c = firstExposedColumn; c < exposedColumnCount; c++) { - var colRect = [self rectOfColumn:columnIndexes[c]], - colX = _CGRectGetMaxX(rect) - 0.5; - console.log("colX"); + //console.log(columnIndexes); + var colRect = [self rectOfColumn:exposedColumnIndexes[c]], + colX = CGRectGetMaxX(colRect) + 0.5; + //console.log(colX); CGContextMoveToPoint(context, colX, minY); CGContextAddLineToPoint(context, colX, maxY); } - }*/ + } CGContextMoveToPoint(context, minX, maxY); CGContextAddLineToPoint(context, maxX, maxY); From 146bff67665602f4cfaa0d1bca9135f8fa9bcb81 Mon Sep 17 00:00:00 2001 From: Randall Luecke Date: Mon, 1 Feb 2010 03:27:03 -0500 Subject: [PATCH 15/16] Initial documentation of CPTableView --- AppKit/CPTableView.j | 158 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 142 insertions(+), 16 deletions(-) diff --git a/AppKit/CPTableView.j b/AppKit/CPTableView.j index 5f787e0e8..899539a3a 100644 --- a/AppKit/CPTableView.j +++ b/AppKit/CPTableView.j @@ -265,6 +265,11 @@ window.setTimeout(function(){ return self; } + +/*! + Sets the receiverŐs data source to a given object. + @param anObject The data source for the receiver. The object must implement the appropriate methods. +*/ - (void)setDataSource:(id)aDataSource { if (_dataSource === aDataSource) @@ -302,6 +307,9 @@ window.setTimeout(function(){ [self reloadData]; } +/*! + Returns the object that provides the data displayed by the receiver. +*/ - (id)dataSource { return _dataSource; @@ -309,6 +317,11 @@ window.setTimeout(function(){ //Loading Data +/*! + Reloads the data for only the specified rows and columns. + @param rowIndexes The indexes of the rows to update. + @param columnIndexes The indexes of the columns to update. +*/ - (void)reloadDataForRowIndexes:(CPIndexSet)rowIndexes columnIndexes:(CPIndexSet)columnIndexes { [self reloadData]; @@ -316,7 +329,10 @@ window.setTimeout(function(){ // [_previouslyExposedColumns removeIndexes:columnIndexes]; } - +/*! + Reloads the data for all rows and columns. + +*/ - (void)reloadData { if (!_dataSource) @@ -333,7 +349,10 @@ window.setTimeout(function(){ } //Target-action Behavior - +/*! + Sets the message sent to the target when the user double-clicks an uneditable cell or a column header to a given selector. + @param aSelector The message the receiver sends to its target when the user double-clicks an uneditable cell or a column header. +*/ - (void)setDoubleAction:(SEL)anAction { _doubleAction = anAction; @@ -370,6 +389,10 @@ window.setTimeout(function(){ return _allowsColumnResizing; } +/*! + Controls whether the user can select more than one row or column at a time. + @param aFlag YES to allow the user to select multiple rows or columns, otherwise NO. +*/ - (void)setAllowsMultipleSelection:(BOOL)shouldAllowMultipleSelection { _allowsMultipleSelection = !!shouldAllowMultipleSelection; @@ -380,6 +403,10 @@ window.setTimeout(function(){ return _allowsMultipleSelection; } +/*! + Controls whether the receiver allows zero rows or columns to be selected. + @param aFlag YES if an empty selection is allowed, otherwise NO. +*/ - (void)setAllowsEmptySelection:(BOOL)shouldAllowEmptySelection { _allowsEmptySelection = !!shouldAllowEmptySelection; @@ -390,6 +417,11 @@ window.setTimeout(function(){ return _allowsEmptySelection; } +/*! + Controls whether the user can select an entire column by clicking its header. + @param aFlag YES to allow the user to select columns, otherwise NO. +*/ + - (void)setAllowsColumnSelection:(BOOL)shouldAllowColumnSelection { _allowsColumnSelection = !!shouldAllowColumnSelection; @@ -438,13 +470,12 @@ window.setTimeout(function(){ return _rowHeight; } +/*! + Sets whether the receiver uses the standard alternating row colors for its background. + @param aFlag YES to specify standard alternating row colors for the background, NO to specify a solid color. +*/ - (void)setUsesAlternatingRowBackgroundColors:(BOOL)shouldUseAlternatingRowBackgroundColors { - // TODO:need to look at how one actually sets the alternating row, a tip at: - // http://forums.macnn.com/79/developer-center/228347/nstableview-alternating-row-colors/ - // otherwise this may not be feasible or may introduce an additional change req'd in CP - // we'd probably need to iterate through rowId % 2 == 0 and setBackgroundColor with - // whatever the alternating row color is. _usesAlternatingRowBackgroundColors = shouldUseAlternatingRowBackgroundColors; } @@ -453,6 +484,11 @@ window.setTimeout(function(){ return _usesAlternatingRowBackgroundColors; } +/*! + Sets the colors for the rows as they alternate. The number of colors can be arbitrary. By deafult these colors are white and light blue. + @param anArray an array of CPColors +*/ + - (void)setAlternatingRowBackgroundColors:(CPArray)alternatingRowBackgroundColors { if ([_alternatingRowBackgroundColors isEqual:alternatingRowBackgroundColors]) @@ -489,6 +525,11 @@ window.setTimeout(function(){ } } +/*! + Sets the highlight color for rows. By default this color is blue. + @param aColor a CPColor +*/ + - (void)setSelectionHightlightColor:(CPColor)aColor { _selectionHightlightColor = aColor; @@ -504,6 +545,10 @@ window.setTimeout(function(){ * - setIndicatorImage:inTableColumn: */ +/*! + Sets the grid color in the non highlighted state. + @param aColor a CPColor +*/ - (void)setGridColor:(CPColor)aColor { if (_gridColor === aColor) @@ -519,6 +564,11 @@ window.setTimeout(function(){ return _gridColor; } +/*! + Sets the grid style mask to specify if no grid lines, vertical grid lines, or horizontal grid lines should be displayed. + @param gridType The grid style mask. CPTableViewGridNone, CPTableViewSolidVerticalGridLineMask, CPTableViewSolidHorizontalGridLineMask +*/ + - (void)setGridStyleMask:(unsigned)aGrideStyleMask { if (_gridStyleMask === aGrideStyleMask) @@ -536,6 +586,10 @@ window.setTimeout(function(){ //Column Management +/*! + Adds a given column as the last column of the receiver. + @param aColumn The column to add to the receiver. +*/ - (void)addTableColumn:(CPTableColumn)aTableColumn { [_tableColumns addObject:aTableColumn]; @@ -549,6 +603,10 @@ window.setTimeout(function(){ [self setNeedsLayout]; } +/*! + Removes a given column from the receiver. + @param aTableColumn The column to remove from the receiver. +*/ - (void)removeTableColumn:(CPTableColumn)aTableColumn { if ([aTableColumn tableView] !== self) @@ -575,6 +633,12 @@ window.setTimeout(function(){ [self setNeedsLayout]; } + +/*! + Moves the column and heading at a given index to a new given index. + @param columnIndex The current index of the column to move. + @param newIndex The new index for the moved column. +*/ - (void)moveColumn:(unsigned)fromIndex toColumn:(unsigned)toIndex { fromIndex = +fromIndex; @@ -627,6 +691,12 @@ window.setTimeout(function(){ } //Selecting Columns and Rows + +/*! + Sets the column selection using indexes. + @param columns a CPIndexSet of columns to select + @param aFlag should extend the selection thereby retaining the previous selection +*/ - (void)selectColumnIndexes:(CPIndexSet)columns byExtendingSelection:(BOOL)shouldExtendSelection { // If we're out of range, just return @@ -655,6 +725,11 @@ window.setTimeout(function(){ [self _noteSelectionDidChange]; } +/*! + Sets the row selection using indexes. + @param rows a CPIndexSet of rows to select + @param aFlag should extend the selection thereby retaining the previous selection +*/ - (void)selectRowIndexes:(CPIndexSet)rows byExtendingSelection:(BOOL)shouldExtendSelection { if ([rows isEqualToIndexSet:_selectedRowIndexes] || (([rows firstIndex] != CPNotFound && [rows firstIndex] < 0) || [rows lastIndex] >= [self numberOfRows])) @@ -811,6 +886,10 @@ window.setTimeout(function(){ * - allowsTypeSelect * - setAllowsTypeSelect: */ + +/*! + Deselects all rows +*/ - (void)deselectAll { [self selectRowIndexes:[CPIndexSet indexSet] byExtendingSelection:NO]; @@ -958,6 +1037,11 @@ window.setTimeout(function(){ // Complexity: // O(1) +/*! + Returns a range of indices for the rows that lie wholly or partially within the vertical boundaries of a given rectangle. + @param aRect A rectangle in the coordinate system of the receiver. +*/ + - (CPRange)rowsInRect:(CGRect)aRect { // If we have no rows, then we won't intersect anything. @@ -988,6 +1072,11 @@ window.setTimeout(function(){ // Complexity: // O(lg Columns) if table view contains no hidden columns // O(Columns) if table view contains hidden columns + +/*! + Returns the indexes of the receiverŐs columns that intersect the specified rectangle. + @param aRect A rectangle in the coordinate system of the receiver. +*/ - (CPIndexSet)columnIndexesInRect:(CGRect)aRect { var column = MAX(0, [self columnAtPoint:_CGPointMake(aRect.origin.x, 0.0)]), @@ -1183,6 +1272,10 @@ window.setTimeout(function(){ } +/*! + Sets the column autoresizing style of the receiver to a given style. + @param aStyle The column autoresizing style for the receiver. CPTableViewNoColumnAutoresizing, CPTableViewUniformColumnAutoresizingStyle, CPTableViewLastColumnOnlyAutoresizingStyle, CPTableViewFirstColumnOnlyAutoresizingStyle +*/ - (void)setColumnAutoresizingStyle:(unsigned)style { //FIX ME: CPTableViewSequentialColumnAutoresizingStyle and CPTableViewReverseSequentialColumnAutoresizingStyle are not yet implemented @@ -1194,6 +1287,9 @@ window.setTimeout(function(){ return _columnAutoResizingStyle; } +/*! + Resizes the last column if thereŐs room so the receiver fits exactly within its enclosing clip view. +*/ - (void)sizeLastColumnToFit { var superview = [self superview]; @@ -1268,11 +1364,19 @@ window.setTimeout(function(){ * - scrollColumnToVisible: */ +/*! + Scrolls the receiver vertically in an enclosing NSClipView so the row specified by rowIndex is visible. + @param aRowIndex the index of the row to scroll to. +*/ - (void)scrollRowToVisible:(int)rowIndex { [self scrollRectToVisible:[self rectOfRow:rowIndex]]; } +/*! + Scrolls the receiver and header view horizontally in an enclosing NSClipView so the column specified by columnIndex is visible. + @param aColumnIndex the index of the column to scroll to. +*/ - (void)scrollColumnToVisible:(int)columnIndex { [self scrollRectToVisible:[self rectOfColumn:columnIndex]]; @@ -1432,6 +1536,11 @@ window.setTimeout(function(){ * - setVerticalMotionCanBeginDrag: * - verticalMotionCanBeginDrag */ +/*! + Returns whether the receiver allows dragging the rows at rowIndexes with a drag initiated at mousedDownPoint. + @param rowIndexes an index set of rows to be dragged + @param aPoint the point at which the mouse was clicked. +*/ - (BOOL)canDragRowsWithIndexes:(CPIndexSet)rowIndexes atPoint:(CGPoint)mouseDownPoint { return YES; @@ -1503,8 +1612,8 @@ window.setTimeout(function(){ _dragOperationDefaultMask = mask; } -/* - this should be called inside tableView:validateDrop:... method +/*! + This should be called inside tableView:validateDrop:... method either drop on or above, specify the row as -1 to select the whole table for drop on */ @@ -1520,16 +1629,16 @@ window.setTimeout(function(){ _retargetedDropOperation = operation; } -/* - can be: +/*! + sets the feedback style for when the table is the destination of a drag operation + Can be: None Regular Source List - - FIX ME: this should vary up the highlight color, currently nothing is being done with it */ - (void)setDraggingDestinationFeedbackStyle:(CPTableViewDraggingDestinationFeedbackStyle)aStyle { + //FIX ME: this should vary up the highlight color, currently nothing is being done with it _destinationDragStyle = aStyle; } @@ -1538,6 +1647,10 @@ window.setTimeout(function(){ return _destinationDragStyle; } +/*! + Sets whether vertical motion is treated as a drag or selection change to flag. + @param aFlag If flag is NO then vertical motion will not start a drag. The default is YES. +*/ - (void)setVerticalMotionCanBeginDrag:(BOOL)aFlag { _verticalMotionCanDrag = aFlag; @@ -2130,12 +2243,17 @@ window.setTimeout(function(){ */ +/* + @ignore +*/ - (BOOL)tracksMouseOutsideOfFrame { return YES; } -/* ignore */ +/* + @ignore +*/ - (BOOL)startTrackingAt:(CGPoint)aPoint { var row = [self rowAtPoint:aPoint]; @@ -2169,6 +2287,9 @@ window.setTimeout(function(){ return YES; } +/* + @ignore +*/ - (void)trackMouse:(CPEvent)anEvent { // Prevent CPControl from eating the mouse events when we are in a drag session @@ -2178,7 +2299,9 @@ window.setTimeout(function(){ [CPApp sendEvent:anEvent]; } -/* ignore */ +/* + @ignore +*/ - (BOOL)continueTracking:(CGPoint)lastPoint at:(CGPoint)aPoint { var row = [self rowAtPoint:aPoint]; @@ -2253,6 +2376,9 @@ window.setTimeout(function(){ return YES; } +/*! + @ignore +*/ - (void)stopTracking:(CGPoint)lastPoint at:(CGPoint)aPoint mouseIsUp:(BOOL)mouseIsUp { _isSelectingSession = NO; @@ -2315,7 +2441,7 @@ window.setTimeout(function(){ [self sendAction:_doubleAction to:_target]; } -/* +/*! @ignore */ - (CPDragOperation)draggingEntered:(id)sender From 050a132bd52b0be9a75f0dd8265470fb3ac75bdd Mon Sep 17 00:00:00 2001 From: Randall Luecke Date: Mon, 1 Feb 2010 03:40:09 -0500 Subject: [PATCH 16/16] Initial documentation of CPTableView. --- AppKit/CPTableView.j | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/AppKit/CPTableView.j b/AppKit/CPTableView.j index 899539a3a..062ab6594 100644 --- a/AppKit/CPTableView.j +++ b/AppKit/CPTableView.j @@ -122,6 +122,13 @@ CPTableViewFirstColumnOnlyAutoresizingStyle = 5; @end +/*! + @ingroup appkit + @class CPTableView + + CPTableView object displays record-oriented data in a table and allows the user to edit values and resize and rearrange columns. + A CPTableView requires you to set a dataSource which implements numberOfRowsInTableView: and tableView:objectValueForTableColumn:row: +*/ @implementation CPTableView : CPControl { id _dataSource;