Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4458884048 | ||
|
|
7245fb99a6 | ||
|
|
5d27661354 | ||
|
|
b33b2df778 | ||
|
|
d2f27408a5 | ||
|
|
66a87c472b | ||
|
|
688aed72cb | ||
|
|
6310733881 | ||
|
|
3fe505b8e5 | ||
|
|
00915083d4 | ||
|
|
4e1ecbef72 | ||
|
|
e4f6214005 | ||
|
|
ed98a44116 | ||
|
|
50d36e76ac | ||
|
|
818bf475f2 | ||
|
|
47afb96c4c | ||
|
|
467dc3c2d5 | ||
|
|
7e3079add6 | ||
|
|
9796f5d5d7 | ||
|
|
37323b811c | ||
|
|
8720a952b0 | ||
|
|
bf4724d401 | ||
|
|
c73e2e1a91 | ||
|
|
630cd121a6 | ||
|
|
5d88ffbe66 | ||
|
|
bd5aa1c959 | ||
|
|
c65bfd22a2 | ||
|
|
e656e0561b | ||
|
|
ddbba22533 | ||
|
|
91b5596034 | ||
|
|
e0185a0eff | ||
|
|
2fe8845842 | ||
|
|
c02128a1fd | ||
|
|
27ad98e160 | ||
|
|
fc746db70f | ||
|
|
6a6256bdb4 | ||
|
|
5a0cfc1595 | ||
|
|
32107ab650 | ||
|
|
494f615aaa | ||
|
|
5c2ebd546c | ||
|
|
72b8ed2faf | ||
|
|
6b8c85df7c | ||
|
|
cce4e3ded8 | ||
|
|
0240c648aa | ||
|
|
6019ff9107 | ||
|
|
c4ee83e4c1 | ||
|
|
61b0cbb1af | ||
|
|
af30e96b7b | ||
|
|
b7bdec189a | ||
|
|
2a27a87ae6 | ||
|
|
31ac84f683 | ||
|
|
c41defe864 | ||
|
|
6bc109f7fc | ||
|
|
2d603df83c | ||
|
|
dcf440396d | ||
|
|
1dc10440b7 | ||
|
|
0ef2557ec3 | ||
|
|
05e69c85c7 | ||
|
|
9c6476615d | ||
|
|
b393d0597f | ||
|
|
f69e2e8d8f | ||
|
|
5fd470acea | ||
|
|
28e660c295 | ||
|
|
9a76b4451f | ||
|
|
b50f955cfd | ||
|
|
0aa2e2b298 | ||
|
|
1f5ad49591 | ||
|
|
3e45c7895c | ||
|
|
29301f440e | ||
|
|
2f86c0d9d2 | ||
|
|
e7dbd5a5cc | ||
|
|
62c00bb7f5 | ||
|
|
12f0d2a867 | ||
|
|
5af66b60e1 | ||
|
|
028a4fe5b2 | ||
|
|
fa6e711c2f | ||
|
|
c620c7bf39 | ||
|
|
f3066594fe | ||
|
|
4db1e28677 | ||
|
|
d6cbc52790 | ||
|
|
0943065498 | ||
|
|
42cc3f309f | ||
|
|
6d7dc24775 | ||
|
|
8faa17ad33 | ||
|
|
3d5232b308 | ||
|
|
c2bab5b369 | ||
|
|
eee1dcef13 | ||
|
|
8254543da7 | ||
|
|
2028efabc3 | ||
|
|
011c033478 | ||
|
|
477e9f85be | ||
|
|
0d5ae63013 | ||
|
|
aa60a7b975 | ||
|
|
c071569f3c | ||
|
|
1d717ffe99 | ||
|
|
c53fff058b | ||
|
|
c836bd48e0 | ||
|
|
ec675a5662 | ||
|
|
02e72493ef | ||
|
|
dd2ad410b8 | ||
|
|
92fb183c22 | ||
|
|
46eca09d69 | ||
|
|
f7bc2b6d06 | ||
|
|
c87cb4bacd | ||
|
|
b6ea6530b7 | ||
|
|
af4e69afc9 | ||
|
|
a292936d55 | ||
|
|
a000687a42 | ||
|
|
03aaa89a61 | ||
|
|
be71d957e1 | ||
|
|
651970899d | ||
|
|
ae67b00c4d | ||
|
|
51848b6cce | ||
|
|
8e0b3a5df3 | ||
|
|
692c43a3cc | ||
|
|
29430df66d | ||
|
|
9954a75cdd | ||
|
|
6ee7964fa6 | ||
|
|
db6608571a | ||
|
|
76d5051833 | ||
|
|
9cdcbb1988 | ||
|
|
33882942e4 | ||
|
|
6c2c690504 | ||
|
|
c78f232e4a | ||
|
|
5f39046a52 | ||
|
|
fff2be49fc | ||
|
|
95a2b46ae1 | ||
|
|
754324d253 | ||
|
|
b350b89376 | ||
|
|
4445f752f3 | ||
|
|
9e92947b2c | ||
|
|
92d44b12bd | ||
|
|
36c673c660 | ||
|
|
db509cb72f | ||
|
|
c0af2af7e7 | ||
|
|
35b2b5263c | ||
|
|
fa3df44535 | ||
|
|
08dd7d6951 | ||
|
|
d7316918a3 | ||
|
|
044fc3af69 | ||
|
|
d1eb20e7b3 | ||
|
|
c27edb2475 | ||
|
|
58d4030133 | ||
|
|
e8b1063647 | ||
|
|
3caa703ced | ||
|
|
f7e016a98c | ||
|
|
156e9b8e54 | ||
|
|
7aa00a961a | ||
|
|
4678efff72 | ||
|
|
f3b4e7f752 | ||
|
|
e39fa44cdb | ||
|
|
3fb4d1e4c1 | ||
|
|
06b8636817 | ||
|
|
4b653ee367 | ||
|
|
d2cdd46466 | ||
|
|
2d46fb885d | ||
|
|
b3e0c4a5d5 | ||
|
|
ab6609282d | ||
|
|
6ff21692f1 | ||
|
|
f64cc4c655 | ||
|
|
e31af96ef9 | ||
|
|
a431b34c43 | ||
|
|
562bb8a878 | ||
|
|
719dbf02d4 | ||
|
|
e2327fcf94 | ||
|
|
5a0c8f4a8b | ||
|
|
031a380c25 | ||
|
|
23c4e584d4 | ||
|
|
452febd73e | ||
|
|
645741aa23 | ||
|
|
97b141b653 | ||
|
|
67ac778d4c | ||
|
|
76b5682234 | ||
|
|
e45ed19dc7 | ||
|
|
f79c2346a5 | ||
|
|
e964c60830 | ||
|
|
f8ffb4abbd | ||
|
|
37931f08b5 | ||
|
|
4aa4f1a62a | ||
|
|
7ae14e9eb5 | ||
|
|
bfe03a8874 | ||
|
|
66b6b44f86 | ||
|
|
b70018bd80 | ||
|
|
9b75e37e1f | ||
|
|
232f1d008d | ||
|
|
3947bd65f2 | ||
|
|
1d39299a7d | ||
|
|
da1389b0b4 | ||
|
|
818c7dac3d | ||
|
|
15b05304cc | ||
|
|
e33c7f6be4 | ||
|
|
d23bf7b927 | ||
|
|
de1ebe6319 | ||
|
|
3e9e0802f6 | ||
|
|
b8f9263d18 | ||
|
|
946cd381a0 | ||
|
|
0a49d09878 | ||
|
|
f936277a4d | ||
|
|
ac16c5663b | ||
|
|
83058b01d3 | ||
|
|
3c8619db5d | ||
|
|
14226ef69c | ||
|
|
910691ad4b | ||
|
|
115d29b6f8 | ||
|
|
05ef7c83a8 | ||
|
|
2311fb9a6d | ||
|
|
c1b8ec8da1 | ||
|
|
a1efd1d024 | ||
|
|
088b6eac35 | ||
|
|
ea1068c465 | ||
|
|
978545af94 | ||
|
|
86c10e687b | ||
|
|
24ab9f9fdf | ||
|
|
5d69bbc4ca | ||
|
|
3c3b7ff61c | ||
|
|
5a6e266c8d | ||
|
|
6f724e34f5 | ||
|
|
7cec421419 | ||
|
|
967f541659 | ||
|
|
6e78d903e0 | ||
|
|
03a243fd20 | ||
|
|
0b8d3744bb | ||
|
|
a0bb3b31a3 | ||
|
|
1f79402a0a | ||
|
|
f7db4058a8 | ||
|
|
4d9854695a | ||
|
|
e90133ebd0 | ||
|
|
d4818b5a71 | ||
|
|
68a15c5c7c | ||
|
|
42db55fabd | ||
|
|
e6c1dfc51e | ||
|
|
4f3146dc7b | ||
|
|
4372edb7c4 | ||
|
|
d105388d82 | ||
|
|
fd812f25a5 | ||
|
|
9f5904eaf2 | ||
|
|
d246b19750 | ||
|
|
128a3ac4d9 | ||
|
|
abd908949a | ||
|
|
ab083a3baf | ||
|
|
45ee3aa0a3 | ||
|
|
d587016cc3 | ||
|
|
8edee4e755 | ||
|
|
8aeaa6681a | ||
|
|
8a0a68248c | ||
|
|
251ba407be | ||
|
|
bd28d688aa | ||
|
|
6ab679a725 | ||
|
|
6b7d636b0d | ||
|
|
f72749fbd6 | ||
|
|
9a032a57d0 | ||
|
|
244ff0d846 | ||
|
|
c65726fb12 | ||
|
|
8ef7f07195 | ||
|
|
2af2fc31a1 | ||
|
|
9bf0edb5df | ||
|
|
53f4baa9ac | ||
|
|
63cc9c4b36 | ||
|
|
8b60ef1156 | ||
|
|
751a80afb7 | ||
|
|
f2b2852b76 | ||
|
|
f36d8224a6 | ||
|
|
c5c2a80af9 | ||
|
|
b9dfd2a795 | ||
|
|
b381fe6c27 | ||
|
|
003dcface0 | ||
|
|
0e05f1a8b7 | ||
|
|
5a340804fe | ||
|
|
65f6c35c88 | ||
|
|
cfee75b6e9 | ||
|
|
0463af26b3 | ||
|
|
ced3c2d778 | ||
|
|
7e4e6932a0 | ||
|
|
13940c97e7 | ||
|
|
91d28cbbdd | ||
|
|
adc2d2b513 | ||
|
|
c80116e90d | ||
|
|
f667c39ade | ||
|
|
ce0ddb2e1f | ||
|
|
3a716c08f8 | ||
|
|
d69f46f7ee | ||
|
|
3cda75986b | ||
|
|
ffea2de826 | ||
|
|
ac6ccc3257 | ||
|
|
29ed8f3116 | ||
|
|
3f2dd34ee5 | ||
|
|
df7c8bf508 | ||
|
|
1e2fdc3e1b | ||
|
|
901f3fe63b | ||
|
|
a767d2199d | ||
|
|
ceb4432b49 | ||
|
|
b80c48886a | ||
|
|
55121d501b | ||
|
|
2c0c8b59a2 | ||
|
|
788419d64c | ||
|
|
735a38d134 | ||
|
|
8d80903cf2 | ||
|
|
432c98f5f7 | ||
|
|
f7495155af | ||
|
|
c2ee9a9a5e | ||
|
|
71bbd85ba4 | ||
|
|
3776a7bee1 | ||
|
|
fb51a0f892 | ||
|
|
2d74d9fa92 | ||
|
|
2014f47046 | ||
|
|
79c2edca2d | ||
|
|
175f1a9acd | ||
|
|
18e943a65b | ||
|
|
20f36eaa9a | ||
|
|
6cbff694ab | ||
|
|
54e106bb14 | ||
|
|
3d1992440b | ||
|
|
1cbaea0e3d | ||
|
|
400bdb5103 | ||
|
|
dd560fb78c | ||
|
|
e71cbfbde2 | ||
|
|
eb6c103396 | ||
|
|
45c585e5c2 | ||
|
|
0ab92c77bd | ||
|
|
2d1fd1b3a5 | ||
|
|
d4d831b9ac | ||
|
|
c713a3fb25 | ||
|
|
ff60125183 | ||
|
|
94d28a2593 | ||
|
|
43f8b50ef7 | ||
|
|
7c098753cf | ||
|
|
b46d283dc4 | ||
|
|
f9639eb695 | ||
|
|
9fc0006316 | ||
|
|
a51672cc82 | ||
|
|
32decc31db | ||
|
|
14d9aac98b | ||
|
|
327962bc01 | ||
|
|
4197bbe73c | ||
|
|
e3ef20eec3 | ||
|
|
8ddb80fca2 | ||
|
|
b8eb72f823 | ||
|
|
9003177bb7 | ||
|
|
591142ba84 | ||
|
|
7b4f7f75b0 | ||
|
|
31b2cb35f7 | ||
|
|
20eb2a9fb0 | ||
|
|
37d9bff77f | ||
|
|
f3f0bf3524 | ||
|
|
b9ca57a921 | ||
|
|
04546e39a5 | ||
|
|
e6cf98f743 | ||
|
|
a528a503d3 | ||
|
|
8345788e59 | ||
|
|
21c2b8f74a | ||
|
|
69c004093d | ||
|
|
5bec411bdc | ||
|
|
34339fbcd9 | ||
|
|
b49dc87a86 | ||
|
|
535d6c9dc5 | ||
|
|
221fad6c3e | ||
|
|
aeb3873f3c | ||
|
|
4f6c83cb3a | ||
|
|
2ba5cffe44 | ||
|
|
1e85a054ac | ||
|
|
ca60e50128 | ||
|
|
70c13a7588 | ||
|
|
6653bab492 | ||
|
|
741c235f08 | ||
|
|
70bc3557b4 | ||
|
|
7509e5c99b | ||
|
|
5a2c401e05 | ||
|
|
75427973f0 | ||
|
|
63d5c442a3 | ||
|
|
45f74386b8 | ||
|
|
6093530175 | ||
|
|
6bd064f289 | ||
|
|
31d57b0c37 | ||
|
|
22a185b52e | ||
|
|
0067bd0d16 | ||
|
|
6521202e68 | ||
|
|
67e87c7367 | ||
|
|
a4eeb91290 | ||
|
|
c0b1322c77 | ||
|
|
3c18282510 | ||
|
|
55674e31ea | ||
|
|
39a69b6850 | ||
|
|
2b8a5d6176 | ||
|
|
eb692e672e | ||
|
|
381a6a999b | ||
|
|
e276a830d3 | ||
|
|
e4ee9284b4 | ||
|
|
9e441f69b8 | ||
|
|
0d2b13dd75 | ||
|
|
2df07344c8 | ||
|
|
38ad5a8e2c | ||
|
|
bd15d2f331 | ||
|
|
80ec35fd0a | ||
|
|
fb8d834036 | ||
|
|
4191153d0b | ||
|
|
ace66b2b2f | ||
|
|
c8afcde4e5 | ||
|
|
a302fdfb8f | ||
|
|
8b9a0edeba | ||
|
|
923770d95a | ||
|
|
011b8d250a | ||
|
|
0f8aa1e644 | ||
|
|
9179a31a93 | ||
|
|
c9d32b4163 | ||
|
|
57c691c2e2 | ||
|
|
bb9e1a830d | ||
|
|
9b7f8ec31e | ||
|
|
17b40fcb9d | ||
|
|
8a75c9078e | ||
|
|
fbcf84e63f | ||
|
|
ea5ab5e921 | ||
|
|
3a8773baec | ||
|
|
ab4dd1ac6d | ||
|
|
6f38b2aa0d | ||
|
|
929ec28436 | ||
|
|
04a19543a5 | ||
|
|
5d505f5271 | ||
|
|
60ff3ca0a1 | ||
|
|
e4f5d9b32f | ||
|
|
6b42ef3cb1 | ||
|
|
345b9d9297 | ||
|
|
4bad3c2823 | ||
|
|
38033d9dcb | ||
|
|
5c961d4f16 | ||
|
|
c21cdc2916 | ||
|
|
1a797b10c3 | ||
|
|
3bfa427134 | ||
|
|
9a8c4bd431 | ||
|
|
dc72b55361 | ||
|
|
ee4ef882dd | ||
|
|
23c2f4bb8c | ||
|
|
bd01955f39 | ||
|
|
3f1e1e57d8 | ||
|
|
ee343c7533 | ||
|
|
961071e3fa | ||
|
|
0219341ee8 | ||
|
|
5df3c7838d | ||
|
|
bf63147ca3 | ||
|
|
b7d7b99a82 | ||
|
|
5a0129018a | ||
|
|
e48a437c88 | ||
|
|
187c32d231 | ||
|
|
c680e31817 | ||
|
|
cc177eeb2b | ||
|
|
918db24c63 | ||
|
|
7e005f4559 | ||
|
|
5d49c1346a | ||
|
|
f6147850b9 | ||
|
|
731e50da32 | ||
|
|
5078c3e9cf | ||
|
|
de0a09899a | ||
|
|
4041ef8746 | ||
|
|
3b35219beb | ||
|
|
ca289e081e | ||
|
|
5cd00d71c7 | ||
|
|
ea924fbb26 | ||
|
|
da23a89910 | ||
|
|
e4b47090ba | ||
|
|
386ded05fd | ||
|
|
e3b6cbcee9 | ||
|
|
fd7651e895 | ||
|
|
8ca2f53828 | ||
|
|
fc385935ef | ||
|
|
ed1c5714a3 | ||
|
|
dfe03458d0 | ||
|
|
c55cd03db1 | ||
|
|
6a2b347b21 | ||
|
|
b96abb5fd4 | ||
|
|
4974a47c94 | ||
|
|
7e229652f1 | ||
|
|
81f2959417 | ||
|
|
9d46c688ed | ||
|
|
60a8ddd306 | ||
|
|
4817a87499 | ||
|
|
91ce1c3f6c | ||
|
|
0c9cba4e71 | ||
|
|
c833de2e0a | ||
|
|
6824e42c69 | ||
|
|
67a41534bd | ||
|
|
3d0d522f76 | ||
|
|
accd29804c | ||
|
|
0c62609e76 | ||
|
|
6148654604 | ||
|
|
40c1957484 | ||
|
|
6f754d9810 | ||
|
|
9a4c9e4306 | ||
|
|
c52b40657a | ||
|
|
db2c88f2e5 | ||
|
|
b9095b2176 | ||
|
|
ec9fac6629 | ||
|
|
b2dac594dc | ||
|
|
28029030b6 | ||
|
|
4b1fbf1eff | ||
|
|
24fbecb2e6 | ||
|
|
4a142b5c02 | ||
|
|
dfba974572 | ||
|
|
c1fd31fa23 | ||
|
|
fd3e10f793 | ||
|
|
6a7358920b | ||
|
|
c0aa180e83 | ||
|
|
82cf7df7e9 | ||
|
|
4c58c602ff | ||
|
|
14e4b71d20 | ||
|
|
6483ea233c | ||
|
|
895ed4f6ff | ||
|
|
5ff7e66981 | ||
|
|
a2ff814796 | ||
|
|
c1e42a2f3e | ||
|
|
9e1c07b195 | ||
|
|
c71c732fc0 | ||
|
|
b3e0ec60df | ||
|
|
513cc2cac7 | ||
|
|
b0feeb3d31 | ||
|
|
9c7b3475d8 | ||
|
|
99e4a4fb4f | ||
|
|
7b7b46a61e | ||
|
|
ed4a264108 | ||
|
|
ae5d56471f | ||
|
|
bafb23ae44 | ||
|
|
c481d55976 | ||
|
|
7aa7d61984 | ||
|
|
fc545ed995 | ||
|
|
f85ab24993 | ||
|
|
4e1766485f | ||
|
|
8e5471d0fe | ||
|
|
a09878dcb4 | ||
|
|
b3f2ba035e | ||
|
|
10a620017d | ||
|
|
c10b06e29b | ||
|
|
411a634242 | ||
|
|
4ab421f183 | ||
|
|
8e3e15080b | ||
|
|
fd625c96d6 | ||
|
|
4f721fc1e2 | ||
|
|
373210e610 | ||
|
|
0ddb17862c | ||
|
|
aae415c1ee | ||
|
|
c79b2456f5 | ||
|
|
5104d323bb | ||
|
|
80c4be6e5f | ||
|
|
970859311d | ||
|
|
449581e7c4 | ||
|
|
02a8fc7f72 | ||
|
|
7bbeee8234 | ||
|
|
00532fe7ac | ||
|
|
073a934b2b | ||
|
|
ea7631de9e | ||
|
|
81e15c91f4 | ||
|
|
b8afbb66a7 | ||
|
|
9e9eba695f | ||
|
|
c6e3cad944 | ||
|
|
3af0e3249a | ||
|
|
510a836b90 | ||
|
|
25f415045a | ||
|
|
0af9c18ef2 |
@@ -24,6 +24,7 @@
|
|||||||
@import "CPAlert.j"
|
@import "CPAlert.j"
|
||||||
@import "CPAnimation.j"
|
@import "CPAnimation.j"
|
||||||
@import "CPApplication.j"
|
@import "CPApplication.j"
|
||||||
|
@import "CPArrayController.j"
|
||||||
@import "CPBezierPath.j"
|
@import "CPBezierPath.j"
|
||||||
@import "CPBox.j"
|
@import "CPBox.j"
|
||||||
@import "CPBrowser.j"
|
@import "CPBrowser.j"
|
||||||
@@ -31,6 +32,7 @@
|
|||||||
@import "CPButtonBar.j"
|
@import "CPButtonBar.j"
|
||||||
@import "CPCheckBox.j"
|
@import "CPCheckBox.j"
|
||||||
@import "CPCib.j"
|
@import "CPCib.j"
|
||||||
|
@import "CPCibBindingConnector.j"
|
||||||
@import "CPCibConnector.j"
|
@import "CPCibConnector.j"
|
||||||
@import "CPCibControlConnector.j"
|
@import "CPCibControlConnector.j"
|
||||||
@import "CPCibLoading.j"
|
@import "CPCibLoading.j"
|
||||||
@@ -74,15 +76,17 @@
|
|||||||
@import "CPSegmentedControl.j"
|
@import "CPSegmentedControl.j"
|
||||||
@import "CPShadow.j"
|
@import "CPShadow.j"
|
||||||
@import "CPSlider.j"
|
@import "CPSlider.j"
|
||||||
|
@import "CPSound.j"
|
||||||
@import "CPSplitView.j"
|
@import "CPSplitView.j"
|
||||||
|
@import "CPStepper.j"
|
||||||
@import "CPTableColumn.j"
|
@import "CPTableColumn.j"
|
||||||
@import "CPTableView.j"
|
@import "CPTableView.j"
|
||||||
@import "CPTabView.j"
|
@import "CPTabView.j"
|
||||||
@import "CPText.j"
|
@import "CPText.j"
|
||||||
@import "CPTextField.j"
|
@import "CPTextField.j"
|
||||||
|
@import "CPTokenField.j"
|
||||||
@import "CPToolbar.j"
|
@import "CPToolbar.j"
|
||||||
@import "CPToolbarItem.j"
|
@import "CPToolbarItem.j"
|
||||||
@import "CPTokenField.j"
|
|
||||||
@import "CPTreeNode.j"
|
@import "CPTreeNode.j"
|
||||||
@import "CPView.j"
|
@import "CPView.j"
|
||||||
@import "CPViewAnimation.j"
|
@import "CPViewAnimation.j"
|
||||||
@@ -90,4 +94,4 @@
|
|||||||
@import "CPWebView.j"
|
@import "CPWebView.j"
|
||||||
@import "CPWindow.j"
|
@import "CPWindow.j"
|
||||||
@import "CPWindowController.j"
|
@import "CPWindowController.j"
|
||||||
@import "CPArrayController.j"
|
|
||||||
|
|||||||
@@ -7,6 +7,8 @@
|
|||||||
*
|
*
|
||||||
* 11/10/2008 Ross Boucher
|
* 11/10/2008 Ross Boucher
|
||||||
* - Make it conform to style guidelines, general cleanup and ehancements
|
* - Make it conform to style guidelines, general cleanup and ehancements
|
||||||
|
* 11/10/2010 Antoine Mercadal
|
||||||
|
* - Enhancements, better compliance with Cocoa API
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
@@ -75,22 +77,587 @@ CPCriticalAlertStyle = 2;
|
|||||||
*/
|
*/
|
||||||
@implementation CPAlert : CPView
|
@implementation CPAlert : CPView
|
||||||
{
|
{
|
||||||
CPPanel _alertPanel;
|
BOOL _showHelp @accessors(property=showsHelp);
|
||||||
|
BOOL _showSuppressionButton @accessors(property=showsSuppressionButton);
|
||||||
|
|
||||||
CPTextField _messageLabel;
|
CPAlertStyle _alertStyle @accessors(property=alertStyle);
|
||||||
CPTextField _informativeLabel;
|
CPString _title @accessors(property=title);
|
||||||
CPImageView _alertImageView;
|
CPView _accessoryView @accessors(property=accessoryView);
|
||||||
|
CPImage _icon @accessors(property=icon);
|
||||||
|
|
||||||
CPAlertStyle _alertStyle;
|
CPArray _buttons @accessors(property=buttons,readonly);
|
||||||
CPString _windowTitle;
|
CPCheckBox _suppressionButton @accessors(property=suppressionButton,readonly);
|
||||||
int _windowStyle;
|
|
||||||
CPArray _buttons;
|
|
||||||
|
|
||||||
id _delegate;
|
id _delegate @accessors(property=delegate);
|
||||||
SEL _didEndSelector;
|
|
||||||
id _modalDelegate;
|
id _modalDelegate;
|
||||||
|
SEL _didEndSelector;
|
||||||
|
|
||||||
|
CPWindow _window @accessors(property=window,readonly);
|
||||||
|
int _defaultWindowStyle;
|
||||||
|
|
||||||
|
CPImageView _alertImageView;
|
||||||
|
CPTextField _informativeLabel;
|
||||||
|
CPTextField _messageLabel;
|
||||||
|
CPButton _alertHelpButton;
|
||||||
|
|
||||||
|
BOOL _needsLayout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma mark Creating Alerts
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns a CPAlert object with the provided info
|
||||||
|
|
||||||
|
@param aMessage the main body text of the alert
|
||||||
|
@param defaultButton the title of the default button
|
||||||
|
@param alternateButton if not nil, the title of a second button
|
||||||
|
@param otherButton if not nil, the title of the third button
|
||||||
|
@param informativeText if not nil the informative text of the alert
|
||||||
|
@return fully initialized CPAlert
|
||||||
|
*/
|
||||||
|
+ (CPAlert)alertWithMessageText:(CPString)aMessage defaultButton:(CPString)defaultButtonTitle alternateButton:(CPString)alternateButtonTitle otherButton:(CPString)otherButtonTitle informativeTextWithFormat:(CPString)informativeText
|
||||||
|
{
|
||||||
|
var alert = [[CPAlert alloc] init];
|
||||||
|
|
||||||
|
[alert setMessageText:aMessage];
|
||||||
|
[alert addButtonWithTitle:defaultButtonTitle];
|
||||||
|
|
||||||
|
if (alternateButtonTitle)
|
||||||
|
[alert addButtonWithTitle:alternateButtonTitle];
|
||||||
|
|
||||||
|
if (otherButtonTitle)
|
||||||
|
[alert addButtonWithTitle:otherButtonTitle];
|
||||||
|
|
||||||
|
if (informativeText)
|
||||||
|
[alert setInformativeText:informativeText];
|
||||||
|
|
||||||
|
return alert;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Return an CPAlert with type error
|
||||||
|
|
||||||
|
@param anErrorMessage the message of the alert
|
||||||
|
@return fully initialized CPAlert
|
||||||
|
*/
|
||||||
|
+ (CPAlert)alertWithError:(CPString)anErrorMessage
|
||||||
|
{
|
||||||
|
var alert = [[CPAlert alloc] init];
|
||||||
|
|
||||||
|
[alert setMessageText:anErrorMessage];
|
||||||
|
[alert setAlertStyle:CPCriticalAlertStyle];
|
||||||
|
|
||||||
|
return alert;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Initializes a \c CPAlert panel with the default alert style \c CPWarningAlertStyle.
|
||||||
|
*/
|
||||||
|
- (id)init
|
||||||
|
{
|
||||||
|
self = [super init];
|
||||||
|
|
||||||
|
if (self)
|
||||||
|
{
|
||||||
|
_buttons = [];
|
||||||
|
_alertStyle = CPWarningAlertStyle;
|
||||||
|
_showHelp = NO;
|
||||||
|
_needsLayout = YES;
|
||||||
|
_defaultWindowStyle = CPTitledWindowMask;
|
||||||
|
|
||||||
|
_messageLabel = [CPTextField labelWithTitle:@"Alert"];
|
||||||
|
_alertImageView = [[CPImageView alloc] init];
|
||||||
|
_informativeLabel = [[CPTextField alloc] init];
|
||||||
|
_suppressionButton = [CPCheckBox checkBoxWithTitle:@"Do not show this message again"];
|
||||||
|
|
||||||
|
_alertHelpButton = [[CPButton alloc] initWithFrame:CGRectMake(0.0, 0.0, 16.0, 16.0)];
|
||||||
|
[_alertHelpButton setTarget:self];
|
||||||
|
[_alertHelpButton setAction:@selector(_showHelp:)];
|
||||||
|
}
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark Accessors
|
||||||
|
|
||||||
|
/*!
|
||||||
|
set the theme to use
|
||||||
|
|
||||||
|
@param the theme to use
|
||||||
|
*/
|
||||||
|
- (void)setTheme:(CPTheme)aTheme
|
||||||
|
{
|
||||||
|
if (aTheme === [self theme])
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (aTheme === [CPTheme defaultHudTheme])
|
||||||
|
_defaultWindowStyle = CPTitledWindowMask | CPHUDBackgroundWindowMask;
|
||||||
|
else
|
||||||
|
_defaultWindowStyle = CPTitledWindowMask;
|
||||||
|
|
||||||
|
_window = nil; // will be regenerated at next layout
|
||||||
|
_needsLayout = YES;
|
||||||
|
[super setTheme:aTheme];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @deprecated
|
||||||
|
*/
|
||||||
|
- (void)setWindowStyle:(int)aStyle
|
||||||
|
{
|
||||||
|
CPLog.warn("DEPRECATED: setWindowStyle: is deprecated. use setTheme: instead");
|
||||||
|
[self setTheme:(aStyle === CPHUDBackgroundWindowMask) ? [CPTheme defaultHudTheme] : [CPTheme defaultTheme]];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @deprecated
|
||||||
|
*/
|
||||||
|
- (int)windowStyle
|
||||||
|
{
|
||||||
|
CPLog.warn("DEPRECATED: windowStyle: is deprecated. use theme instead");
|
||||||
|
return _defaultWindowStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
set the text of the alert's message
|
||||||
|
|
||||||
|
@param aText CPString containing the text
|
||||||
|
*/
|
||||||
|
- (void)setMessageText:(CPString)aText
|
||||||
|
{
|
||||||
|
[_messageLabel setStringValue:aText];
|
||||||
|
_needsLayout = YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
return the content of the message text
|
||||||
|
@return CPString containing the message text
|
||||||
|
*/
|
||||||
|
- (CPString)messageText
|
||||||
|
{
|
||||||
|
return [_messageLabel stringValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
set the text of the alert's informative text
|
||||||
|
|
||||||
|
@param aText CPString containing the informative text
|
||||||
|
*/
|
||||||
|
- (void)setInformativeText:(CPString)aText
|
||||||
|
{
|
||||||
|
[_informativeLabel setStringValue:aText];
|
||||||
|
_needsLayout = YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
return the content of the message text
|
||||||
|
|
||||||
|
@return CPString containing the message text
|
||||||
|
*/
|
||||||
|
- (CPString)informativeText
|
||||||
|
{
|
||||||
|
return [_informativeLabel stringValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Sets the title of the alert window.
|
||||||
|
This API is not present in Cocoa.
|
||||||
|
@param aTitle CPString containing the window title
|
||||||
|
*/
|
||||||
|
- (void)setTitle:(CPString)aTitle
|
||||||
|
{
|
||||||
|
_title = aTitle;
|
||||||
|
[_window setTitle:aTitle];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
set the accessory view
|
||||||
|
|
||||||
|
@param aView the accessory view
|
||||||
|
*/
|
||||||
|
- (void)setAccessoryView:(CPView)aView
|
||||||
|
{
|
||||||
|
_accessoryView = aView;
|
||||||
|
_needsLayout = YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
set if alert shows the suppression button
|
||||||
|
|
||||||
|
@param shouldShowSuppressionButton YES or NO
|
||||||
|
*/
|
||||||
|
- (void)setShowsSuppressionButton:(BOOL)shouldShowSuppressionButton
|
||||||
|
{
|
||||||
|
_showSuppressionButton = shouldShowSuppressionButton;
|
||||||
|
_needsLayout = YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark Accessing Buttons
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Adds a button with a given title to the receiver.
|
||||||
|
Buttons will be added starting from the right hand side of the \c CPAlert panel.
|
||||||
|
The first button will have the index 0, the second button 1 and so on.
|
||||||
|
|
||||||
|
The first button will automatically be given a key equivalent of Return,
|
||||||
|
and any button titled "Cancel" will be given a key equivalent of Escape.
|
||||||
|
|
||||||
|
You really shouldn't need more than 3 buttons.
|
||||||
|
|
||||||
|
@param title the title of the button
|
||||||
|
*/
|
||||||
|
- (void)addButtonWithTitle:(CPString)aTitle
|
||||||
|
{
|
||||||
|
var bounds = [[_window contentView] bounds],
|
||||||
|
count = [_buttons count],
|
||||||
|
|
||||||
|
button = [[CPButton alloc] initWithFrame:CGRectMakeZero()];
|
||||||
|
|
||||||
|
[button setTitle:aTitle];
|
||||||
|
[button setTag:count];
|
||||||
|
[button setTarget:self];
|
||||||
|
[button setAction:@selector(_takeReturnCodeFrom:)];
|
||||||
|
|
||||||
|
[[_window contentView] addSubview:button];
|
||||||
|
|
||||||
|
if (count == 0)
|
||||||
|
[button setKeyEquivalent:CPCarriageReturnCharacter];
|
||||||
|
else if ([aTitle lowercaseString] === @"cancel")
|
||||||
|
[button setKeyEquivalent:CPEscapeFunctionKey];
|
||||||
|
|
||||||
|
[_buttons insertObject:button atIndex:0];
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark Layout
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
|
- (void)_layoutMessageView
|
||||||
|
{
|
||||||
|
var inset = [self currentValueForThemeAttribute:@"content-inset"],
|
||||||
|
sizeWithFontCorrection = 6.0,
|
||||||
|
messageLabelWidth,
|
||||||
|
messageLabelTextSize;
|
||||||
|
|
||||||
|
[_messageLabel setTextColor:[self currentValueForThemeAttribute:@"message-text-color"]];
|
||||||
|
[_messageLabel setFont:[self currentValueForThemeAttribute:@"message-text-font"]];
|
||||||
|
[_messageLabel setTextShadowColor:[self currentValueForThemeAttribute:@"message-text-shadow-color"]];
|
||||||
|
[_messageLabel setTextShadowOffset:[self currentValueForThemeAttribute:@"message-text-shadow-offset"]];
|
||||||
|
[_messageLabel setAlignment:[self currentValueForThemeAttribute:@"message-text-alignment"]];
|
||||||
|
[_messageLabel setLineBreakMode:CPLineBreakByWordWrapping];
|
||||||
|
|
||||||
|
messageLabelWidth = CGRectGetWidth([[_window contentView] frame]) - inset.left - inset.right;
|
||||||
|
messageLabelTextSize = [[_messageLabel stringValue] sizeWithFont:[_messageLabel font] inWidth:messageLabelWidth];
|
||||||
|
|
||||||
|
[_messageLabel setFrame:CGRectMake(inset.left, inset.top, messageLabelTextSize.width, messageLabelTextSize.height + sizeWithFontCorrection)];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
|
- (void)_layoutInformativeView
|
||||||
|
{
|
||||||
|
var inset = [self currentValueForThemeAttribute:@"content-inset"],
|
||||||
|
defaultElementsMargin = [self currentValueForThemeAttribute:@"default-elements-margin"],
|
||||||
|
sizeWithFontCorrection = 6.0,
|
||||||
|
informativeLabelWidth,
|
||||||
|
informativeLabelOriginY,
|
||||||
|
informativeLabelTextSize;
|
||||||
|
|
||||||
|
[_informativeLabel setTextColor:[self currentValueForThemeAttribute:@"informative-text-color"]];
|
||||||
|
[_informativeLabel setFont:[self currentValueForThemeAttribute:@"informative-text-font"]];
|
||||||
|
[_informativeLabel setTextShadowColor:[self currentValueForThemeAttribute:@"informative-text-shadow-color"]];
|
||||||
|
[_informativeLabel setTextShadowOffset:[self currentValueForThemeAttribute:@"informative-text-shadow-offset"]];
|
||||||
|
[_informativeLabel setAlignment:[self currentValueForThemeAttribute:@"informative-text-alignment"]];
|
||||||
|
[_informativeLabel setLineBreakMode:CPLineBreakByWordWrapping];
|
||||||
|
|
||||||
|
informativeLabelWidth = CGRectGetWidth([[_window contentView] frame]) - inset.left - inset.right,
|
||||||
|
informativeLabelOriginY = [_messageLabel frameOrigin].y + [_messageLabel frameSize].height + defaultElementsMargin,
|
||||||
|
informativeLabelTextSize = [[_informativeLabel stringValue] sizeWithFont:[_informativeLabel font] inWidth:informativeLabelWidth];
|
||||||
|
|
||||||
|
[_informativeLabel setFrame:CGRectMake(inset.left, informativeLabelOriginY, informativeLabelTextSize.width, informativeLabelTextSize.height + sizeWithFontCorrection)];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
|
- (void)_layoutAccessoryView
|
||||||
|
{
|
||||||
|
if (!_accessoryView)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var inset = [self currentValueForThemeAttribute:@"content-inset"],
|
||||||
|
defaultElementsMargin = [self currentValueForThemeAttribute:@"default-elements-margin"],
|
||||||
|
accessoryViewWidth = CGRectGetWidth([[_window contentView] frame]) - inset.left - inset.right,
|
||||||
|
accessoryViewOriginY = CGRectGetMaxY([_informativeLabel frame]) + defaultElementsMargin;
|
||||||
|
|
||||||
|
[_accessoryView setFrameOrigin:CGPointMake(inset.left, accessoryViewOriginY)];
|
||||||
|
[[_window contentView] addSubview:_accessoryView];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
|
- (void)_layoutSuppressionButton
|
||||||
|
{
|
||||||
|
if (!_showSuppressionButton)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var inset = [self currentValueForThemeAttribute:@"content-inset"],
|
||||||
|
suppressionViewXOffset = [self currentValueForThemeAttribute:@"suppression-button-x-offset"],
|
||||||
|
suppressionViewYOffset = [self currentValueForThemeAttribute:@"suppression-button-y-offset"],
|
||||||
|
defaultElementsMargin = [self currentValueForThemeAttribute:@"default-elements-margin"],
|
||||||
|
suppressionButtonViewOriginY = CGRectGetMaxY([(_accessoryView || _informativeLabel) frame]) + defaultElementsMargin + suppressionViewYOffset;
|
||||||
|
|
||||||
|
[_suppressionButton setTextColor:[self currentValueForThemeAttribute:@"suppression-button-text-color"]];
|
||||||
|
[_suppressionButton setFont:[self currentValueForThemeAttribute:@"suppression-button-text-font"]];
|
||||||
|
[_suppressionButton setTextShadowColor:[self currentValueForThemeAttribute:@"suppression-button-text-shadow-color"]];
|
||||||
|
[_suppressionButton setTextShadowOffset:[self currentValueForThemeAttribute:@"suppression-button-text-shadow-offset"]];
|
||||||
|
[_suppressionButton sizeToFit];
|
||||||
|
|
||||||
|
[_suppressionButton setFrameOrigin:CGPointMake(inset.left + suppressionViewXOffset, suppressionButtonViewOriginY)];
|
||||||
|
[[_window contentView] addSubview:_suppressionButton];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
|
- (CGSize)_layoutButtonsFromView:(CPView)lastView
|
||||||
|
{
|
||||||
|
var inset = [self currentValueForThemeAttribute:@"content-inset"],
|
||||||
|
minimumSize = [self currentValueForThemeAttribute:@"size"],
|
||||||
|
buttonOffset = [self currentValueForThemeAttribute:@"button-offset"],
|
||||||
|
helpLeftOffset = [self currentValueForThemeAttribute:@"help-image-left-offset"],
|
||||||
|
aRepresentativeButton = [_buttons objectAtIndex:0],
|
||||||
|
defaultElementsMargin = [self currentValueForThemeAttribute:@"default-elements-margin"],
|
||||||
|
panelSize = [[_window contentView] frame].size,
|
||||||
|
buttonsOriginY,
|
||||||
|
offsetX;
|
||||||
|
|
||||||
|
[aRepresentativeButton setTheme:[self theme]];
|
||||||
|
[aRepresentativeButton sizeToFit];
|
||||||
|
|
||||||
|
panelSize.height = CGRectGetMaxY([lastView frame]) + defaultElementsMargin + [aRepresentativeButton frameSize].height;
|
||||||
|
if (panelSize.height < minimumSize.height)
|
||||||
|
panelSize.height = minimumSize.height;
|
||||||
|
|
||||||
|
buttonsOriginY = panelSize.height - [aRepresentativeButton frameSize].height + buttonOffset;
|
||||||
|
offsetX = panelSize.width - inset.right;
|
||||||
|
|
||||||
|
for (var i = [_buttons count] - 1; i >= 0 ; i--)
|
||||||
|
{
|
||||||
|
var button = _buttons[i];
|
||||||
|
[button setTheme:[self theme]];
|
||||||
|
[button sizeToFit];
|
||||||
|
|
||||||
|
var buttonFrame = [button frame],
|
||||||
|
width = MAX(80.0, CGRectGetWidth(buttonFrame)),
|
||||||
|
height = CGRectGetHeight(buttonFrame);
|
||||||
|
|
||||||
|
offsetX -= width;
|
||||||
|
[button setFrame:CGRectMake(offsetX, buttonsOriginY, width, height)];
|
||||||
|
offsetX -= 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_showHelp)
|
||||||
|
{
|
||||||
|
var helpImage = [self currentValueForThemeAttribute:@"help-image"],
|
||||||
|
helpImagePressed = [self currentValueForThemeAttribute:@"help-image-pressed"],
|
||||||
|
helpImageSize = helpImage ? [helpImage size] : CGSizeMakeZero(),
|
||||||
|
helpFrame = CGRectMake(helpLeftOffset, buttonsOriginY, helpImageSize.width, helpImageSize.height);
|
||||||
|
|
||||||
|
[_alertHelpButton setImage:helpImage];
|
||||||
|
[_alertHelpButton setAlternateImage:helpImagePressed];
|
||||||
|
[_alertHelpButton setBordered:NO];
|
||||||
|
[_alertHelpButton setFrame:helpFrame];
|
||||||
|
}
|
||||||
|
|
||||||
|
panelSize.height += [aRepresentativeButton frameSize].height + inset.bottom + buttonOffset;
|
||||||
|
return panelSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
|
- (void)layout
|
||||||
|
{
|
||||||
|
if (!_needsLayout)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!_window)
|
||||||
|
[self _createWindowWithStyle:nil];
|
||||||
|
|
||||||
|
var iconOffset = [self currentValueForThemeAttribute:@"image-offset"],
|
||||||
|
theImage = _icon,
|
||||||
|
finalSize;
|
||||||
|
|
||||||
|
if (!theImage)
|
||||||
|
switch (_alertStyle)
|
||||||
|
{
|
||||||
|
case CPWarningAlertStyle:
|
||||||
|
theImage = [self currentValueForThemeAttribute:@"warning-image"];
|
||||||
|
break;
|
||||||
|
case CPInformationalAlertStyle:
|
||||||
|
theImage = [self currentValueForThemeAttribute:@"information-image"];
|
||||||
|
break;
|
||||||
|
case CPCriticalAlertStyle:
|
||||||
|
theImage = [self currentValueForThemeAttribute:@"error-image"];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
[_alertImageView setImage:theImage];
|
||||||
|
|
||||||
|
var imageSize = theImage ? [theImage size] : CGSizeMakeZero();
|
||||||
|
[_alertImageView setFrame:CGRectMake(iconOffset.x, iconOffset.y, imageSize.width, imageSize.height)];
|
||||||
|
|
||||||
|
[self _layoutMessageView];
|
||||||
|
[self _layoutInformativeView];
|
||||||
|
[self _layoutAccessoryView];
|
||||||
|
[self _layoutSuppressionButton];
|
||||||
|
|
||||||
|
var lastView = _informativeLabel;
|
||||||
|
if (_showSuppressionButton)
|
||||||
|
lastView = _suppressionButton;
|
||||||
|
else if (_accessoryView)
|
||||||
|
lastView = _accessoryView
|
||||||
|
|
||||||
|
finalSize = [self _layoutButtonsFromView:lastView];
|
||||||
|
if ([_window styleMask] & CPDocModalWindowMask)
|
||||||
|
finalSize.height -= 26; // adjust the absence of title bar
|
||||||
|
|
||||||
|
[_window setFrameSize:finalSize];
|
||||||
|
[_window center];
|
||||||
|
|
||||||
|
_needsLayout = NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark Displaying Alerts
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Displays the \c CPAlert panel as a modal dialog. The user will not be
|
||||||
|
able to interact with any other controls until s/he has dismissed the alert
|
||||||
|
by clicking on one of the buttons.
|
||||||
|
*/
|
||||||
|
- (void)runModal
|
||||||
|
{
|
||||||
|
if (!([_window styleMask] & _defaultWindowStyle))
|
||||||
|
{
|
||||||
|
_needsLayout = YES;
|
||||||
|
[self _createWindowWithStyle:_defaultWindowStyle];
|
||||||
|
}
|
||||||
|
|
||||||
|
[self layout];
|
||||||
|
[CPApp runModalForWindow:_window];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Runs the receiver modally as an alert sheet attached to a specified window.
|
||||||
|
|
||||||
|
@param window The parent window for the sheet.
|
||||||
|
@param modalDelegate The delegate for the modal-dialog session.
|
||||||
|
@param alertDidEndSelector Message the alert sends to modalDelegate after the sheet is dismissed.
|
||||||
|
@param contextInfo Contextual data passed to modalDelegate in didEndSelector message.
|
||||||
|
*/
|
||||||
|
- (void)beginSheetModalForWindow:(CPWindow)aWindow modalDelegate:(id)modalDelegate didEndSelector:(SEL)alertDidEndSelector contextInfo:(id)contextInfo
|
||||||
|
{
|
||||||
|
if (!([_window styleMask] & CPDocModalWindowMask))
|
||||||
|
{
|
||||||
|
_needsLayout = YES;
|
||||||
|
[self _createWindowWithStyle:CPDocModalWindowMask];
|
||||||
|
}
|
||||||
|
|
||||||
|
[self layout];
|
||||||
|
|
||||||
|
_modalDelegate = modalDelegate;
|
||||||
|
_didEndSelector = alertDidEndSelector;
|
||||||
|
|
||||||
|
[CPApp beginSheet:_window modalForWindow:aWindow modalDelegate:self didEndSelector:@selector(_alertDidEnd:returnCode:contextInfo:) contextInfo:contextInfo];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Runs the receiver modally as an alert sheet attached to a specified window.
|
||||||
|
|
||||||
|
@param window The parent window for the sheet.
|
||||||
|
*/
|
||||||
|
- (void)beginSheetModalForWindow:(CPWindow)aWindow
|
||||||
|
{
|
||||||
|
[self beginSheetModalForWindow:aWindow modalDelegate:nil didEndSelector:nil contextInfo:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark Private
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
|
- (void)_createWindowWithStyle:(int)forceStyle
|
||||||
|
{
|
||||||
|
var frame = CGRectMakeZero();
|
||||||
|
frame.size = [self currentValueForThemeAttribute:@"size"];
|
||||||
|
|
||||||
|
_window = [[CPWindow alloc] initWithContentRect:frame styleMask:forceStyle || _defaultWindowStyle];
|
||||||
|
|
||||||
|
if (_title)
|
||||||
|
[_window setTitle:_title];
|
||||||
|
|
||||||
|
var contentView = [_window contentView],
|
||||||
|
count = [_buttons count];
|
||||||
|
|
||||||
|
if (count)
|
||||||
|
while (count--)
|
||||||
|
[contentView addSubview:_buttons[count]];
|
||||||
|
else
|
||||||
|
[self addButtonWithTitle:@"OK"];
|
||||||
|
|
||||||
|
[contentView addSubview:_messageLabel];
|
||||||
|
[contentView addSubview:_alertImageView];
|
||||||
|
[contentView addSubview:_informativeLabel];
|
||||||
|
|
||||||
|
if (_showHelp)
|
||||||
|
[contentView addSubview:_alertHelpButton];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
|
- (@action)_showHelp:(id)aSender
|
||||||
|
{
|
||||||
|
if ([_delegate respondsToSelector:@selector(alertShowHelp:)])
|
||||||
|
[_delegate alertShowHelp:self];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
|
- (@action)_takeReturnCodeFrom:(id)aSender
|
||||||
|
{
|
||||||
|
if ([_window isSheet])
|
||||||
|
[CPApp endSheet:_window returnCode:[aSender tag]];
|
||||||
|
else
|
||||||
|
{
|
||||||
|
[CPApp abortModal];
|
||||||
|
[_window close];
|
||||||
|
|
||||||
|
[self _alertDidEnd:_window returnCode:[aSender tag] contextInfo:nil];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
|
- (void)_alertDidEnd:(CPWindow)aWindow returnCode:(int)returnCode contextInfo:(id)contextInfo
|
||||||
|
{
|
||||||
|
if ([_delegate respondsToSelector:@selector(alertDidEnd:returnCode:)])
|
||||||
|
[_delegate alertDidEnd:self returnCode:returnCode];
|
||||||
|
|
||||||
|
if (_didEndSelector)
|
||||||
|
objj_msgSend(_modalDelegate, _didEndSelector, self, returnCode, contextInfo);
|
||||||
|
|
||||||
|
_modalDelegate = nil;
|
||||||
|
_didEndSelector = nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark Theme Attributes
|
||||||
|
|
||||||
+ (CPString)defaultThemeClass
|
+ (CPString)defaultThemeClass
|
||||||
{
|
{
|
||||||
return @"alert";
|
return @"alert";
|
||||||
@@ -104,7 +671,17 @@ CPCriticalAlertStyle = 2;
|
|||||||
CGPointMake(15, 12),
|
CGPointMake(15, 12),
|
||||||
[CPNull null],
|
[CPNull null],
|
||||||
[CPNull null],
|
[CPNull null],
|
||||||
[CPNull null]
|
[CPNull null],
|
||||||
|
[CPNull null],
|
||||||
|
[CPNull null],
|
||||||
|
[CPNull null],
|
||||||
|
0.0,
|
||||||
|
0.0,
|
||||||
|
3.0,
|
||||||
|
[CPColor blackColor],
|
||||||
|
[CPFont systemFontOfSize:12.0],
|
||||||
|
[CPNull null],
|
||||||
|
0.0
|
||||||
]
|
]
|
||||||
forKeys:[@"size", @"content-inset", @"informative-offset", @"button-offset",
|
forKeys:[@"size", @"content-inset", @"informative-offset", @"button-offset",
|
||||||
@"message-text-alignment", @"message-text-color", @"message-text-font", @"message-text-shadow-color", @"message-text-shadow-offset",
|
@"message-text-alignment", @"message-text-color", @"message-text-font", @"message-text-shadow-color", @"message-text-shadow-offset",
|
||||||
@@ -112,359 +689,18 @@ CPCriticalAlertStyle = 2;
|
|||||||
@"image-offset",
|
@"image-offset",
|
||||||
@"information-image",
|
@"information-image",
|
||||||
@"warning-image",
|
@"warning-image",
|
||||||
@"error-image"
|
@"error-image",
|
||||||
|
@"help-image",
|
||||||
|
@"help-image-left-offset",
|
||||||
|
@"help-image-pressed",
|
||||||
|
@"suppression-button-y-offset",
|
||||||
|
@"suppression-button-x-offset",
|
||||||
|
@"default-elements-margin",
|
||||||
|
@"suppression-button-text-color",
|
||||||
|
@"suppression-button-text-font",
|
||||||
|
@"suppression-button-text-shadow-color",
|
||||||
|
@"suppression-button-text-shadow-offset"
|
||||||
]];
|
]];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
Initializes a \c CPAlert panel with the default alert style \c CPWarningAlertStyle.
|
|
||||||
*/
|
|
||||||
- (id)init
|
|
||||||
{
|
|
||||||
if (self = [super init])
|
|
||||||
{
|
|
||||||
_buttons = [CPArray array];
|
|
||||||
_alertStyle = CPWarningAlertStyle;
|
|
||||||
_alertPanel = nil;
|
|
||||||
_windowStyle = nil;
|
|
||||||
_didEndSelector = nil;
|
|
||||||
|
|
||||||
_messageLabel = [CPTextField labelWithTitle:@"Alert"];
|
|
||||||
_alertImageView = [[CPImageView alloc] initWithFrame:CGRectMakeZero()];
|
|
||||||
_informativeLabel = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
|
|
||||||
}
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
Sets the window appearance. If CPHUDBackgroundWindowMask is set, the default HUD theme
|
|
||||||
will be activated.
|
|
||||||
|
|
||||||
@param styleMask - Either CPHUDBackgroundWindowMask or nil for standard.
|
|
||||||
*/
|
|
||||||
- (void)setWindowStyle:(int)styleMask
|
|
||||||
{
|
|
||||||
_windowStyle = styleMask;
|
|
||||||
|
|
||||||
[self setTheme:(_windowStyle & CPHUDBackgroundWindowMask) ? [CPTheme defaultHudTheme] : [CPTheme defaultTheme]];
|
|
||||||
|
|
||||||
// We'll need to recreate the panel to get the new window style.
|
|
||||||
_alertPanel = nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)_createPanel
|
|
||||||
{
|
|
||||||
var frame = CGRectMakeZero();
|
|
||||||
frame.size = [self currentValueForThemeAttribute:@"size"];
|
|
||||||
_alertPanel = [[CPPanel alloc] initWithContentRect:frame styleMask:_windowStyle ? _windowStyle | CPTitledWindowMask : CPTitledWindowMask];
|
|
||||||
|
|
||||||
var contentView = [_alertPanel contentView],
|
|
||||||
count = [_buttons count];
|
|
||||||
|
|
||||||
if (count)
|
|
||||||
{
|
|
||||||
while (count--)
|
|
||||||
[contentView addSubview:_buttons[count]];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
[self addButtonWithTitle:@"OK"];
|
|
||||||
|
|
||||||
[contentView addSubview:_messageLabel];
|
|
||||||
[contentView addSubview:_alertImageView];
|
|
||||||
[contentView addSubview:_informativeLabel];
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
Sets the window's title. If this is not defined, a default title based on your warning level will be used.
|
|
||||||
@param aTitle the title to use in place of the default. Set to nil to use default.
|
|
||||||
*/
|
|
||||||
- (void)setTitle:(CPString)aTitle
|
|
||||||
{
|
|
||||||
_windowTitle = aTitle;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
Gets the window's title.
|
|
||||||
*/
|
|
||||||
- (CPString)title
|
|
||||||
{
|
|
||||||
return _windowTitle;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
Gets the window's style.
|
|
||||||
*/
|
|
||||||
- (int)windowStyle
|
|
||||||
{
|
|
||||||
return _windowStyle;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
Sets the receiver’s delegate.
|
|
||||||
@param delegate - Delegate for the alert. nil removes the delegate.
|
|
||||||
*/
|
|
||||||
- (void)setDelegate:(id)delegate
|
|
||||||
{
|
|
||||||
_delegate = delegate;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
Gets the receiver's delegate.
|
|
||||||
*/
|
|
||||||
- (void)delegate
|
|
||||||
{
|
|
||||||
return _delegate;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
Sets the alert style of the receiver.
|
|
||||||
@param style - Alert style for the alert.
|
|
||||||
*/
|
|
||||||
- (void)setAlertStyle:(CPAlertStyle)style
|
|
||||||
{
|
|
||||||
_alertStyle = style;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
Gets the alert style.
|
|
||||||
*/
|
|
||||||
- (CPAlertStyle)alertStyle
|
|
||||||
{
|
|
||||||
return _alertStyle;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
Sets the receiver’s message text, or title, to a given text.
|
|
||||||
@param messageText - Message text for the alert.
|
|
||||||
*/
|
|
||||||
- (void)setMessageText:(CPString)messageText
|
|
||||||
{
|
|
||||||
[_messageLabel setStringValue:messageText];
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
Returns the receiver's message text body.
|
|
||||||
*/
|
|
||||||
- (CPString)messageText
|
|
||||||
{
|
|
||||||
return [_messageLabel stringValue];
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
Sets the receiver's informative text, shown below the message text.
|
|
||||||
@param informativeText - The informative text.
|
|
||||||
*/
|
|
||||||
- (void)setInformativeText:(CPString)informativeText
|
|
||||||
{
|
|
||||||
[_informativeLabel setStringValue:informativeText];
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
Returns the receiver's informative text.
|
|
||||||
*/
|
|
||||||
- (CPString)informativeText
|
|
||||||
{
|
|
||||||
return [_informativeLabel stringValue];
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
Adds a button with a given title to the receiver.
|
|
||||||
Buttons will be added starting from the right hand side of the \c CPAlert panel.
|
|
||||||
The first button will have the index 0, the second button 1 and so on.
|
|
||||||
|
|
||||||
The first button will automatically be given a key equivalent of Return,
|
|
||||||
and any button titled "Cancel" will be given a key equivalent of Escape.
|
|
||||||
|
|
||||||
You really shouldn't need more than 3 buttons.
|
|
||||||
*/
|
|
||||||
- (void)addButtonWithTitle:(CPString)title
|
|
||||||
{
|
|
||||||
var bounds = [[_alertPanel contentView] bounds],
|
|
||||||
button = [[CPButton alloc] initWithFrame:CGRectMakeZero()],
|
|
||||||
_buttonCount = [_buttons count];
|
|
||||||
|
|
||||||
[button setTitle:title];
|
|
||||||
[button setTarget:self];
|
|
||||||
[button setTag:_buttonCount];
|
|
||||||
[button setAction:@selector(_dismissAlert:)];
|
|
||||||
|
|
||||||
[[_alertPanel contentView] addSubview:button];
|
|
||||||
|
|
||||||
if (_buttonCount == 0)
|
|
||||||
[button setKeyEquivalent:CPCarriageReturnCharacter];
|
|
||||||
else if ([title lowercaseString] === "cancel")
|
|
||||||
[button setKeyEquivalent:CPEscapeFunctionKey];
|
|
||||||
else
|
|
||||||
[button setKeyEquivalent:nil];
|
|
||||||
|
|
||||||
[_buttons insertObject:button atIndex:0];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)layoutPanel
|
|
||||||
{
|
|
||||||
if (!_alertPanel)
|
|
||||||
[self _createPanel];
|
|
||||||
|
|
||||||
var inset = [self currentValueForThemeAttribute:@"content-inset"],
|
|
||||||
iconOffset = [self currentValueForThemeAttribute:@"image-offset"],
|
|
||||||
theTitle,
|
|
||||||
theImage;
|
|
||||||
|
|
||||||
switch (_alertStyle)
|
|
||||||
{
|
|
||||||
case CPWarningAlertStyle: theImage = [self currentValueForThemeAttribute:@"warning-image"];
|
|
||||||
theTitle = @"Warning";
|
|
||||||
break;
|
|
||||||
case CPInformationalAlertStyle: theImage = [self currentValueForThemeAttribute:@"information-image"];
|
|
||||||
theTitle = @"Information";
|
|
||||||
break;
|
|
||||||
case CPCriticalAlertStyle: theImage = [self currentValueForThemeAttribute:@"error-image"];
|
|
||||||
theTitle = @"Error";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
[_alertImageView setImage:theImage];
|
|
||||||
|
|
||||||
var imageSize = theImage ? [theImage size] : CGSizeMakeZero();
|
|
||||||
[_alertImageView setFrame:CGRectMake(iconOffset.x, iconOffset.y, imageSize.width, imageSize.height)];
|
|
||||||
|
|
||||||
[_alertPanel setTitle:_windowTitle ? _windowTitle : theTitle];
|
|
||||||
[_alertPanel setFloatingPanel:YES];
|
|
||||||
[_alertPanel center];
|
|
||||||
|
|
||||||
[_messageLabel setTextColor:[self currentValueForThemeAttribute:@"message-text-color"]];
|
|
||||||
[_messageLabel setFont:[self currentValueForThemeAttribute:@"message-text-font"]];
|
|
||||||
[_messageLabel setTextShadowColor:[self currentValueForThemeAttribute:@"message-text-shadow-color"]];
|
|
||||||
[_messageLabel setTextShadowOffset:[self currentValueForThemeAttribute:@"message-text-shadow-offset"]];
|
|
||||||
[_messageLabel setAlignment:[self currentValueForThemeAttribute:@"message-text-alignment"]];
|
|
||||||
[_messageLabel setLineBreakMode:CPLineBreakByWordWrapping];
|
|
||||||
|
|
||||||
[_informativeLabel setTextColor:[self currentValueForThemeAttribute:@"informative-text-color"]];
|
|
||||||
[_informativeLabel setFont:[self currentValueForThemeAttribute:@"informative-text-font"]];
|
|
||||||
[_informativeLabel setTextShadowColor:[self currentValueForThemeAttribute:@"informative-text-shadow-color"]];
|
|
||||||
[_informativeLabel setTextShadowOffset:[self currentValueForThemeAttribute:@"informative-text-shadow-offset"]];
|
|
||||||
[_informativeLabel setLineBreakMode:CPLineBreakByWordWrapping];
|
|
||||||
|
|
||||||
// FIXME sizeWithFontCorrection shouldn't be needed.
|
|
||||||
var bounds = [[_alertPanel contentView] bounds],
|
|
||||||
offsetX = CGRectGetWidth(bounds) - inset.right,
|
|
||||||
informativeOffset = [self currentValueForThemeAttribute:@"informative-offset"],
|
|
||||||
buttonOffset = [self currentValueForThemeAttribute:@"button-offset"],
|
|
||||||
|
|
||||||
textWidth = offsetX - inset.left,
|
|
||||||
messageSize = [([_messageLabel stringValue] || " ") sizeWithFont:[_messageLabel font] inWidth:textWidth],
|
|
||||||
informationString = [_informativeLabel stringValue],
|
|
||||||
informativeSize = [(informationString || " ") sizeWithFont:[_informativeLabel font] inWidth:textWidth],
|
|
||||||
sizeWithFontCorrection = 6.0;
|
|
||||||
|
|
||||||
[_messageLabel setFrame:CGRectMake(inset.left, inset.top, textWidth, messageSize.height + sizeWithFontCorrection)];
|
|
||||||
[_informativeLabel setFrame:CGRectMake(inset.left, CGRectGetMaxY([_messageLabel frame]) + informativeOffset, textWidth, informativeSize.height + sizeWithFontCorrection)];
|
|
||||||
// Don't let an empty informative label partially cover the buttons.
|
|
||||||
[_informativeLabel setHidden:!informationString];
|
|
||||||
|
|
||||||
var aRepresentativeButton = _buttons[0],
|
|
||||||
buttonY = MAX(CGRectGetMaxY([_alertImageView frame]), CGRectGetMaxY(informationString ? [_informativeLabel frame] : [_messageLabel frame])) + buttonOffset; // the lower of the bottom of the text and the bottom of the icon.
|
|
||||||
|
|
||||||
[aRepresentativeButton setTheme:[self theme]];
|
|
||||||
[aRepresentativeButton sizeToFit];
|
|
||||||
|
|
||||||
// Make the window just tall enough to fit everything. Bit of a hack really.
|
|
||||||
var minimumSize = [self currentValueForThemeAttribute:@"size"],
|
|
||||||
desiredHeight = MAX(minimumSize.height, buttonY + CGRectGetHeight([aRepresentativeButton bounds]) + inset.bottom),
|
|
||||||
deltaY = desiredHeight - CGRectGetHeight(bounds),
|
|
||||||
frameSize = CGSizeMakeCopy([_alertPanel frame].size);
|
|
||||||
|
|
||||||
frameSize.height += deltaY;
|
|
||||||
[_alertPanel setFrameSize:frameSize];
|
|
||||||
|
|
||||||
var count = [_buttons count];
|
|
||||||
|
|
||||||
while (count--)
|
|
||||||
{
|
|
||||||
var button = _buttons[count];
|
|
||||||
[button setTheme:[self theme]];
|
|
||||||
[button sizeToFit];
|
|
||||||
|
|
||||||
var buttonBounds = [button bounds],
|
|
||||||
width = MAX(80.0, CGRectGetWidth(buttonBounds)),
|
|
||||||
height = CGRectGetHeight(buttonBounds);
|
|
||||||
|
|
||||||
offsetX -= width;
|
|
||||||
[button setFrame:CGRectMake(offsetX, buttonY, width, height)];
|
|
||||||
offsetX -= 10;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
Displays the \c CPAlert panel as a modal dialog. The user will not be
|
|
||||||
able to interact with any other controls until s/he has dismissed the alert
|
|
||||||
by clicking on one of the buttons.
|
|
||||||
*/
|
|
||||||
- (void)runModal
|
|
||||||
{
|
|
||||||
[self layoutPanel];
|
|
||||||
[CPApp runModalForWindow:_alertPanel];
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
Runs the receiver modally as an alert sheet attached to a specified window.
|
|
||||||
|
|
||||||
@param window The parent window for the sheet.
|
|
||||||
@param modalDelegate The delegate for the modal-dialog session.
|
|
||||||
@param alertDidEndSelector Message the alert sends to modalDelegate after the sheet is dismissed.
|
|
||||||
@param contextInfo Contextual data passed to modalDelegate in didEndSelector message.
|
|
||||||
*/
|
|
||||||
- (void)beginSheetModalForWindow:(CPWindow)window modalDelegate:(id)modalDelegate didEndSelector:(SEL)alertDidEndSelector contextInfo:(void)contextInfo
|
|
||||||
{
|
|
||||||
if (!(_windowStyle & CPDocModalWindowMask))
|
|
||||||
[self setWindowStyle:CPDocModalWindowMask];
|
|
||||||
[self layoutPanel];
|
|
||||||
|
|
||||||
_didEndSelector = alertDidEndSelector;
|
|
||||||
_modalDelegate = modalDelegate;
|
|
||||||
|
|
||||||
[CPApp beginSheet:_alertPanel modalForWindow:window modalDelegate:self didEndSelector:@selector(_alertDidEnd:returnCode:contextInfo:) contextInfo:contextInfo];
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
Runs the receiver modally as an alert sheet attached to a specified window.
|
|
||||||
|
|
||||||
@param window The parent window for the sheet.
|
|
||||||
*/
|
|
||||||
- (void)beginSheetModalForWindow:(CPWindow)window
|
|
||||||
{
|
|
||||||
if (!(_windowStyle & CPDocModalWindowMask))
|
|
||||||
[self setWindowStyle:CPDocModalWindowMask];
|
|
||||||
[self layoutPanel];
|
|
||||||
|
|
||||||
[CPApp beginSheet:_alertPanel modalForWindow:window modalDelegate:self didEndSelector:@selector(_alertDidEnd:returnCode:contextInfo:) contextInfo:nil];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)_alertDidEnd:(CPWindow)aSheet returnCode:(CPInteger)returnCode contextInfo:(id)contextInfo
|
|
||||||
{
|
|
||||||
if ([_delegate respondsToSelector:@selector(alertDidEnd:returnCode:)])
|
|
||||||
[_delegate alertDidEnd:self returnCode:returnCode];
|
|
||||||
|
|
||||||
if (_didEndSelector)
|
|
||||||
objj_msgSend(_modalDelegate, _didEndSelector, self, returnCode, contextInfo);
|
|
||||||
|
|
||||||
_didEndSelector = nil;
|
|
||||||
_modalDelegate = nil;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* @ignore */
|
|
||||||
- (void)_dismissAlert:(CPButton)button
|
|
||||||
{
|
|
||||||
if ([_alertPanel isSheet])
|
|
||||||
[CPApp endSheet:_alertPanel returnCode:[button tag]];
|
|
||||||
else
|
|
||||||
{
|
|
||||||
[CPApp abortModal];
|
|
||||||
[_alertPanel close];
|
|
||||||
|
|
||||||
[self _alertDidEnd:nil returnCode:[button tag] contextInfo:nil];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -312,7 +312,7 @@ ACTUAL_FRAME_RATE = 0;
|
|||||||
[_timingFunction getControlPointAtIndex:1 values:c1];
|
[_timingFunction getControlPointAtIndex:1 values:c1];
|
||||||
[_timingFunction getControlPointAtIndex:2 values:c2];
|
[_timingFunction getControlPointAtIndex:2 values:c2];
|
||||||
|
|
||||||
return CubicBezierAtTime(t,c1[0],c1[1],c2[0],c2[1],_duration);
|
return CubicBezierAtTime(t, c1[0], c1[1], c2[0], c2[1], _duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -320,28 +320,104 @@ ACTUAL_FRAME_RATE = 0;
|
|||||||
// currently used function to determine time
|
// currently used function to determine time
|
||||||
// 1:1 conversion to js from webkit source files
|
// 1:1 conversion to js from webkit source files
|
||||||
// UnitBezier.h, WebCore_animation_AnimationBase.cpp
|
// UnitBezier.h, WebCore_animation_AnimationBase.cpp
|
||||||
var CubicBezierAtTime = function CubicBezierAtTime(t,p1x,p1y,p2x,p2y,duration)
|
var CubicBezierAtTime = function CubicBezierAtTime(t, p1x, p1y, p2x, p2y, duration)
|
||||||
{
|
{
|
||||||
var ax=0,bx=0,cx=0,ay=0,by=0,cy=0;
|
var ax = 0,
|
||||||
|
bx = 0,
|
||||||
|
cx = 0,
|
||||||
|
ay = 0,
|
||||||
|
by = 0,
|
||||||
|
cy = 0;
|
||||||
// `ax t^3 + bx t^2 + cx t' expanded using Horner's rule.
|
// `ax t^3 + bx t^2 + cx t' expanded using Horner's rule.
|
||||||
function sampleCurveX(t) {return ((ax*t+bx)*t+cx)*t;};
|
function sampleCurveX(t)
|
||||||
function sampleCurveY(t) {return ((ay*t+by)*t+cy)*t;};
|
{
|
||||||
function sampleCurveDerivativeX(t) {return (3.0*ax*t+2.0*bx)*t+cx;};
|
return ((ax * t + bx) * t + cx) * t;
|
||||||
|
}
|
||||||
|
|
||||||
|
function sampleCurveY(t)
|
||||||
|
{
|
||||||
|
return ((ay * t + by) * t + cy) * t;
|
||||||
|
}
|
||||||
|
|
||||||
|
function sampleCurveDerivativeX(t)
|
||||||
|
{
|
||||||
|
return (3.0 * ax * t + 2.0 * bx) * t + cx;
|
||||||
|
}
|
||||||
|
|
||||||
// The epsilon value to pass given that the animation is going to run over |duration| seconds. The longer the animation, the more precision is needed in the timing function result to avoid ugly discontinuities.
|
// The epsilon value to pass given that the animation is going to run over |duration| seconds. The longer the animation, the more precision is needed in the timing function result to avoid ugly discontinuities.
|
||||||
function solveEpsilon(duration) {return 1.0/(200.0*duration);};
|
function solveEpsilon(duration)
|
||||||
function solve(x,epsilon) {return sampleCurveY(solveCurveX(x,epsilon));};
|
{
|
||||||
|
return 1.0 / (200.0 * duration);
|
||||||
|
}
|
||||||
|
|
||||||
|
function solve(x, epsilon)
|
||||||
|
{
|
||||||
|
return sampleCurveY(solveCurveX(x, epsilon));
|
||||||
|
}
|
||||||
|
|
||||||
// Given an x value, find a parametric value it came from.
|
// Given an x value, find a parametric value it came from.
|
||||||
function solveCurveX(x,epsilon) {var t0,t1,t2,x2,d2,i;
|
function solveCurveX(x, epsilon)
|
||||||
function fabs(n) {if(n>=0) {return n;}else {return 0-n;}};
|
{
|
||||||
|
var t0,
|
||||||
|
t1,
|
||||||
|
t2 = x,
|
||||||
|
x2,
|
||||||
|
d2,
|
||||||
|
i = 0;
|
||||||
|
|
||||||
// First try a few iterations of Newton's method -- normally very fast.
|
// First try a few iterations of Newton's method -- normally very fast.
|
||||||
for(t2=x, i=0; i<8; i++) {x2=sampleCurveX(t2)-x; if(fabs(x2)<epsilon) {return t2;} d2=sampleCurveDerivativeX(t2); if(fabs(d2)<1e-6) {break;} t2=t2-x2/d2;}
|
for (; i < 8; i++)
|
||||||
|
{
|
||||||
|
x2 = sampleCurveX(t2) - x;
|
||||||
|
|
||||||
|
if (ABS(x2) < epsilon)
|
||||||
|
return t2;
|
||||||
|
|
||||||
|
d2 = sampleCurveDerivativeX(t2);
|
||||||
|
|
||||||
|
if (ABS(d2) < 1e-6)
|
||||||
|
break;
|
||||||
|
|
||||||
|
t2 = t2 - x2 / d2;
|
||||||
|
}
|
||||||
|
|
||||||
// Fall back to the bisection method for reliability.
|
// Fall back to the bisection method for reliability.
|
||||||
t0=0.0; t1=1.0; t2=x; if(t2<t0) {return t0;} if(t2>t1) {return t1;}
|
t0 = 0.0;
|
||||||
while(t0<t1) {x2=sampleCurveX(t2); if(fabs(x2-x)<epsilon) {return t2;} if(x>x2) {t0=t2;}else {t1=t2;} t2=(t1-t0)*.5+t0;}
|
t1 = 1.0;
|
||||||
|
t2 = x;
|
||||||
|
|
||||||
|
if (t2 < t0)
|
||||||
|
return t0;
|
||||||
|
|
||||||
|
if (t2 > t1)
|
||||||
|
return t1;
|
||||||
|
|
||||||
|
while (t0 < t1)
|
||||||
|
{
|
||||||
|
x2 = sampleCurveX(t2);
|
||||||
|
|
||||||
|
if (ABS(x2 - x) < epsilon)
|
||||||
|
return t2;
|
||||||
|
|
||||||
|
if (x > x2)
|
||||||
|
t0 = t2;
|
||||||
|
|
||||||
|
else
|
||||||
|
t1 = t2;
|
||||||
|
|
||||||
|
t2 = (t1 - t0) * 0.5 + t0;
|
||||||
|
}
|
||||||
|
|
||||||
return t2; // Failure.
|
return t2; // Failure.
|
||||||
};
|
};
|
||||||
// Calculate the polynomial coefficients, implicit first and last control points are (0,0) and (1,1).
|
// Calculate the polynomial coefficients, implicit first and last control points are (0,0) and (1,1).
|
||||||
cx=3.0*p1x; bx=3.0*(p2x-p1x)-cx; ax=1.0-cx-bx; cy=3.0*p1y; by=3.0*(p2y-p1y)-cy; ay=1.0-cy-by;
|
cx = 3.0 * p1x;
|
||||||
|
bx = 3.0 * (p2x - p1x) - cx;
|
||||||
|
ax = 1.0 - cx - bx;
|
||||||
|
cy = 3.0 * p1y;
|
||||||
|
by = 3.0 * (p2y - p1y) - cy;
|
||||||
|
ay = 1.0 - cy - by;
|
||||||
|
|
||||||
// Convert from input time to parametric value in curve, then from that to output time.
|
// Convert from input time to parametric value in curve, then from that to output time.
|
||||||
return solve(t, solveEpsilon(duration));
|
return solve(t, solveEpsilon(duration));
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -90,7 +90,6 @@ CPRunContinuesResponse = -1002;
|
|||||||
CPWindow _previousKeyWindow;
|
CPWindow _previousKeyWindow;
|
||||||
CPWindow _previousMainWindow;
|
CPWindow _previousMainWindow;
|
||||||
|
|
||||||
CPMenu _mainMenu;
|
|
||||||
CPDocumentController _documentController;
|
CPDocumentController _documentController;
|
||||||
|
|
||||||
CPModalSession _currentSession;
|
CPModalSession _currentSession;
|
||||||
@@ -530,7 +529,7 @@ CPRunContinuesResponse = -1002;
|
|||||||
- (BOOL)_handleKeyEquivalent:(CPEvent)anEvent
|
- (BOOL)_handleKeyEquivalent:(CPEvent)anEvent
|
||||||
{
|
{
|
||||||
return [[self keyWindow] performKeyEquivalent:anEvent] ||
|
return [[self keyWindow] performKeyEquivalent:anEvent] ||
|
||||||
[_mainMenu performKeyEquivalent:anEvent];
|
[[self mainMenu] performKeyEquivalent:anEvent];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -637,7 +636,7 @@ CPRunContinuesResponse = -1002;
|
|||||||
*/
|
*/
|
||||||
- (CPMenu)mainMenu
|
- (CPMenu)mainMenu
|
||||||
{
|
{
|
||||||
return _mainMenu;
|
return [self menu];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -645,16 +644,21 @@ CPRunContinuesResponse = -1002;
|
|||||||
@param aMenu the menu to set for the application
|
@param aMenu the menu to set for the application
|
||||||
*/
|
*/
|
||||||
- (void)setMainMenu:(CPMenu)aMenu
|
- (void)setMainMenu:(CPMenu)aMenu
|
||||||
|
{
|
||||||
|
[self setMenu:aMenu];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setMenu:(CPMenu)aMenu
|
||||||
{
|
{
|
||||||
if ([aMenu _menuName] === "CPMainMenu")
|
if ([aMenu _menuName] === "CPMainMenu")
|
||||||
{
|
{
|
||||||
if (_mainMenu === aMenu)
|
if ([self menu] === aMenu)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_mainMenu = aMenu;
|
[super setMenu:aMenu];
|
||||||
|
|
||||||
if ([CPPlatform supportsNativeMainMenu])
|
if ([CPPlatform supportsNativeMainMenu])
|
||||||
window.cpSetMainMenu(_mainMenu);
|
window.cpSetMainMenu([self menu]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
[aMenu _setMenuName:@"CPMainMenu"];
|
[aMenu _setMenuName:@"CPMainMenu"];
|
||||||
@@ -908,7 +912,7 @@ CPRunContinuesResponse = -1002;
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([args class] != CPArray)
|
if (![args isKindOfClass:CPArray])
|
||||||
args = [CPArray arrayWithObject:args];
|
args = [CPArray arrayWithObject:args];
|
||||||
|
|
||||||
_args = args;
|
_args = args;
|
||||||
|
|||||||
@@ -29,7 +29,14 @@
|
|||||||
@import "CPObjectController.j"
|
@import "CPObjectController.j"
|
||||||
@import "CPKeyValueBinding.j"
|
@import "CPKeyValueBinding.j"
|
||||||
|
|
||||||
|
/*!
|
||||||
|
|
||||||
|
@class CPArrayController
|
||||||
|
|
||||||
|
CPArrayController is a bindings compatible class that manages an array.
|
||||||
|
CPArrayController also provides selection management and sorting capabilities.
|
||||||
|
|
||||||
|
*/
|
||||||
@implementation CPArrayController : CPObjectController
|
@implementation CPArrayController : CPObjectController
|
||||||
{
|
{
|
||||||
BOOL _avoidsEmptySelection;
|
BOOL _avoidsEmptySelection;
|
||||||
@@ -102,12 +109,14 @@
|
|||||||
return [CPSet setWithObjects:"selectionIndexes"];
|
return [CPSet setWithObjects:"selectionIndexes"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
- (id)init
|
- (id)init
|
||||||
{
|
{
|
||||||
self = [super init];
|
self = [super init];
|
||||||
|
|
||||||
if (self)
|
if (self)
|
||||||
{
|
{
|
||||||
|
_sortDescriptors = [CPArray array];
|
||||||
_selectionIndexes = [CPIndexSet indexSet];
|
_selectionIndexes = [CPIndexSet indexSet];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,37 +127,64 @@
|
|||||||
{
|
{
|
||||||
[self _setContentArray:[[self newObject]]];
|
[self _setContentArray:[[self newObject]]];
|
||||||
}
|
}
|
||||||
|
/*!
|
||||||
|
Returns YES if the selection should try to be preserved when the content changes, otherwise NO.
|
||||||
|
@return BOOL YES if the selection is preserved, otherwise NO.
|
||||||
|
*/
|
||||||
- (BOOL)preservesSelection
|
- (BOOL)preservesSelection
|
||||||
{
|
{
|
||||||
return _preservesSelection;
|
return _preservesSelection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Sets whether the selection is kept when the content changes.
|
||||||
|
|
||||||
|
@param BOOL aFlag - YES if the selection should be kept, otherwise NO.
|
||||||
|
*/
|
||||||
- (void)setPreservesSelection:(BOOL)value
|
- (void)setPreservesSelection:(BOOL)value
|
||||||
{
|
{
|
||||||
_preservesSelection = value;
|
_preservesSelection = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@return BOOL - Returns YES if new objects are automatically selected, otherwise NO.
|
||||||
|
*/
|
||||||
- (BOOL)selectsInsertedObjects
|
- (BOOL)selectsInsertedObjects
|
||||||
{
|
{
|
||||||
return _selectsInsertedObjects;
|
return _selectsInsertedObjects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Sets whether the controller will automatically select objects as they are inserted.
|
||||||
|
@return BOOL aFlag - YES if new objects are selected, otherwise NO.
|
||||||
|
*/
|
||||||
- (void)setSelectsInsertedObjects:(BOOL)value
|
- (void)setSelectsInsertedObjects:(BOOL)value
|
||||||
{
|
{
|
||||||
_selectsInsertedObjects = value;
|
_selectsInsertedObjects = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@return BOOL aFlag - Returns YES if the controller should try to avoid an empty selection otherwise NO.
|
||||||
|
*/
|
||||||
- (BOOL)avoidsEmptySelection
|
- (BOOL)avoidsEmptySelection
|
||||||
{
|
{
|
||||||
return _avoidsEmptySelection;
|
return _avoidsEmptySelection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Sets whether the controller should try to avoid an empty selection.
|
||||||
|
@param BOOL aFlag - YES if the reciver should attempt to avoid an empty selection, otherwise NO.
|
||||||
|
*/
|
||||||
- (void)setAvoidsEmptySelection:(BOOL)value
|
- (void)setAvoidsEmptySelection:(BOOL)value
|
||||||
{
|
{
|
||||||
_avoidsEmptySelection = value;
|
_avoidsEmptySelection = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Sets the controller's content object.
|
||||||
|
|
||||||
|
@param id value - the content object of the controller.
|
||||||
|
*/
|
||||||
- (void)setContent:(id)value
|
- (void)setContent:(id)value
|
||||||
{
|
{
|
||||||
if (value === nil)
|
if (value === nil)
|
||||||
@@ -198,26 +234,47 @@
|
|||||||
[self didChangeValueForKey:@"filterPredicate"];
|
[self didChangeValueForKey:@"filterPredicate"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
- (void)_setContentArray:(id)anArray
|
- (void)_setContentArray:(id)anArray
|
||||||
{
|
{
|
||||||
[self setContent:anArray];
|
[self setContent:anArray];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
- (void)_setContentSet:(id)aSet
|
- (void)_setContentSet:(id)aSet
|
||||||
{
|
{
|
||||||
[self setContent:aSet];
|
[self setContent:[aSet allObjects]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns the content array of the controller.
|
||||||
|
@return id the content array of the reciever
|
||||||
|
*/
|
||||||
- (id)contentArray
|
- (id)contentArray
|
||||||
{
|
{
|
||||||
return [self content];
|
return [self content];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns the content of the reciever as a CPSet.
|
||||||
|
|
||||||
|
@return id - the content of the controller as a set.
|
||||||
|
*/
|
||||||
- (id)contentSet
|
- (id)contentSet
|
||||||
{
|
{
|
||||||
return [self content];
|
return [CPSet setWithArray:[self content]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Sorts and filters a given array and returns it.
|
||||||
|
|
||||||
|
@param CPArray anArray - an array of objects.
|
||||||
|
@return CPArray - the array of sorted objects.
|
||||||
|
*/
|
||||||
- (CPArray)arrangeObjects:(CPArray)objects
|
- (CPArray)arrangeObjects:(CPArray)objects
|
||||||
{
|
{
|
||||||
var filterPredicate = [self filterPredicate],
|
var filterPredicate = [self filterPredicate],
|
||||||
@@ -237,6 +294,9 @@
|
|||||||
return [objects copy];
|
return [objects copy];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Triggers the filtering of the objects in the controller.
|
||||||
|
*/
|
||||||
- (void)rearrangeObjects
|
- (void)rearrangeObjects
|
||||||
{
|
{
|
||||||
[self willChangeValueForKey:@"arrangedObjects"];
|
[self willChangeValueForKey:@"arrangedObjects"];
|
||||||
@@ -270,6 +330,9 @@
|
|||||||
[self __setSelectionIndexes:oldSelectionIndexes];
|
[self __setSelectionIndexes:oldSelectionIndexes];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
- (void)__setArrangedObjects:(id)value
|
- (void)__setArrangedObjects:(id)value
|
||||||
{
|
{
|
||||||
if (_arrangedObjects === value)
|
if (_arrangedObjects === value)
|
||||||
@@ -278,16 +341,29 @@
|
|||||||
_arrangedObjects = [[_CPObservableArray alloc] initWithArray:value];
|
_arrangedObjects = [[_CPObservableArray alloc] initWithArray:value];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns an array of the controller's objects sorted and filtered.
|
||||||
|
@return - array of objects
|
||||||
|
*/
|
||||||
- (id)arrangedObjects
|
- (id)arrangedObjects
|
||||||
{
|
{
|
||||||
return _arrangedObjects;
|
return _arrangedObjects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns the receiver's array of sort descriptors.
|
||||||
|
@return CPArray an array of sort descriptors
|
||||||
|
*/
|
||||||
- (CPArray)sortDescriptors
|
- (CPArray)sortDescriptors
|
||||||
{
|
{
|
||||||
return _sortDescriptors;
|
return _sortDescriptors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Sets the sort descriptors for the controller.
|
||||||
|
|
||||||
|
@param CPArray descriptors - the new sort descriptors.
|
||||||
|
*/
|
||||||
- (void)setSortDescriptors:(CPArray)value
|
- (void)setSortDescriptors:(CPArray)value
|
||||||
{
|
{
|
||||||
if (_sortDescriptors === value)
|
if (_sortDescriptors === value)
|
||||||
@@ -299,11 +375,23 @@
|
|||||||
[self _rearrangeObjects];
|
[self _rearrangeObjects];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns the predicate used by the controller to filter the contents of the reciever.
|
||||||
|
If no predicate is set nil is returned.
|
||||||
|
|
||||||
|
@return CPPredicate the predicate used by the controller
|
||||||
|
*/
|
||||||
- (CPPredicate)filterPredicate
|
- (CPPredicate)filterPredicate
|
||||||
{
|
{
|
||||||
return _filterPredicate;
|
return _filterPredicate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Sets the predicate for the controller to filter the content.
|
||||||
|
Passing nil will remove an existing prediate.
|
||||||
|
|
||||||
|
@param CPPrediate aPredicate - the new predicate.
|
||||||
|
*/
|
||||||
- (void)setFilterPredicate:(CPPredicate)value
|
- (void)setFilterPredicate:(CPPredicate)value
|
||||||
{
|
{
|
||||||
[self __setFilterPredicate:value];
|
[self __setFilterPredicate:value];
|
||||||
@@ -324,28 +412,52 @@
|
|||||||
[self _rearrangeObjects];
|
[self _rearrangeObjects];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns a BOOL indicating whether the receiver always returns the multiple values marker when multiple objects are selected.
|
||||||
|
@return BOOL YES is the controller always uses multiple value markers, otherwise NO.
|
||||||
|
*/
|
||||||
- (BOOL)alwaysUsesMultipleValuesMarker
|
- (BOOL)alwaysUsesMultipleValuesMarker
|
||||||
{
|
{
|
||||||
return _alwaysUsesMultipleValuesMarker;
|
return _alwaysUsesMultipleValuesMarker;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Selection
|
//Selection
|
||||||
|
/*!
|
||||||
|
Returns the index of the first object in the controller's selection.
|
||||||
|
@return unsigned - Index of the first selected object.
|
||||||
|
*/
|
||||||
- (unsigned)selectionIndex
|
- (unsigned)selectionIndex
|
||||||
{
|
{
|
||||||
return [_selectionIndexes firstIndex];
|
return [_selectionIndexes firstIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Sets the selected index
|
||||||
|
|
||||||
|
@param unsided anIndex - the new index to select
|
||||||
|
@return BOOL - Returns YES if the selection was changed, otherwise NO.
|
||||||
|
*/
|
||||||
- (BOOL)setSelectionIndex:(unsigned)index
|
- (BOOL)setSelectionIndex:(unsigned)index
|
||||||
{
|
{
|
||||||
return [self setSelectionIndexes:[CPIndexSet indexSetWithIndex:index]];
|
return [self setSelectionIndexes:[CPIndexSet indexSetWithIndex:index]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns an index set of the selected indexes.
|
||||||
|
|
||||||
|
@return CPIndexSet - The selected indexes.
|
||||||
|
*/
|
||||||
- (CPIndexSet)selectionIndexes
|
- (CPIndexSet)selectionIndexes
|
||||||
{
|
{
|
||||||
return _selectionIndexes;
|
return _selectionIndexes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Sets the selection indexes of the controller.
|
||||||
|
|
||||||
|
@param CPIndexSet indexes - the indexes to select
|
||||||
|
@return BOOL - Returns YES if the selection changed, otherwise NO.
|
||||||
|
*/
|
||||||
- (BOOL)setSelectionIndexes:(CPIndexSet)indexes
|
- (BOOL)setSelectionIndexes:(CPIndexSet)indexes
|
||||||
{
|
{
|
||||||
[self _selectionWillChange]
|
[self _selectionWillChange]
|
||||||
@@ -393,11 +505,16 @@
|
|||||||
|
|
||||||
// Push back the new selection to the model for selectionIndexes if we have one.
|
// Push back the new selection to the model for selectionIndexes if we have one.
|
||||||
// There won't be an infinite loop because of the equality check above.
|
// There won't be an infinite loop because of the equality check above.
|
||||||
[[CPKeyValueBinding getBinding:@"selectionIndexes" forObject:self] reverseSetValueFor:@"selectionIndexes"];
|
var binderClass = [[self class] _binderClassForBinding:@"selectionIndexes"];
|
||||||
|
[[binderClass getBinding:@"selectionIndexes" forObject:self] reverseSetValueFor:@"selectionIndexes"];
|
||||||
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns an array of the selected objects.
|
||||||
|
@return CPArray - the selected objects.
|
||||||
|
*/
|
||||||
- (CPArray)selectedObjects
|
- (CPArray)selectedObjects
|
||||||
{
|
{
|
||||||
var objects = [[self arrangedObjects] objectsAtIndexes:[self selectionIndexes]];
|
var objects = [[self arrangedObjects] objectsAtIndexes:[self selectionIndexes]];
|
||||||
@@ -405,6 +522,12 @@
|
|||||||
return [_CPObservableArray arrayWithArray:(objects || [])];
|
return [_CPObservableArray arrayWithArray:(objects || [])];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Sets the selected objects of the controller.
|
||||||
|
|
||||||
|
@param CPArray anArray - the objects to select
|
||||||
|
@return BOOL - Returns YES if the selection was changed, otherwise NO.
|
||||||
|
*/
|
||||||
- (BOOL)setSelectedObjects:(CPArray)objects
|
- (BOOL)setSelectedObjects:(CPArray)objects
|
||||||
{
|
{
|
||||||
[self willChangeValueForKey:@"selectionIndexes"];
|
[self willChangeValueForKey:@"selectionIndexes"];
|
||||||
@@ -439,12 +562,20 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Moving selection
|
//Moving selection
|
||||||
|
/*!
|
||||||
|
Returns YES if the previous object, relative to the current selection, in the controller's content array can be selected.
|
||||||
|
|
||||||
|
@return BOOL - YES if the object can be selected, otherwise NO.
|
||||||
|
*/
|
||||||
- (BOOL)canSelectPrevious
|
- (BOOL)canSelectPrevious
|
||||||
{
|
{
|
||||||
return [[self selectionIndexes] firstIndex] > 0
|
return [[self selectionIndexes] firstIndex] > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Selects the previous object, relative to the current selection, in the controllers arranged content.
|
||||||
|
@param id sender - the sender of the message.
|
||||||
|
*/
|
||||||
- (void)selectPrevious:(id)sender
|
- (void)selectPrevious:(id)sender
|
||||||
{
|
{
|
||||||
var index = [[self selectionIndexes] firstIndex] - 1;
|
var index = [[self selectionIndexes] firstIndex] - 1;
|
||||||
@@ -453,11 +584,20 @@
|
|||||||
[self setSelectionIndexes:[CPIndexSet indexSetWithIndex:index]];
|
[self setSelectionIndexes:[CPIndexSet indexSetWithIndex:index]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns YES if the next object, relative to the current selection, in the controller's content array can be selected.
|
||||||
|
|
||||||
|
@return BOOL - YES if the object can be selected, otherwise NO.
|
||||||
|
*/
|
||||||
- (BOOL)canSelectNext
|
- (BOOL)canSelectNext
|
||||||
{
|
{
|
||||||
return [[self selectionIndexes] firstIndex] < [[self arrangedObjects] count] - 1;
|
return [[self selectionIndexes] firstIndex] < [[self arrangedObjects] count] - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Selects the next object, relative to the current selection, in the controllers arranged content.
|
||||||
|
@param id sender - the sender of the message.
|
||||||
|
*/
|
||||||
- (void)selectNext:(id)sender
|
- (void)selectNext:(id)sender
|
||||||
{
|
{
|
||||||
var index = [[self selectionIndexes] firstIndex] + 1;
|
var index = [[self selectionIndexes] firstIndex] + 1;
|
||||||
@@ -468,6 +608,11 @@
|
|||||||
|
|
||||||
//Add/Remove
|
//Add/Remove
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Adds object to the receiver's content collection and the arranged objects array.
|
||||||
|
|
||||||
|
@param id anObject - the object to add the controller.
|
||||||
|
*/
|
||||||
- (void)addObject:(id)object
|
- (void)addObject:(id)object
|
||||||
{
|
{
|
||||||
if (![self canAdd])
|
if (![self canAdd])
|
||||||
@@ -501,6 +646,12 @@
|
|||||||
[self didChangeValueForKey:@"filterPredicate"];
|
[self didChangeValueForKey:@"filterPredicate"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Adds an object at a given index to the reciever's collection.
|
||||||
|
|
||||||
|
@param id anObject - The object to add to the collection.
|
||||||
|
@param int anIndex - The index to insert the object at.
|
||||||
|
*/
|
||||||
- (void)insertObject:(id)anObject atArrangedObjectIndex:(int)anIndex
|
- (void)insertObject:(id)anObject atArrangedObjectIndex:(int)anIndex
|
||||||
{
|
{
|
||||||
if (![self canAdd])
|
if (![self canAdd])
|
||||||
@@ -532,11 +683,13 @@
|
|||||||
[self didChangeValueForKey:@"filterPredicate"];
|
[self didChangeValueForKey:@"filterPredicate"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Removes a given object from the reciever's collection.
|
||||||
|
|
||||||
|
@param id anObject - The object to remove from the collection.
|
||||||
|
*/
|
||||||
- (void)removeObject:(id)object
|
- (void)removeObject:(id)object
|
||||||
{
|
{
|
||||||
if (![self canRemove])
|
|
||||||
return;
|
|
||||||
|
|
||||||
[self willChangeValueForKey:@"content"];
|
[self willChangeValueForKey:@"content"];
|
||||||
[_contentObject removeObject:object];
|
[_contentObject removeObject:object];
|
||||||
|
|
||||||
@@ -553,6 +706,11 @@
|
|||||||
[self didChangeValueForKey:@"content"];
|
[self didChangeValueForKey:@"content"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Creates and adds a new object to the receiver's content and arranged objects.
|
||||||
|
|
||||||
|
@param id sender - The sender of the message.
|
||||||
|
*/
|
||||||
- (void)add:(id)sender
|
- (void)add:(id)sender
|
||||||
{
|
{
|
||||||
if (![self canAdd])
|
if (![self canAdd])
|
||||||
@@ -561,6 +719,10 @@
|
|||||||
[self insert:sender];
|
[self insert:sender];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Creates a new object and inserts it into the receiver's content array.
|
||||||
|
@param id sender - The sender of the message.
|
||||||
|
*/
|
||||||
- (void)insert:(id)sender
|
- (void)insert:(id)sender
|
||||||
{
|
{
|
||||||
if (![self canInsert])
|
if (![self canInsert])
|
||||||
@@ -571,17 +733,29 @@
|
|||||||
[self addObject:newObject];
|
[self addObject:newObject];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Removes the controller's selected objects from the controller's collection.
|
||||||
|
@param id sender - The sender of the message.
|
||||||
|
*/
|
||||||
- (void)remove:(id)sender
|
- (void)remove:(id)sender
|
||||||
{
|
{
|
||||||
[self removeObjects:[[self arrangedObjects] objectsAtIndexes:[self selectionIndexes]]];
|
[self removeObjects:[[self arrangedObjects] objectsAtIndexes:[self selectionIndexes]]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Removes the objects at the specified indexes in the controller's arranged objects from the content array.
|
||||||
|
@param CPIndexSet indexes - indexes of the objects to remove.
|
||||||
|
*/
|
||||||
- (void)removeObjectsAtArrangedObjectIndexes:(CPIndexSet)indexes
|
- (void)removeObjectsAtArrangedObjectIndexes:(CPIndexSet)indexes
|
||||||
{
|
{
|
||||||
[self _removeObjects:[[self arrangedObjects] objectsAtIndexes:indexes]];
|
[self _removeObjects:[[self arrangedObjects] objectsAtIndexes:indexes]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Adds an array of objects to the controller's collection.
|
||||||
|
|
||||||
|
@param CPArray anArray - The array of objects to add to the collection.
|
||||||
|
*/
|
||||||
- (void)addObjects:(CPArray)objects
|
- (void)addObjects:(CPArray)objects
|
||||||
{
|
{
|
||||||
if (![self canAdd])
|
if (![self canAdd])
|
||||||
@@ -596,14 +770,18 @@
|
|||||||
[self setContent:contentArray];
|
[self setContent:contentArray];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Removes an array of objects from the collection.
|
||||||
|
@param CPArray anArray - The array of objects to remove
|
||||||
|
*/
|
||||||
- (void)removeObjects:(CPArray)objects
|
- (void)removeObjects:(CPArray)objects
|
||||||
{
|
{
|
||||||
if (![self canRemove])
|
|
||||||
return;
|
|
||||||
|
|
||||||
[self _removeObjects:objects];
|
[self _removeObjects:objects];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
- (void)_removeObjects:(CPArray)objects
|
- (void)_removeObjects:(CPArray)objects
|
||||||
{
|
{
|
||||||
[self willChangeValueForKey:@"content"];
|
[self willChangeValueForKey:@"content"];
|
||||||
@@ -635,6 +813,10 @@
|
|||||||
[self didChangeValueForKey:@"content"];
|
[self didChangeValueForKey:@"content"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns a BOOL indicating whether an object can be inserted into the controller's collection.
|
||||||
|
@return BOOL - YES if an object can be inserted, otherwise NO.
|
||||||
|
*/
|
||||||
- (BOOL)canInsert
|
- (BOOL)canInsert
|
||||||
{
|
{
|
||||||
return [self isEditable];
|
return [self isEditable];
|
||||||
@@ -642,30 +824,49 @@
|
|||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
var CPArrayControllerAvoidsEmptySelection = @"CPArrayControllerAvoidsEmptySelection",
|
||||||
|
CPArrayControllerClearsFilterPredicateOnInsertion = @"CPArrayControllerClearsFilterPredicateOnInsertion",
|
||||||
|
CPArrayControllerFilterRestrictsInsertion = @"CPArrayControllerFilterRestrictsInsertion",
|
||||||
|
CPArrayControllerPreservesSelection = @"CPArrayControllerPreservesSelection",
|
||||||
|
CPArrayControllerSelectsInsertedObjects = @"CPArrayControllerSelectsInsertedObjects",
|
||||||
|
CPArrayControllerAlwaysUsesMultipleValuesMarker = @"CPArrayControllerAlwaysUsesMultipleValuesMarker";
|
||||||
|
|
||||||
@implementation CPArrayController (CPCoding)
|
@implementation CPArrayController (CPCoding)
|
||||||
|
|
||||||
- (id)initWithCoder:(CPCoder)aCoder
|
- (id)initWithCoder:(CPCoder)aCoder
|
||||||
{
|
{
|
||||||
self = [super initWithCoder:coder];
|
self = [super initWithCoder:aCoder];
|
||||||
|
|
||||||
if (self)
|
if (self)
|
||||||
{
|
{
|
||||||
_avoidsEmptySelection = [coder decodeBoolForKey:@"CPArrayControllerAvoidsEmptySelection"];
|
_avoidsEmptySelection = [aCoder decodeBoolForKey:CPArrayControllerAvoidsEmptySelection];
|
||||||
_clearsFilterPredicateOnInsertion = [coder decodeBoolForKey:@"CPClearsFilterPredicateOnInsertion"];
|
_clearsFilterPredicateOnInsertion = [aCoder decodeBoolForKey:CPArrayControllerClearsFilterPredicateOnInsertion];
|
||||||
_filterRestrictsInsertion = [coder decodeBoolForKey:@"CPArrayControllerFilterRestrictsInsertion"];
|
_filterRestrictsInsertion = [aCoder decodeBoolForKey:CPArrayControllerFilterRestrictsInsertion];
|
||||||
_preservesSelection = [coder decodeBoolForKey:@"CPArrayControllerPreservesSelection"];
|
_preservesSelection = [aCoder decodeBoolForKey:CPArrayControllerPreservesSelection];
|
||||||
_selectsInsertedObjects = [coder decodeBoolForKey:@"CPArrayControllerSelectsInsertedObjects"];
|
_selectsInsertedObjects = [aCoder decodeBoolForKey:CPArrayControllerSelectsInsertedObjects];
|
||||||
_alwaysUsesMultipleValuesMarker = [coder decodeBoolForKey:@"CPArrayControllerAlwaysUsesMultipleValuesMarker"];
|
_alwaysUsesMultipleValuesMarker = [aCoder decodeBoolForKey:CPArrayControllerAlwaysUsesMultipleValuesMarker];
|
||||||
|
|
||||||
if ([self automaticallyPreparesContent])
|
if (![self content] && [self automaticallyPreparesContent])
|
||||||
[self prepareContent];
|
[self prepareContent];
|
||||||
else
|
else if (![self content])
|
||||||
[self _setContentArray:[]];
|
[self _setContentArray:[]];
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)encodeWithCoder:(CPCoder)aCoder
|
||||||
|
{
|
||||||
|
[super encodeWithCoder:aCoder];
|
||||||
|
|
||||||
|
[aCoder encodeBool:_avoidsEmptySelection forKey:CPArrayControllerAvoidsEmptySelection];
|
||||||
|
[aCoder encodeBool:_clearsFilterPredicateOnInsertion forKey:CPArrayControllerClearsFilterPredicateOnInsertion];
|
||||||
|
[aCoder encodeBool:_filterRestrictsInsertion forKey:CPArrayControllerFilterRestrictsInsertion];
|
||||||
|
[aCoder encodeBool:_preservesSelection forKey:CPArrayControllerPreservesSelection];
|
||||||
|
[aCoder encodeBool:_selectsInsertedObjects forKey:CPArrayControllerSelectsInsertedObjects];
|
||||||
|
[aCoder encodeBool:_alwaysUsesMultipleValuesMarker forKey:CPArrayControllerAlwaysUsesMultipleValuesMarker];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)awakeFromCib
|
- (void)awakeFromCib
|
||||||
{
|
{
|
||||||
[self _selectionWillChange];
|
[self _selectionWillChange];
|
||||||
|
|||||||
@@ -184,7 +184,6 @@ var DefaultLineWidth = 1.0;
|
|||||||
CGContextBeginPath(ctx);
|
CGContextBeginPath(ctx);
|
||||||
CGContextAddPath(ctx, _path);
|
CGContextAddPath(ctx, _path);
|
||||||
CGContextSetLineWidth(ctx, [self lineWidth]);
|
CGContextSetLineWidth(ctx, [self lineWidth]);
|
||||||
CGContextClosePath(ctx);
|
|
||||||
CGContextStrokePath(ctx);
|
CGContextStrokePath(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -281,6 +280,7 @@ var DefaultLineWidth = 1.0;
|
|||||||
{
|
{
|
||||||
CGPathAddPath(_path, nil, other._path);
|
CGPathAddPath(_path, nil, other._path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Remove all path elements; clears path.
|
Remove all path elements; clears path.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
// CPBoxType
|
// CPBoxType
|
||||||
CPBoxPrimary = 0;
|
CPBoxPrimary = 0;
|
||||||
CPBoxSecondary = 1;
|
CPBoxSecondary = 1;
|
||||||
CPBoxSeperator = 2;
|
CPBoxSeparator = 2;
|
||||||
CPBoxOldStyle = 3;
|
CPBoxOldStyle = 3;
|
||||||
CPBoxCustom = 4;
|
CPBoxCustom = 4;
|
||||||
|
|
||||||
@@ -234,7 +234,7 @@ CPGrooveBorder = 3;
|
|||||||
|
|
||||||
switch (_boxType)
|
switch (_boxType)
|
||||||
{
|
{
|
||||||
case CPBoxSeperator:
|
case CPBoxSeparator:
|
||||||
// NSBox does not include a horitontal flag for the seperator type. We have to determine
|
// NSBox does not include a horitontal flag for the seperator type. We have to determine
|
||||||
// the type of seperator to draw by the width and height of the frame.
|
// the type of seperator to draw by the width and height of the frame.
|
||||||
if (CGRectGetWidth(bounds) === 5.0)
|
if (CGRectGetWidth(bounds) === 5.0)
|
||||||
@@ -265,8 +265,8 @@ CPGrooveBorder = 3;
|
|||||||
CGContextSetStrokeColor(context, [self borderColor]);
|
CGContextSetStrokeColor(context, [self borderColor]);
|
||||||
CGContextSetLineWidth(context, 1.0);
|
CGContextSetLineWidth(context, 1.0);
|
||||||
|
|
||||||
CGContextMoveToPoint(context, CGRectGetMinX(aRect), CGRectGetMinY(aRect));
|
CGContextMoveToPoint(context, CGRectGetMinX(aRect), CGRectGetMinY(aRect) + 0.5);
|
||||||
CGContextAddLineToPoint(context, CGRectGetWidth(aRect), CGRectGetMinY(aRect));
|
CGContextAddLineToPoint(context, CGRectGetWidth(aRect), CGRectGetMinY(aRect) + 0.5);
|
||||||
CGContextStrokePath(context);
|
CGContextStrokePath(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,8 +277,8 @@ CPGrooveBorder = 3;
|
|||||||
CGContextSetStrokeColor(context, [self borderColor]);
|
CGContextSetStrokeColor(context, [self borderColor]);
|
||||||
CGContextSetLineWidth(context, 1.0);
|
CGContextSetLineWidth(context, 1.0);
|
||||||
|
|
||||||
CGContextMoveToPoint(context, CGRectGetMinX(aRect), CGRectGetMinY(aRect));
|
CGContextMoveToPoint(context, CGRectGetMinX(aRect) + 0.5, CGRectGetMinY(aRect));
|
||||||
CGContextAddLineToPoint(context, CGRectGetMinX(aRect), CGRectGetHeight(aRect));
|
CGContextAddLineToPoint(context, CGRectGetMinX(aRect) + 0.5, CGRectGetHeight(aRect));
|
||||||
CGContextStrokePath(context);
|
CGContextStrokePath(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -83,42 +83,47 @@
|
|||||||
{
|
{
|
||||||
if (self = [super initWithFrame:aFrame])
|
if (self = [super initWithFrame:aFrame])
|
||||||
{
|
{
|
||||||
_rowHeight = 23.0;
|
[self _init];
|
||||||
_defaultColumnWidth = 140.0;
|
|
||||||
_minColumnWidth = 80.0;
|
|
||||||
_imageWidth = 23.0;
|
|
||||||
_leafWidth = 13.0;
|
|
||||||
_columnWidths = [];
|
|
||||||
|
|
||||||
_pathSeparator = "/";
|
|
||||||
_tableViews = [];
|
|
||||||
_tableDelegates = [];
|
|
||||||
_allowsMultipleSelection = YES;
|
|
||||||
_allowsEmptySelection = YES;
|
|
||||||
_tableViewClass = [_CPBrowserTableView class];
|
|
||||||
|
|
||||||
_prototypeView = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
|
|
||||||
[_prototypeView setVerticalAlignment:CPCenterVerticalTextAlignment];
|
|
||||||
[_prototypeView setValue:[CPColor whiteColor] forThemeAttribute:"text-color" inState:CPThemeStateSelectedDataView];
|
|
||||||
[_prototypeView setLineBreakMode:CPLineBreakByTruncatingTail];
|
|
||||||
|
|
||||||
_horizontalScrollView = [[CPScrollView alloc] initWithFrame:[self bounds]];
|
|
||||||
|
|
||||||
[_horizontalScrollView setHasVerticalScroller:NO];
|
|
||||||
[_horizontalScrollView setAutohidesScrollers:YES];
|
|
||||||
[_horizontalScrollView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
|
|
||||||
|
|
||||||
_contentView = [[CPView alloc] initWithFrame:CGRectMake(0, 0, 0, CGRectGetHeight([self bounds]))];
|
|
||||||
[_contentView setAutoresizingMask:CPViewHeightSizable];
|
|
||||||
|
|
||||||
[_horizontalScrollView setDocumentView:_contentView];
|
|
||||||
|
|
||||||
[self addSubview:_horizontalScrollView];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)_init
|
||||||
|
{
|
||||||
|
_rowHeight = 23.0;
|
||||||
|
_defaultColumnWidth = 140.0;
|
||||||
|
_minColumnWidth = 80.0;
|
||||||
|
_imageWidth = 23.0;
|
||||||
|
_leafWidth = 13.0;
|
||||||
|
_columnWidths = [];
|
||||||
|
|
||||||
|
_pathSeparator = "/";
|
||||||
|
_tableViews = [];
|
||||||
|
_tableDelegates = [];
|
||||||
|
_allowsMultipleSelection = YES;
|
||||||
|
_allowsEmptySelection = YES;
|
||||||
|
_tableViewClass = [_CPBrowserTableView class];
|
||||||
|
|
||||||
|
_prototypeView = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
|
||||||
|
[_prototypeView setVerticalAlignment:CPCenterVerticalTextAlignment];
|
||||||
|
[_prototypeView setValue:[CPColor whiteColor] forThemeAttribute:"text-color" inState:CPThemeStateSelectedDataView];
|
||||||
|
[_prototypeView setLineBreakMode:CPLineBreakByTruncatingTail];
|
||||||
|
|
||||||
|
_horizontalScrollView = [[CPScrollView alloc] initWithFrame:[self bounds]];
|
||||||
|
|
||||||
|
[_horizontalScrollView setHasVerticalScroller:NO];
|
||||||
|
[_horizontalScrollView setAutohidesScrollers:YES];
|
||||||
|
[_horizontalScrollView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
|
||||||
|
|
||||||
|
_contentView = [[CPView alloc] initWithFrame:CGRectMake(0, 0, 0, CGRectGetHeight([self bounds]))];
|
||||||
|
[_contentView setAutoresizingMask:CPViewHeightSizable];
|
||||||
|
|
||||||
|
[_horizontalScrollView setDocumentView:_contentView];
|
||||||
|
|
||||||
|
[self addSubview:_horizontalScrollView];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)setPrototypeView:(CPView)aPrototypeView
|
- (void)setPrototypeView:(CPView)aPrototypeView
|
||||||
{
|
{
|
||||||
_prototypeView = [CPKeyedUnarchiver unarchiveObjectWithData:
|
_prototypeView = [CPKeyedUnarchiver unarchiveObjectWithData:
|
||||||
@@ -650,6 +655,53 @@
|
|||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@implementation CPBrowser (CPCoding)
|
||||||
|
|
||||||
|
- (id)initWithCoder:(CPCoder)aCoder
|
||||||
|
{
|
||||||
|
self = [super initWithCoder:aCoder];
|
||||||
|
|
||||||
|
if (self)
|
||||||
|
{
|
||||||
|
[self _init];
|
||||||
|
|
||||||
|
_allowsEmptySelection = [aCoder decodeBoolForKey:@"CPBrowserAllowsEmptySelectionKey"];
|
||||||
|
_allowsMultipleSelection = [aCoder decodeBoolForKey:@"CPBrowserAllowsMultipleSelectionKey"];
|
||||||
|
_prototypeView = [aCoder decodeObjectForKey:@"CPBrowserPrototypeViewKey"];
|
||||||
|
_rowHeight = [aCoder decodeFloatForKey:@"CPBrowserRowHeightKey"];
|
||||||
|
_imageWidth = [aCoder decodeFloatForKey:@"CPBrowserImageWidthKey"];
|
||||||
|
_minColumnWidth = [aCoder decodeFloatForKey:@"CPBrowserMinColumnWidthKey"];
|
||||||
|
_columnWidths = [aCoder decodeObjectForKey:@"CPBrowserColumnWidthsKey"];
|
||||||
|
|
||||||
|
[self setDelegate:[aCoder decodeObjectForKey:@"CPBrowserDelegateKey"]];
|
||||||
|
[self setAutohidesScroller:[aCoder decodeBoolForKey:@"CPBrowserAutohidesScrollerKey"]];
|
||||||
|
}
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)encodeWithCoder:(CPCoder)aCoder
|
||||||
|
{
|
||||||
|
// Don't encode the subviews, they're transient and will be recreated from data.
|
||||||
|
var actualSubviews = _subviews;
|
||||||
|
_subviews = [];
|
||||||
|
[super encodeWithCoder:aCoder];
|
||||||
|
_subviews = actualSubviews;
|
||||||
|
|
||||||
|
[aCoder encodeBool:[self autohidesScroller] forKey:@"CPBrowserAutohidesScrollerKey"];
|
||||||
|
[aCoder encodeBool:_allowsEmptySelection forKey:@"CPBrowserAllowsEmptySelectionKey"];
|
||||||
|
[aCoder encodeBool:_allowsMultipleSelection forKey:@"CPBrowserAllowsMultipleSelectionKey"];
|
||||||
|
[aCoder encodeObject:_delegate forKey:@"CPBrowserDelegateKey"];
|
||||||
|
[aCoder encodeObject:_prototypeView forKey:@"CPBrowserPrototypeViewKey"];
|
||||||
|
[aCoder encodeFloat:_rowHeight forKey:@"CPBrowserRowHeightKey"];
|
||||||
|
[aCoder encodeFloat:_imageWidth forKey:@"CPBrowserImageWidthKey"];
|
||||||
|
[aCoder encodeFloat:_minColumnWidth forKey:@"CPBrowserMinColumnWidthKey"];
|
||||||
|
[aCoder encodeObject:_columnWidths forKey:@"CPBrowserColumnWidthsKey"];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
var _CPBrowserResizeControlBackgroundImage = nil;
|
var _CPBrowserResizeControlBackgroundImage = nil;
|
||||||
|
|
||||||
@implementation _CPBrowserResizeControl : CPView
|
@implementation _CPBrowserResizeControl : CPView
|
||||||
|
|||||||
@@ -70,7 +70,13 @@ CPPushInCellMask = CPPushInButtonMask;
|
|||||||
CPChangeGrayCellMask = CPGrayButtonMask;
|
CPChangeGrayCellMask = CPGrayButtonMask;
|
||||||
CPChangeBackgroundCellMask = CPBackgroundButtonMask;
|
CPChangeBackgroundCellMask = CPBackgroundButtonMask;
|
||||||
|
|
||||||
CPButtonStateMixed = CPThemeState("mixed");
|
CPButtonStateMixed = CPThemeState("mixed");
|
||||||
|
CPButtonStateBezelStyleRounded = CPThemeState("rounded");
|
||||||
|
|
||||||
|
// add all future correspondance between bezel styles and theme state here.
|
||||||
|
var CPButtonBezelStyleStateMap = [CPDictionary dictionaryWithObjects:[CPButtonStateBezelStyleRounded, nil]
|
||||||
|
forKeys:[CPRoundedBezelStyle, CPRoundRectBezelStyle]];
|
||||||
|
|
||||||
|
|
||||||
CPButtonDefaultHeight = 24.0;
|
CPButtonDefaultHeight = 24.0;
|
||||||
CPButtonImageOffset = 3.0;
|
CPButtonImageOffset = 3.0;
|
||||||
@@ -129,6 +135,11 @@ CPButtonImageOffset = 3.0;
|
|||||||
forKeys:[@"image", @"image-offset", @"bezel-inset", @"content-inset", @"bezel-color"]];
|
forKeys:[@"image", @"image-offset", @"bezel-inset", @"content-inset", @"bezel-color"]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Initializes and returns a newly allocated CPButton object with a specified frame rectangle.
|
||||||
|
@param aFrame The frame rectangle for the created button object.
|
||||||
|
@return An initialized CPView object or nil if the object couldn't be created.
|
||||||
|
*/
|
||||||
- (id)initWithFrame:(CGRect)aFrame
|
- (id)initWithFrame:(CGRect)aFrame
|
||||||
{
|
{
|
||||||
self = [super initWithFrame:aFrame];
|
self = [super initWithFrame:aFrame];
|
||||||
@@ -146,7 +157,7 @@ CPButtonImageOffset = 3.0;
|
|||||||
_keyEquivalent = @"";
|
_keyEquivalent = @"";
|
||||||
_keyEquivalentModifierMask = 0;
|
_keyEquivalentModifierMask = 0;
|
||||||
|
|
||||||
// [self setBezelStyle:CPRoundRectBezelStyle];
|
[self setBezelStyle:CPRoundRectBezelStyle];
|
||||||
[self setBordered:YES];
|
[self setBordered:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,7 +166,8 @@ CPButtonImageOffset = 3.0;
|
|||||||
|
|
||||||
// Setting the state
|
// Setting the state
|
||||||
/*!
|
/*!
|
||||||
Returns \c YES if the button has a 'mixed' state in addition to on and off.
|
Returns a Boolean value indicating whether the button allows a mixed state.
|
||||||
|
@return \c YES if the button has a 'mixed' state in addition to on and off.
|
||||||
*/
|
*/
|
||||||
- (BOOL)allowsMixedState
|
- (BOOL)allowsMixedState
|
||||||
{
|
{
|
||||||
@@ -179,6 +191,10 @@ CPButtonImageOffset = 3.0;
|
|||||||
[self setState:CPOnState];
|
[self setState:CPOnState];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Sets the value of the button using an Objective-J object.
|
||||||
|
@param anObjectValue The value of the button interpreted as an Objective-J object.
|
||||||
|
*/
|
||||||
- (void)setObjectValue:(id)anObjectValue
|
- (void)setObjectValue:(id)anObjectValue
|
||||||
{
|
{
|
||||||
if (!anObjectValue || anObjectValue === @"" || ([anObjectValue intValue] === 0))
|
if (!anObjectValue || anObjectValue === @"" || ([anObjectValue intValue] === 0))
|
||||||
@@ -187,7 +203,7 @@ CPButtonImageOffset = 3.0;
|
|||||||
else if (![anObjectValue isKindOfClass:[CPNumber class]])
|
else if (![anObjectValue isKindOfClass:[CPNumber class]])
|
||||||
anObjectValue = CPOnState;
|
anObjectValue = CPOnState;
|
||||||
|
|
||||||
else if (anObjectValue > CPOnState)
|
else if (anObjectValue >= CPOnState)
|
||||||
anObjectValue = CPOnState
|
anObjectValue = CPOnState
|
||||||
|
|
||||||
else if (anObjectValue < CPOffState)
|
else if (anObjectValue < CPOffState)
|
||||||
@@ -213,6 +229,13 @@ CPButtonImageOffset = 3.0;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns the button's next state.
|
||||||
|
@return The button's state. A button can have two or three states.
|
||||||
|
If it has two, this value is either \c CPOffState (the normal or unpressed state)
|
||||||
|
or \c CPOnState (the alternate or pressed state).
|
||||||
|
If it has three, this value can be \c CPOnState (the feature is in effect everywhere), \c CPOffState (the feature is in effect nowhere), or \c CPMixedState (the feature is in effect somewhere).
|
||||||
|
*/
|
||||||
- (CPInteger)nextState
|
- (CPInteger)nextState
|
||||||
{
|
{
|
||||||
if ([self allowsMixedState])
|
if ([self allowsMixedState])
|
||||||
@@ -225,8 +248,16 @@ CPButtonImageOffset = 3.0;
|
|||||||
return 1 - [self state];
|
return 1 - [self state];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Sets the button's next state to \c aState.
|
||||||
|
@param aState Possible states are any of the CPButton globals:
|
||||||
|
\c CPOffState, \c CPOnState, \c CPMixedState
|
||||||
|
*/
|
||||||
- (void)setNextState
|
- (void)setNextState
|
||||||
{
|
{
|
||||||
|
if ([self infoForBinding:CPValueBinding])
|
||||||
|
[self setAllowsMixedState:NO];
|
||||||
|
|
||||||
[self setState:[self nextState]];
|
[self setState:[self nextState]];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,6 +279,11 @@ CPButtonImageOffset = 3.0;
|
|||||||
return [self intValue];
|
return [self intValue];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Sets the title displayed by the button when in its normal state.
|
||||||
|
@param aTitle The string to set as the button's title. This title is always shown on buttons
|
||||||
|
that don’t use their alternate contents when highlighting or displaying their alternate state.
|
||||||
|
*/
|
||||||
- (void)setTitle:(CPString)aTitle
|
- (void)setTitle:(CPString)aTitle
|
||||||
{
|
{
|
||||||
if (_title === aTitle)
|
if (_title === aTitle)
|
||||||
@@ -259,6 +295,11 @@ CPButtonImageOffset = 3.0;
|
|||||||
[self setNeedsDisplay:YES];
|
[self setNeedsDisplay:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns the title displayed on the button when it’s in its normal state.
|
||||||
|
@return The title displayed on the receiver when it’s in its normal state
|
||||||
|
or the empty string if the button doesn’t display a title.
|
||||||
|
*/
|
||||||
- (CPString)title
|
- (CPString)title
|
||||||
{
|
{
|
||||||
return _title;
|
return _title;
|
||||||
@@ -493,6 +534,9 @@ CPButtonImageOffset = 3.0;
|
|||||||
size.height = MIN(size.height, maxSize.height);
|
size.height = MIN(size.height, maxSize.height);
|
||||||
|
|
||||||
[self setFrameSize:size];
|
[self setFrameSize:size];
|
||||||
|
|
||||||
|
if (contentView)
|
||||||
|
[self layoutSubviews];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (CGRect)rectForEphemeralSubviewNamed:(CPString)aName
|
- (CGRect)rectForEphemeralSubviewNamed:(CPString)aName
|
||||||
@@ -643,10 +687,24 @@ CPButtonImageOffset = 3.0;
|
|||||||
|
|
||||||
- (void)setBezelStyle:(unsigned)aBezelStyle
|
- (void)setBezelStyle:(unsigned)aBezelStyle
|
||||||
{
|
{
|
||||||
|
if (aBezelStyle === _bezelStyle)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var currentState = [CPButtonBezelStyleStateMap objectForKey:_bezelStyle],
|
||||||
|
newState = [CPButtonBezelStyleStateMap objectForKey:aBezelStyle];
|
||||||
|
|
||||||
|
if (currentState)
|
||||||
|
[self unsetThemeState:currentState];
|
||||||
|
|
||||||
|
if (newState)
|
||||||
|
[self setThemeState:newState];
|
||||||
|
|
||||||
|
_bezelStyle = aBezelStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (unsigned)bezelStyle
|
- (unsigned)bezelStyle
|
||||||
{
|
{
|
||||||
|
return _bezelStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -44,6 +44,14 @@ CPCheckBoxImageOffset = 4.0;
|
|||||||
return @"check-box";
|
return @"check-box";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (Class)_binderClassForBinding:(CPString)theBinding
|
||||||
|
{
|
||||||
|
if (theBinding === CPValueBinding)
|
||||||
|
return [_CPCheckBoxValueBinder class];
|
||||||
|
|
||||||
|
return [super _binderClassForBinding:theBinding];
|
||||||
|
}
|
||||||
|
|
||||||
- (id)initWithFrame:(CGRect)aFrame
|
- (id)initWithFrame:(CGRect)aFrame
|
||||||
{
|
{
|
||||||
self = [super initWithFrame:aFrame];
|
self = [super initWithFrame:aFrame];
|
||||||
@@ -87,3 +95,53 @@ CPCheckBoxImageOffset = 4.0;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@implementation _CPCheckBoxValueBinder : CPBinder
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setValueFor:(CPString)theBinding
|
||||||
|
{
|
||||||
|
var destination = [_info objectForKey:CPObservedObjectKey],
|
||||||
|
keyPath = [_info objectForKey:CPObservedKeyPathKey],
|
||||||
|
options = [_info objectForKey:CPOptionsKey],
|
||||||
|
newValue = [destination valueForKeyPath:keyPath],
|
||||||
|
isPlaceholder = CPIsControllerMarker(newValue);
|
||||||
|
|
||||||
|
if (isPlaceholder)
|
||||||
|
{
|
||||||
|
switch (newValue)
|
||||||
|
{
|
||||||
|
case CPMultipleValuesMarker:
|
||||||
|
newValue = CPMixedState;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CPNoSelectionMarker:
|
||||||
|
newValue = CPOffState;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CPNotApplicableMarker:
|
||||||
|
if ([options objectForKey:CPRaisesForNotApplicableKeysBindingOption])
|
||||||
|
[CPException raise:CPGenericException reason:@"can't transform non applicable key on: "+_source+" value: "+newValue];
|
||||||
|
|
||||||
|
newValue = CPOffState;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newValue === CPMixedState)
|
||||||
|
{
|
||||||
|
[_source setAllowsMixedState:YES];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Cocoa will always set allowsMixedState to NO
|
||||||
|
// This behavior will be fine for Cappuccino as well if we (like Cocoa)
|
||||||
|
// default the CPConditionallySetsEnabledBindingOption to YES
|
||||||
|
[_source setAllowsMixedState:NO];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[_source setState:newValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|||||||
@@ -203,8 +203,8 @@
|
|||||||
*/
|
*/
|
||||||
- (void)setContent:(CPArray)anArray
|
- (void)setContent:(CPArray)anArray
|
||||||
{
|
{
|
||||||
if (_content == anArray)
|
// reset the _selectionIndexes
|
||||||
return;
|
[self setSelectionIndexes:[CPIndexSet indexSet]];
|
||||||
|
|
||||||
_content = anArray;
|
_content = anArray;
|
||||||
|
|
||||||
@@ -312,7 +312,8 @@
|
|||||||
while ((index = [_selectionIndexes indexGreaterThanIndex:index]) != CPNotFound)
|
while ((index = [_selectionIndexes indexGreaterThanIndex:index]) != CPNotFound)
|
||||||
[_items[index] setSelected:YES];
|
[_items[index] setSelected:YES];
|
||||||
|
|
||||||
[[CPKeyValueBinding getBinding:@"selectionIndexes" forObject:self] reverseSetValueFor:@"selectionIndexes"];
|
var binderClass = [[self class] _binderClassForBinding:@"selectionIndexes"];
|
||||||
|
[[binderClass getBinding:@"selectionIndexes" forObject:self] reverseSetValueFor:@"selectionIndexes"];
|
||||||
|
|
||||||
if ([_delegate respondsToSelector:@selector(collectionViewDidChangeSelection:)])
|
if ([_delegate respondsToSelector:@selector(collectionViewDidChangeSelection:)])
|
||||||
[_delegate collectionViewDidChangeSelection:self];
|
[_delegate collectionViewDidChangeSelection:self];
|
||||||
|
|||||||
@@ -534,7 +534,7 @@ var CPColorPanelSwatchesCookie = "CPColorPanelSwatchesCookie";
|
|||||||
{
|
{
|
||||||
var point = [self convertPoint:[anEvent locationInWindow] fromView:nil];
|
var point = [self convertPoint:[anEvent locationInWindow] fromView:nil];
|
||||||
|
|
||||||
if(point.x > [self bounds].size.width - 1 || point.x < 1)
|
if (point.x > [self bounds].size.width - 1 || point.x < 1)
|
||||||
return NO;
|
return NO;
|
||||||
|
|
||||||
[[CPPasteboard pasteboardWithName:CPDragPboard] declareTypes:[CPArray arrayWithObject:CPColorDragType] owner:self];
|
[[CPPasteboard pasteboardWithName:CPDragPboard] declareTypes:[CPArray arrayWithObject:CPColorDragType] owner:self];
|
||||||
|
|||||||
@@ -141,18 +141,20 @@ var CPControlBlackColor = [CPColor blackColor];
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)_reverseSetBinding
|
+ (Class)_binderClassForBinding:(CPString)theBinding
|
||||||
{
|
{
|
||||||
var theBinding = [CPKeyValueBinding getBinding:CPValueBinding forObject:self];
|
if (theBinding === CPValueBinding)
|
||||||
[theBinding reverseSetValueFor:@"objectValue"];
|
return [_CPValueBinder class];
|
||||||
|
|
||||||
|
return [super _binderClassForBinding:theBinding];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)_replacementKeyPathForBinding:(CPString)aBinding
|
- (void)_reverseSetBinding
|
||||||
{
|
{
|
||||||
if (aBinding === @"value")
|
var binderClass = [[self class] _binderClassForBinding:CPValueBinding],
|
||||||
return @"objectValue";
|
theBinding = [binderClass getBinding:CPValueBinding forObject:self];
|
||||||
|
|
||||||
return [super _replacementKeyPathForBinding:aBinding];
|
[theBinding reverseSetValueFor:@"objectValue"];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)initWithFrame:(CGRect)aFrame
|
- (id)initWithFrame:(CGRect)aFrame
|
||||||
@@ -286,9 +288,14 @@ var CPControlBlackColor = [CPColor blackColor];
|
|||||||
[self stopTracking:_previousTrackingLocation at:currentLocation mouseIsUp:YES];
|
[self stopTracking:_previousTrackingLocation at:currentLocation mouseIsUp:YES];
|
||||||
|
|
||||||
_trackingMouseDownFlags = 0;
|
_trackingMouseDownFlags = 0;
|
||||||
|
|
||||||
|
if (isWithinFrame)
|
||||||
|
[self setThemeState:CPThemeStateHovered];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
[self unsetThemeState:CPThemeStateHovered];
|
||||||
|
|
||||||
if (type === CPLeftMouseDown)
|
if (type === CPLeftMouseDown)
|
||||||
{
|
{
|
||||||
_trackingMouseDownFlags = [anEvent modifierFlags];
|
_trackingMouseDownFlags = [anEvent modifierFlags];
|
||||||
@@ -384,6 +391,25 @@ var CPControlBlackColor = [CPColor blackColor];
|
|||||||
[self trackMouse:anEvent];
|
[self trackMouse:anEvent];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)mouseEntered:(CPEvent)anEvent
|
||||||
|
{
|
||||||
|
if (![self isEnabled])
|
||||||
|
return;
|
||||||
|
|
||||||
|
[self setThemeState:CPThemeStateHovered];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)mouseExited:(CPEvent)anEvent
|
||||||
|
{
|
||||||
|
var currentLocation = [self convertPoint:[anEvent locationInWindow] fromView:nil],
|
||||||
|
isWithinFrame = [self tracksMouseOutsideOfFrame] || CGRectContainsPoint([self bounds], currentLocation);
|
||||||
|
|
||||||
|
// Make sure we're not still in the frame because Cappuccino will sent mouseExited events
|
||||||
|
// for all of the (ephemeral) subviews of a view as well.
|
||||||
|
if (!isWithinFrame)
|
||||||
|
[self unsetThemeState:CPThemeStateHovered];
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Returns the receiver's object value
|
Returns the receiver's object value
|
||||||
*/
|
*/
|
||||||
@@ -727,8 +753,10 @@ var __Deprecated__CPImageViewImageKey = @"CPImageViewImageKey";
|
|||||||
if (_sendsActionOnEndEditing)
|
if (_sendsActionOnEndEditing)
|
||||||
[aCoder encodeBool:_sendsActionOnEndEditing forKey:CPControlSendsActionOnEndEditingKey];
|
[aCoder encodeBool:_sendsActionOnEndEditing forKey:CPControlSendsActionOnEndEditingKey];
|
||||||
|
|
||||||
if (_value !== nil)
|
var objectValue = [self objectValue];
|
||||||
[aCoder encodeObject:_value forKey:CPControlValueKey];
|
|
||||||
|
if (objectValue !== nil)
|
||||||
|
[aCoder encodeObject:objectValue forKey:CPControlValueKey];
|
||||||
|
|
||||||
if (_target !== nil)
|
if (_target !== nil)
|
||||||
[aCoder encodeConditionalObject:_target forKey:CPControlTargetKey];
|
[aCoder encodeConditionalObject:_target forKey:CPControlTargetKey];
|
||||||
|
|||||||
@@ -390,13 +390,14 @@ var CPSharedDocumentController = nil;
|
|||||||
|
|
||||||
- (void)noteNewRecentDocument:(CPDocument)aDocument
|
- (void)noteNewRecentDocument:(CPDocument)aDocument
|
||||||
{
|
{
|
||||||
[self noteNewRecentDocumentURL:[[aDocument fileURL] absoluteString]];
|
[self noteNewRecentDocumentURL:[aDocument fileURL]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)noteNewRecentDocumentURL:(CPString)aURL
|
- (void)noteNewRecentDocumentURL:(CPURL)aURL
|
||||||
{
|
{
|
||||||
|
var urlAsString = [aURL isKindOfClass:CPString] ? aURL : [aURL absoluteString];
|
||||||
if (typeof window["cpNoteNewRecentDocumentPath"] === 'function')
|
if (typeof window["cpNoteNewRecentDocumentPath"] === 'function')
|
||||||
window.cpNoteNewRecentDocumentPath(aURL);
|
window.cpNoteNewRecentDocumentPath(urlAsString);
|
||||||
|
|
||||||
[self _updateRecentDocumentsMenu];
|
[self _updateRecentDocumentsMenu];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -220,14 +220,14 @@ var CPDraggingSource_draggedImage_movedTo_ = 1 << 0,
|
|||||||
[_draggingUpdateTimer invalidate];
|
[_draggingUpdateTimer invalidate];
|
||||||
_draggingUpdateTimer = nil;
|
_draggingUpdateTimer = nil;
|
||||||
|
|
||||||
var dragOperation = CPDragOperationCopy;
|
var dragOperation = CPDragOperationCopy,
|
||||||
// We have to convert base to bridge since the drag event comes from the source window, not the drag window.
|
// We have to convert base to bridge since the drag event comes from the source window, not the drag window.
|
||||||
var draggingDestination = [aPlatformWindow _dragHitTest:aLocation pasteboard:[CPDragServerDraggingInfo draggingPasteboard]];
|
draggingDestination = [aPlatformWindow _dragHitTest:aLocation pasteboard:[CPDragServerDraggingInfo draggingPasteboard]];
|
||||||
|
|
||||||
if (draggingDestination)
|
if (draggingDestination)
|
||||||
_draggingLocation = [DRAGGING_WINDOW(draggingDestination) convertPlatformWindowToBase:aLocation];
|
_draggingLocation = [DRAGGING_WINDOW(draggingDestination) convertPlatformWindowToBase:aLocation];
|
||||||
|
|
||||||
if(draggingDestination !== _draggingDestination)
|
if (draggingDestination !== _draggingDestination)
|
||||||
{
|
{
|
||||||
if ([_draggingDestination respondsToSelector:@selector(draggingExited:)])
|
if ([_draggingDestination respondsToSelector:@selector(draggingExited:)])
|
||||||
[_draggingDestination draggingExited:CPDragServerDraggingInfo];
|
[_draggingDestination draggingExited:CPDragServerDraggingInfo];
|
||||||
@@ -456,8 +456,8 @@ var CPDraggingSource_draggedImage_movedTo_ = 1 << 0,
|
|||||||
}
|
}
|
||||||
else if (type === CPKeyDown)
|
else if (type === CPKeyDown)
|
||||||
{
|
{
|
||||||
var keyCode = [anEvent keyCode];
|
var characters = [anEvent characters];
|
||||||
if (keyCode === CPEscapeKeyCode)
|
if (characters === CPEscapeFunctionKey)
|
||||||
{
|
{
|
||||||
_dragOperation = CPDragOperationNone;
|
_dragOperation = CPDragOperationNone;
|
||||||
[self draggingEndedInPlatformWindow:platformWindow globalLocation:CGPointMakeZero() operation:_dragOperation];
|
[self draggingEndedInPlatformWindow:platformWindow globalLocation:CGPointMakeZero() operation:_dragOperation];
|
||||||
|
|||||||
@@ -158,6 +158,7 @@ CPFindFunctionKey = "\uF745";
|
|||||||
CPHelpFunctionKey = "\uF746";
|
CPHelpFunctionKey = "\uF746";
|
||||||
CPModeSwitchFunctionKey = "\uF747";
|
CPModeSwitchFunctionKey = "\uF747";
|
||||||
CPEscapeFunctionKey = "\u001B";
|
CPEscapeFunctionKey = "\u001B";
|
||||||
|
CPSpaceFunctionKey = "\u0020";
|
||||||
|
|
||||||
|
|
||||||
CPDOMEventDoubleClick = "dblclick",
|
CPDOMEventDoubleClick = "dblclick",
|
||||||
@@ -527,7 +528,8 @@ var _CPEventPeriodicEventPeriod = 0,
|
|||||||
if (_CPEventUpperCaseRegex.test(aKeyEquivalent))
|
if (_CPEventUpperCaseRegex.test(aKeyEquivalent))
|
||||||
aKeyEquivalentModifierMask |= CPShiftKeyMask;
|
aKeyEquivalentModifierMask |= CPShiftKeyMask;
|
||||||
|
|
||||||
if (CPBrowserIsOperatingSystem(CPWindowsOperatingSystem) && (aKeyEquivalentModifierMask & CPCommandKeyMask))
|
// Windows and Linux don't have command keys, so just switch it to ctrl.
|
||||||
|
if (!CPBrowserIsOperatingSystem(CPMacOperatingSystem) && (aKeyEquivalentModifierMask & CPCommandKeyMask))
|
||||||
{
|
{
|
||||||
aKeyEquivalentModifierMask |= CPControlKeyMask;
|
aKeyEquivalentModifierMask |= CPControlKeyMask;
|
||||||
aKeyEquivalentModifierMask &= ~CPCommandKeyMask;
|
aKeyEquivalentModifierMask &= ~CPCommandKeyMask;
|
||||||
@@ -556,9 +558,9 @@ var _CPEventPeriodicEventPeriod = 0,
|
|||||||
if (_modifierFlags & (CPCommandKeyMask | CPControlKeyMask))
|
if (_modifierFlags & (CPCommandKeyMask | CPControlKeyMask))
|
||||||
return YES;
|
return YES;
|
||||||
|
|
||||||
for(var i=0; i<characterCount; i++)
|
for (var i = 0; i < characterCount; i++)
|
||||||
{
|
{
|
||||||
switch(_characters.charAt(i))
|
switch (_characters.charAt(i))
|
||||||
{
|
{
|
||||||
case CPBackspaceCharacter:
|
case CPBackspaceCharacter:
|
||||||
case CPDeleteCharacter:
|
case CPDeleteCharacter:
|
||||||
@@ -566,6 +568,7 @@ var _CPEventPeriodicEventPeriod = 0,
|
|||||||
case CPTabCharacter:
|
case CPTabCharacter:
|
||||||
case CPCarriageReturnCharacter:
|
case CPCarriageReturnCharacter:
|
||||||
case CPNewlineCharacter:
|
case CPNewlineCharacter:
|
||||||
|
case CPSpaceFunctionKey:
|
||||||
case CPEscapeFunctionKey:
|
case CPEscapeFunctionKey:
|
||||||
case CPPageUpFunctionKey:
|
case CPPageUpFunctionKey:
|
||||||
case CPPageDownFunctionKey:
|
case CPPageDownFunctionKey:
|
||||||
@@ -573,10 +576,12 @@ var _CPEventPeriodicEventPeriod = 0,
|
|||||||
case CPUpArrowFunctionKey:
|
case CPUpArrowFunctionKey:
|
||||||
case CPRightArrowFunctionKey:
|
case CPRightArrowFunctionKey:
|
||||||
case CPDownArrowFunctionKey:
|
case CPDownArrowFunctionKey:
|
||||||
|
case CPEndFunctionKey:
|
||||||
|
case CPHomeFunctionKey:
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// FIXME: More cases? Space?
|
// FIXME: More cases?
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -75,12 +75,13 @@ var CPSharedFontManager = nil,
|
|||||||
div.appendChild(_CPFontDetectSpan);
|
div.appendChild(_CPFontDetectSpan);
|
||||||
document.getElementsByTagName("body")[0].appendChild(div);
|
document.getElementsByTagName("body")[0].appendChild(div);
|
||||||
|
|
||||||
_CPFontDetectReferenceFonts = _CPFontDetectPickTwoDifferentFonts(["monospace", "serif", "sans-serif", "cursive"]);
|
_CPFontDetectReferenceFonts = _CPFontDetectPickTwoDifferentFonts(["monospace", "serif", "sans-serif", "cursive"]);
|
||||||
|
|
||||||
_availableFonts = [];
|
_availableFonts = [];
|
||||||
for (var i = 0; i < _CPFontDetectAllFonts.length; i++) {
|
for (var i = 0; i < _CPFontDetectAllFonts.length; i++)
|
||||||
|
{
|
||||||
var available = _CPFontDetectFontAvailable(_CPFontDetectAllFonts[i]);
|
var available = _CPFontDetectFontAvailable(_CPFontDetectAllFonts[i]);
|
||||||
if (available)
|
if (available)
|
||||||
_availableFonts.push(_CPFontDetectAllFonts[i]);
|
_availableFonts.push(_CPFontDetectAllFonts[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -136,39 +137,44 @@ var _CPFontDetectSpan,
|
|||||||
"Zapfino"];
|
"Zapfino"];
|
||||||
|
|
||||||
// Compare against the reference fonts. Return true if it produces a different size than at least one of them.
|
// Compare against the reference fonts. Return true if it produces a different size than at least one of them.
|
||||||
var _CPFontDetectFontAvailable = function(font) {
|
var _CPFontDetectFontAvailable = function(font)
|
||||||
for (var i = 0; i < _CPFontDetectReferenceFonts.length; i++)
|
{
|
||||||
if (_CPFontDetectCompareFonts(_CPFontDetectReferenceFonts[i], font))
|
for (var i = 0; i < _CPFontDetectReferenceFonts.length; i++)
|
||||||
return true;
|
if (_CPFontDetectCompareFonts(_CPFontDetectReferenceFonts[i], font))
|
||||||
return false;
|
return true;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var _CPFontDetectCache = {};
|
var _CPFontDetectCache = {};
|
||||||
|
|
||||||
// Compares two given fonts. Returns true if they produce different sizes (i.e. fontA didn't fallback to fontB)
|
// Compares two given fonts. Returns true if they produce different sizes (i.e. fontA didn't fallback to fontB)
|
||||||
var _CPFontDetectCompareFonts = function(fontA, fontB) {
|
var _CPFontDetectCompareFonts = function(fontA, fontB)
|
||||||
|
{
|
||||||
var a;
|
var a;
|
||||||
if (_CPFontDetectCache[fontA]) {
|
if (_CPFontDetectCache[fontA])
|
||||||
a = _CPFontDetectCache[fontA];
|
a = _CPFontDetectCache[fontA];
|
||||||
} else {
|
|
||||||
_CPFontDetectSpan.style.fontFamily = '"' + fontA + '"';
|
else
|
||||||
|
{
|
||||||
|
_CPFontDetectSpan.style.fontFamily = '"' + fontA + '"';
|
||||||
_CPFontDetectCache[fontA] = a = { w: _CPFontDetectSpan.offsetWidth, h: _CPFontDetectSpan.offsetHeight };
|
_CPFontDetectCache[fontA] = a = { w: _CPFontDetectSpan.offsetWidth, h: _CPFontDetectSpan.offsetHeight };
|
||||||
}
|
}
|
||||||
|
|
||||||
_CPFontDetectSpan.style.fontFamily= '"' + fontB + '", "' + fontA + '"';
|
_CPFontDetectSpan.style.fontFamily = '"' + fontB + '", "' + fontA + '"';
|
||||||
var bWidth = _CPFontDetectSpan.offsetWidth;
|
var bWidth = _CPFontDetectSpan.offsetWidth,
|
||||||
var bHeight = _CPFontDetectSpan.offsetHeight;
|
bHeight = _CPFontDetectSpan.offsetHeight;
|
||||||
|
|
||||||
return (a.w != bWidth || a.h != bHeight);
|
return (a.w != bWidth || a.h != bHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test the candidate fonts pairwise until we find two that are different. Otherwise return the first.
|
// Test the candidate fonts pairwise until we find two that are different. Otherwise return the first.
|
||||||
var _CPFontDetectPickTwoDifferentFonts = function(candidates) {
|
var _CPFontDetectPickTwoDifferentFonts = function(candidates)
|
||||||
for (var i = 0; i < candidates.length; i++)
|
{
|
||||||
for (var j = 0; j < i; j++)
|
for (var i = 0; i < candidates.length; i++)
|
||||||
if (_CPFontDetectCompareFonts(candidates[i], candidates[j]))
|
for (var j = 0; j < i; j++)
|
||||||
return [candidates[i], candidates[j]];
|
if (_CPFontDetectCompareFonts(candidates[i], candidates[j]))
|
||||||
return [candidates[0]];
|
return [candidates[i], candidates[j]];
|
||||||
|
return [candidates[0]];
|
||||||
}
|
}
|
||||||
|
|
||||||
[CPFontManager setFontManagerFactory:[CPFontManager class]];
|
[CPFontManager setFontManagerFactory:[CPFontManager class]];
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ function CPPointMake(x, y)
|
|||||||
function CPRectInset(aRect, dX, dY)
|
function CPRectInset(aRect, dX, dY)
|
||||||
{
|
{
|
||||||
return CPRectMake( aRect.origin.x + dX, aRect.origin.y + dY,
|
return CPRectMake( aRect.origin.x + dX, aRect.origin.y + dY,
|
||||||
aRect.size.width - 2 * dX, aRect.size.height - 2*dY);
|
aRect.size.width - 2 * dX, aRect.size.height - 2 * dY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
@@ -357,7 +357,8 @@ var LEFT_SHADOW_INSET = 3.0,
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
var x, y;
|
var x,
|
||||||
|
y;
|
||||||
|
|
||||||
switch (_imageAlignment)
|
switch (_imageAlignment)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ var exposedBindingsMap = [CPDictionary new],
|
|||||||
var CPBindingOperationAnd = 0,
|
var CPBindingOperationAnd = 0,
|
||||||
CPBindingOperationOr = 1;
|
CPBindingOperationOr = 1;
|
||||||
|
|
||||||
@implementation CPKeyValueBinding : CPObject
|
@implementation CPBinder : CPObject
|
||||||
{
|
{
|
||||||
CPDictionary _info;
|
CPDictionary _info;
|
||||||
id _source;
|
id _source;
|
||||||
@@ -43,12 +43,12 @@ var CPBindingOperationAnd = 0,
|
|||||||
|
|
||||||
+ (void)exposeBinding:(CPString)aBinding forClass:(Class)aClass
|
+ (void)exposeBinding:(CPString)aBinding forClass:(Class)aClass
|
||||||
{
|
{
|
||||||
var bindings = [exposedBindingsMap objectForKey:[aClass hash]];
|
var bindings = [exposedBindingsMap objectForKey:[aClass UID]];
|
||||||
|
|
||||||
if (!bindings)
|
if (!bindings)
|
||||||
{
|
{
|
||||||
bindings = [];
|
bindings = [];
|
||||||
[exposedBindingsMap setObject:bindings forKey:[aClass hash]];
|
[exposedBindingsMap setObject:bindings forKey:[aClass UID]];
|
||||||
}
|
}
|
||||||
|
|
||||||
bindings.push(aBinding);
|
bindings.push(aBinding);
|
||||||
@@ -56,12 +56,12 @@ var CPBindingOperationAnd = 0,
|
|||||||
|
|
||||||
+ (CPArray)exposedBindingsForClass:(Class)aClass
|
+ (CPArray)exposedBindingsForClass:(Class)aClass
|
||||||
{
|
{
|
||||||
return [[exposedBindingsMap objectForKey:[aClass hash]] copy];
|
return [[exposedBindingsMap objectForKey:[aClass UID]] copy];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (CPKeyValueBinding)getBinding:(CPString)aBinding forObject:(id)anObject
|
+ (CPBinder)getBinding:(CPString)aBinding forObject:(id)anObject
|
||||||
{
|
{
|
||||||
return [[bindingsMap objectForKey:[anObject hash]] objectForKey:aBinding];
|
return [[bindingsMap objectForKey:[anObject UID]] objectForKey:aBinding];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (CPDictionary)infoForBinding:(CPString)aBinding forObject:(id)anObject
|
+ (CPDictionary)infoForBinding:(CPString)aBinding forObject:(id)anObject
|
||||||
@@ -76,12 +76,12 @@ var CPBindingOperationAnd = 0,
|
|||||||
|
|
||||||
+ (CPDictionary)allBindingsForObject:(id)anObject
|
+ (CPDictionary)allBindingsForObject:(id)anObject
|
||||||
{
|
{
|
||||||
return [bindingsMap objectForKey:[anObject hash]];
|
return [bindingsMap objectForKey:[anObject UID]];
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (void)unbind:(CPString)aBinding forObject:(id)anObject
|
+ (void)unbind:(CPString)aBinding forObject:(id)anObject
|
||||||
{
|
{
|
||||||
var bindings = [bindingsMap objectForKey:[anObject hash]];
|
var bindings = [bindingsMap objectForKey:[anObject UID]];
|
||||||
|
|
||||||
if (!bindings)
|
if (!bindings)
|
||||||
return;
|
return;
|
||||||
@@ -101,7 +101,7 @@ var CPBindingOperationAnd = 0,
|
|||||||
|
|
||||||
+ (void)unbindAllForObject:(id)anObject
|
+ (void)unbindAllForObject:(id)anObject
|
||||||
{
|
{
|
||||||
var bindings = [bindingsMap objectForKey:[anObject hash]];
|
var bindings = [bindingsMap objectForKey:[anObject UID]];
|
||||||
if (!bindings)
|
if (!bindings)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -111,7 +111,7 @@ var CPBindingOperationAnd = 0,
|
|||||||
while (count--)
|
while (count--)
|
||||||
[anObject unbind:[bindings objectForKey:allKeys[count]]];
|
[anObject unbind:[bindings objectForKey:allKeys[count]]];
|
||||||
|
|
||||||
[bindingsMap removeObjectForKey:[anObject hash]];
|
[bindingsMap removeObjectForKey:[anObject UID]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)initWithBinding:(CPString)aBinding name:(CPString)aName to:(id)aDestination keyPath:(CPString)aKeyPath options:(CPDictionary)options from:(id)aSource
|
- (id)initWithBinding:(CPString)aBinding name:(CPString)aName to:(id)aDestination keyPath:(CPString)aKeyPath options:(CPDictionary)options from:(id)aSource
|
||||||
@@ -128,11 +128,11 @@ var CPBindingOperationAnd = 0,
|
|||||||
|
|
||||||
[aDestination addObserver:self forKeyPath:aKeyPath options:CPKeyValueObservingOptionNew context:aBinding];
|
[aDestination addObserver:self forKeyPath:aKeyPath options:CPKeyValueObservingOptionNew context:aBinding];
|
||||||
|
|
||||||
var bindings = [bindingsMap objectForKey:[_source hash]];
|
var bindings = [bindingsMap objectForKey:[_source UID]];
|
||||||
if (!bindings)
|
if (!bindings)
|
||||||
{
|
{
|
||||||
bindings = [CPDictionary new];
|
bindings = [CPDictionary new];
|
||||||
[bindingsMap setObject:bindings forKey:[_source hash]];
|
[bindingsMap setObject:bindings forKey:[_source UID]];
|
||||||
}
|
}
|
||||||
|
|
||||||
[bindings setObject:self forKey:aName];
|
[bindings setObject:self forKey:aName];
|
||||||
@@ -147,39 +147,10 @@ var CPBindingOperationAnd = 0,
|
|||||||
var destination = [_info objectForKey:CPObservedObjectKey],
|
var destination = [_info objectForKey:CPObservedObjectKey],
|
||||||
keyPath = [_info objectForKey:CPObservedKeyPathKey],
|
keyPath = [_info objectForKey:CPObservedKeyPathKey],
|
||||||
options = [_info objectForKey:CPOptionsKey],
|
options = [_info objectForKey:CPOptionsKey],
|
||||||
newValue = [destination valueForKeyPath:keyPath],
|
newValue = [destination valueForKeyPath:keyPath];
|
||||||
isPlaceholder = CPIsControllerMarker(newValue);
|
|
||||||
|
|
||||||
if (isPlaceholder)
|
|
||||||
{
|
|
||||||
switch (newValue)
|
|
||||||
{
|
|
||||||
case CPMultipleValuesMarker:
|
|
||||||
newValue = [options objectForKey:CPMultipleValuesPlaceholderBindingOption] || @"Multiple Values";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CPNoSelectionMarker:
|
|
||||||
newValue = [options objectForKey:CPNoSelectionPlaceholderBindingOption] || @"No Selection";
|
|
||||||
break;
|
|
||||||
|
|
||||||
case CPNotApplicableMarker:
|
|
||||||
if ([options objectForKey:CPRaisesForNotApplicableKeysBindingOption])
|
|
||||||
[CPException raise:CPGenericException reason:@"can't transform non applicable key on: "+_source+" value: "+newValue];
|
|
||||||
|
|
||||||
newValue = [options objectForKey:CPNotApplicablePlaceholderBindingOption] || @"Not Applicable";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Only transform the value if the current value is not a placeholder
|
|
||||||
newValue = [self transformValue:newValue withOptions:options];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
newValue = [self transformValue:newValue withOptions:options];
|
||||||
[_source setValue:newValue forKey:aBinding];
|
[_source setValue:newValue forKey:aBinding];
|
||||||
|
|
||||||
if ([_source respondsToSelector:@selector(_setCurrentValueIsPlaceholder:)])
|
|
||||||
[_source _setCurrentValueIsPlaceholder:isPlaceholder];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)reverseSetValueFor:(CPString)aBinding
|
- (void)reverseSetValueFor:(CPString)aBinding
|
||||||
@@ -231,7 +202,7 @@ var CPBindingOperationAnd = 0,
|
|||||||
aValue = [valueTransformer transformedValue:aValue];
|
aValue = [valueTransformer transformedValue:aValue];
|
||||||
|
|
||||||
|
|
||||||
if (aValue === undefined || aValue === nil)
|
if (aValue === undefined || aValue === nil || aValue === [CPNull null])
|
||||||
aValue = [options objectForKey:CPNullPlaceholderBindingOption] || nil;
|
aValue = [options objectForKey:CPNullPlaceholderBindingOption] || nil;
|
||||||
|
|
||||||
return aValue;
|
return aValue;
|
||||||
@@ -259,7 +230,13 @@ var CPBindingOperationAnd = 0,
|
|||||||
|
|
||||||
+ (void)exposeBinding:(CPString)aBinding
|
+ (void)exposeBinding:(CPString)aBinding
|
||||||
{
|
{
|
||||||
[CPKeyValueBinding exposeBinding:aBinding forClass:[self class]];
|
[CPBinder exposeBinding:aBinding forClass:[self class]];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
+ (Class)_binderClassForBinding:(CPString)theBinding
|
||||||
|
{
|
||||||
|
return [CPBinder class];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (CPArray)exposedBindings
|
- (CPArray)exposedBindings
|
||||||
@@ -269,7 +246,7 @@ var CPBindingOperationAnd = 0,
|
|||||||
|
|
||||||
while (theClass)
|
while (theClass)
|
||||||
{
|
{
|
||||||
var temp = [CPKeyValueBinding exposedBindingsForClass:theClass];
|
var temp = [CPBinder exposedBindingsForClass:theClass];
|
||||||
|
|
||||||
if (temp)
|
if (temp)
|
||||||
[exposedBindings addObjectsFromArray:temp];
|
[exposedBindings addObjectsFromArray:temp];
|
||||||
@@ -293,18 +270,21 @@ var CPBindingOperationAnd = 0,
|
|||||||
//if (![[self exposedBindings] containsObject:aBinding])
|
//if (![[self exposedBindings] containsObject:aBinding])
|
||||||
// CPLog.warn("No binding exposed on "+self+" for "+aBinding);
|
// CPLog.warn("No binding exposed on "+self+" for "+aBinding);
|
||||||
|
|
||||||
|
var binderClass = [[self class] _binderClassForBinding:aBinding];
|
||||||
|
|
||||||
[self unbind:aBinding];
|
[self unbind:aBinding];
|
||||||
[[CPKeyValueBinding alloc] initWithBinding:[self _replacementKeyPathForBinding:aBinding] name:aBinding to:anObject keyPath:aKeyPath options:options from:self];
|
[[binderClass alloc] initWithBinding:[self _replacementKeyPathForBinding:aBinding] name:aBinding to:anObject keyPath:aKeyPath options:options from:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (CPDictionary)infoForBinding:(CPString)aBinding
|
- (CPDictionary)infoForBinding:(CPString)aBinding
|
||||||
{
|
{
|
||||||
return [CPKeyValueBinding infoForBinding:aBinding forObject:self];
|
return [CPBinder infoForBinding:aBinding forObject:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)unbind:(CPString)aBinding
|
- (void)unbind:(CPString)aBinding
|
||||||
{
|
{
|
||||||
[CPKeyValueBinding unbind:aBinding forObject:self];
|
var binderClass = [[self class] _binderClassForBinding:aBinding];
|
||||||
|
[binderClass unbind:aBinding forObject:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)_replacementKeyPathForBinding:(CPString)binding
|
- (id)_replacementKeyPathForBinding:(CPString)binding
|
||||||
@@ -314,13 +294,35 @@ var CPBindingOperationAnd = 0,
|
|||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation _CPKeyValueOrBinding : CPKeyValueBinding
|
/*!
|
||||||
|
@ignore
|
||||||
|
Provides stub implementations that simply call super for the "objectValue" binding
|
||||||
|
This class should not be necessary but assures backwards compliance with our old way of doing bindings
|
||||||
|
Every class with a value binding should implement a subclass to handle it's specific value binding logic
|
||||||
|
*/
|
||||||
|
@implementation _CPValueBinder : CPBinder
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setValueFor:(CPString)theBinding
|
||||||
|
{
|
||||||
|
[super setValueFor:@"objectValue"];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)reverseSetValueFor:(CPString)theBinding
|
||||||
|
{
|
||||||
|
[super reverseSetValueFor:@"objectValue"];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation _CPKeyValueOrBinding : CPBinder
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setValueFor:(CPString)aBinding
|
- (void)setValueFor:(CPString)aBinding
|
||||||
{
|
{
|
||||||
var bindings = [bindingsMap valueForKey:[_source hash]];
|
var bindings = [bindingsMap valueForKey:[_source UID]];
|
||||||
|
|
||||||
if (!bindings)
|
if (!bindings)
|
||||||
return;
|
return;
|
||||||
@@ -335,13 +337,13 @@ var CPBindingOperationAnd = 0,
|
|||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation _CPKeyValueAndBinding : CPKeyValueBinding
|
@implementation _CPKeyValueAndBinding : CPBinder
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setValueFor:(CPString)aBinding
|
- (void)setValueFor:(CPString)aBinding
|
||||||
{
|
{
|
||||||
var bindings = [bindingsMap objectForKey:[_source hash]];
|
var bindings = [bindingsMap objectForKey:[_source UID]];
|
||||||
|
|
||||||
if (!bindings)
|
if (!bindings)
|
||||||
return;
|
return;
|
||||||
@@ -441,30 +443,30 @@ CPToolTipBinding = @"CPToolTipBinding";
|
|||||||
CPValueBinding = @"value";
|
CPValueBinding = @"value";
|
||||||
|
|
||||||
//Binding options constants
|
//Binding options constants
|
||||||
CPAllowsEditingMultipleValuesSelectionBindingOption = @"CPAllowsEditingMultipleValuesSelectionBindingOption";
|
CPAllowsEditingMultipleValuesSelectionBindingOption = @"CPAllowsEditingMultipleValuesSelection";
|
||||||
CPAllowsNullArgumentBindingOption = @"CPAllowsNullArgumentBindingOption";
|
CPAllowsNullArgumentBindingOption = @"CPAllowsNullArgument";
|
||||||
CPConditionallySetsEditableBindingOption = @"CPConditionallySetsEditableBindingOption";
|
CPConditionallySetsEditableBindingOption = @"CPConditionallySetsEditable";
|
||||||
CPConditionallySetsEnabledBindingOption = @"CPConditionallySetsEnabledBindingOption";
|
CPConditionallySetsEnabledBindingOption = @"CPConditionallySetsEnabled";
|
||||||
CPConditionallySetsHiddenBindingOption = @"CPConditionallySetsHiddenBindingOption";
|
CPConditionallySetsHiddenBindingOption = @"CPConditionallySetsHidden";
|
||||||
CPContinuouslyUpdatesValueBindingOption = @"CPContinuouslyUpdatesValueBindingOption";
|
CPContinuouslyUpdatesValueBindingOption = @"CPContinuouslyUpdatesValue";
|
||||||
CPCreatesSortDescriptorBindingOption = @"CPCreatesSortDescriptorBindingOption";
|
CPCreatesSortDescriptorBindingOption = @"CPCreatesSortDescriptor";
|
||||||
CPDeletesObjectsOnRemoveBindingsOption = @"CPDeletesObjectsOnRemoveBindingsOption";
|
CPDeletesObjectsOnRemoveBindingsOption = @"CPDeletesObjectsOnRemove";
|
||||||
CPDisplayNameBindingOption = @"CPDisplayNameBindingOption";
|
CPDisplayNameBindingOption = @"CPDisplayName";
|
||||||
CPDisplayPatternBindingOption = @"CPDisplayPatternBindingOption";
|
CPDisplayPatternBindingOption = @"CPDisplayPattern";
|
||||||
CPHandlesContentAsCompoundValueBindingOption = @"CPHandlesContentAsCompoundValueBindingOption";
|
CPHandlesContentAsCompoundValueBindingOption = @"CPHandlesContentAsCompoundValue";
|
||||||
CPInsertsNullPlaceholderBindingOption = @"CPInsertsNullPlaceholderBindingOption";
|
CPInsertsNullPlaceholderBindingOption = @"CPInsertsNullPlaceholder";
|
||||||
CPInvokesSeparatelyWithArrayObjectsBindingOption = @"CPInvokesSeparatelyWithArrayObjectsBindingOption";
|
CPInvokesSeparatelyWithArrayObjectsBindingOption = @"CPInvokesSeparatelyWithArrayObjects";
|
||||||
CPMultipleValuesPlaceholderBindingOption = @"CPMultipleValuesPlaceholderBindingOption";
|
CPMultipleValuesPlaceholderBindingOption = @"CPMultipleValuesPlaceholder";
|
||||||
CPNoSelectionPlaceholderBindingOption = @"CPNoSelectionPlaceholderBindingOption";
|
CPNoSelectionPlaceholderBindingOption = @"CPNoSelectionPlaceholder";
|
||||||
CPNotApplicablePlaceholderBindingOption = @"CPNotApplicablePlaceholderBindingOption";
|
CPNotApplicablePlaceholderBindingOption = @"CPNotApplicablePlaceholder";
|
||||||
CPNullPlaceholderBindingOption = @"CPNullPlaceholderBindingOption";
|
CPNullPlaceholderBindingOption = @"CPNullPlaceholder";
|
||||||
CPPredicateFormatBindingOption = @"CPPredicateFormatBindingOption";
|
CPPredicateFormatBindingOption = @"CPPredicateFormat";
|
||||||
CPRaisesForNotApplicableKeysBindingOption = @"CPRaisesForNotApplicableKeysBindingOption";
|
CPRaisesForNotApplicableKeysBindingOption = @"CPRaisesForNotApplicableKeys";
|
||||||
CPSelectorNameBindingOption = @"CPSelectorNameBindingOption";
|
CPSelectorNameBindingOption = @"CPSelectorName";
|
||||||
CPSelectsAllWhenSettingContentBindingOption = @"CPSelectsAllWhenSettingContentBindingOption";
|
CPSelectsAllWhenSettingContentBindingOption = @"CPSelectsAllWhenSettingContent";
|
||||||
CPValidatesImmediatelyBindingOption = @"CPValidatesImmediatelyBindingOption";
|
CPValidatesImmediatelyBindingOption = @"CPValidatesImmediately";
|
||||||
CPValueTransformerNameBindingOption = @"CPValueTransformerNameBindingOption";
|
CPValueTransformerNameBindingOption = @"CPValueTransformerName";
|
||||||
CPValueTransformerBindingOption = @"CPValueTransformerBindingOption";
|
CPValueTransformerBindingOption = @"CPValueTransformer";
|
||||||
|
|
||||||
CPIsControllerMarker = function(/*id*/anObject)
|
CPIsControllerMarker = function(/*id*/anObject)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -80,6 +80,9 @@ var _CPMenuBarVisible = NO,
|
|||||||
|
|
||||||
+ (void)initialize
|
+ (void)initialize
|
||||||
{
|
{
|
||||||
|
if (self !== CPMenu)
|
||||||
|
return;
|
||||||
|
|
||||||
[[self class] setMenuBarAttributes:[CPDictionary dictionary]];
|
[[self class] setMenuBarAttributes:[CPDictionary dictionary]];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -274,22 +277,7 @@ var _CPMenuBarVisible = NO,
|
|||||||
*/
|
*/
|
||||||
- (void)insertItem:(CPMenuItem)aMenuItem atIndex:(unsigned)anIndex
|
- (void)insertItem:(CPMenuItem)aMenuItem atIndex:(unsigned)anIndex
|
||||||
{
|
{
|
||||||
var menu = [aMenuItem menu];
|
[self insertObject:aMenuItem inItemsAtIndex:anIndex];
|
||||||
|
|
||||||
if (menu)
|
|
||||||
if (menu !== self)
|
|
||||||
[CPException raise:CPInternalInconsistencyException reason:@"Attempted to insert item into menu that was already in another menu."];
|
|
||||||
else
|
|
||||||
return;
|
|
||||||
|
|
||||||
[aMenuItem setMenu:self];
|
|
||||||
[_items insertObject:aMenuItem atIndex:anIndex];
|
|
||||||
|
|
||||||
[[CPNotificationCenter defaultCenter]
|
|
||||||
postNotificationName:CPMenuDidAddItemNotification
|
|
||||||
object:self
|
|
||||||
userInfo:[CPDictionary dictionaryWithObject:anIndex forKey:@"CPMenuItemIndex"]];
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -346,16 +334,7 @@ var _CPMenuBarVisible = NO,
|
|||||||
*/
|
*/
|
||||||
- (void)removeItemAtIndex:(unsigned)anIndex
|
- (void)removeItemAtIndex:(unsigned)anIndex
|
||||||
{
|
{
|
||||||
if (anIndex < 0 || anIndex >= _items.length)
|
[self removeObjectFromItemsAtIndex:anIndex];
|
||||||
return;
|
|
||||||
|
|
||||||
[_items[anIndex] setMenu:nil];
|
|
||||||
[_items removeObjectAtIndex:anIndex];
|
|
||||||
|
|
||||||
[[CPNotificationCenter defaultCenter]
|
|
||||||
postNotificationName:CPMenuDidRemoveItemNotification
|
|
||||||
object:self
|
|
||||||
userInfo:[CPDictionary dictionaryWithObject:anIndex forKey:@"CPMenuItemIndex"]];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -364,9 +343,11 @@ var _CPMenuBarVisible = NO,
|
|||||||
*/
|
*/
|
||||||
- (void)itemChanged:(CPMenuItem)aMenuItem
|
- (void)itemChanged:(CPMenuItem)aMenuItem
|
||||||
{
|
{
|
||||||
if ([aMenuItem menu] != self)
|
if ([aMenuItem menu] !== self)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
[aMenuItem setValue:[aMenuItem valueForKey:@"changeCount"] + 1 forKey:@"changeCount"];
|
||||||
|
|
||||||
[[CPNotificationCenter defaultCenter]
|
[[CPNotificationCenter defaultCenter]
|
||||||
postNotificationName:CPMenuDidChangeItemNotification
|
postNotificationName:CPMenuDidChangeItemNotification
|
||||||
object:self
|
object:self
|
||||||
@@ -692,7 +673,7 @@ var _CPMenuBarVisible = NO,
|
|||||||
var delegate = [self delegate];
|
var delegate = [self delegate];
|
||||||
|
|
||||||
if ([delegate respondsToSelector:@selector(menuWillOpen:)])
|
if ([delegate respondsToSelector:@selector(menuWillOpen:)])
|
||||||
[delegate menuWillOpen:aMenu];
|
[delegate menuWillOpen:self];
|
||||||
|
|
||||||
// Convert location to global coordinates if not already in them.
|
// Convert location to global coordinates if not already in them.
|
||||||
if (aView)
|
if (aView)
|
||||||
@@ -1035,6 +1016,61 @@ var _CPMenuBarVisible = NO,
|
|||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@implementation CPMenu (CPKeyValueCoding)
|
||||||
|
|
||||||
|
- (CPUInteger)countOfItems
|
||||||
|
{
|
||||||
|
return [_items count];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (CPMenuItem)objectInItemsAtIndex:(CPUInteger)anIndex
|
||||||
|
{
|
||||||
|
return [_items objectAtIndex:anIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (CPArray)itemsAtIndexes:(CPIndexSet)indexes
|
||||||
|
{
|
||||||
|
return [_items objectsAtIndexes:indexes];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation CPMenu (CPKeyValueObserving)
|
||||||
|
|
||||||
|
- (void)insertObject:(CPMenuItem)aMenuItem inItemsAtIndex:(CPUInteger)anIndex
|
||||||
|
{
|
||||||
|
var menu = [aMenuItem menu];
|
||||||
|
|
||||||
|
if (menu)
|
||||||
|
if (menu !== self)
|
||||||
|
[CPException raise:CPInternalInconsistencyException reason:@"Attempted to insert item into menu that was already in another menu."];
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
|
||||||
|
[aMenuItem setMenu:self];
|
||||||
|
[_items insertObject:aMenuItem atIndex:anIndex];
|
||||||
|
|
||||||
|
[[CPNotificationCenter defaultCenter]
|
||||||
|
postNotificationName:CPMenuDidAddItemNotification
|
||||||
|
object:self
|
||||||
|
userInfo:[CPDictionary dictionaryWithObject:anIndex forKey:@"CPMenuItemIndex"]];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)removeObjectFromItemsAtIndex:(CPUInteger)anIndex
|
||||||
|
{
|
||||||
|
if (anIndex < 0 || anIndex >= [_items count])
|
||||||
|
return;
|
||||||
|
|
||||||
|
[[_items objectAtIndex:anIndex] setMenu:nil];
|
||||||
|
[_items removeObjectAtIndex:anIndex];
|
||||||
|
|
||||||
|
[[CPNotificationCenter defaultCenter]
|
||||||
|
postNotificationName:CPMenuDidRemoveItemNotification
|
||||||
|
object:self
|
||||||
|
userInfo:[CPDictionary dictionaryWithObject:anIndex forKey:@"CPMenuItemIndex"]];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
var CPMenuTitleKey = @"CPMenuTitleKey",
|
var CPMenuTitleKey = @"CPMenuTitleKey",
|
||||||
CPMenuNameKey = @"CPMenuNameKey",
|
CPMenuNameKey = @"CPMenuNameKey",
|
||||||
|
|||||||
@@ -77,6 +77,8 @@
|
|||||||
id _representedObject;
|
id _representedObject;
|
||||||
CPView _view;
|
CPView _view;
|
||||||
|
|
||||||
|
int _changeCount;
|
||||||
|
|
||||||
_CPMenuItemView _menuItemView;
|
_CPMenuItemView _menuItemView;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,12 +100,14 @@
|
|||||||
|
|
||||||
if (self)
|
if (self)
|
||||||
{
|
{
|
||||||
|
_changeCount = 0;
|
||||||
_isSeparator = NO;
|
_isSeparator = NO;
|
||||||
|
|
||||||
_title = aTitle;
|
_title = aTitle;
|
||||||
_action = anAction;
|
_action = anAction;
|
||||||
|
|
||||||
_isEnabled = YES;
|
_isEnabled = YES;
|
||||||
|
_isHidden = NO;
|
||||||
|
|
||||||
_tag = 0;
|
_tag = 0;
|
||||||
_state = CPOffState;
|
_state = CPOffState;
|
||||||
@@ -459,7 +463,7 @@ CPOffState
|
|||||||
|
|
||||||
if (supermenu)
|
if (supermenu)
|
||||||
[CPException raise:CPInvalidArgumentException
|
[CPException raise:CPInvalidArgumentException
|
||||||
reason: @"Can't add submenu \"" + [aMenu title] + "\" to item \"" + [self title] + "\", because it is already submenu of \"" + [[aMenu supermenu] title] + "\""];
|
reason: @"Can't add submenu \"" + [aMenu title] + "\" to item \"" + [self title] + "\", because it is already submenu of \"" + [[aMenu supermenu] title] + "\""];
|
||||||
|
|
||||||
_submenu = aMenu;
|
_submenu = aMenu;
|
||||||
|
|
||||||
@@ -890,6 +894,7 @@ var CPMenuItemIsSeparatorKey = @"CPMenuItemIsSeparatorKey",
|
|||||||
|
|
||||||
if (self)
|
if (self)
|
||||||
{
|
{
|
||||||
|
_changeCount = 0;
|
||||||
_isSeparator = [aCoder containsValueForKey:CPMenuItemIsSeparatorKey] && [aCoder decodeBoolForKey:CPMenuItemIsSeparatorKey];
|
_isSeparator = [aCoder containsValueForKey:CPMenuItemIsSeparatorKey] && [aCoder decodeBoolForKey:CPMenuItemIsSeparatorKey];
|
||||||
|
|
||||||
_title = [aCoder decodeObjectForKey:CPMenuItemTitleKey];
|
_title = [aCoder decodeObjectForKey:CPMenuItemTitleKey];
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ var _CPMenuItemSelectionColor = nil,
|
|||||||
BOOL _isDirty;
|
BOOL _isDirty;
|
||||||
BOOL _showsStateColumn;
|
BOOL _showsStateColumn;
|
||||||
|
|
||||||
CPImageView _stateView;
|
|
||||||
_CPImageAndTextView _imageAndTextView;
|
_CPImageAndTextView _imageAndTextView;
|
||||||
CPView _submenuView;
|
CPView _submenuView;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,13 +4,23 @@
|
|||||||
|
|
||||||
@import "CPController.j"
|
@import "CPController.j"
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@class
|
||||||
|
|
||||||
|
CPObjectController is a bindings-compatible controller class.
|
||||||
|
Properties of the content object of an object of this class can be bound to user interface elements to change and access their values.
|
||||||
|
|
||||||
|
The content of an CPObjectController instance is an CPMutableDictionary object by default.
|
||||||
|
This allows a single CPObjectController instance to be used to manage several properties accessed by key value paths.
|
||||||
|
The default content object class can be changed by calling setObjectClass:, which a subclass must override.
|
||||||
|
*/
|
||||||
@implementation CPObjectController : CPController
|
@implementation CPObjectController : CPController
|
||||||
{
|
{
|
||||||
id _contentObject;
|
id _contentObject;
|
||||||
id _selection;
|
id _selection;
|
||||||
|
|
||||||
Class _objectClass;
|
Class _objectClass;
|
||||||
|
CPString _objectClassName;
|
||||||
|
|
||||||
BOOL _isEditable;
|
BOOL _isEditable;
|
||||||
BOOL _automaticallyPreparesContent;
|
BOOL _automaticallyPreparesContent;
|
||||||
@@ -52,11 +62,20 @@
|
|||||||
return [CPSet setWithObjects:"editable", "selection"];
|
return [CPSet setWithObjects:"editable", "selection"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
- (id)init
|
- (id)init
|
||||||
{
|
{
|
||||||
return [self initWithContent:nil];
|
return [self initWithContent:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Inits and returns a CPObjectController object with the given content.
|
||||||
|
|
||||||
|
@param id aContent - The object the conroller will use.
|
||||||
|
@return id the CPObjectConroller instance.
|
||||||
|
*/
|
||||||
- (id)initWithContent:(id)aContent
|
- (id)initWithContent:(id)aContent
|
||||||
{
|
{
|
||||||
if (self = [super init])
|
if (self = [super init])
|
||||||
@@ -71,11 +90,19 @@
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns the controller's content object.
|
||||||
|
@return id - The content object of the controller.
|
||||||
|
*/
|
||||||
- (id)content
|
- (id)content
|
||||||
{
|
{
|
||||||
return _contentObject;
|
return _contentObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Sets the content object for the controller.
|
||||||
|
@param id aContent - The new content object for the controller.
|
||||||
|
*/
|
||||||
- (void)setContent:(id)aContent
|
- (void)setContent:(id)aContent
|
||||||
{
|
{
|
||||||
[self willChangeValueForKey:@"contentObject"];
|
[self willChangeValueForKey:@"contentObject"];
|
||||||
@@ -87,109 +114,193 @@
|
|||||||
[self _selectionDidChange];
|
[self _selectionDidChange];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
- (void)_setContentObject:(id)aContent
|
- (void)_setContentObject:(id)aContent
|
||||||
{
|
{
|
||||||
[self setContent:aContent];
|
[self setContent:aContent];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
- (id)_contentObject
|
- (id)_contentObject
|
||||||
{
|
{
|
||||||
return [self content];
|
return [self content];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Sets whether the controller automatically creates and inserts new content objects automatically when loading from a cib file.
|
||||||
|
If you pass YES and the controller uses prepareContent to create the content object.
|
||||||
|
The default is NO.
|
||||||
|
|
||||||
|
@param BOOL shouldAutomaticallyPrepareContent - YES if the content should be prepared, otherwise NO.
|
||||||
|
*/
|
||||||
- (void)setAutomaticallyPreparesContent:(BOOL)shouldAutomaticallyPrepareContent
|
- (void)setAutomaticallyPreparesContent:(BOOL)shouldAutomaticallyPrepareContent
|
||||||
{
|
{
|
||||||
_automaticallyPreparesContent = shouldAutomaticallyPrepareContent;
|
_automaticallyPreparesContent = shouldAutomaticallyPrepareContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns if the controller prepares the content automatically.
|
||||||
|
@return BOOL - YES if the content is prepared, otherwise NO.
|
||||||
|
*/
|
||||||
- (BOOL)automaticallyPreparesContent
|
- (BOOL)automaticallyPreparesContent
|
||||||
{
|
{
|
||||||
return _automaticallyPreparesContent;
|
return _automaticallyPreparesContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Overridden by a subclass that require control over the creation of new objects.
|
||||||
|
*/
|
||||||
- (void)prepareContent
|
- (void)prepareContent
|
||||||
{
|
{
|
||||||
[self setContent:[self newObject]];
|
[self setContent:[self newObject]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Sets the object class when creating new objects.
|
||||||
|
@param Class - the class of new objects that will be created.
|
||||||
|
*/
|
||||||
- (void)setObjectClass:(Class)aClass
|
- (void)setObjectClass:(Class)aClass
|
||||||
{
|
{
|
||||||
_objectClass = aClass;
|
_objectClass = aClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns the class of what new objects will be when they are created.
|
||||||
|
|
||||||
|
@return Class - The class of new objects.
|
||||||
|
*/
|
||||||
- (Class)objectClass
|
- (Class)objectClass
|
||||||
{
|
{
|
||||||
return _objectClass;
|
return _objectClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)newObject
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
|
- (id)_defaultNewObject
|
||||||
{
|
{
|
||||||
return [[[self objectClass] alloc] init];
|
return [[[self objectClass] alloc] init];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Creates and returns a new object of the appropriate class.
|
||||||
|
@return id - The object created.
|
||||||
|
*/
|
||||||
|
- (id)newObject
|
||||||
|
{
|
||||||
|
return [self _defaultNewObject];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Sets the controller's content object.
|
||||||
|
@param id anObject - The object to set for the controller.
|
||||||
|
*/
|
||||||
- (void)addObject:(id)anObject
|
- (void)addObject:(id)anObject
|
||||||
{
|
{
|
||||||
[self setContent:anObject];
|
[self setContent:anObject];
|
||||||
|
|
||||||
[[CPKeyValueBinding getBinding:@"contentObject" forObject:self] reverseSetValueFor:@"contentObject"];
|
var binderClass = [[self class] _binderClassForBinding:@"contentObject"];
|
||||||
|
[[binderClass getBinding:@"contentObject" forObject:self] reverseSetValueFor:@"contentObject"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Removes a given object from the controller.
|
||||||
|
@param id anObject - The object to remove from the reciver.
|
||||||
|
*/
|
||||||
- (void)removeObject:(id)anObject
|
- (void)removeObject:(id)anObject
|
||||||
{
|
{
|
||||||
if ([self content] === anObject)
|
if ([self content] === anObject)
|
||||||
[self setContent:nil];
|
[self setContent:nil];
|
||||||
|
|
||||||
[[CPKeyValueBinding getBinding:@"contentObject" forObject:self] reverseSetValueFor:@"contentObject"];
|
var binderClass = [[self class] _binderClassForBinding:@"contentObject"];
|
||||||
|
[[binderClass getBinding:@"contentObject" forObject:self] reverseSetValueFor:@"contentObject"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Creates and adds a sets the object as the controller's content.
|
||||||
|
@param id aSender - The sender of the message.
|
||||||
|
*/
|
||||||
- (void)add:(id)aSender
|
- (void)add:(id)aSender
|
||||||
{
|
{
|
||||||
// FIXME: This should happen on the next run loop?
|
// FIXME: This should happen on the next run loop?
|
||||||
[self addObject:[self newObject]];
|
[self addObject:[self newObject]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@return BOOL - YES if you can added to the controller using add:
|
||||||
|
*/
|
||||||
- (BOOL)canAdd
|
- (BOOL)canAdd
|
||||||
{
|
{
|
||||||
return [self isEditable];
|
return [self isEditable];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Removes the content object from the controller.
|
||||||
|
@param id aSender - The sender of the message.
|
||||||
|
*/
|
||||||
- (void)remove:(id)aSender
|
- (void)remove:(id)aSender
|
||||||
{
|
{
|
||||||
// FIXME: This should happen on the next run loop?
|
// FIXME: This should happen on the next run loop?
|
||||||
[self removeObject:[self content]];
|
[self removeObject:[self content]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@return BOOL - Returns YES if you can remove the controller's content using remove:
|
||||||
|
*/
|
||||||
- (BOOL)canRemove
|
- (BOOL)canRemove
|
||||||
{
|
{
|
||||||
return [self isEditable] && [[self selectedObjects] count];
|
return [self isEditable] && [[self selectedObjects] count];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Sets whether the controller allows for the editing of the content.
|
||||||
|
@param BOOL shouldBeEditable - YES if the content should be editable, otherwise NO.
|
||||||
|
*/
|
||||||
- (void)setEditable:(BOOL)shouldBeEditable
|
- (void)setEditable:(BOOL)shouldBeEditable
|
||||||
{
|
{
|
||||||
_isEditable = shouldBeEditable;
|
_isEditable = shouldBeEditable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@return BOOL - Returns YES if the content of the controller is editable, otherwise NO.
|
||||||
|
*/
|
||||||
- (BOOL)isEditable
|
- (BOOL)isEditable
|
||||||
{
|
{
|
||||||
return _isEditable;
|
return _isEditable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@return CPArray - Returns an array of all objects to be affected by editing.
|
||||||
|
*/
|
||||||
- (CPArray)selectedObjects
|
- (CPArray)selectedObjects
|
||||||
{
|
{
|
||||||
return [[_CPObservableArray alloc] initWithObjects:[_contentObject] count:1];
|
return [[_CPObservableArray alloc] initWithArray:[_contentObject]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns a proxy object representing the controller's selection.
|
||||||
|
*/
|
||||||
- (id)selection
|
- (id)selection
|
||||||
{
|
{
|
||||||
return _selection;
|
return _selection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
- (void)_selectionWillChange
|
- (void)_selectionWillChange
|
||||||
{
|
{
|
||||||
[_selection controllerWillChange];
|
[_selection controllerWillChange];
|
||||||
[self willChangeValueForKey:@"selection"];
|
[self willChangeValueForKey:@"selection"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
- (void)_selectionDidChange
|
- (void)_selectionDidChange
|
||||||
{
|
{
|
||||||
if (_selection === undefined || _selection === nil)
|
if (_selection === undefined || _selection === nil)
|
||||||
@@ -199,6 +310,9 @@
|
|||||||
[self didChangeValueForKey:@"selection"];
|
[self didChangeValueForKey:@"selection"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@return id - Returns the keys which are being observed.
|
||||||
|
*/
|
||||||
- (id)observedKeys
|
- (id)observedKeys
|
||||||
{
|
{
|
||||||
return _observedKeys;
|
return _observedKeys;
|
||||||
@@ -218,7 +332,8 @@
|
|||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
var CPObjectControllerObjectClassNameKey = @"CPObjectControllerObjectClassNameKey",
|
var CPObjectControllerContentKey = @"CPObjectControllerContentKey",
|
||||||
|
CPObjectControllerObjectClassNameKey = @"CPObjectControllerObjectClassNameKey",
|
||||||
CPObjectControllerIsEditableKey = @"CPObjectControllerIsEditableKey",
|
CPObjectControllerIsEditableKey = @"CPObjectControllerIsEditableKey",
|
||||||
CPObjectControllerAutomaticallyPreparesContentKey = @"CPObjectControllerAutomaticallyPreparesContentKey";
|
CPObjectControllerAutomaticallyPreparesContentKey = @"CPObjectControllerAutomaticallyPreparesContentKey";
|
||||||
|
|
||||||
@@ -233,11 +348,10 @@ var CPObjectControllerObjectClassNameKey = @"CPObjectControllerOb
|
|||||||
var objectClassName = [aCoder decodeObjectForKey:CPObjectControllerObjectClassNameKey],
|
var objectClassName = [aCoder decodeObjectForKey:CPObjectControllerObjectClassNameKey],
|
||||||
objectClass = CPClassFromString(objectClassName);
|
objectClass = CPClassFromString(objectClassName);
|
||||||
|
|
||||||
// FIXME: Error if objectClass === nil
|
[self setObjectClass:objectClass || [CPMutableDictionary class]];
|
||||||
|
|
||||||
[self setObjectClass:objectClass];
|
|
||||||
[self setEditable:[aCoder decodeBoolForKey:CPObjectControllerIsEditableKey]];
|
[self setEditable:[aCoder decodeBoolForKey:CPObjectControllerIsEditableKey]];
|
||||||
[self setAutomaticallyPreparesContent:[aCoder decodeBoolForKey:CPObjectControllerAutomaticallyPreparesContentKey] || NO];
|
[self setAutomaticallyPreparesContent:[aCoder decodeBoolForKey:CPObjectControllerAutomaticallyPreparesContentKey] || NO];
|
||||||
|
[self setContent:[aCoder decodeObjectForKey:CPObjectControllerContentKey]];
|
||||||
|
|
||||||
_observedKeys = [[CPCountedSet alloc] init];
|
_observedKeys = [[CPCountedSet alloc] init];
|
||||||
}
|
}
|
||||||
@@ -247,11 +361,15 @@ var CPObjectControllerObjectClassNameKey = @"CPObjectControllerOb
|
|||||||
|
|
||||||
- (void)encodeWithCoder:(CPCoder)aCoder
|
- (void)encodeWithCoder:(CPCoder)aCoder
|
||||||
{
|
{
|
||||||
[aCoder encodeObject:CPStringFromClass(objectClass) forKey:CPObjectControllerObjectClassNameKey];
|
[aCoder encodeObject:[self content] forKey:CPObjectControllerContentKey];
|
||||||
[aCoder encodeObject:[self isEditable] forKey:CPObjectControllerIsEditableKey];
|
|
||||||
|
|
||||||
if (![self automaticallyPreparesContent])
|
if (_objectClass)
|
||||||
[aCoder encodeBOOL:YES forKey:CPObjectControllerAutomaticallyPreparesContentKey];
|
[aCoder encodeObject:CPStringFromClass(_objectClass) forKey:CPObjectControllerObjectClassNameKey];
|
||||||
|
else if (_objectClassName)
|
||||||
|
[aCoder encodeObject:_objectClassName forKey:CPObjectControllerObjectClassNameKey];
|
||||||
|
|
||||||
|
[aCoder encodeBool:[self isEditable] forKey:CPObjectControllerIsEditableKey];
|
||||||
|
[aCoder encodeBool:[self automaticallyPreparesContent] forKey:CPObjectControllerAutomaticallyPreparesContentKey];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -270,7 +388,7 @@ var CPObjectControllerObjectClassNameKey = @"CPObjectControllerOb
|
|||||||
|
|
||||||
- (id)initWithKeyPath:(id)aKeyPath observer:(id)anObserver object:(id)anObject
|
- (id)initWithKeyPath:(id)aKeyPath observer:(id)anObserver object:(id)anObject
|
||||||
{
|
{
|
||||||
if (self=[super init])
|
if (self = [super init])
|
||||||
{
|
{
|
||||||
_keyPath = aKeyPath;
|
_keyPath = aKeyPath;
|
||||||
_observer = anObserver;
|
_observer = anObserver;
|
||||||
@@ -319,9 +437,9 @@ var CPObjectControllerObjectClassNameKey = @"CPObjectControllerOb
|
|||||||
- (void)observeValueForKeyPath:(CPString)aKeyPath ofObject:(id)anObject change:(CPDictionary)change context:(id)context
|
- (void)observeValueForKeyPath:(CPString)aKeyPath ofObject:(id)anObject change:(CPDictionary)change context:(id)context
|
||||||
{
|
{
|
||||||
if (_notifyObject)
|
if (_notifyObject)
|
||||||
[_object observeValueForKeyPath:_keyPath ofObject:_object change:change context:context];
|
[_object observeValueForKeyPath:aKeyPath ofObject:_object change:change context:context];
|
||||||
|
|
||||||
[_observer observeValueForKeyPath:_keyPath ofObject:_object change:change context:context];
|
[_observer observeValueForKeyPath:aKeyPath ofObject:_object change:change context:context];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (CPString)description
|
- (CPString)description
|
||||||
@@ -331,7 +449,8 @@ var CPObjectControllerObjectClassNameKey = @"CPObjectControllerOb
|
|||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation _CPObservableArray : CPMutableArray
|
// FIXME: This should subclass CPMutableArray not _CPJavaScriptArray
|
||||||
|
@implementation _CPObservableArray : _CPJavaScriptArray
|
||||||
{
|
{
|
||||||
CPArray _observationProxies;
|
CPArray _observationProxies;
|
||||||
}
|
}
|
||||||
@@ -357,25 +476,15 @@ var CPObjectControllerObjectClassNameKey = @"CPObjectControllerOb
|
|||||||
|
|
||||||
- (id)initWithArray:(CPArray)anArray
|
- (id)initWithArray:(CPArray)anArray
|
||||||
{
|
{
|
||||||
if (self = [super initWithArray:anArray])
|
self = [super initWithArray:anArray];
|
||||||
{
|
|
||||||
_observationProxies = [];
|
self.isa = [_CPObservableArray class];
|
||||||
}
|
self._observationProxies = [];
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)initWithObjects:(CPArray)objects count:(unsigned)count
|
- (void)addObserver:(id)anObserver forKeyPath:(CPString)aKeyPath options:(CPKeyValueObservingOptions)options context:(id)context
|
||||||
{
|
|
||||||
if (self = [super initWithObjects:objects count:count])
|
|
||||||
{
|
|
||||||
_observationProxies = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
-(void)addObserver:(id)anObserver forKeyPath:(CPString)aKeyPath options:(CPKeyValueObservingOptions)options context:(id)context
|
|
||||||
{
|
{
|
||||||
if (aKeyPath.indexOf("@") === 0)
|
if (aKeyPath.indexOf("@") === 0)
|
||||||
{
|
{
|
||||||
@@ -387,7 +496,7 @@ var CPObjectControllerObjectClassNameKey = @"CPObjectControllerOb
|
|||||||
[_observationProxies addObject:proxy];
|
[_observationProxies addObject:proxy];
|
||||||
|
|
||||||
var dotIndex = aKeyPath.indexOf("."),
|
var dotIndex = aKeyPath.indexOf("."),
|
||||||
remaining = aKeyPath.substring(dotIndex+1),
|
remaining = aKeyPath.substring(dotIndex + 1),
|
||||||
indexes = [CPIndexSet indexSetWithIndexesInRange:CPMakeRange(0, [self count])];
|
indexes = [CPIndexSet indexSetWithIndexesInRange:CPMakeRange(0, [self count])];
|
||||||
|
|
||||||
[self addObserver:proxy toObjectsAtIndexes:indexes forKeyPath:remaining options:options context:context];
|
[self addObserver:proxy toObjectsAtIndexes:indexes forKeyPath:remaining options:options context:context];
|
||||||
@@ -409,7 +518,7 @@ var CPObjectControllerObjectClassNameKey = @"CPObjectControllerOb
|
|||||||
proxy = [_observationProxies objectAtIndex:index];
|
proxy = [_observationProxies objectAtIndex:index];
|
||||||
|
|
||||||
var dotIndex = aKeyPath.indexOf("."),
|
var dotIndex = aKeyPath.indexOf("."),
|
||||||
remaining = aKeyPath.substring(dotIndex+1),
|
remaining = aKeyPath.substring(dotIndex + 1),
|
||||||
indexes = [CPIndexSet indexSetWithIndexesInRange:CPMakeRange(0, [self count])];
|
indexes = [CPIndexSet indexSetWithIndexesInRange:CPMakeRange(0, [self count])];
|
||||||
|
|
||||||
[self removeObserver:proxy fromObjectsAtIndexes:indexes forKeyPath:remaining];
|
[self removeObserver:proxy fromObjectsAtIndexes:indexes forKeyPath:remaining];
|
||||||
@@ -423,7 +532,7 @@ var CPObjectControllerObjectClassNameKey = @"CPObjectControllerOb
|
|||||||
|
|
||||||
- (void)insertObject:(id)anObject atIndex:(unsigned)anIndex
|
- (void)insertObject:(id)anObject atIndex:(unsigned)anIndex
|
||||||
{
|
{
|
||||||
for (var i=0, count=[_observationProxies count]; i<count; i++)
|
for (var i = 0, count = [_observationProxies count]; i < count; i++)
|
||||||
{
|
{
|
||||||
var proxy = [_observationProxies objectAtIndex:i],
|
var proxy = [_observationProxies objectAtIndex:i],
|
||||||
keyPath = [proxy keyPath],
|
keyPath = [proxy keyPath],
|
||||||
@@ -443,7 +552,7 @@ var CPObjectControllerObjectClassNameKey = @"CPObjectControllerOb
|
|||||||
|
|
||||||
- (void)removeObjectAtIndex:(unsigned)anIndex
|
- (void)removeObjectAtIndex:(unsigned)anIndex
|
||||||
{
|
{
|
||||||
for (var i=0, count=[_observationProxies count]; i<count; i++)
|
for (var i = 0, count = [_observationProxies count]; i < count; i++)
|
||||||
{
|
{
|
||||||
var proxy = [_observationProxies objectAtIndex:i],
|
var proxy = [_observationProxies objectAtIndex:i],
|
||||||
keyPath = [proxy keyPath],
|
keyPath = [proxy keyPath],
|
||||||
@@ -480,7 +589,7 @@ var CPObjectControllerObjectClassNameKey = @"CPObjectControllerOb
|
|||||||
{
|
{
|
||||||
var currentObject = [self objectAtIndex:anIndex];
|
var currentObject = [self objectAtIndex:anIndex];
|
||||||
|
|
||||||
for (var i=0, count=[_observationProxies count]; i<count; i++)
|
for (var i = 0, count = [_observationProxies count]; i < count; i++)
|
||||||
{
|
{
|
||||||
var proxy = [_observationProxies objectAtIndex:i],
|
var proxy = [_observationProxies objectAtIndex:i],
|
||||||
keyPath = [proxy keyPath],
|
keyPath = [proxy keyPath],
|
||||||
@@ -503,11 +612,13 @@ var CPObjectControllerObjectClassNameKey = @"CPObjectControllerOb
|
|||||||
|
|
||||||
@implementation CPControllerSelectionProxy : CPObject
|
@implementation CPControllerSelectionProxy : CPObject
|
||||||
{
|
{
|
||||||
id _controller;
|
id _controller;
|
||||||
id _keys;
|
id _keys;
|
||||||
|
|
||||||
CPDictionary _cachedValues;
|
CPDictionary _cachedValues;
|
||||||
CPArray _observationProxies;
|
CPArray _observationProxies;
|
||||||
|
|
||||||
|
Object _observedObjectsByKeyPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)initWithController:(id)aController
|
- (id)initWithController:(id)aController
|
||||||
@@ -517,46 +628,65 @@ var CPObjectControllerObjectClassNameKey = @"CPObjectControllerOb
|
|||||||
_cachedValues = [CPDictionary dictionary];
|
_cachedValues = [CPDictionary dictionary];
|
||||||
_observationProxies = [CPArray array];
|
_observationProxies = [CPArray array];
|
||||||
_controller = aController;
|
_controller = aController;
|
||||||
|
_observedObjectsByKeyPath = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)valueForKey:(CPString)aKey
|
- (id)_controllerMarkerForValues:(CPArray)theValues
|
||||||
{
|
{
|
||||||
var value = [_cachedValues objectForKey:aKey];
|
var count = [theValues count];
|
||||||
|
|
||||||
if (value !== undefined && value !== nil)
|
|
||||||
return value;
|
|
||||||
|
|
||||||
var allValues = [[_controller selectedObjects] valueForKeyPath:aKey],
|
|
||||||
count = [allValues count];
|
|
||||||
|
|
||||||
if (!count)
|
if (!count)
|
||||||
value = CPNoSelectionMarker;
|
value = CPNoSelectionMarker;
|
||||||
else if (count === 1)
|
else if (count === 1)
|
||||||
value = [allValues objectAtIndex:0];
|
value = [theValues objectAtIndex:0];
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ([_controller alwaysUsesMultipleValuesMarker])
|
if ([_controller alwaysUsesMultipleValuesMarker])
|
||||||
value = CPMultipleValuesMarker;
|
value = CPMultipleValuesMarker;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
value = [allValues objectAtIndex:0];
|
value = [theValues objectAtIndex:0];
|
||||||
|
|
||||||
for (var i=0, count=[allValues count]; i<count && value!=CPMultipleValuesMarker; i++)
|
for (var i = 0, count= [theValues count]; i < count && value != CPMultipleValuesMarker; i++)
|
||||||
{
|
{
|
||||||
if (![value isEqual:[allValues objectAtIndex:i]])
|
if (![value isEqual:[theValues objectAtIndex:i]])
|
||||||
value = CPMultipleValuesMarker;
|
value = CPMultipleValuesMarker;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[_cachedValues setValue:value forKey:aKey];
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id)valueForKeyPath:(CPString)theKeyPath
|
||||||
|
{
|
||||||
|
var values = [[_controller selectedObjects] valueForKeyPath:theKeyPath];
|
||||||
|
value = [self _controllerMarkerForValues:values];
|
||||||
|
|
||||||
|
[_cachedValues setObject:value forKey:theKeyPath];
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (id)valueForKey:(CPString)theKeyPath
|
||||||
|
{
|
||||||
|
return [self valueForKeyPath:theKeyPath];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setValue:(id)theValue forKeyPath:(CPString)theKeyPath
|
||||||
|
{
|
||||||
|
[[_controller selectedObjects] setValue:theValue forKeyPath:theKeyPath];
|
||||||
|
[_cachedValues removeObjectForKey:theKeyPath];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setValue:(id)theValue forKey:(CPString)theKeyPath
|
||||||
|
{
|
||||||
|
[self setValue:theKeyPath forKeyPath:theKeyPath];
|
||||||
|
}
|
||||||
|
|
||||||
- (unsigned)count
|
- (unsigned)count
|
||||||
{
|
{
|
||||||
return [_cachedValues count];
|
return [_cachedValues count];
|
||||||
@@ -567,32 +697,27 @@ var CPObjectControllerObjectClassNameKey = @"CPObjectControllerOb
|
|||||||
return [_cachedValues keyEnumerator];
|
return [_cachedValues keyEnumerator];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setValue:(id)aValue forKey:(CPString)aKey
|
- (void)controllerWillChange
|
||||||
{
|
|
||||||
[[_controller selectedObjects] setValue:aValue forKey:aKey];
|
|
||||||
}
|
|
||||||
|
|
||||||
-(void)controllerWillChange
|
|
||||||
{
|
{
|
||||||
_keys = [_cachedValues allKeys];
|
_keys = [_cachedValues allKeys];
|
||||||
|
|
||||||
if (!_keys)
|
if (!_keys)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (var i=0, count=_keys.length; i<count; i++)
|
for (var i = 0, count = _keys.length; i < count; i++)
|
||||||
[self willChangeValueForKey:_keys[i]];
|
[self willChangeValueForKey:_keys[i]];
|
||||||
|
|
||||||
[_cachedValues removeAllObjects];
|
[_cachedValues removeAllObjects];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)controllerDidChange
|
- (void)controllerDidChange
|
||||||
{
|
{
|
||||||
[_cachedValues removeAllObjects];
|
[_cachedValues removeAllObjects];
|
||||||
|
|
||||||
if (!_keys)
|
if (!_keys)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (var i=0, count=_keys.length; i<count; i++)
|
for (var i = 0, count = _keys.length; i < count; i++)
|
||||||
[self didChangeValueForKey:_keys[i]];
|
[self didChangeValueForKey:_keys[i]];
|
||||||
|
|
||||||
_keys = nil;
|
_keys = nil;
|
||||||
@@ -610,7 +735,11 @@ var CPObjectControllerObjectClassNameKey = @"CPObjectControllerOb
|
|||||||
[proxy setNotifyObject:YES];
|
[proxy setNotifyObject:YES];
|
||||||
[_observationProxies addObject:proxy];
|
[_observationProxies addObject:proxy];
|
||||||
|
|
||||||
[[_controller selectedObjects] addObserver:proxy forKeyPath:aKeyPath options:options context:context];
|
// We keep are reference to the observed objects
|
||||||
|
// because the removeObserver: will be called after the selection changes
|
||||||
|
var observedObjects = [_controller selectedObjects];
|
||||||
|
_observedObjectsByKeyPath[aKeyPath] = observedObjects;
|
||||||
|
[observedObjects addObserver:proxy forKeyPath:aKeyPath options:options context:context];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)removeObserver:(id)anObject forKeyPath:(CPString)aKeyPath
|
- (void)removeObserver:(id)anObject forKeyPath:(CPString)aKeyPath
|
||||||
@@ -618,8 +747,12 @@ var CPObjectControllerObjectClassNameKey = @"CPObjectControllerOb
|
|||||||
var proxy = [[_CPObservationProxy alloc] initWithKeyPath:aKeyPath observer:anObject object:self],
|
var proxy = [[_CPObservationProxy alloc] initWithKeyPath:aKeyPath observer:anObject object:self],
|
||||||
index = [_observationProxies indexOfObject:proxy];
|
index = [_observationProxies indexOfObject:proxy];
|
||||||
|
|
||||||
[[_controller selectedObjects] removeObserver:[_observationProxies objectAtIndex:index] forKeyPath:aKeyPath];
|
var observedObjects = _observedObjectsByKeyPath[aKeyPath];
|
||||||
|
[observedObjects removeObserver:[_observationProxies objectAtIndex:index] forKeyPath:aKeyPath];
|
||||||
|
|
||||||
[_observationProxies removeObjectAtIndex:index];
|
[_observationProxies removeObjectAtIndex:index];
|
||||||
|
|
||||||
|
_observedObjects = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -75,6 +75,21 @@ var CPOutlineViewDelegate_outlineView_dataViewForTableColumn_item_
|
|||||||
|
|
||||||
CPOutlineViewDropOnItemIndex = -1;
|
CPOutlineViewDropOnItemIndex = -1;
|
||||||
|
|
||||||
|
var CPOutlineViewCoalesceSelectionNotificationStateOff = 0,
|
||||||
|
CPOutlineViewCoalesceSelectionNotificationStateOn = 1,
|
||||||
|
CPOutlineViewCoalesceSelectionNotificationStateDid = 2;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ingroup appkit
|
||||||
|
@class CPOutlineView
|
||||||
|
|
||||||
|
CPOutlineView is a subclass of CPTableView that inherates the row and column format to display hierarchial data.
|
||||||
|
The outlineview adds the ability to expand and collapse items. This is useful for browsing a tree like structure such as directories or a filesystem.
|
||||||
|
|
||||||
|
Like the tableview, an outlineview uses a data source to supply its data. For this reason you must implement a couple data source methods (documented in setDataSource:)
|
||||||
|
|
||||||
|
Theme states for custom data views are documented in CPTableView
|
||||||
|
*/
|
||||||
@implementation CPOutlineView : CPTableView
|
@implementation CPOutlineView : CPTableView
|
||||||
{
|
{
|
||||||
id _outlineViewDataSource;
|
id _outlineViewDataSource;
|
||||||
@@ -103,6 +118,8 @@ CPOutlineViewDropOnItemIndex = -1;
|
|||||||
CPInteger _retargedChildIndex;
|
CPInteger _retargedChildIndex;
|
||||||
CPTimer _dragHoverTimer;
|
CPTimer _dragHoverTimer;
|
||||||
id _dropItem;
|
id _dropItem;
|
||||||
|
|
||||||
|
BOOL _coalesceSelectionNotificationState;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)initWithFrame:(CGRect)aFrame
|
- (id)initWithFrame:(CGRect)aFrame
|
||||||
@@ -111,7 +128,6 @@ CPOutlineViewDropOnItemIndex = -1;
|
|||||||
|
|
||||||
if (self)
|
if (self)
|
||||||
{
|
{
|
||||||
|
|
||||||
_selectionHighlightStyle = CPTableViewSelectionHighlightStyleSourceList;
|
_selectionHighlightStyle = CPTableViewSelectionHighlightStyleSourceList;
|
||||||
|
|
||||||
// The root item has weight "0", thus represents the weight solely of its descendants.
|
// The root item has weight "0", thus represents the weight solely of its descendants.
|
||||||
@@ -139,7 +155,55 @@ CPOutlineViewDropOnItemIndex = -1;
|
|||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
/*!
|
||||||
|
<pre>
|
||||||
|
In addition to standard delegation, the outline view also supports data source delegation. This method sets the data source object.
|
||||||
|
Just like the TableView you have CPTableColumns but instead of rows you deal with items.
|
||||||
|
|
||||||
|
You must implement these data source methods:
|
||||||
|
|
||||||
|
- (id)outlineView:(CPOutlineView)outlineView child:(CPInteger)index ofItem:(id)item;
|
||||||
|
Returns the child item at an index of a given item. if item is nil you should return the appropriate root item.
|
||||||
|
|
||||||
|
- (BOOL)outlineView:(CPOutlineView)outlineView isItemExpandable:(id)item;
|
||||||
|
Returns YES if the item is expandable, otherwise NO.
|
||||||
|
|
||||||
|
- (int)outlineView:(CPOutlineView)outlineView numberOfChildrenOfItem:(id)item;
|
||||||
|
Returns the number of child items of a given item. If item is nil you should return the number of top level (root) items.
|
||||||
|
|
||||||
|
- (id)outlineView:(CPOutlineView)outlineView objectValueForTableColumn:(CPTableColumn)tableColumn byItem:(id)item;
|
||||||
|
Returns the object value of the item in a given column.
|
||||||
|
|
||||||
|
|
||||||
|
The following methods are optional:
|
||||||
|
|
||||||
|
Editing:
|
||||||
|
- (void)outlineView:(CPOutlineView)outlineView setObjectValue:(id)object forTableColumn:(CPTableColumn)tableColumn byItem:(id)item;
|
||||||
|
Sets the data object value for an item in a given column. This needs to be implemented if you want inline editing support.
|
||||||
|
|
||||||
|
|
||||||
|
Sorting:
|
||||||
|
- (void)outlineView:(CPOutlineView)outlineView sortDescriptorsDidChange:(CPArray)oldDescriptors;
|
||||||
|
The outlineview will call this method if you click the tableheader. You should sort the datasource based off of the new sort descriptors and reload the data
|
||||||
|
|
||||||
|
Drag and Drop:
|
||||||
|
In order for the outlineview to recieve drops dont forget to first register the tableview for drag types like you do with every other view
|
||||||
|
|
||||||
|
- (BOOL)outlineView:(CPOutlineView)outlineView acceptDrop:(id < CPDraggingInfo >)info item:(id)item childIndex:(CPInteger)index;
|
||||||
|
Return YES if the operation was successful otherwise return NO.
|
||||||
|
The data source should incorporate the data from the dragging pasteboard in this method implementation.
|
||||||
|
To get this data use the draggingPasteboard method on the CPDraggingInfo object.
|
||||||
|
|
||||||
|
- (CPDragOperation)outlineView:(CPOutlineView)outlineView validateDrop:(id < CPDraggingInfo >)info proposedItem:(id)item proposedChildIndex:(CPInteger)index;
|
||||||
|
Return the drag operation (move, copy, etc) that should be performaned if a registered drag type is over the tableview
|
||||||
|
The data source can retarget a drop if you want by calling -(void)setDropItem:(id)anItem dropChildIndex:(int)anIndex;
|
||||||
|
|
||||||
|
- (BOOL)outlineView:(CPOutlineView)outlineView writeItems:(CPArray)items toPasteboard:(CPPasteboard)pboard;
|
||||||
|
Returns YES if the drop operation is allowed otherwise NO.
|
||||||
|
This method is invoked by the outlineview after a drag should begin, but before it is started. If you dont want the drag to being return NO.
|
||||||
|
If you want the drag to begin you should return YES and place the drag data on the pboard.
|
||||||
|
</pre>
|
||||||
|
*/
|
||||||
- (void)setDataSource:(id)aDataSource
|
- (void)setDataSource:(id)aDataSource
|
||||||
{
|
{
|
||||||
if (_outlineViewDataSource === aDataSource)
|
if (_outlineViewDataSource === aDataSource)
|
||||||
@@ -193,11 +257,22 @@ CPOutlineViewDropOnItemIndex = -1;
|
|||||||
[self reloadData];
|
[self reloadData];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns the datasource object.
|
||||||
|
@return id - The data source object
|
||||||
|
*/
|
||||||
- (id)dataSource
|
- (id)dataSource
|
||||||
{
|
{
|
||||||
return _outlineViewDataSource;
|
return _outlineViewDataSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Used to query whether an item is expandable or not.
|
||||||
|
|
||||||
|
@param anItem - the item you are interested in.
|
||||||
|
|
||||||
|
@return BOOL - YES if the item is expandable, otherwise NO.
|
||||||
|
*/
|
||||||
- (BOOL)isExpandable:(id)anItem
|
- (BOOL)isExpandable:(id)anItem
|
||||||
{
|
{
|
||||||
if (!anItem)
|
if (!anItem)
|
||||||
@@ -211,7 +286,14 @@ CPOutlineViewDropOnItemIndex = -1;
|
|||||||
return itemInfo.isExpandable;
|
return itemInfo.isExpandable;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)isItemExpanded:(id)anItem
|
/*!
|
||||||
|
Used to find if an item is already expanded.
|
||||||
|
|
||||||
|
@param anItem - the item you are interest in.
|
||||||
|
|
||||||
|
@return BOOL - Yes if the item is already expanded, otherwise NO.
|
||||||
|
*/
|
||||||
|
- (BOOL)isItemExpanded:(id)anItem
|
||||||
{
|
{
|
||||||
if (!anItem)
|
if (!anItem)
|
||||||
return YES;
|
return YES;
|
||||||
@@ -224,11 +306,22 @@ CPOutlineViewDropOnItemIndex = -1;
|
|||||||
return itemInfo.isExpanded;
|
return itemInfo.isExpanded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Expends a given item.
|
||||||
|
|
||||||
|
@param anItem - the item to expand.
|
||||||
|
*/
|
||||||
- (void)expandItem:(id)anItem
|
- (void)expandItem:(id)anItem
|
||||||
{
|
{
|
||||||
[self expandItem:anItem expandChildren:NO];
|
[self expandItem:anItem expandChildren:NO];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Expands a given item, and optionally all the children of that item.
|
||||||
|
|
||||||
|
@param anItem - the item you want to expand.
|
||||||
|
@param shouldExpandChildren - Pass YES if you want to expand all the children of anItem, otherwise NO.
|
||||||
|
*/
|
||||||
- (void)expandItem:(id)anItem expandChildren:(BOOL)shouldExpandChildren
|
- (void)expandItem:(id)anItem expandChildren:(BOOL)shouldExpandChildren
|
||||||
{
|
{
|
||||||
var itemInfo = null;
|
var itemInfo = null;
|
||||||
@@ -241,13 +334,42 @@ CPOutlineViewDropOnItemIndex = -1;
|
|||||||
if (!itemInfo)
|
if (!itemInfo)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// When shouldExpandChildren is YES, we need to make sure we're collecting
|
||||||
|
// selection notifications so that exactly one IsChanging and one DidChange
|
||||||
|
// is sent as needed, for the totallity of the operation.
|
||||||
|
var isTopLevel = NO;
|
||||||
|
if (!_coalesceSelectionNotificationState)
|
||||||
|
{
|
||||||
|
isTopLevel = YES;
|
||||||
|
_coalesceSelectionNotificationState = CPOutlineViewCoalesceSelectionNotificationStateOn;
|
||||||
|
}
|
||||||
|
|
||||||
// to prevent items which are already expanded from firing notifications
|
// to prevent items which are already expanded from firing notifications
|
||||||
if (!itemInfo.isExpanded)
|
if (!itemInfo.isExpanded)
|
||||||
{
|
{
|
||||||
[self _noteItemWillExpand:anItem];
|
[self _noteItemWillExpand:anItem];
|
||||||
|
|
||||||
|
var previousRowCount = [self numberOfRows];
|
||||||
|
|
||||||
itemInfo.isExpanded = YES;
|
itemInfo.isExpanded = YES;
|
||||||
|
// XXX Shouldn't the items reload before the notification is sent?
|
||||||
[self _noteItemDidExpand:anItem];
|
[self _noteItemDidExpand:anItem];
|
||||||
[self reloadItem:anItem reloadChildren:YES];
|
[self reloadItem:anItem reloadChildren:YES];
|
||||||
|
|
||||||
|
// Shift selection indexes below so that the same items remain selected.
|
||||||
|
var rowCountDelta = [self numberOfRows] - previousRowCount;
|
||||||
|
if (rowCountDelta)
|
||||||
|
{
|
||||||
|
var selection = [self selectedRowIndexes],
|
||||||
|
expandIndex = [self rowForItem:anItem] + 1;
|
||||||
|
|
||||||
|
if ([selection intersectsIndexesInRange:CPMakeRange(expandIndex, _itemsForRows.length)])
|
||||||
|
{
|
||||||
|
[self _noteSelectionIsChanging];
|
||||||
|
[selection shiftIndexesStartingAtIndex:expandIndex by:rowCountDelta];
|
||||||
|
[self _setSelectedRowIndexes:selection]; // _noteSelectionDidChange will be suppressed.
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldExpandChildren)
|
if (shouldExpandChildren)
|
||||||
@@ -258,8 +380,21 @@ CPOutlineViewDropOnItemIndex = -1;
|
|||||||
while (childIndex--)
|
while (childIndex--)
|
||||||
[self expandItem:children[childIndex] expandChildren:YES];
|
[self expandItem:children[childIndex] expandChildren:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isTopLevel)
|
||||||
|
{
|
||||||
|
var r = _coalesceSelectionNotificationState;
|
||||||
|
_coalesceSelectionNotificationState = CPOutlineViewCoalesceSelectionNotificationStateOff;
|
||||||
|
if (r === CPOutlineViewCoalesceSelectionNotificationStateDid)
|
||||||
|
[self _noteSelectionDidChange];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Collapse a given item.
|
||||||
|
|
||||||
|
@param anItem - The item you want to collapse.
|
||||||
|
*/
|
||||||
- (void)collapseItem:(id)anItem
|
- (void)collapseItem:(id)anItem
|
||||||
{
|
{
|
||||||
if (!anItem)
|
if (!anItem)
|
||||||
@@ -273,18 +408,71 @@ CPOutlineViewDropOnItemIndex = -1;
|
|||||||
if (!itemInfo.isExpanded)
|
if (!itemInfo.isExpanded)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
[self _noteItemWillCollapse:anItem];
|
// Don't spam notifications.
|
||||||
itemInfo.isExpanded = NO;
|
_coalesceSelectionNotificationState = CPOutlineViewCoalesceSelectionNotificationStateOn;
|
||||||
[self _noteItemDidCollapse:anItem];
|
|
||||||
|
|
||||||
|
[self _noteItemWillCollapse:anItem];
|
||||||
|
// Update selections:
|
||||||
|
// * Deselect items inside the collapsed item.
|
||||||
|
// * Shift row selections below the collapsed item so that the same logical items remain selected.
|
||||||
|
var collapseTopIndex = [self rowForItem:anItem],
|
||||||
|
topLevel = [self levelForRow:collapseTopIndex],
|
||||||
|
collapseEndIndex = collapseTopIndex;
|
||||||
|
|
||||||
|
while (collapseEndIndex + 1 < _itemsForRows.length && [self levelForRow:collapseEndIndex + 1] > topLevel)
|
||||||
|
collapseEndIndex++;
|
||||||
|
|
||||||
|
var collapseRange = CPMakeRange(collapseTopIndex + 1, collapseEndIndex - collapseTopIndex);
|
||||||
|
|
||||||
|
if (collapseRange.length)
|
||||||
|
{
|
||||||
|
var selection = [self selectedRowIndexes];
|
||||||
|
|
||||||
|
if ([selection intersectsIndexesInRange:collapseRange])
|
||||||
|
{
|
||||||
|
[self _noteSelectionIsChanging];
|
||||||
|
[selection removeIndexesInRange:collapseRange];
|
||||||
|
[self _setSelectedRowIndexes:selection]; // _noteSelectionDidChange will be suppressed.
|
||||||
|
}
|
||||||
|
|
||||||
|
// Shift any selected rows below upwards.
|
||||||
|
if ([selection intersectsIndexesInRange:CPMakeRange(collapseEndIndex + 1, _itemsForRows.length)])
|
||||||
|
{
|
||||||
|
[self _noteSelectionIsChanging];
|
||||||
|
[selection shiftIndexesStartingAtIndex:collapseEndIndex + 1 by:-collapseRange.length];
|
||||||
|
[self _setSelectedRowIndexes:selection]; // _noteSelectionDidChange will be suppressed.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
itemInfo.isExpanded = NO;
|
||||||
|
|
||||||
|
// XXX Shouldn't the items reload before the notification is sent?
|
||||||
|
[self _noteItemDidCollapse:anItem];
|
||||||
[self reloadItem:anItem reloadChildren:YES];
|
[self reloadItem:anItem reloadChildren:YES];
|
||||||
|
|
||||||
|
// Send selection notifications only after the items have loaded so that
|
||||||
|
// the new selection is consistent with the actual rows for any observers.
|
||||||
|
var r = _coalesceSelectionNotificationState;
|
||||||
|
_coalesceSelectionNotificationState = CPOutlineViewCoalesceSelectionNotificationStateOff;
|
||||||
|
if (r === CPOutlineViewCoalesceSelectionNotificationStateDid)
|
||||||
|
[self _noteSelectionDidChange];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Reloads the data for an item.
|
||||||
|
|
||||||
|
@param anItem - The item you want to reload.
|
||||||
|
*/
|
||||||
- (void)reloadItem:(id)anItem
|
- (void)reloadItem:(id)anItem
|
||||||
{
|
{
|
||||||
[self reloadItem:anItem reloadChildren:NO];
|
[self reloadItem:anItem reloadChildren:NO];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Reloads the data for a given item and optionally the children.
|
||||||
|
|
||||||
|
@param anItem - The item you want to reload.
|
||||||
|
@param shouldReloadChildren - Pass YES if you want to reload all the children, otherwise NO.
|
||||||
|
*/
|
||||||
- (void)reloadItem:(id)anItem reloadChildren:(BOOL)shouldReloadChildren
|
- (void)reloadItem:(id)anItem reloadChildren:(BOOL)shouldReloadChildren
|
||||||
{
|
{
|
||||||
if (!!shouldReloadChildren || !anItem)
|
if (!!shouldReloadChildren || !anItem)
|
||||||
@@ -295,11 +483,23 @@ CPOutlineViewDropOnItemIndex = -1;
|
|||||||
[super reloadData];
|
[super reloadData];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns the item at a given row index. If no item exists nil is returned.
|
||||||
|
|
||||||
|
@param aRow - The rown index you want to find the item at.
|
||||||
|
@return id - The item at a given index.
|
||||||
|
*/
|
||||||
- (id)itemAtRow:(CPInteger)aRow
|
- (id)itemAtRow:(CPInteger)aRow
|
||||||
{
|
{
|
||||||
return _itemsForRows[aRow] || nil;
|
return _itemsForRows[aRow] || nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns the row of a given item
|
||||||
|
|
||||||
|
@param anItem - The item you want to find the row of.
|
||||||
|
@return int - The row index of a given item.
|
||||||
|
*/
|
||||||
- (CPInteger)rowForItem:(id)anItem
|
- (CPInteger)rowForItem:(id)anItem
|
||||||
{
|
{
|
||||||
if (!anItem)
|
if (!anItem)
|
||||||
@@ -313,6 +513,11 @@ CPOutlineViewDropOnItemIndex = -1;
|
|||||||
return itemInfo.row;
|
return itemInfo.row;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Sets the table column you want to display the disclosure button in.
|
||||||
|
If you do not want an outline column pass nil.
|
||||||
|
@param aTableColumn - The CPTableColumn you want to use for hierarchical data.
|
||||||
|
*/
|
||||||
- (void)setOutlineTableColumn:(CPTableColumn)aTableColumn
|
- (void)setOutlineTableColumn:(CPTableColumn)aTableColumn
|
||||||
{
|
{
|
||||||
if (_outlineTableColumn === aTableColumn)
|
if (_outlineTableColumn === aTableColumn)
|
||||||
@@ -324,11 +529,22 @@ CPOutlineViewDropOnItemIndex = -1;
|
|||||||
[self reloadData];
|
[self reloadData];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns the table column used to display hierarchical data.
|
||||||
|
|
||||||
|
@return CPTableColumn - The table column that displays the disclosure button.
|
||||||
|
*/
|
||||||
- (CPTableColumn)outlineTableColumn
|
- (CPTableColumn)outlineTableColumn
|
||||||
{
|
{
|
||||||
return _outlineTableColumn;
|
return _outlineTableColumn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns the indentation level of a given item. If the item is nil (the top level root item) CPNotFound is returned. Indentation levels are zero based, thus items that are not indented return 0.
|
||||||
|
|
||||||
|
@param anItem - The item you want the indentation level for.
|
||||||
|
@return int - the indentation level of anItem.
|
||||||
|
*/
|
||||||
- (CPInteger)levelForItem:(id)anItem
|
- (CPInteger)levelForItem:(id)anItem
|
||||||
{
|
{
|
||||||
if (!anItem)
|
if (!anItem)
|
||||||
@@ -342,11 +558,22 @@ CPOutlineViewDropOnItemIndex = -1;
|
|||||||
return itemInfo.level;
|
return itemInfo.level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns the indentation level for a given row. If the row is invalid CPNotFound is returned. Rows that are nto indented return 0.
|
||||||
|
|
||||||
|
@param aRow - the row of the reciever
|
||||||
|
@return int - the indentation level of aRow.
|
||||||
|
*/
|
||||||
- (CPInteger)levelForRow:(CPInteger)aRow
|
- (CPInteger)levelForRow:(CPInteger)aRow
|
||||||
{
|
{
|
||||||
return [self levelForItem:[self itemAtRow:aRow]];
|
return [self levelForItem:[self itemAtRow:aRow]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Sets the number of pixels to indent an item at each indentation level.
|
||||||
|
|
||||||
|
@param anIndentationWidth - the width of each indentation level.
|
||||||
|
*/
|
||||||
- (void)setIndentationPerLevel:(float)anIndentationWidth
|
- (void)setIndentationPerLevel:(float)anIndentationWidth
|
||||||
{
|
{
|
||||||
if (_indentationPerLevel === anIndentationWidth)
|
if (_indentationPerLevel === anIndentationWidth)
|
||||||
@@ -358,11 +585,21 @@ CPOutlineViewDropOnItemIndex = -1;
|
|||||||
[self reloadData];
|
[self reloadData];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns the width of an indentation level.
|
||||||
|
|
||||||
|
@return float - the width of the indentation per level.
|
||||||
|
*/
|
||||||
- (float)indentationPerLevel
|
- (float)indentationPerLevel
|
||||||
{
|
{
|
||||||
return _indentationPerLevel;
|
return _indentationPerLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Sets the layout behaviour of disclosure button. If you pass NO the disclosure button will always align itself to the left of the outline column.
|
||||||
|
|
||||||
|
@param indentationMarkerShouldFollowDataView - Pass YES if the disclosure control should be indented along with the dataview, otherwise NO.
|
||||||
|
*/
|
||||||
- (void)setIndentationMarkerFollowsDataView:(BOOL)indentationMarkerShouldFollowDataView
|
- (void)setIndentationMarkerFollowsDataView:(BOOL)indentationMarkerShouldFollowDataView
|
||||||
{
|
{
|
||||||
if (_indentationMarkerFollowsDataView === indentationMarkerShouldFollowDataView)
|
if (_indentationMarkerFollowsDataView === indentationMarkerShouldFollowDataView)
|
||||||
@@ -374,11 +611,22 @@ CPOutlineViewDropOnItemIndex = -1;
|
|||||||
[self reloadData];
|
[self reloadData];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns the layout behaviour of the disclosure buttons.
|
||||||
|
|
||||||
|
@return BOOL - YES if the disclosure control indents itself with the dataview, otherwise NO if the control is always aligned to the left of the outline column
|
||||||
|
*/
|
||||||
- (BOOL)indentationMarkerFollowsDataView
|
- (BOOL)indentationMarkerFollowsDataView
|
||||||
{
|
{
|
||||||
return _indentationMarkerFollowsDataView;
|
return _indentationMarkerFollowsDataView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns the parent item for a given item. If the item is a top level root object nil is returned.
|
||||||
|
|
||||||
|
@param anItem - The item of the reciver.
|
||||||
|
@return id - The parent item of anItem. If no parent exists (the item is a root item) nil is returned.
|
||||||
|
*/
|
||||||
- (id)parentForItem:(id)anItem
|
- (id)parentForItem:(id)anItem
|
||||||
{
|
{
|
||||||
if (!anItem)
|
if (!anItem)
|
||||||
@@ -398,9 +646,15 @@ CPOutlineViewDropOnItemIndex = -1;
|
|||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (CGRect)frameOfOutlineDataViewAtColumn:(CPInteger)aColumn row:(CPInteger)aRow
|
/*!
|
||||||
|
@ignore
|
||||||
|
|
||||||
|
Returns the frame of the dataview at the row given for the outline column
|
||||||
|
*/
|
||||||
|
- (CGRect)_frameOfOutlineDataViewAtRow:(CPInteger)aRow
|
||||||
{
|
{
|
||||||
var frame = [super frameOfDataViewAtColumn:aColumn row:aRow],
|
var columnIndex = [[self tableColumns] indexOfObject:_outlineTableColumn],
|
||||||
|
frame = [super frameOfDataViewAtColumn:columnIndex row:aRow],
|
||||||
indentationWidth = ([self levelForRow:aRow] + 1) * [self indentationPerLevel];
|
indentationWidth = ([self levelForRow:aRow] + 1) * [self indentationPerLevel];
|
||||||
|
|
||||||
frame.origin.x += indentationWidth;
|
frame.origin.x += indentationWidth;
|
||||||
@@ -409,6 +663,29 @@ CPOutlineViewDropOnItemIndex = -1;
|
|||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns the frame of the disclosure button for the outline column.
|
||||||
|
If the item is not expandable a CGZeroRect is returned.
|
||||||
|
Subclasses can return a CGZeroRect to prevent the disclosure control from being displayed.
|
||||||
|
|
||||||
|
@param aRow - The row of the reciever
|
||||||
|
@return CGRect - The rect of the disclosure button at aRow.
|
||||||
|
*/
|
||||||
|
- (CGRect)frameOfOutlineDisclosureControlAtRow:(CPInteger)aRow
|
||||||
|
{
|
||||||
|
if (![self isExpandable:[self itemAtRow:aRow]])
|
||||||
|
return _CGRectMakeZero();
|
||||||
|
|
||||||
|
var dataViewFrame = [self _frameOfOutlineDataViewAtRow:aRow],
|
||||||
|
frame = _CGRectMake(_CGRectGetMinX(dataViewFrame) - 10, _CGRectGetMinY(dataViewFrame), 10, _CGRectGetHeight(dataViewFrame));
|
||||||
|
|
||||||
|
return frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
Select or deselect rows, this is overridden because we need to change the color or the outline control
|
||||||
|
*/
|
||||||
- (void)_performSelection:(BOOL)select forRow:(CPInteger)rowIndex context:(id)context
|
- (void)_performSelection:(BOOL)select forRow:(CPInteger)rowIndex context:(id)context
|
||||||
{
|
{
|
||||||
[super _performSelection:select forRow:rowIndex context:context];
|
[super _performSelection:select forRow:rowIndex context:context];
|
||||||
@@ -419,6 +696,76 @@ CPOutlineViewDropOnItemIndex = -1;
|
|||||||
[control performSelector:CPSelectorFromString(selector) withObject:CPThemeStateSelected];
|
[control performSelector:CPSelectorFromString(selector) withObject:CPThemeStateSelected];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
<pre>
|
||||||
|
Sets the delegate for the outlineview.
|
||||||
|
|
||||||
|
The following methods can be implemented:
|
||||||
|
|
||||||
|
User Interaction Notifications:
|
||||||
|
- (void)outlineViewColumnDidMove:(CPNotification)notification;
|
||||||
|
Called when the user moves a column in the outlineview.
|
||||||
|
|
||||||
|
- (void)outlineViewColumnDidResize:(CPNotification)notification;
|
||||||
|
Called when the user resizes a column in the outlineview.
|
||||||
|
|
||||||
|
- (void)outlineViewItemDidCollapse:(CPNotification)notification;
|
||||||
|
Called when the user collapses an item in teh outlineview.
|
||||||
|
|
||||||
|
- (void)outlineViewItemDidExpand:(CPNotification)notification;
|
||||||
|
Called when the user expands an item in the outlineview.
|
||||||
|
|
||||||
|
- (void)outlineViewItemWillCollapse:(CPNotification)notification;
|
||||||
|
Called when the user collapses an item in the outlineview, but before the item is actually collapsed.
|
||||||
|
|
||||||
|
- (void)outlineViewItemWillExpand:(CPNotification)notification;
|
||||||
|
Called when the used expands an item, but before the item is actually expanded.
|
||||||
|
|
||||||
|
- (void)outlineViewSelectionDidChange:(CPNotification)notification;
|
||||||
|
Called when the user changes the selection of the outlineview.
|
||||||
|
|
||||||
|
- (void)outlineViewSelectionIsChanging:(CPNotification)notification
|
||||||
|
Called when the user changes the selection of the outlineview, but before the change is made.
|
||||||
|
|
||||||
|
Expanding and collapsing items:
|
||||||
|
- (BOOL)outlineView:(CPOutlineView)outlineView shouldExpandItem:(id)item;
|
||||||
|
Return YES if the item should be given permission to expand, otherwise NO.
|
||||||
|
|
||||||
|
- (BOOL)outlineView:(CPOutlineView)outlineView shouldCollapseItem:(id)item;
|
||||||
|
Return YES if the item should be given permission to collapse, otherwise NO.
|
||||||
|
|
||||||
|
Selection:
|
||||||
|
- (BOOL)outlineView:(CPOutlineView)outlineView shouldSelectTableColumn:(CPTableColumn)tableColumn;
|
||||||
|
Return YES to allow the selection of tableColumn, otherwise NO.
|
||||||
|
|
||||||
|
- (BOOL)outlineView:(CPOutlineView)outlineView shouldSelectItem:(id)item;
|
||||||
|
Return YES to allow the selection of an item, otherwise NO.
|
||||||
|
|
||||||
|
- (BOOL)selectionShouldChangeInOutlineView:(CPOutlineView)outlineView;
|
||||||
|
Return YES to allow the selection of the outlineview to be changed, otherwise NO.
|
||||||
|
|
||||||
|
Displaying DataViews:
|
||||||
|
- (void)outlineView:(CPOutlineView)outlineView willDisplayView:(id)dataView forTableColumn:(CPTableColumn)tableColumn item:(id)item;
|
||||||
|
Called when a dataView is about to be displayed. This gives you the ability to alter the dataView if needed.
|
||||||
|
|
||||||
|
Editing:
|
||||||
|
- (BOOL)outlineView:(CPOutlineView)outlineView shouldEditTableColumn:(CPTableColumn)tableColumn item:(id)item;
|
||||||
|
Return YES to allow for editing of a dataview at given item and tableColumn, otherwise NO to prevent the edit.
|
||||||
|
|
||||||
|
Group Items:
|
||||||
|
- (BOOL)outlineView:(CPOutlineView)outlineView isGroupItem:(id)item;
|
||||||
|
Implement this to indicate whether a given item should be rendered using the group item style.
|
||||||
|
Return YES if the item is a group item, otherwise NO.
|
||||||
|
|
||||||
|
Variable Item Heights
|
||||||
|
- (int)outlineView:(CPOutlineView)outlineView heightOfRowByItem:(id)anItem;
|
||||||
|
Implement this method to get custom heights of rows based on the item.
|
||||||
|
This delegate method will be passed your 'item' object and expects you to return an integer height.
|
||||||
|
NOTE: this should only be implemented if rows will be different heights, if you want to set a height for ALL of your rows see -setRowHeight:
|
||||||
|
|
||||||
|
@param aDelegate - the delegate object you wish to set for the reciever.
|
||||||
|
<pre>
|
||||||
|
*/
|
||||||
- (void)setDelegate:(id)aDelegate
|
- (void)setDelegate:(id)aDelegate
|
||||||
{
|
{
|
||||||
if (_outlineViewDelegate === aDelegate)
|
if (_outlineViewDelegate === aDelegate)
|
||||||
@@ -513,10 +860,10 @@ CPOutlineViewDropOnItemIndex = -1;
|
|||||||
],
|
],
|
||||||
delegateCount = [delegateMethods count];
|
delegateCount = [delegateMethods count];
|
||||||
|
|
||||||
for (var i=0; i < delegateCount; i += 2)
|
for (var i = 0; i < delegateCount; i += 2)
|
||||||
{
|
{
|
||||||
var bitMask = delegateMethods[i],
|
var bitMask = delegateMethods[i],
|
||||||
selector = delegateMethods[i+1];
|
selector = delegateMethods[i + 1];
|
||||||
|
|
||||||
if ([_outlineViewDelegate respondsToSelector:selector])
|
if ([_outlineViewDelegate respondsToSelector:selector])
|
||||||
_implementedOutlineViewDelegateMethods |= bitMask;
|
_implementedOutlineViewDelegateMethods |= bitMask;
|
||||||
@@ -581,11 +928,20 @@ CPOutlineViewDropOnItemIndex = -1;
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns the delegate object for the outlineview.
|
||||||
|
*/
|
||||||
- (id)delegate
|
- (id)delegate
|
||||||
{
|
{
|
||||||
return _outlineViewDelegate;
|
return _outlineViewDelegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Sets the prototype of the disclosure control. This is used if you want to set a special type of button, instead of the default triangle.
|
||||||
|
The control must implement CPCoding.
|
||||||
|
|
||||||
|
@param aControl - the control to be used to expand and collapse items.
|
||||||
|
*/
|
||||||
- (void)setDisclosureControlPrototype:(CPControl)aControl
|
- (void)setDisclosureControlPrototype:(CPControl)aControl
|
||||||
{
|
{
|
||||||
_disclosureControlPrototype = aControl;
|
_disclosureControlPrototype = aControl;
|
||||||
@@ -596,21 +952,120 @@ CPOutlineViewDropOnItemIndex = -1;
|
|||||||
[self reloadData];
|
[self reloadData];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Reloads all the data of the outlineview.
|
||||||
|
*/
|
||||||
- (void)reloadData
|
- (void)reloadData
|
||||||
{
|
{
|
||||||
[self reloadItem:nil reloadChildren:YES];
|
[self reloadItem:nil reloadChildren:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Adds a new table column to the reciever. If this is the first column added it will automatically be set to the outline column.
|
||||||
|
Also see -setOutlineTableColumn:
|
||||||
|
NOTE: This behavior deviates from cocoa slightly.
|
||||||
|
@param CPTableColumn aTableColumn - The table column to add.
|
||||||
|
*/
|
||||||
|
- (void)addTableColumn:(CPTableColumn)aTableColumn
|
||||||
|
{
|
||||||
|
[super addTableColumn:aTableColumn];
|
||||||
|
|
||||||
|
if ([self numberOfColumns] === 1)
|
||||||
|
_outlineTableColumn = aTableColumn;
|
||||||
|
}
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
|
- (void)removeTableColumn:(CPTableColumn)aTableColumn
|
||||||
|
{
|
||||||
|
if (aTableColumn === [self outlineTableColumn])
|
||||||
|
CPLog("CPOutlineView cannot remove outlineTableColumn with removeTableColumn:. User setOutlineTableColumn: instead.");
|
||||||
|
else
|
||||||
|
[super removeTableColumn:aTableColumn];
|
||||||
|
}
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
We overide this because we need a special behaviour for the outline column
|
||||||
|
*/
|
||||||
- (CGRect)frameOfDataViewAtColumn:(CPInteger)aColumn row:(CPInteger)aRow
|
- (CGRect)frameOfDataViewAtColumn:(CPInteger)aColumn row:(CPInteger)aRow
|
||||||
{
|
{
|
||||||
var tableColumn = [self tableColumns][aColumn];
|
var tableColumn = [self tableColumns][aColumn];
|
||||||
|
|
||||||
if (tableColumn === _outlineTableColumn)
|
if (tableColumn === _outlineTableColumn)
|
||||||
return [self frameOfOutlineDataViewAtColumn:aColumn row:aRow];
|
return [self _frameOfOutlineDataViewAtRow:aRow];
|
||||||
|
|
||||||
return [super frameOfDataViewAtColumn:aColumn row:aRow];
|
return [super frameOfDataViewAtColumn:aColumn row:aRow];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
we need to offset the dataview and add the dislosure triangle
|
||||||
|
*/
|
||||||
|
- (CPView)_dragViewForColumn:(int)theColumnIndex event:(CPEvent)theDragEvent offset:(CPPointPointer)theDragViewOffset
|
||||||
|
{
|
||||||
|
var dragView = [[_CPColumnDragView alloc] initWithLineColor:[self gridColor]],
|
||||||
|
tableColumn = [[self tableColumns] objectAtIndex:theColumnIndex],
|
||||||
|
bounds = _CGRectMake(0.0, 0.0, [tableColumn width], _CGRectGetHeight([self exposedRect]) + 23.0),
|
||||||
|
columnRect = [self rectOfColumn:theColumnIndex],
|
||||||
|
headerView = [tableColumn headerView],
|
||||||
|
row = [_exposedRows firstIndex];
|
||||||
|
|
||||||
|
while (row !== CPNotFound)
|
||||||
|
{
|
||||||
|
var dataView = [self _newDataViewForRow:row tableColumn:tableColumn],
|
||||||
|
dataViewFrame = [self frameOfDataViewAtColumn:theColumnIndex row:row];
|
||||||
|
|
||||||
|
// Only one column is ever dragged so we just place the view at
|
||||||
|
dataViewFrame.origin.x = 0.0;
|
||||||
|
|
||||||
|
// Offset by table header height - scroll position
|
||||||
|
dataViewFrame.origin.y = ( _CGRectGetMinY(dataViewFrame) - _CGRectGetMinY([self exposedRect]) ) + 23.0;
|
||||||
|
[dataView setFrame:dataViewFrame];
|
||||||
|
|
||||||
|
[dataView setObjectValue:[self _objectValueForTableColumn:tableColumn row:row]];
|
||||||
|
|
||||||
|
|
||||||
|
if (tableColumn === _outlineTableColumn)
|
||||||
|
{
|
||||||
|
// first inset the dragview
|
||||||
|
var indentationWidth = ([self levelForRow:row] + 1) * [self indentationPerLevel];
|
||||||
|
|
||||||
|
dataViewFrame.origin.x += indentationWidth;
|
||||||
|
dataViewFrame.size.width -= indentationWidth;
|
||||||
|
|
||||||
|
[dataView setFrame:dataViewFrame];
|
||||||
|
}
|
||||||
|
|
||||||
|
[dragView addSubview:dataView];
|
||||||
|
|
||||||
|
row = [_exposedRows indexGreaterThanIndex:row];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the column header view
|
||||||
|
var headerFrame = [headerView frame];
|
||||||
|
headerFrame.origin = _CGPointMakeZero();
|
||||||
|
|
||||||
|
var columnHeaderView = [[_CPTableColumnHeaderView alloc] initWithFrame:headerFrame];
|
||||||
|
[columnHeaderView setStringValue:[headerView stringValue]];
|
||||||
|
[columnHeaderView setThemeState:[headerView themeState]];
|
||||||
|
[dragView addSubview:columnHeaderView];
|
||||||
|
|
||||||
|
[dragView setBackgroundColor:[CPColor whiteColor]];
|
||||||
|
[dragView setAlphaValue:0.7];
|
||||||
|
[dragView setFrame:bounds];
|
||||||
|
|
||||||
|
return dragView;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Retargets the drop item for the outlineview.
|
||||||
|
To specify a drop on theItem, you specify item as theItem and index as CPOutlineViewDropOnItemIndex.
|
||||||
|
To specify a drop between child 1 and 2 of theItem, you specify item as theItem and index as 2.
|
||||||
|
To specify a drop on an item that can't be expanded theItem, you specify item as someOutlineItem and index as CPOutlineViewDropOnItemIndex.
|
||||||
|
|
||||||
|
@param theItem - The item you want to retarget the drop on.
|
||||||
|
@param theIndex - The index of the child item you want to retarget the drop between. Pass CPOutlineViewDropOnItemIndex if you want to drop on theItem.
|
||||||
|
*/
|
||||||
- (void)setDropItem:(id)theItem dropChildIndex:(int)theIndex
|
- (void)setDropItem:(id)theItem dropChildIndex:(int)theIndex
|
||||||
{
|
{
|
||||||
if (_dropItem !== theItem && theIndex < 0 && [self isExpandable:theItem] && ![self isItemExpanded:theItem])
|
if (_dropItem !== theItem && theIndex < 0 && [self isExpandable:theItem] && ![self isItemExpanded:theItem])
|
||||||
@@ -657,6 +1112,9 @@ CPOutlineViewDropOnItemIndex = -1;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
- (void)_draggingEnded
|
- (void)_draggingEnded
|
||||||
{
|
{
|
||||||
[super _draggingEnded];
|
[super _draggingEnded];
|
||||||
@@ -665,13 +1123,16 @@ CPOutlineViewDropOnItemIndex = -1;
|
|||||||
_dragHoverTimer = nil;
|
_dragHoverTimer = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
- (id)_parentItemForUpperRow:(int)theUpperRowIndex andLowerRow:(int)theLowerRowIndex atMouseOffset:(CPPoint)theOffset
|
- (id)_parentItemForUpperRow:(int)theUpperRowIndex andLowerRow:(int)theLowerRowIndex atMouseOffset:(CPPoint)theOffset
|
||||||
{
|
{
|
||||||
if (_shouldRetargetItem)
|
if (_shouldRetargetItem)
|
||||||
return _retargetedItem;
|
return _retargetedItem;
|
||||||
|
|
||||||
var lowerLevel = [self levelForRow:theLowerRowIndex]
|
var lowerLevel = [self levelForRow:theLowerRowIndex],
|
||||||
upperItem = [self itemAtRow:theUpperRowIndex];
|
upperItem = [self itemAtRow:theUpperRowIndex],
|
||||||
upperLevel = [self levelForItem:upperItem];
|
upperLevel = [self levelForItem:upperItem];
|
||||||
|
|
||||||
// If the row above us has a higher level the item can be added to multiple parent items
|
// If the row above us has a higher level the item can be added to multiple parent items
|
||||||
@@ -692,6 +1153,9 @@ CPOutlineViewDropOnItemIndex = -1;
|
|||||||
return [self parentForItem:[self itemAtRow:theLowerRowIndex]];
|
return [self parentForItem:[self itemAtRow:theLowerRowIndex]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
- (CPRect)_rectForDropHighlightViewBetweenUpperRow:(int)theUpperRowIndex andLowerRow:(int)theLowerRowIndex offset:(CPPoint)theOffset
|
- (CPRect)_rectForDropHighlightViewBetweenUpperRow:(int)theUpperRowIndex andLowerRow:(int)theLowerRowIndex offset:(CPPoint)theOffset
|
||||||
{
|
{
|
||||||
// Call super and the update x to reflect the current indentation level
|
// Call super and the update x to reflect the current indentation level
|
||||||
@@ -705,13 +1169,59 @@ CPOutlineViewDropOnItemIndex = -1;
|
|||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
We need to move the disclosure control too
|
||||||
|
*/
|
||||||
|
- (void)_layoutDataViewsInRows:(CPIndexSet)rows columns:(CPIndexSet)columns
|
||||||
|
{
|
||||||
|
var rowArray = [],
|
||||||
|
columnArray = [];
|
||||||
|
|
||||||
|
[rows getIndexes:rowArray maxCount:-1 inIndexRange:nil];
|
||||||
|
[columns getIndexes:columnArray maxCount:-1 inIndexRange:nil];
|
||||||
|
|
||||||
|
var columnIndex = 0,
|
||||||
|
columnsCount = columnArray.length;
|
||||||
|
|
||||||
|
for (; columnIndex < columnsCount; ++columnIndex)
|
||||||
|
{
|
||||||
|
var column = columnArray[columnIndex],
|
||||||
|
tableColumn = _tableColumns[column],
|
||||||
|
tableColumnUID = [tableColumn UID],
|
||||||
|
dataViewsForTableColumn = _dataViewsForTableColumns[tableColumnUID],
|
||||||
|
rowIndex = 0,
|
||||||
|
rowsCount = rowArray.length;
|
||||||
|
|
||||||
|
for (; rowIndex < rowsCount; ++rowIndex)
|
||||||
|
{
|
||||||
|
var row = rowArray[rowIndex],
|
||||||
|
dataView = dataViewsForTableColumn[row],
|
||||||
|
dataViewFrame = [self frameOfDataViewAtColumn:column row:row];
|
||||||
|
|
||||||
|
[dataView setFrame:dataViewFrame];
|
||||||
|
|
||||||
|
if (tableColumn === _outlineTableColumn)
|
||||||
|
{
|
||||||
|
var control = _disclosureControlsForRows[row],
|
||||||
|
frame = [self frameOfOutlineDisclosureControlAtRow:row];
|
||||||
|
|
||||||
|
[control setFrame:frame];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
- (void)_loadDataViewsInRows:(CPIndexSet)rows columns:(CPIndexSet)columns
|
- (void)_loadDataViewsInRows:(CPIndexSet)rows columns:(CPIndexSet)columns
|
||||||
{
|
{
|
||||||
[super _loadDataViewsInRows:rows columns:columns];
|
[super _loadDataViewsInRows:rows columns:columns];
|
||||||
|
|
||||||
var outlineColumn = [[self tableColumns] indexOfObjectIdenticalTo:[self outlineTableColumn]];
|
var outlineColumn = [[self tableColumns] indexOfObjectIdenticalTo:[self outlineTableColumn]];
|
||||||
|
|
||||||
if (![columns containsIndex:outlineColumn])
|
if (![columns containsIndex:outlineColumn] || [self outlineTableColumn] === _draggedColumn)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var rowArray = [];
|
var rowArray = [];
|
||||||
@@ -730,27 +1240,22 @@ CPOutlineViewDropOnItemIndex = -1;
|
|||||||
if (!isExpandable)
|
if (!isExpandable)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var control = [self _dequeueDisclosureControl],
|
var control = [self _dequeueDisclosureControl];
|
||||||
frame = [control frame],
|
|
||||||
dataViewFrame = [self frameOfDataViewAtColumn:outlineColumn row:row];
|
|
||||||
|
|
||||||
frame.origin.x = _indentationMarkerFollowsDataView ? _CGRectGetMinX(dataViewFrame) - _CGRectGetWidth(frame) : 0.0;
|
|
||||||
frame.origin.y = _CGRectGetMinY(dataViewFrame);
|
|
||||||
frame.size.height = _CGRectGetHeight(dataViewFrame);
|
|
||||||
// FIXME: center instead?
|
|
||||||
//frame.origin.y = _CGRectGetMidY(dataViewFrame) - _CGRectGetHeight(frame) / 2.0;
|
|
||||||
|
|
||||||
_disclosureControlsForRows[row] = control;
|
_disclosureControlsForRows[row] = control;
|
||||||
|
|
||||||
[control setState:[self isItemExpanded:item] ? CPOnState : CPOffState];
|
[control setState:[self isItemExpanded:item] ? CPOnState : CPOffState];
|
||||||
var selector = [self isRowSelected:row] ? @"setThemeState:" : @"unsetThemeState:";
|
var selector = [self isRowSelected:row] ? @"setThemeState:" : @"unsetThemeState:";
|
||||||
[control performSelector:CPSelectorFromString(selector) withObject:CPThemeStateSelected];
|
[control performSelector:CPSelectorFromString(selector) withObject:CPThemeStateSelected];
|
||||||
[control setFrame:frame];
|
[control setFrame:[self frameOfOutlineDisclosureControlAtRow:row]];
|
||||||
|
|
||||||
[self addSubview:control];
|
[self addSubview:control];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
- (void)_unloadDataViewsInRows:(CPIndexSet)rows columns:(CPIndexSet)columns
|
- (void)_unloadDataViewsInRows:(CPIndexSet)rows columns:(CPIndexSet)columns
|
||||||
{
|
{
|
||||||
[super _unloadDataViewsInRows:rows columns:columns];
|
[super _unloadDataViewsInRows:rows columns:columns];
|
||||||
@@ -783,6 +1288,9 @@ CPOutlineViewDropOnItemIndex = -1;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
- (void)_toggleFromDisclosureControl:(CPControl)aControl
|
- (void)_toggleFromDisclosureControl:(CPControl)aControl
|
||||||
{
|
{
|
||||||
var controlFrame = [aControl frame],
|
var controlFrame = [aControl frame],
|
||||||
@@ -795,11 +1303,17 @@ CPOutlineViewDropOnItemIndex = -1;
|
|||||||
[self expandItem:item];
|
[self expandItem:item];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
- (void)_enqueueDisclosureControl:(CPControl)aControl
|
- (void)_enqueueDisclosureControl:(CPControl)aControl
|
||||||
{
|
{
|
||||||
_disclosureControlQueue.push(aControl);
|
_disclosureControlQueue.push(aControl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
- (CPControl)_dequeueDisclosureControl
|
- (CPControl)_dequeueDisclosureControl
|
||||||
{
|
{
|
||||||
if (_disclosureControlQueue.length)
|
if (_disclosureControlQueue.length)
|
||||||
@@ -819,22 +1333,43 @@ CPOutlineViewDropOnItemIndex = -1;
|
|||||||
return disclosureControl;
|
return disclosureControl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
- (void)_noteSelectionIsChanging
|
- (void)_noteSelectionIsChanging
|
||||||
{
|
{
|
||||||
[[CPNotificationCenter defaultCenter]
|
if (!_coalesceSelectionNotificationState || _coalesceSelectionNotificationState === CPOutlineViewCoalesceSelectionNotificationStateOn)
|
||||||
postNotificationName:CPOutlineViewSelectionIsChangingNotification
|
{
|
||||||
object:self
|
[[CPNotificationCenter defaultCenter]
|
||||||
userInfo:nil];
|
postNotificationName:CPOutlineViewSelectionIsChangingNotification
|
||||||
|
object:self
|
||||||
|
userInfo:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_coalesceSelectionNotificationState === CPOutlineViewCoalesceSelectionNotificationStateOn)
|
||||||
|
_coalesceSelectionNotificationState = CPOutlineViewCoalesceSelectionNotificationStateDid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
- (void)_noteSelectionDidChange
|
- (void)_noteSelectionDidChange
|
||||||
{
|
{
|
||||||
[[CPNotificationCenter defaultCenter]
|
if (!_coalesceSelectionNotificationState)
|
||||||
postNotificationName:CPOutlineViewSelectionDidChangeNotification
|
{
|
||||||
object:self
|
[[CPNotificationCenter defaultCenter]
|
||||||
userInfo:nil];
|
postNotificationName:CPOutlineViewSelectionDidChangeNotification
|
||||||
|
object:self
|
||||||
|
userInfo:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_coalesceSelectionNotificationState === CPOutlineViewCoalesceSelectionNotificationStateOn)
|
||||||
|
_coalesceSelectionNotificationState = CPOutlineViewCoalesceSelectionNotificationStateDid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
- (void)_noteItemWillExpand:(id)item
|
- (void)_noteItemWillExpand:(id)item
|
||||||
{
|
{
|
||||||
[[CPNotificationCenter defaultCenter]
|
[[CPNotificationCenter defaultCenter]
|
||||||
@@ -843,6 +1378,9 @@ CPOutlineViewDropOnItemIndex = -1;
|
|||||||
userInfo:[CPDictionary dictionaryWithObject:item forKey:"CPObject"]];
|
userInfo:[CPDictionary dictionaryWithObject:item forKey:"CPObject"]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
- (void)_noteItemDidExpand:(id)item
|
- (void)_noteItemDidExpand:(id)item
|
||||||
{
|
{
|
||||||
[[CPNotificationCenter defaultCenter]
|
[[CPNotificationCenter defaultCenter]
|
||||||
@@ -851,6 +1389,9 @@ CPOutlineViewDropOnItemIndex = -1;
|
|||||||
userInfo:[CPDictionary dictionaryWithObject:item forKey:"CPObject"]];
|
userInfo:[CPDictionary dictionaryWithObject:item forKey:"CPObject"]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
- (void)_noteItemWillCollapse:(id)item
|
- (void)_noteItemWillCollapse:(id)item
|
||||||
{
|
{
|
||||||
[[CPNotificationCenter defaultCenter]
|
[[CPNotificationCenter defaultCenter]
|
||||||
@@ -859,6 +1400,9 @@ CPOutlineViewDropOnItemIndex = -1;
|
|||||||
userInfo:[CPDictionary dictionaryWithObject:item forKey:"CPObject"]];
|
userInfo:[CPDictionary dictionaryWithObject:item forKey:"CPObject"]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
- (void)_noteItemDidCollapse:(id)item
|
- (void)_noteItemDidCollapse:(id)item
|
||||||
{
|
{
|
||||||
[[CPNotificationCenter defaultCenter]
|
[[CPNotificationCenter defaultCenter]
|
||||||
@@ -875,7 +1419,7 @@ var _reloadItem = function(/*CPOutlineView*/ anOutlineView, /*id*/ anItem)
|
|||||||
if (!anItem)
|
if (!anItem)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
with(anOutlineView)
|
with (anOutlineView)
|
||||||
{
|
{
|
||||||
// Get the existing info if it exists.
|
// Get the existing info if it exists.
|
||||||
var itemInfosForItems = _itemInfosForItems,
|
var itemInfosForItems = _itemInfosForItems,
|
||||||
@@ -911,7 +1455,7 @@ var _reloadItem = function(/*CPOutlineView*/ anOutlineView, /*id*/ anItem)
|
|||||||
// FIX ME: We're using with() here because Safari fails if we use anOutlineView._itemInfosForItems or whatever...
|
// FIX ME: We're using with() here because Safari fails if we use anOutlineView._itemInfosForItems or whatever...
|
||||||
var _loadItemInfoForItem = function(/*CPOutlineView*/ anOutlineView, /*id*/ anItem, /*BOOL*/ isIntermediate)
|
var _loadItemInfoForItem = function(/*CPOutlineView*/ anOutlineView, /*id*/ anItem, /*BOOL*/ isIntermediate)
|
||||||
{
|
{
|
||||||
with(anOutlineView)
|
with (anOutlineView)
|
||||||
{
|
{
|
||||||
var itemInfosForItems = _itemInfosForItems,
|
var itemInfosForItems = _itemInfosForItems,
|
||||||
dataSource = _outlineViewDataSource;
|
dataSource = _outlineViewDataSource;
|
||||||
@@ -1119,8 +1663,8 @@ var _loadItemInfoForItem = function(/*CPOutlineView*/ anOutlineView, /*id*/ anIt
|
|||||||
if (!(_outlineView._implementedOutlineViewDataSourceMethods & CPOutlineViewDataSource_outlineView_acceptDrop_item_childIndex_))
|
if (!(_outlineView._implementedOutlineViewDataSourceMethods & CPOutlineViewDataSource_outlineView_acceptDrop_item_childIndex_))
|
||||||
return NO;
|
return NO;
|
||||||
|
|
||||||
var location = [_outlineView convertPoint:[theInfo draggingLocation] fromView:nil],
|
var location = [_outlineView convertPoint:[theInfo draggingLocation] fromView:nil],
|
||||||
parentItem = [self _parentItemForDropOperation:theOperation row:theRow offset:location];
|
parentItem = [self _parentItemForDropOperation:theOperation row:theRow offset:location],
|
||||||
childIndex = [self _childIndexForDropOperation:theOperation row:theRow offset:location];
|
childIndex = [self _childIndexForDropOperation:theOperation row:theRow offset:location];
|
||||||
|
|
||||||
_outlineView._retargetedItem = nil;
|
_outlineView._retargetedItem = nil;
|
||||||
@@ -1261,12 +1805,16 @@ var _loadItemInfoForItem = function(/*CPOutlineView*/ anOutlineView, /*id*/ anIt
|
|||||||
|
|
||||||
CGContextBeginPath(context);
|
CGContextBeginPath(context);
|
||||||
CGContextMoveToPoint(context, 0.0, 0.0);
|
CGContextMoveToPoint(context, 0.0, 0.0);
|
||||||
if(_angle === 0.0) {
|
|
||||||
|
if (_angle === 0.0)
|
||||||
|
{
|
||||||
CGContextAddLineToPoint(context, 4.5, 8.0);
|
CGContextAddLineToPoint(context, 4.5, 8.0);
|
||||||
CGContextAddLineToPoint(context, 9.0, 0.0);
|
CGContextAddLineToPoint(context, 9.0, 0.0);
|
||||||
} else {
|
|
||||||
CGContextAddLineToPoint(context, 4.5, 8.0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
CGContextAddLineToPoint(context, 4.5, 8.0);
|
||||||
|
|
||||||
CGContextSetStrokeColor(context, [CPColor colorWithCalibratedWhite:1.0 alpha: 0.8]);
|
CGContextSetStrokeColor(context, [CPColor colorWithCalibratedWhite:1.0 alpha: 0.8]);
|
||||||
CGContextStrokePath(context);
|
CGContextStrokePath(context);
|
||||||
}
|
}
|
||||||
@@ -1304,6 +1852,7 @@ var CPOutlineViewIndentationPerLevelKey = @"CPOutlineViewIndentationPerLevelKey"
|
|||||||
_outlineViewDelegate = [aCoder decodeObjectForKey:CPOutlineViewDelegateKey];
|
_outlineViewDelegate = [aCoder decodeObjectForKey:CPOutlineViewDelegateKey];
|
||||||
|
|
||||||
[super setDataSource:[[_CPOutlineViewTableViewDataSource alloc] initWithOutlineView:self]];
|
[super setDataSource:[[_CPOutlineViewTableViewDataSource alloc] initWithOutlineView:self]];
|
||||||
|
[super setDelegate:[[_CPOutlineViewTableViewDelegate alloc] initWithOutlineView:self]];
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
@@ -1311,7 +1860,14 @@ var CPOutlineViewIndentationPerLevelKey = @"CPOutlineViewIndentationPerLevelKey"
|
|||||||
|
|
||||||
- (void)encodeWithCoder:(CPCoder)aCoder
|
- (void)encodeWithCoder:(CPCoder)aCoder
|
||||||
{
|
{
|
||||||
|
// Make sure we don't encode our internal delegate and data source.
|
||||||
|
var internalDelegate = _delegate,
|
||||||
|
internalDataSource = _dataSource;
|
||||||
|
_delegate = nil;
|
||||||
|
_dataSource = nil;
|
||||||
[super encodeWithCoder:aCoder];
|
[super encodeWithCoder:aCoder];
|
||||||
|
_delegate = internalDelegate;
|
||||||
|
_dataSource = internalDataSource;
|
||||||
|
|
||||||
[aCoder encodeObject:_outlineTableColumn forKey:CPOutlineViewOutlineTableColumnKey];
|
[aCoder encodeObject:_outlineTableColumn forKey:CPOutlineViewOutlineTableColumnKey];
|
||||||
[aCoder encodeFloat:_indentationPerLevel forKey:CPOutlineViewIndentationPerLevelKey];
|
[aCoder encodeFloat:_indentationPerLevel forKey:CPOutlineViewIndentationPerLevelKey];
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ CPCancelButton = 0;
|
|||||||
@global
|
@global
|
||||||
@class CPWindow
|
@class CPWindow
|
||||||
*/
|
*/
|
||||||
CPDocModalWindowMask = 1 << 6;
|
CPDocModalWindowMask = 1 << 6;
|
||||||
|
|
||||||
@implementation CPPanel : CPWindow
|
@implementation CPPanel : CPWindow
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ var CPPasteboards = nil,
|
|||||||
{
|
{
|
||||||
var type = types[i];
|
var type = types[i];
|
||||||
|
|
||||||
if(![_owners objectForKey:type])
|
if (![_owners objectForKey:type])
|
||||||
{
|
{
|
||||||
[_types addObject:type];
|
[_types addObject:type];
|
||||||
[_provided removeObjectForKey:type];
|
[_provided removeObjectForKey:type];
|
||||||
|
|||||||
@@ -38,10 +38,8 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
|
|||||||
*/
|
*/
|
||||||
@implementation CPPopUpButton : CPButton
|
@implementation CPPopUpButton : CPButton
|
||||||
{
|
{
|
||||||
int _selectedIndex;
|
CPUInteger _selectedIndex;
|
||||||
CPRectEdge _preferredEdge;
|
CPRectEdge _preferredEdge;
|
||||||
|
|
||||||
CPMenu _menu;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (CPString)defaultThemeClass
|
+ (CPString)defaultThemeClass
|
||||||
@@ -49,6 +47,16 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
|
|||||||
return "popup-button";
|
return "popup-button";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (CPSet)keyPathsForValuesAffectingSelectedIndex
|
||||||
|
{
|
||||||
|
return [CPSet setWithObject:@"objectValue"];
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (CPSet)keyPathsForValuesAffectingSelectedTag
|
||||||
|
{
|
||||||
|
return [CPSet setWithObject:@"selectedIndex"];
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Initializes the pop-up button to the specified size.
|
Initializes the pop-up button to the specified size.
|
||||||
@param aFrame the size for the button
|
@param aFrame the size for the button
|
||||||
@@ -61,7 +69,8 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
|
|||||||
|
|
||||||
if (self)
|
if (self)
|
||||||
{
|
{
|
||||||
_selectedIndex = CPNotFound;
|
[self selectItemAtIndex:CPNotFound];
|
||||||
|
|
||||||
_preferredEdge = CPMaxYEdge;
|
_preferredEdge = CPMaxYEdge;
|
||||||
|
|
||||||
[self setValue:CPImageLeft forThemeAttribute:@"image-position"];
|
[self setValue:CPImageLeft forThemeAttribute:@"image-position"];
|
||||||
@@ -71,6 +80,14 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
|
|||||||
[self setMenu:[[CPMenu alloc] initWithTitle:@""]];
|
[self setMenu:[[CPMenu alloc] initWithTitle:@""]];
|
||||||
|
|
||||||
[self setPullsDown:shouldPullDown];
|
[self setPullsDown:shouldPullDown];
|
||||||
|
|
||||||
|
var options = CPKeyValueObservingOptionNew |
|
||||||
|
CPKeyValueObservingOptionOld;/* |
|
||||||
|
CPKeyValueObservingOptionInitial;
|
||||||
|
*/
|
||||||
|
[self addObserver:self forKeyPath:@"menu.items" options:options context:nil];
|
||||||
|
[self addObserver:self forKeyPath:@"_firstItem.changeCount" options:options context:nil];
|
||||||
|
[self addObserver:self forKeyPath:@"selectedItem.changeCount" options:options context:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
@@ -98,7 +115,7 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
|
|||||||
if (!changed)
|
if (!changed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var items = [_menu itemArray];
|
var items = [[self menu] itemArray];
|
||||||
|
|
||||||
if ([items count] <= 0)
|
if ([items count] <= 0)
|
||||||
return;
|
return;
|
||||||
@@ -123,7 +140,7 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
|
|||||||
*/
|
*/
|
||||||
- (void)addItem:(CPMenuItem)anItem
|
- (void)addItem:(CPMenuItem)anItem
|
||||||
{
|
{
|
||||||
[_menu addItem:anItem];
|
[[self menu] addItem:anItem];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -132,7 +149,7 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
|
|||||||
*/
|
*/
|
||||||
- (void)addItemWithTitle:(CPString)aTitle
|
- (void)addItemWithTitle:(CPString)aTitle
|
||||||
{
|
{
|
||||||
[_menu addItemWithTitle:aTitle action:NULL keyEquivalent:nil];
|
[[self menu] addItemWithTitle:aTitle action:NULL keyEquivalent:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -162,7 +179,7 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
|
|||||||
if ([items[count] title] == aTitle)
|
if ([items[count] title] == aTitle)
|
||||||
[self removeItemAtIndex:count];
|
[self removeItemAtIndex:count];
|
||||||
|
|
||||||
[_menu insertItemWithTitle:aTitle action:NULL keyEquivalent:nil atIndex:anIndex];
|
[[self menu] insertItemWithTitle:aTitle action:NULL keyEquivalent:nil atIndex:anIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -170,10 +187,11 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
|
|||||||
*/
|
*/
|
||||||
- (void)removeAllItems
|
- (void)removeAllItems
|
||||||
{
|
{
|
||||||
var count = [_menu numberOfItems];
|
var menu = [self menu],
|
||||||
|
count = [menu numberOfItems];
|
||||||
|
|
||||||
while (count--)
|
while (count--)
|
||||||
[_menu removeItemAtIndex:0];
|
[menu removeItemAtIndex:0];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -192,7 +210,7 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
|
|||||||
*/
|
*/
|
||||||
- (void)removeItemAtIndex:(int)anIndex
|
- (void)removeItemAtIndex:(int)anIndex
|
||||||
{
|
{
|
||||||
[_menu removeItemAtIndex:anIndex];
|
[[self menu] removeItemAtIndex:anIndex];
|
||||||
[self synchronizeTitleAndSelectedItem];
|
[self synchronizeTitleAndSelectedItem];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,10 +220,12 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
|
|||||||
*/
|
*/
|
||||||
- (CPMenuItem)selectedItem
|
- (CPMenuItem)selectedItem
|
||||||
{
|
{
|
||||||
if (_selectedIndex < 0 || _selectedIndex > [self numberOfItems] - 1)
|
var indexOfSelectedItem = [self indexOfSelectedItem];
|
||||||
|
|
||||||
|
if (indexOfSelectedItem < 0 || indexOfSelectedItem > [self numberOfItems] - 1)
|
||||||
return nil;
|
return nil;
|
||||||
|
|
||||||
return [_menu itemAtIndex:_selectedIndex];
|
return [[self menu] itemAtIndex:indexOfSelectedItem];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -224,13 +244,20 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
|
|||||||
return _selectedIndex;
|
return _selectedIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
// For us, CPNumber is toll-free bridged to Number, so just return the selected index.
|
|
||||||
/*!
|
/*!
|
||||||
Returns the selected item's index. If no item is selected, it returns CPNotFound.
|
@ignore
|
||||||
*/
|
*/
|
||||||
- (id)objectValue
|
- (int)selectedTag
|
||||||
{
|
{
|
||||||
return _selectedIndex;
|
return [[self selectedItem] tag];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
|
- (void)_setSelectedTag:(int)aTag
|
||||||
|
{
|
||||||
|
[self selectItemWithTag:aTag];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setting the Current Selection
|
// Setting the Current Selection
|
||||||
@@ -247,22 +274,50 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
|
|||||||
Selects the item at the specified index
|
Selects the item at the specified index
|
||||||
@param anIndex the index of the item to select
|
@param anIndex the index of the item to select
|
||||||
*/
|
*/
|
||||||
- (void)selectItemAtIndex:(int)anIndex
|
- (void)selectItemAtIndex:(CPUInteger)anIndex
|
||||||
{
|
{
|
||||||
if (_selectedIndex == anIndex)
|
[self setObjectValue:anIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setSelectedIndex:(CPUInteger)anIndex
|
||||||
|
{
|
||||||
|
[self setObjectValue:anIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (CPUInteger)selectedIndex
|
||||||
|
{
|
||||||
|
return [self objectValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Selects the item at the specified index
|
||||||
|
@param anIndex the index of the item to select
|
||||||
|
*/
|
||||||
|
- (void)setObjectValue:(int)anIndex
|
||||||
|
{
|
||||||
|
var indexOfSelectedItem = [self objectValue];
|
||||||
|
|
||||||
|
anIndex = parseInt(+anIndex, 10);
|
||||||
|
|
||||||
|
if (indexOfSelectedItem === anIndex)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_selectedIndex >= 0 && ![self pullsDown])
|
if (indexOfSelectedItem >= 0 && ![self pullsDown])
|
||||||
[[self selectedItem] setState:CPOffState];
|
[[self selectedItem] setState:CPOffState];
|
||||||
|
|
||||||
_selectedIndex = anIndex;
|
_selectedIndex = anIndex;
|
||||||
|
|
||||||
if (_selectedIndex >= 0 && ![self pullsDown])
|
if (indexOfSelectedItem >= 0 && ![self pullsDown])
|
||||||
[[self selectedItem] setState:CPOnState];
|
[[self selectedItem] setState:CPOnState];
|
||||||
|
|
||||||
[self synchronizeTitleAndSelectedItem];
|
[self synchronizeTitleAndSelectedItem];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (id)objectValue
|
||||||
|
{
|
||||||
|
return _selectedIndex;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Selects the menu item with the specified tag
|
Selects the menu item with the specified tag
|
||||||
@param the tag of the item to select
|
@param the tag of the item to select
|
||||||
@@ -281,84 +336,14 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
|
|||||||
[self selectItemAtIndex:[self indexOfItemWithTitle:aTitle]];
|
[self selectItemAtIndex:[self indexOfItemWithTitle:aTitle]];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
Sets the object for the selected item. If no item is selected, then this method has no effect.
|
|
||||||
@param the object set for the selected item
|
|
||||||
*/
|
|
||||||
- (void)setObjectValue:(id)aValue
|
|
||||||
{
|
|
||||||
[self selectItemAtIndex:[aValue intValue]];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Getting Menu Items
|
// Getting Menu Items
|
||||||
/*!
|
|
||||||
Returns the button's menu of items.
|
|
||||||
*/
|
|
||||||
- (CPMenu)menu
|
|
||||||
{
|
|
||||||
return _menu;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
Sets the menu for the button
|
|
||||||
*/
|
|
||||||
- (void)setMenu:(CPMenu)aMenu
|
|
||||||
{
|
|
||||||
if (_menu === aMenu)
|
|
||||||
return;
|
|
||||||
|
|
||||||
var defaultCenter = [CPNotificationCenter defaultCenter];
|
|
||||||
|
|
||||||
if (_menu)
|
|
||||||
{
|
|
||||||
[defaultCenter
|
|
||||||
removeObserver:self
|
|
||||||
name:CPMenuDidAddItemNotification
|
|
||||||
object:_menu];
|
|
||||||
|
|
||||||
[defaultCenter
|
|
||||||
removeObserver:self
|
|
||||||
name:CPMenuDidChangeItemNotification
|
|
||||||
object:_menu];
|
|
||||||
|
|
||||||
[defaultCenter
|
|
||||||
removeObserver:self
|
|
||||||
name:CPMenuDidRemoveItemNotification
|
|
||||||
object:_menu];
|
|
||||||
}
|
|
||||||
|
|
||||||
_menu = aMenu;
|
|
||||||
|
|
||||||
if (_menu)
|
|
||||||
{
|
|
||||||
[defaultCenter
|
|
||||||
addObserver:self
|
|
||||||
selector:@selector(menuDidAddItem:)
|
|
||||||
name:CPMenuDidAddItemNotification
|
|
||||||
object:_menu];
|
|
||||||
|
|
||||||
[defaultCenter
|
|
||||||
addObserver:self
|
|
||||||
selector:@selector(menuDidChangeItem:)
|
|
||||||
name:CPMenuDidChangeItemNotification
|
|
||||||
object:_menu];
|
|
||||||
|
|
||||||
[defaultCenter
|
|
||||||
addObserver:self
|
|
||||||
selector:@selector(menuDidRemoveItem:)
|
|
||||||
name:CPMenuDidRemoveItemNotification
|
|
||||||
object:_menu];
|
|
||||||
}
|
|
||||||
|
|
||||||
[self synchronizeTitleAndSelectedItem];
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Returns a count of the number of items in the button's menu.
|
Returns a count of the number of items in the button's menu.
|
||||||
*/
|
*/
|
||||||
- (int)numberOfItems
|
- (int)numberOfItems
|
||||||
{
|
{
|
||||||
return [_menu numberOfItems];
|
return [[self menu] numberOfItems];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -366,7 +351,7 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
|
|||||||
*/
|
*/
|
||||||
- (CPArray)itemArray
|
- (CPArray)itemArray
|
||||||
{
|
{
|
||||||
return [_menu itemArray];
|
return [[self menu] itemArray];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -375,7 +360,7 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
|
|||||||
*/
|
*/
|
||||||
- (CPMenuItem)itemAtIndex:(unsigned)anIndex
|
- (CPMenuItem)itemAtIndex:(unsigned)anIndex
|
||||||
{
|
{
|
||||||
return [_menu itemAtIndex:anIndex];
|
return [[self menu] itemAtIndex:anIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -384,7 +369,7 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
|
|||||||
*/
|
*/
|
||||||
- (CPString)itemTitleAtIndex:(unsigned)anIndex
|
- (CPString)itemTitleAtIndex:(unsigned)anIndex
|
||||||
{
|
{
|
||||||
return [[_menu itemAtIndex:anIndex] title];
|
return [[[self menu] itemAtIndex:anIndex] title];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -409,7 +394,9 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
|
|||||||
*/
|
*/
|
||||||
- (CPMenuItem)itemWithTitle:(CPString)aTitle
|
- (CPMenuItem)itemWithTitle:(CPString)aTitle
|
||||||
{
|
{
|
||||||
return [_menu itemAtIndex:[_menu indexOfItemWithTitle:aTitle]];
|
var menu = [self menu];
|
||||||
|
|
||||||
|
return [menu itemAtIndex:[menu indexOfItemWithTitle:aTitle]];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -417,7 +404,7 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
|
|||||||
*/
|
*/
|
||||||
- (CPMenuItem)lastItem
|
- (CPMenuItem)lastItem
|
||||||
{
|
{
|
||||||
return [[_menu itemArray] lastObject];
|
return [[[self menu] itemArray] lastObject];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getting the Indices of Menu Items
|
// Getting the Indices of Menu Items
|
||||||
@@ -427,7 +414,7 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
|
|||||||
*/
|
*/
|
||||||
- (int)indexOfItem:(CPMenuItem)aMenuItem
|
- (int)indexOfItem:(CPMenuItem)aMenuItem
|
||||||
{
|
{
|
||||||
return [_menu indexOfItem:aMenuItem];
|
return [[self menu] indexOfItem:aMenuItem];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -436,7 +423,7 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
|
|||||||
*/
|
*/
|
||||||
- (int)indexOfItemWithTag:(int)aTag
|
- (int)indexOfItemWithTag:(int)aTag
|
||||||
{
|
{
|
||||||
return [_menu indexOfItemWithTag:aTag];
|
return [[self menu] indexOfItemWithTag:aTag];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -445,7 +432,7 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
|
|||||||
*/
|
*/
|
||||||
- (int)indexOfItemWithTitle:(CPString)aTitle
|
- (int)indexOfItemWithTitle:(CPString)aTitle
|
||||||
{
|
{
|
||||||
return [_menu indexOfItemWithTitle:aTitle];
|
return [[self menu] indexOfItemWithTitle:aTitle];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -456,7 +443,7 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
|
|||||||
*/
|
*/
|
||||||
- (int)indexOfItemWithRepresentedObject:(id)anObject
|
- (int)indexOfItemWithRepresentedObject:(id)anObject
|
||||||
{
|
{
|
||||||
return [_menu indexOfItemWithRepresentedObject:anObject];
|
return [[self menu] indexOfItemWithRepresentedObject:anObject];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -468,7 +455,7 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
|
|||||||
*/
|
*/
|
||||||
- (int)indexOfItemWithTarget:(id)aTarget action:(SEL)anAction
|
- (int)indexOfItemWithTarget:(id)aTarget action:(SEL)anAction
|
||||||
{
|
{
|
||||||
return [_menu indexOfItemWithTarget:aTarget action:anAction];
|
return [[self menu] indexOfItemWithTarget:aTarget action:anAction];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setting the Cell Edge to Pop out in Restricted Situations
|
// Setting the Cell Edge to Pop out in Restricted Situations
|
||||||
@@ -504,7 +491,7 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
|
|||||||
|
|
||||||
if ([self pullsDown])
|
if ([self pullsDown])
|
||||||
{
|
{
|
||||||
var items = [_menu itemArray];
|
var items = [[self menu] itemArray];
|
||||||
|
|
||||||
if ([items count] <= 0)
|
if ([items count] <= 0)
|
||||||
[self addItemWithTitle:aTitle];
|
[self addItemWithTitle:aTitle];
|
||||||
@@ -552,7 +539,7 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
|
|||||||
|
|
||||||
if ([self pullsDown])
|
if ([self pullsDown])
|
||||||
{
|
{
|
||||||
var items = [_menu itemArray];
|
var items = [[self menu] itemArray];
|
||||||
|
|
||||||
if ([items count] > 0)
|
if ([items count] > 0)
|
||||||
item = items[0];
|
item = items[0];
|
||||||
@@ -564,73 +551,117 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
|
|||||||
[super setTitle:[item title]];
|
[super setTitle:[item title]];
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
- (void)observeValueForKeyPath:(CPString)aKeyPath ofObject:(id)anObject change:(CPDictionary)changes context:(id)aContext
|
||||||
/*!
|
|
||||||
Called when the menu has a new item added to it.
|
|
||||||
@param aNotification information about the event
|
|
||||||
*/
|
|
||||||
- (void)menuDidAddItem:(CPNotification)aNotification
|
|
||||||
{
|
{
|
||||||
var index = [[aNotification userInfo] objectForKey:@"CPMenuItemIndex"];
|
var pullsDown = [self pullsDown];
|
||||||
|
|
||||||
if (_selectedIndex < 0)
|
if (!pullsDown && aKeyPath === @"selectedItem.changeCount" ||
|
||||||
[self selectItemAtIndex:0];
|
pullsDown && (aKeyPath === @"_firstItem" || aKeyPath === @"_firstItem.changeCount"))
|
||||||
|
|
||||||
else if (index == _selectedIndex)
|
|
||||||
[self synchronizeTitleAndSelectedItem];
|
[self synchronizeTitleAndSelectedItem];
|
||||||
|
|
||||||
else if (index < _selectedIndex)
|
// FIXME: This is due to a bug in KVO, we should never get it for "menu".
|
||||||
++_selectedIndex;
|
if (aKeyPath === @"menu")
|
||||||
|
|
||||||
if (index == 0 && [self pullsDown])
|
|
||||||
{
|
{
|
||||||
var items = [_menu itemArray];
|
aKeyPath = @"menu.items";
|
||||||
|
|
||||||
[items[0] setHidden:YES];
|
[changes setObject:CPKeyValueChangeSetting forKey:CPKeyValueChangeKindKey];
|
||||||
|
[changes setObject:[[self menu] itemArray] forKey:CPKeyValueChangeNewKey];
|
||||||
if (items.length > 0)
|
|
||||||
[items[1] setHidden:NO];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var item = [_menu itemArray][index],
|
if (aKeyPath === @"menu.items")
|
||||||
action = [item action];
|
|
||||||
|
|
||||||
if (!action || (action === @selector(_popUpItemAction:)))
|
|
||||||
{
|
{
|
||||||
[item setTarget:self];
|
var changeKind = [changes objectForKey:CPKeyValueChangeKindKey],
|
||||||
[item setAction:@selector(_popUpItemAction:)];
|
indexOfSelectedItem = [self indexOfSelectedItem];
|
||||||
|
|
||||||
|
if (changeKind === CPKeyValueChangeRemoval)
|
||||||
|
{
|
||||||
|
var index = CPNotFound,
|
||||||
|
indexes = [changes objectForKey:CPKeyValueChangeIndexesKey];
|
||||||
|
|
||||||
|
if ([indexes containsIndex:0] && [self pullsDown])
|
||||||
|
[self _firstItemDidChange];
|
||||||
|
|
||||||
|
// See whether the index has changed, despite the actual item not changing.
|
||||||
|
while ((index = [indexes indexGreaterThanIndex:index]) !== CPNotFound &&
|
||||||
|
index <= indexOfSelectedItem)
|
||||||
|
--indexOfSelectedItem;
|
||||||
|
|
||||||
|
[self selectItemAtIndex:indexOfSelectedItem];
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (changeKind === CPKeyValueChangeReplacement)
|
||||||
|
{
|
||||||
|
var indexes = [changes objectForKey:CPKeyValueChangeIndexesKey];
|
||||||
|
|
||||||
|
if (pullsDown && [indexes containsIndex:0] ||
|
||||||
|
!pullsDown && [indexes containsIndex:indexOfSelectedItem])
|
||||||
|
[self synchronizeTitleAndSelectedItem];
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// No matter what, we want to prepare the new items.
|
||||||
|
var newItems = [changes objectForKey:CPKeyValueChangeNewKey];
|
||||||
|
|
||||||
|
[newItems enumerateObjectsUsingBlock:function(aMenuItem)
|
||||||
|
{
|
||||||
|
var action = [aMenuItem action];
|
||||||
|
|
||||||
|
if (!action)
|
||||||
|
[aMenuItem setAction:action = @selector(_popUpItemAction:)];
|
||||||
|
|
||||||
|
if (action === @selector(_popUpItemAction:))
|
||||||
|
[aMenuItem setTarget:self];
|
||||||
|
}];
|
||||||
|
|
||||||
|
if (changeKind === CPKeyValueChangeSetting)
|
||||||
|
{
|
||||||
|
[self _firstItemDidChange];
|
||||||
|
|
||||||
|
[self selectItemAtIndex:CPNotFound];
|
||||||
|
[self selectItemAtIndex:MIN([newItems count] - 1, indexOfSelectedItem)];
|
||||||
|
}
|
||||||
|
|
||||||
|
else //if (changeKind === CPKeyValueChangeInsertion)
|
||||||
|
{
|
||||||
|
var indexes = [changes objectForKey:CPKeyValueChangeIndexesKey];
|
||||||
|
|
||||||
|
if ([self pullsDown] && [indexes containsIndex:0])
|
||||||
|
{
|
||||||
|
[self _firstItemDidChange];
|
||||||
|
|
||||||
|
if ([self numberOfItems] > 1)
|
||||||
|
{
|
||||||
|
var index = CPNotFound,
|
||||||
|
originalIndex = 0;
|
||||||
|
|
||||||
|
while ((index = [indexes indexGreaterThanIndex:index]) !== CPNotFound &&
|
||||||
|
index <= originalIndex)
|
||||||
|
++originalIndex;
|
||||||
|
|
||||||
|
[[self itemAtIndex:originalIndex] setHidden:NO];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (indexOfSelectedItem < 0)
|
||||||
|
[self selectItemAtIndex:0];
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var index = CPNotFound;
|
||||||
|
|
||||||
|
// See whether the index has changed, despite the actual item not changing.
|
||||||
|
while ((index = [indexes indexGreaterThanIndex:index]) !== CPNotFound &&
|
||||||
|
index <= indexOfSelectedItem)
|
||||||
|
++indexOfSelectedItem;
|
||||||
|
|
||||||
|
[self selectItemAtIndex:indexOfSelectedItem];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
// [super observeValueForKeyPath:aKeyPath ofObject:anObject change:changes context:aContext];
|
||||||
Called when a menu item has changed.
|
|
||||||
@param aNotification information about the event
|
|
||||||
*/
|
|
||||||
- (void)menuDidChangeItem:(CPNotification)aNotification
|
|
||||||
{
|
|
||||||
var index = [[aNotification userInfo] objectForKey:@"CPMenuItemIndex"];
|
|
||||||
|
|
||||||
if ([self pullsDown] && index != 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (![self pullsDown] && index != _selectedIndex)
|
|
||||||
return;
|
|
||||||
|
|
||||||
[self synchronizeTitleAndSelectedItem];
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
Called when an item was removed from the menu.
|
|
||||||
@param aNotification information about the event
|
|
||||||
*/
|
|
||||||
- (void)menuDidRemoveItem:(CPNotification)aNotification
|
|
||||||
{
|
|
||||||
var numberOfItems = [self numberOfItems];
|
|
||||||
|
|
||||||
if (numberOfItems <= _selectedIndex && numberOfItems > 0)
|
|
||||||
[self selectItemAtIndex:numberOfItems - 1];
|
|
||||||
else
|
|
||||||
[self synchronizeTitleAndSelectedItem];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)mouseDown:(CPEvent)anEvent
|
- (void)mouseDown:(CPEvent)anEvent
|
||||||
@@ -710,6 +741,22 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
|
|||||||
[self sendAction:[self action] to:[self target]];
|
[self sendAction:[self action] to:[self target]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)_firstItemDidChange
|
||||||
|
{
|
||||||
|
[self willChangeValueForKey:@"_firstItem"];
|
||||||
|
[self didChangeValueForKey:@"_firstItem"];
|
||||||
|
|
||||||
|
[[self _firstItem] setHidden:YES];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (CPMenuItem)_firstItem
|
||||||
|
{
|
||||||
|
if ([self numberOfItems] <= 0)
|
||||||
|
return nil;
|
||||||
|
|
||||||
|
return [[self menu] itemAtIndex:0];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)takeValueFromKeyPath:(CPString)aKeyPath ofObjects:(CPArray)objects
|
- (void)takeValueFromKeyPath:(CPString)aKeyPath ofObjects:(CPArray)objects
|
||||||
{
|
{
|
||||||
var count = objects.length,
|
var count = objects.length,
|
||||||
@@ -719,19 +766,14 @@ CPPopUpButtonStatePullsDown = CPThemeState("pulls-down");
|
|||||||
[self setEnabled:YES];
|
[self setEnabled:YES];
|
||||||
|
|
||||||
while (count-- > 1)
|
while (count-- > 1)
|
||||||
{
|
|
||||||
if (value !== [objects[count] valueForKeyPath:aKeyPath])
|
if (value !== [objects[count] valueForKeyPath:aKeyPath])
|
||||||
{
|
|
||||||
[[self selectedItem] setState:CPOffState];
|
[[self selectedItem] setState:CPOffState];
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
var CPPopUpButtonMenuKey = @"CPPopUpButtonMenuKey",
|
var DEPRECATED_CPPopUpButtonMenuKey = @"CPPopUpButtonMenuKey",
|
||||||
CPPopUpButtonSelectedIndexKey = @"CPPopUpButtonSelectedIndexKey",
|
DEPRECATED_CPPopUpButtonSelectedIndexKey = @"CPPopUpButtonSelectedIndexKey";
|
||||||
CPPopUpButtonPullsDownKey = @"CPPopUpButtonPullsDownKey";
|
|
||||||
|
|
||||||
@implementation CPPopUpButton (CPCoding)
|
@implementation CPPopUpButton (CPCoding)
|
||||||
/*!
|
/*!
|
||||||
@@ -747,27 +789,30 @@ var CPPopUpButtonMenuKey = @"CPPopUpButtonMenuKey",
|
|||||||
|
|
||||||
if (self)
|
if (self)
|
||||||
{
|
{
|
||||||
// Nothing is currently selected
|
// FIXME: (or not?) _title is nulled in - [CPButton initWithCoder:],
|
||||||
_selectedIndex = -1;
|
// so we need to do this again.
|
||||||
|
[self synchronizeTitleAndSelectedItem];
|
||||||
|
|
||||||
[self setMenu:[aCoder decodeObjectForKey:CPPopUpButtonMenuKey]];
|
// FIXME: Remove deprecation leniency for 1.0
|
||||||
[self selectItemAtIndex:[aCoder decodeObjectForKey:CPPopUpButtonSelectedIndexKey]];
|
if ([aCoder containsValueForKey:DEPRECATED_CPPopUpButtonMenuKey])
|
||||||
|
{
|
||||||
|
CPLog.warn(self + " was encoded with an older version of Cappuccino. Please nib2cib the original nib again or open and re-save in Atlas.");
|
||||||
|
|
||||||
|
[self setMenu:[aCoder decodeObjectForKey:DEPRECATED_CPPopUpButtonMenuKey]];
|
||||||
|
[self setObjectValue:[aCoder decodeObjectForKey:DEPRECATED_CPPopUpButtonSelectedIndexKey]];
|
||||||
|
}
|
||||||
|
|
||||||
|
var options = CPKeyValueObservingOptionNew |
|
||||||
|
CPKeyValueObservingOptionOld;/* |
|
||||||
|
CPKeyValueObservingOptionInitial;
|
||||||
|
*/
|
||||||
|
|
||||||
|
[self addObserver:self forKeyPath:@"menu.items" options:options context:nil];
|
||||||
|
[self addObserver:self forKeyPath:@"_firstItem.changeCount" options:options context:nil];
|
||||||
|
[self addObserver:self forKeyPath:@"selectedItem.changeCount" options:options context:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
|
||||||
Encodes the data of the pop-up button into a coder
|
|
||||||
@param aCoder the coder to which the data
|
|
||||||
will be written
|
|
||||||
*/
|
|
||||||
- (void)encodeWithCoder:(CPCoder)aCoder
|
|
||||||
{
|
|
||||||
[super encodeWithCoder:aCoder];
|
|
||||||
|
|
||||||
[aCoder encodeObject:_menu forKey:CPPopUpButtonMenuKey];
|
|
||||||
[aCoder encodeInt:_selectedIndex forKey:CPPopUpButtonSelectedIndexKey];
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ var CPProgressIndicatorSpinningStyleColors = nil,
|
|||||||
CPProgressIndicatorClassName + @"Bar" + CPProgressIndicatorStyleIdentifiers[CPProgressIndicatorHUDBarStyle]
|
CPProgressIndicatorClassName + @"Bar" + CPProgressIndicatorStyleIdentifiers[CPProgressIndicatorHUDBarStyle]
|
||||||
];
|
];
|
||||||
|
|
||||||
for (var i = 0, count = prefixes.length; i<count; i++)
|
for (var i = 0, count = prefixes.length; i < count; i++)
|
||||||
{
|
{
|
||||||
var prefix = prefixes[i];
|
var prefix = prefixes[i];
|
||||||
CPProgressIndicatorStyleSizes[prefix + regularIdentifier] = [_CGSizeMake(3.0, 16.0), _CGSizeMake(1.0, 16.0), _CGSizeMake(3.0, 16.0)];
|
CPProgressIndicatorStyleSizes[prefix + regularIdentifier] = [_CGSizeMake(3.0, 16.0), _CGSizeMake(1.0, 16.0), _CGSizeMake(3.0, 16.0)];
|
||||||
@@ -357,8 +357,7 @@ var CPProgressIndicatorSpinningStyleColors = nil,
|
|||||||
[self setFrameSize:[[CPProgressIndicatorSpinningStyleColors[_controlSize] patternImage] size]];
|
[self setFrameSize:[[CPProgressIndicatorSpinningStyleColors[_controlSize] patternImage] size]];
|
||||||
else
|
else
|
||||||
[self setFrameSize:CGSizeMake(CGRectGetWidth([self frame]), CPProgressIndicatorStyleSizes[
|
[self setFrameSize:CGSizeMake(CGRectGetWidth([self frame]), CPProgressIndicatorStyleSizes[
|
||||||
CPProgressIndicatorClassName + @"BezelBorder" + CPProgressIndicatorStyleIdentifiers[CPProgressIndicatorBarStyle] +
|
CPProgressIndicatorClassName + @"BezelBorder" + CPProgressIndicatorStyleIdentifiers[CPProgressIndicatorBarStyle] + _CPControlIdentifierForControlSize(_controlSize)][0].height)];
|
||||||
_CPControlIdentifierForControlSize(_controlSize)][0].height)];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
@@ -358,8 +358,8 @@ var CPResponderNextResponderKey = @"CPResponderNextResponderKey",
|
|||||||
|
|
||||||
if (self)
|
if (self)
|
||||||
{
|
{
|
||||||
_nextResponder = [aCoder decodeObjectForKey:CPResponderNextResponderKey];
|
[self setNextResponder:[aCoder decodeObjectForKey:CPResponderNextResponderKey]];
|
||||||
_menu = [aCoder decodeObjectForKey:CPResponderMenuKey];
|
[self setMenu:[aCoder decodeObjectForKey:CPResponderMenuKey]];
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
|||||||
@@ -354,6 +354,11 @@
|
|||||||
|
|
||||||
/*!
|
/*!
|
||||||
Sets the type of border to be drawn around the view.
|
Sets the type of border to be drawn around the view.
|
||||||
|
Valid types are:
|
||||||
|
CPNoBorder
|
||||||
|
CPLineBorder
|
||||||
|
CPBezelBorder
|
||||||
|
CPGrooveBorder
|
||||||
*/
|
*/
|
||||||
- (void)setBorderType:(CPBorderType)borderType
|
- (void)setBorderType:(CPBorderType)borderType
|
||||||
{
|
{
|
||||||
@@ -974,6 +979,22 @@
|
|||||||
[self moveByOffset:CGSizeMake(0.0, _CGRectGetHeight(contentBounds) - _verticalPageScroll)];
|
[self moveByOffset:CGSizeMake(0.0, _CGRectGetHeight(contentBounds) - _verticalPageScroll)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)scrollToBeginningOfDocument:(id)sender
|
||||||
|
{
|
||||||
|
[_contentView scrollToPoint:_CGPointMakeZero()];
|
||||||
|
[_headerClipView scrollToPoint:_CGPointMakeZero()];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)scrollToEndOfDocument:(id)sender
|
||||||
|
{
|
||||||
|
var contentBounds = [_contentView bounds],
|
||||||
|
documentFrame = [[self documentView] frame],
|
||||||
|
scrollPoint = _CGPointMake(0.0, _CGRectGetHeight(documentFrame) - _CGRectGetHeight(contentBounds));
|
||||||
|
|
||||||
|
[_contentView scrollToPoint:scrollPoint];
|
||||||
|
[_headerClipView scrollToPoint:_CGPointMakeZero()];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)moveLeft:(id)sender
|
- (void)moveLeft:(id)sender
|
||||||
{
|
{
|
||||||
[self moveByOffset:CGSizeMake(-_horizontalLineScroll, 0.0)];
|
[self moveByOffset:CGSizeMake(-_horizontalLineScroll, 0.0)];
|
||||||
@@ -1003,7 +1024,7 @@
|
|||||||
contentBounds.origin.y += aSize.height;
|
contentBounds.origin.y += aSize.height;
|
||||||
|
|
||||||
[_contentView scrollToPoint:contentBounds.origin];
|
[_contentView scrollToPoint:contentBounds.origin];
|
||||||
[_headerClipView scrollToPoint:CGPointMake(contentBounds.origin, 0)];
|
[_headerClipView scrollToPoint:CGPointMake(contentBounds.origin.x, 0)];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -23,12 +23,10 @@
|
|||||||
@import "CPButton.j"
|
@import "CPButton.j"
|
||||||
@import "CPTextField.j"
|
@import "CPTextField.j"
|
||||||
|
|
||||||
|
|
||||||
CPSearchFieldRecentsTitleMenuItemTag = 1000;
|
CPSearchFieldRecentsTitleMenuItemTag = 1000;
|
||||||
CPSearchFieldRecentsMenuItemTag = 1001;
|
CPSearchFieldRecentsMenuItemTag = 1001;
|
||||||
CPSearchFieldClearRecentsMenuItemTag = 1002;
|
CPSearchFieldClearRecentsMenuItemTag = 1002;
|
||||||
CPSearchFieldNoRecentsMenuItemTag = 1003;
|
CPSearchFieldNoRecentsMenuItemTag = 1003;
|
||||||
CPSearchFieldSeparatorMenuItemTag = 1004;
|
|
||||||
|
|
||||||
var CPSearchFieldSearchImage = nil,
|
var CPSearchFieldSearchImage = nil,
|
||||||
CPSearchFieldFindImage = nil,
|
CPSearchFieldFindImage = nil,
|
||||||
@@ -39,8 +37,9 @@ var SEARCH_BUTTON_DEFAULT_WIDTH = 25.0,
|
|||||||
CANCEL_BUTTON_DEFAULT_WIDTH = 22.0,
|
CANCEL_BUTTON_DEFAULT_WIDTH = 22.0,
|
||||||
BUTTON_DEFAULT_HEIGHT = 22.0;
|
BUTTON_DEFAULT_HEIGHT = 22.0;
|
||||||
|
|
||||||
var RECENT_SEARCH_PREFIX = @" ";
|
var CPAutosavedRecentsChangedNotification = @"CPAutosavedRecentsChangedNotification";
|
||||||
|
|
||||||
|
var RECENT_SEARCH_PREFIX = @" ";
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ingroup appkit
|
@ingroup appkit
|
||||||
@@ -182,7 +181,7 @@ var RECENT_SEARCH_PREFIX = @" ";
|
|||||||
[_cancelButton setFrame:[self cancelButtonRectForBounds:[self bounds]]];
|
[_cancelButton setFrame:[self cancelButtonRectForBounds:[self bounds]]];
|
||||||
[_cancelButton setAutoresizingMask:CPViewMinXMargin];
|
[_cancelButton setAutoresizingMask:CPViewMinXMargin];
|
||||||
[_cancelButton setTarget:self];
|
[_cancelButton setTarget:self];
|
||||||
[_cancelButton setAction:@selector(_searchFieldCancel:)];
|
[_cancelButton setAction:@selector(cancelOperation:)];
|
||||||
[self _updateCancelButtonVisibility];
|
[self _updateCancelButtonVisibility];
|
||||||
[self addSubview:_cancelButton];
|
[self addSubview:_cancelButton];
|
||||||
}
|
}
|
||||||
@@ -210,7 +209,7 @@ var RECENT_SEARCH_PREFIX = @" ";
|
|||||||
[button setAlternateImage:CPSearchFieldCancelPressedImage];
|
[button setAlternateImage:CPSearchFieldCancelPressedImage];
|
||||||
[button setAutoresizingMask:CPViewMinXMargin];
|
[button setAutoresizingMask:CPViewMinXMargin];
|
||||||
[button setTarget:self];
|
[button setTarget:self];
|
||||||
[button setAction:@selector(_searchFieldCancel:)];
|
[button setAction:@selector(cancelOperation:)];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Custom Layout
|
// Custom Layout
|
||||||
@@ -403,7 +402,7 @@ var RECENT_SEARCH_PREFIX = @" ";
|
|||||||
|
|
||||||
+ (double)_keyboardDelayForPartialSearchString:(CPString)string
|
+ (double)_keyboardDelayForPartialSearchString:(CPString)string
|
||||||
{
|
{
|
||||||
return (6 - MIN([string length],4))/10;
|
return (6 - MIN([string length], 4)) / 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (CPMenu)menu
|
- (CPMenu)menu
|
||||||
@@ -529,7 +528,7 @@ var RECENT_SEARCH_PREFIX = @" ";
|
|||||||
[item setTarget:self];
|
[item setTarget:self];
|
||||||
[template addItem:item];
|
[template addItem:item];
|
||||||
|
|
||||||
Be sure that your custom items do not use tags in the range 1000-1004 inclusive.
|
Be sure that your custom items do not use tags in the range 1000-1003 inclusive.
|
||||||
If you wish to maintain state in custom menu items that you add, you will need to maintain
|
If you wish to maintain state in custom menu items that you add, you will need to maintain
|
||||||
the item state yourself, then in the action method of the custom items, modify the items
|
the item state yourself, then in the action method of the custom items, modify the items
|
||||||
in the search menu template and send [searchField setSearchMenuTemplate:template] to update the menu.
|
in the search menu template and send [searchField setSearchMenuTemplate:template] to update the menu.
|
||||||
@@ -628,13 +627,7 @@ var RECENT_SEARCH_PREFIX = @" ";
|
|||||||
if ([menu numberOfItems] > 0)
|
if ([menu numberOfItems] > 0)
|
||||||
[self _addSeparatorToMenu:menu];
|
[self _addSeparatorToMenu:menu];
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case CPSearchFieldSeparatorMenuItemTag:
|
|
||||||
item = [CPMenuItem separatorItem];
|
|
||||||
[item setEnabled:NO];
|
|
||||||
[menu addItem:item];
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
[item setEnabled:([item isEnabled] && [item action] != nil && [item target] != nil)];
|
[item setEnabled:([item isEnabled] && [item action] != nil && [item target] != nil)];
|
||||||
[menu addItem:item];
|
[menu addItem:item];
|
||||||
@@ -684,7 +677,7 @@ var RECENT_SEARCH_PREFIX = @" ";
|
|||||||
[_partialStringTimer invalidate];
|
[_partialStringTimer invalidate];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)_searchFieldCancel:(id)sender
|
- (void)cancelOperation:(id)sender
|
||||||
{
|
{
|
||||||
[self setObjectValue:@""];
|
[self setObjectValue:@""];
|
||||||
[self _sendPartialString];
|
[self _sendPartialString];
|
||||||
@@ -715,54 +708,36 @@ var RECENT_SEARCH_PREFIX = @" ";
|
|||||||
|
|
||||||
- (void)_registerForAutosaveNotification
|
- (void)_registerForAutosaveNotification
|
||||||
{
|
{
|
||||||
[[CPNotificationCenter defaultCenter] addObserver:self selector:@selector(_updateAutosavedRecents:) name:@"CPAutosavedRecentsChangedNotification" object:nil];
|
[[CPNotificationCenter defaultCenter] addObserver:self selector:@selector(_updateAutosavedRecents:) name:CPAutosavedRecentsChangedNotification object:_recentsAutosaveName];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)_deregisterForAutosaveNotification
|
- (void)_deregisterForAutosaveNotification
|
||||||
{
|
{
|
||||||
[[CPNotificationCenter defaultCenter] removeObserver:self name:@"CPAutosavedRecentsChangedNotification" object:nil];
|
[[CPNotificationCenter defaultCenter] removeObserver:self name:CPAutosavedRecentsChangedNotification object:_recentsAutosaveName];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)_autosaveRecentSearchList
|
- (void)_autosaveRecentSearchList
|
||||||
{
|
{
|
||||||
if (_recentsAutosaveName != nil)
|
if (_recentsAutosaveName != nil)
|
||||||
[[CPNotificationCenter defaultCenter] postNotificationName:@"CPAutosavedRecentsChangedNotification" object:_recentsAutosaveName];
|
[[CPNotificationCenter defaultCenter] postNotificationName:CPAutosavedRecentsChangedNotification object:_recentsAutosaveName];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)_updateAutosavedRecents:(id)notification
|
- (void)_updateAutosavedRecents:(id)notification
|
||||||
{
|
{
|
||||||
var list = [self recentSearches],
|
var name = [notification object];
|
||||||
name = [notification object],
|
[[CPUserDefaults standardUserDefaults] setObject:_recentSearches forKey:name];
|
||||||
bundle_name = [[[CPBundle mainBundle] infoDictionary] objectForKey:"CPBundleName"],
|
|
||||||
cookie_name = [bundle_name lowercaseString] + "." + [notification object],
|
|
||||||
|
|
||||||
cookie = [[CPCookie alloc] initWithName:cookie_name],
|
|
||||||
cookie_value = [list componentsJoinedByString:@","];
|
|
||||||
|
|
||||||
[cookie setValue:cookie_value
|
|
||||||
expires:[[CPDate alloc] initWithTimeIntervalSinceNow:3600*24*365]
|
|
||||||
domain:(window.location.href.hostname)];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)_loadRecentSearchList
|
- (void)_loadRecentSearchList
|
||||||
{
|
{
|
||||||
var list,
|
var name = [self recentsAutosaveName];
|
||||||
name = [self recentsAutosaveName];
|
|
||||||
|
|
||||||
if (name === nil)
|
if (name === nil)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var bundle_name = [[[CPBundle mainBundle] infoDictionary] objectForKey:"CPBundleName"],
|
var list = [[CPUserDefaults standardUserDefaults] objectForKey:name];
|
||||||
cookie_name = [bundle_name lowercaseString] + "." + name,
|
|
||||||
|
|
||||||
cookie = [[CPCookie alloc] initWithName:cookie_name];
|
if (list !== nil)
|
||||||
|
|
||||||
if (cookie != nil)
|
|
||||||
{
|
|
||||||
var cookie_value = [cookie value];
|
|
||||||
list = (cookie_value != @"") ? [cookie_value componentsSeparatedByString:@","] : [CPArray array];
|
|
||||||
_recentSearches = list;
|
_recentSearches = list;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -802,7 +777,7 @@ var CPRecentsAutosaveNameKey = @"CPRecentsAutosaveNameKey",
|
|||||||
{
|
{
|
||||||
if (self = [super initWithCoder:coder])
|
if (self = [super initWithCoder:coder])
|
||||||
{
|
{
|
||||||
_recentsAutosaveName = [coder decodeObjectForKey:CPRecentsAutosaveNameKey];
|
[self setRecentsAutosaveName:[coder decodeObjectForKey:CPRecentsAutosaveNameKey]];
|
||||||
_sendsWholeSearchString = [coder decodeBoolForKey:CPSendsWholeSearchStringKey];
|
_sendsWholeSearchString = [coder decodeBoolForKey:CPSendsWholeSearchStringKey];
|
||||||
_sendsSearchStringImmediately = [coder decodeBoolForKey:CPSendsSearchStringImmediatelyKey];
|
_sendsSearchStringImmediately = [coder decodeBoolForKey:CPSendsSearchStringImmediatelyKey];
|
||||||
_maximumRecents = [coder decodeIntForKey:CPMaximumRecentsKey];
|
_maximumRecents = [coder decodeIntForKey:CPMaximumRecentsKey];
|
||||||
|
|||||||
@@ -94,7 +94,9 @@ CPSegmentSwitchTrackingMomentary = 2;
|
|||||||
if (_segments.length == aCount)
|
if (_segments.length == aCount)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var height = CGRectGetHeight([self bounds]);
|
var height = CGRectGetHeight([self bounds]),
|
||||||
|
dividersBefore = MAX(0, _segments.length - 1),
|
||||||
|
dividersAfter = MAX(0, aCount - 1);
|
||||||
|
|
||||||
if (_segments.length < aCount)
|
if (_segments.length < aCount)
|
||||||
{
|
{
|
||||||
@@ -113,6 +115,14 @@ CPSegmentSwitchTrackingMomentary = 2;
|
|||||||
if (_selectedSegment >= _segments.length)
|
if (_selectedSegment >= _segments.length)
|
||||||
_selectedSegment = -1;
|
_selectedSegment = -1;
|
||||||
|
|
||||||
|
// Make space for/remove space used by dividers.
|
||||||
|
var thickness = [self currentValueForThemeAttribute:@"divider-thickness"],
|
||||||
|
delta = thickness * (dividersAfter - dividersBefore),
|
||||||
|
frame = [self frame];
|
||||||
|
|
||||||
|
if (delta)
|
||||||
|
[self setFrameSize:CGSizeMake(frame.size.width + delta, frame.size.height)];
|
||||||
|
|
||||||
[self tileWithChangedSegment:0];
|
[self tileWithChangedSegment:0];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -607,7 +617,7 @@ CPSegmentSwitchTrackingMomentary = 2;
|
|||||||
segmentWidth = [segment width],
|
segmentWidth = [segment width],
|
||||||
themeState = _themeStates[aSegment] | (_themeState & CPThemeStateDisabled),
|
themeState = _themeStates[aSegment] | (_themeState & CPThemeStateDisabled),
|
||||||
contentInset = [self valueForThemeAttribute:@"content-inset" inState:themeState],
|
contentInset = [self valueForThemeAttribute:@"content-inset" inState:themeState],
|
||||||
font = [self valueForThemeAttribute:@"font" inState:themeState];
|
font = [self font];
|
||||||
|
|
||||||
if (!segmentWidth)
|
if (!segmentWidth)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -63,22 +63,22 @@
|
|||||||
return [super initWithPickerMask:mask colorPanel: owningColorPanel];
|
return [super initWithPickerMask:mask colorPanel: owningColorPanel];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(id)initView
|
- (id)initView
|
||||||
{
|
{
|
||||||
aFrame = CPRectMake(0, 0, CPColorPickerViewWidth, CPColorPickerViewHeight);
|
aFrame = CGRectMake(0, 0, CPColorPickerViewWidth, CPColorPickerViewHeight);
|
||||||
|
|
||||||
_contentView = [[CPView alloc] initWithFrame:aFrame];
|
_contentView = [[CPView alloc] initWithFrame:aFrame];
|
||||||
[_contentView setAutoresizingMask:CPViewWidthSizable|CPViewHeightSizable];
|
[_contentView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
|
||||||
|
|
||||||
_rgbLabel = [[CPTextField alloc] initWithFrame: CPRectMake(0, 10, 100, 20)];
|
_rgbLabel = [[CPTextField alloc] initWithFrame: CGRectMake(0, 10, 100, 20)];
|
||||||
[_rgbLabel setStringValue: "Red, Green, Blue"];
|
[_rgbLabel setStringValue: "Red, Green, Blue"];
|
||||||
[_rgbLabel setTextColor:[CPColor blackColor]];
|
[_rgbLabel setTextColor:[CPColor blackColor]];
|
||||||
|
|
||||||
_redLabel = [[CPTextField alloc] initWithFrame: CPRectMake(0, 35, 15, 20)];
|
_redLabel = [[CPTextField alloc] initWithFrame: CGRectMake(0, 35, 15, 20)];
|
||||||
[_redLabel setStringValue: "R"];
|
[_redLabel setStringValue: "R"];
|
||||||
[_redLabel setTextColor:[CPColor blackColor]];
|
[_redLabel setTextColor:[CPColor blackColor]];
|
||||||
|
|
||||||
_redSlider = [[CPSlider alloc] initWithFrame: CPRectMake(15, 35, aFrame.size.width - 70, 20)];
|
_redSlider = [[CPSlider alloc] initWithFrame: CGRectMake(15, 35, aFrame.size.width - 70, 20)];
|
||||||
[_redSlider setMaxValue: 1.0];
|
[_redSlider setMaxValue: 1.0];
|
||||||
[_redSlider setMinValue: 0.0];
|
[_redSlider setMinValue: 0.0];
|
||||||
[_redSlider setTarget: self];
|
[_redSlider setTarget: self];
|
||||||
@@ -93,11 +93,11 @@
|
|||||||
[_redValue setDelegate: self];
|
[_redValue setDelegate: self];
|
||||||
[_contentView addSubview: _redValue];
|
[_contentView addSubview: _redValue];
|
||||||
|
|
||||||
_greenLabel = [[CPTextField alloc] initWithFrame: CPRectMake(0, 58, 15, 20)];
|
_greenLabel = [[CPTextField alloc] initWithFrame: CGRectMake(0, 58, 15, 20)];
|
||||||
[_greenLabel setStringValue: "G"];
|
[_greenLabel setStringValue: "G"];
|
||||||
[_greenLabel setTextColor:[CPColor blackColor]];
|
[_greenLabel setTextColor:[CPColor blackColor]];
|
||||||
|
|
||||||
_greenSlider = [[CPSlider alloc] initWithFrame: CPRectMake(15, 58, aFrame.size.width - 70, 20)];
|
_greenSlider = [[CPSlider alloc] initWithFrame: CGRectMake(15, 58, aFrame.size.width - 70, 20)];
|
||||||
[_greenSlider setMaxValue: 1.0];
|
[_greenSlider setMaxValue: 1.0];
|
||||||
[_greenSlider setMinValue: 0.0];
|
[_greenSlider setMinValue: 0.0];
|
||||||
[_greenSlider setTarget: self];
|
[_greenSlider setTarget: self];
|
||||||
@@ -112,11 +112,11 @@
|
|||||||
[_greenValue setDelegate: self];
|
[_greenValue setDelegate: self];
|
||||||
[_contentView addSubview: _greenValue];
|
[_contentView addSubview: _greenValue];
|
||||||
|
|
||||||
_blueLabel = [[CPTextField alloc] initWithFrame: CPRectMake(0, 81, 15, 20)];
|
_blueLabel = [[CPTextField alloc] initWithFrame: CGRectMake(0, 81, 15, 20)];
|
||||||
[_blueLabel setStringValue: "B"];
|
[_blueLabel setStringValue: "B"];
|
||||||
[_blueLabel setTextColor:[CPColor blackColor]];
|
[_blueLabel setTextColor:[CPColor blackColor]];
|
||||||
|
|
||||||
_blueSlider = [[CPSlider alloc] initWithFrame: CPRectMake(15, 81, aFrame.size.width - 70, 20)];
|
_blueSlider = [[CPSlider alloc] initWithFrame: CGRectMake(15, 81, aFrame.size.width - 70, 20)];
|
||||||
[_blueSlider setMaxValue: 1.0];
|
[_blueSlider setMaxValue: 1.0];
|
||||||
[_blueSlider setMinValue: 0.0];
|
[_blueSlider setMinValue: 0.0];
|
||||||
[_blueSlider setTarget: self];
|
[_blueSlider setTarget: self];
|
||||||
@@ -131,15 +131,15 @@
|
|||||||
[_blueValue setDelegate: self];
|
[_blueValue setDelegate: self];
|
||||||
[_contentView addSubview: _blueValue];
|
[_contentView addSubview: _blueValue];
|
||||||
|
|
||||||
_hsbLabel = [[CPTextField alloc] initWithFrame: CPRectMake(0, 120, 190, 20)];
|
_hsbLabel = [[CPTextField alloc] initWithFrame: CGRectMake(0, 120, 190, 20)];
|
||||||
[_hsbLabel setStringValue: "Hue, Saturation, Brightness"];
|
[_hsbLabel setStringValue: "Hue, Saturation, Brightness"];
|
||||||
[_hsbLabel setTextColor:[CPColor blackColor]];
|
[_hsbLabel setTextColor:[CPColor blackColor]];
|
||||||
|
|
||||||
_hueLabel = [[CPTextField alloc] initWithFrame: CPRectMake(0, 145, 15, 20)];
|
_hueLabel = [[CPTextField alloc] initWithFrame: CGRectMake(0, 145, 15, 20)];
|
||||||
[_hueLabel setStringValue: "H"];
|
[_hueLabel setStringValue: "H"];
|
||||||
[_hueLabel setTextColor:[CPColor blackColor]];
|
[_hueLabel setTextColor:[CPColor blackColor]];
|
||||||
|
|
||||||
_hueSlider = [[CPSlider alloc] initWithFrame: CPRectMake(15, 145, aFrame.size.width - 70, 20)];
|
_hueSlider = [[CPSlider alloc] initWithFrame: CGRectMake(15, 145, aFrame.size.width - 70, 20)];
|
||||||
[_hueSlider setMaxValue: 359.0];
|
[_hueSlider setMaxValue: 359.0];
|
||||||
[_hueSlider setMinValue: 0.0];
|
[_hueSlider setMinValue: 0.0];
|
||||||
[_hueSlider setTarget: self];
|
[_hueSlider setTarget: self];
|
||||||
@@ -154,11 +154,11 @@
|
|||||||
[_hueValue setDelegate: self];
|
[_hueValue setDelegate: self];
|
||||||
[_contentView addSubview: _hueValue];
|
[_contentView addSubview: _hueValue];
|
||||||
|
|
||||||
_saturationLabel = [[CPTextField alloc] initWithFrame: CPRectMake(0, 168, 15, 20)];
|
_saturationLabel = [[CPTextField alloc] initWithFrame: CGRectMake(0, 168, 15, 20)];
|
||||||
[_saturationLabel setStringValue: "S"];
|
[_saturationLabel setStringValue: "S"];
|
||||||
[_saturationLabel setTextColor:[CPColor blackColor]];
|
[_saturationLabel setTextColor:[CPColor blackColor]];
|
||||||
|
|
||||||
_saturationSlider = [[CPSlider alloc] initWithFrame: CPRectMake(15, 168, aFrame.size.width - 70, 20)];
|
_saturationSlider = [[CPSlider alloc] initWithFrame: CGRectMake(15, 168, aFrame.size.width - 70, 20)];
|
||||||
[_saturationSlider setMaxValue: 100.0];
|
[_saturationSlider setMaxValue: 100.0];
|
||||||
[_saturationSlider setMinValue: 0.0];
|
[_saturationSlider setMinValue: 0.0];
|
||||||
[_saturationSlider setTarget: self];
|
[_saturationSlider setTarget: self];
|
||||||
@@ -173,11 +173,11 @@
|
|||||||
[_saturationValue setDelegate: self];
|
[_saturationValue setDelegate: self];
|
||||||
[_contentView addSubview: _saturationValue];
|
[_contentView addSubview: _saturationValue];
|
||||||
|
|
||||||
_brightnessLabel = [[CPTextField alloc] initWithFrame: CPRectMake(0, 191, 15, 20)];
|
_brightnessLabel = [[CPTextField alloc] initWithFrame: CGRectMake(0, 191, 15, 20)];
|
||||||
[_brightnessLabel setStringValue: "B"];
|
[_brightnessLabel setStringValue: "B"];
|
||||||
[_brightnessLabel setTextColor:[CPColor blackColor]];
|
[_brightnessLabel setTextColor:[CPColor blackColor]];
|
||||||
|
|
||||||
_brightnessSlider = [[CPSlider alloc] initWithFrame: CPRectMake(15, 191, aFrame.size.width - 70, 20)];
|
_brightnessSlider = [[CPSlider alloc] initWithFrame: CGRectMake(15, 191, aFrame.size.width - 70, 20)];
|
||||||
[_brightnessSlider setMaxValue: 100.0];
|
[_brightnessSlider setMaxValue: 100.0];
|
||||||
[_brightnessSlider setMinValue: 0.0];
|
[_brightnessSlider setMinValue: 0.0];
|
||||||
[_brightnessSlider setTarget: self];
|
[_brightnessSlider setTarget: self];
|
||||||
@@ -192,7 +192,7 @@
|
|||||||
[_brightnessValue setDelegate: self];
|
[_brightnessValue setDelegate: self];
|
||||||
[_contentView addSubview: _brightnessValue];
|
[_contentView addSubview: _brightnessValue];
|
||||||
|
|
||||||
_hexLabel = [[CPTextField alloc] initWithFrame: CPRectMake(0, 230, 30, 20)];
|
_hexLabel = [[CPTextField alloc] initWithFrame: CGRectMake(0, 230, 30, 20)];
|
||||||
[_hexLabel setStringValue: "Hex"];
|
[_hexLabel setStringValue: "Hex"];
|
||||||
[_hexLabel setTextColor:[CPColor blackColor]];
|
[_hexLabel setTextColor:[CPColor blackColor]];
|
||||||
|
|
||||||
@@ -240,13 +240,13 @@
|
|||||||
return (mode == CPSliderColorPickerMode) ? YES : NO;
|
return (mode == CPSliderColorPickerMode) ? YES : NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)sliderChanged:(id)sender
|
- (void)sliderChanged:(id)sender
|
||||||
{
|
{
|
||||||
var newColor,
|
var newColor,
|
||||||
colorPanel = [self colorPanel],
|
colorPanel = [self colorPanel],
|
||||||
alpha = [colorPanel opacity];
|
alpha = [colorPanel opacity];
|
||||||
|
|
||||||
switch(sender)
|
switch (sender)
|
||||||
{
|
{
|
||||||
case _hueSlider:
|
case _hueSlider:
|
||||||
case _saturationSlider:
|
case _saturationSlider:
|
||||||
@@ -274,7 +274,7 @@
|
|||||||
[colorPanel setColor: newColor];
|
[colorPanel setColor: newColor];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)setColor:(CPColor)aColor
|
- (void)setColor:(CPColor)aColor
|
||||||
{
|
{
|
||||||
[self updateRGBSliders: aColor];
|
[self updateRGBSliders: aColor];
|
||||||
[self updateHSBSliders: aColor];
|
[self updateHSBSliders: aColor];
|
||||||
@@ -282,7 +282,7 @@
|
|||||||
[self updateLabels];
|
[self updateLabels];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)updateHSBSliders:(CPColor)aColor
|
- (void)updateHSBSliders:(CPColor)aColor
|
||||||
{
|
{
|
||||||
var hsb = [aColor hsbComponents];
|
var hsb = [aColor hsbComponents];
|
||||||
|
|
||||||
@@ -330,14 +330,21 @@
|
|||||||
{
|
{
|
||||||
var field = [aNotification object],
|
var field = [aNotification object],
|
||||||
value = [[field stringValue] stringByTrimmingWhitespace];
|
value = [[field stringValue] stringByTrimmingWhitespace];
|
||||||
if (field === _hexValue) {
|
|
||||||
|
if (field === _hexValue)
|
||||||
|
{
|
||||||
var newColor = [CPColor colorWithHexString: value];
|
var newColor = [CPColor colorWithHexString: value];
|
||||||
if (newColor) {
|
|
||||||
|
if (newColor)
|
||||||
|
{
|
||||||
[self setColor: newColor];
|
[self setColor: newColor];
|
||||||
[[self colorPanel] setColor: newColor];
|
[[self colorPanel] setColor: newColor];
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
switch(field) {
|
else
|
||||||
|
{
|
||||||
|
switch (field)
|
||||||
|
{
|
||||||
case _redValue: [_redSlider setFloatValue:MAX(MIN(ROUND(value), 255) / 255.0, 0)];
|
case _redValue: [_redSlider setFloatValue:MAX(MIN(ROUND(value), 255) / 255.0, 0)];
|
||||||
[self sliderChanged: _redSlider];
|
[self sliderChanged: _redSlider];
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -0,0 +1,268 @@
|
|||||||
|
/*
|
||||||
|
* CPSound.j
|
||||||
|
* AppKit
|
||||||
|
*
|
||||||
|
* Created by Antoine Mercadal
|
||||||
|
* Copyright 2010, Antoine Mercadal
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
@import <Foundation/CPObject.j>
|
||||||
|
|
||||||
|
CPSoundLoadStateEmpty = 0;
|
||||||
|
CPSoundLoadStateLoading = 1;
|
||||||
|
CPSoundLoadStateCanBePlayed = 2;
|
||||||
|
|
||||||
|
CPSoundPlayBackStatePlay = 0;
|
||||||
|
CPSoundPlayBackStateStop = 1;
|
||||||
|
CPSoundPlayBackStatePause = 2;
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
CPSound provides a way to load and play sounds. In the browser it relies on the
|
||||||
|
HTML5 audio tag being available.
|
||||||
|
|
||||||
|
CPSound delegate:
|
||||||
|
- sound:didFinishPlaying: called when sound has finished to played
|
||||||
|
|
||||||
|
*/
|
||||||
|
@implementation CPSound : CPObject
|
||||||
|
{
|
||||||
|
CPString _name @accessors(property=name);
|
||||||
|
id _delegate @accessors(property=delegate);
|
||||||
|
|
||||||
|
HTMLAudioElement _audioTag;
|
||||||
|
int _loadStatus;
|
||||||
|
int _playBackStatus;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark -
|
||||||
|
#pragma mark Initialization
|
||||||
|
|
||||||
|
- (id)init
|
||||||
|
{
|
||||||
|
if (self = [super init])
|
||||||
|
{
|
||||||
|
_loadStatus = CPSoundLoadStateEmpty;
|
||||||
|
_loops = NO;
|
||||||
|
_audioTag = document.createElement("audio");
|
||||||
|
_audioTag.preload = YES;
|
||||||
|
_audioTag.addEventListener("canplay", function()
|
||||||
|
{
|
||||||
|
[self _soundDidload];
|
||||||
|
});
|
||||||
|
_audioTag.addEventListener("ended", function()
|
||||||
|
{
|
||||||
|
[self _soundDidEnd];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Initialize with the sound contents of the URL represented by aFile.
|
||||||
|
|
||||||
|
@param aFile CPString the path of the sound
|
||||||
|
@param byRef ignored (Cocoa compatibibility)
|
||||||
|
*/
|
||||||
|
- (id)initWithContentsOfFile:(CPString)aFile byReference:(BOOL)byRef
|
||||||
|
{
|
||||||
|
if (self = [self init])
|
||||||
|
{
|
||||||
|
_loadStatus = CPSoundLoadStateLoading;
|
||||||
|
_audioTag.src = aFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Initialize with the sound contents of the file located at aURL.
|
||||||
|
|
||||||
|
@param aURL CPURL containing the URL of the sound
|
||||||
|
@param byRef ignored (Cocoa compatibibility)
|
||||||
|
*/
|
||||||
|
- (id)initWithContentsOfURL:(CPURL)aURL byReference:(BOOL)byRef
|
||||||
|
{
|
||||||
|
return [self initWithContentsOfFile:[aURL absoluteString] byReference:NO];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Initialize with the sound contents of someData.
|
||||||
|
|
||||||
|
@param someData CPData containing the sound
|
||||||
|
@param byRef ignored (Cocoa compatibibility)
|
||||||
|
*/
|
||||||
|
- (id)initWithData:(CPData)someData
|
||||||
|
{
|
||||||
|
if (self = [self init])
|
||||||
|
{
|
||||||
|
_loadStatus = CPSoundLoadStateLoading;
|
||||||
|
_audioTag.src = [someData rawString];
|
||||||
|
}
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#pragma mark -
|
||||||
|
#pragma mark Events listener
|
||||||
|
|
||||||
|
/*! @ignore
|
||||||
|
*/
|
||||||
|
- (void)_soundDidload
|
||||||
|
{
|
||||||
|
_loadStatus = CPSoundLoadStateCanBePlayed;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @ignore
|
||||||
|
*/
|
||||||
|
- (void)_soundDidEnd
|
||||||
|
{
|
||||||
|
if (![self loops])
|
||||||
|
[self stop];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#pragma mark -
|
||||||
|
#pragma mark Media controls
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Play the sound.
|
||||||
|
*/
|
||||||
|
- (void)play
|
||||||
|
{
|
||||||
|
if ((_loadStatus !== CPSoundLoadStateCanBePlayed)
|
||||||
|
|| (_playBackStatus === CPSoundPlayBackStatePlay))
|
||||||
|
return;
|
||||||
|
|
||||||
|
_audioTag.play();
|
||||||
|
_playBackStatus = CPSoundPlayBackStatePlay;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Stop the sound.
|
||||||
|
*/
|
||||||
|
- (void)stop
|
||||||
|
{
|
||||||
|
if ((_loadStatus !== CPSoundLoadStateCanBePlayed)
|
||||||
|
|| (_playBackStatus === CPSoundPlayBackStateStop))
|
||||||
|
return;
|
||||||
|
|
||||||
|
_audioTag.pause();
|
||||||
|
_audioTag.currentTime = 0.0;
|
||||||
|
_playBackStatus = CPSoundPlayBackStateStop;
|
||||||
|
|
||||||
|
if (_delegate && [_delegate respondsToSelector:@selector(sound:didFinishPlaying:)])
|
||||||
|
[_delegate sound:self didFinishPlaying:YES];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Pause the sound.
|
||||||
|
*/
|
||||||
|
- (void)pause
|
||||||
|
{
|
||||||
|
if ((_loadStatus !== CPSoundLoadStateCanBePlayed)
|
||||||
|
|| (_playBackStatus === CPSoundPlayBackStatePause))
|
||||||
|
return;
|
||||||
|
|
||||||
|
_audioTag.pause();
|
||||||
|
_playBackStatus = CPSoundPlayBackStatePause;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Resume playback of a paused sound.
|
||||||
|
*/
|
||||||
|
- (void)resume
|
||||||
|
{
|
||||||
|
if ((_loadStatus !== CPSoundLoadStateCanBePlayed)
|
||||||
|
|| (_playBackStatus !== CPSoundPlayBackStatePause))
|
||||||
|
return;
|
||||||
|
|
||||||
|
_audioTag.play();
|
||||||
|
_playBackStatus = CPSoundPlayBackStatePlay;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Return YES if the sound is in loop mode.
|
||||||
|
|
||||||
|
@return BOOL YES if in loop mode, NO otherwise
|
||||||
|
*/
|
||||||
|
- (BOOL)loops
|
||||||
|
{
|
||||||
|
return _audioTag.loop;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Specifies whether the sound should repeat.
|
||||||
|
|
||||||
|
@param BOOL YES for loop mode, NO otherwise
|
||||||
|
*/
|
||||||
|
- (void)setLoops:(BOOL)shouldLoop
|
||||||
|
{
|
||||||
|
_audioTag.loop = shouldLoop;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns the volume of the receiver.
|
||||||
|
|
||||||
|
@return double from 0.0 to 1.0
|
||||||
|
*/
|
||||||
|
- (double)volume
|
||||||
|
{
|
||||||
|
return _audioTag.volume;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Set the volume the sound should be played at.
|
||||||
|
|
||||||
|
@param double a volume value between 0.0 and 1.0
|
||||||
|
*/
|
||||||
|
- (void)setVolume:(double)aVolume
|
||||||
|
{
|
||||||
|
if (aVolume > 1.0)
|
||||||
|
aVolume = 1.0;
|
||||||
|
else if (aVolume < 0.0)
|
||||||
|
aVolume = 0.0;
|
||||||
|
|
||||||
|
_audioTag.volume = aVolume;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark -
|
||||||
|
#pragma mark Accessors
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns the duration in seconds of the sound.
|
||||||
|
|
||||||
|
@return double the duration
|
||||||
|
*/
|
||||||
|
- (double)duration
|
||||||
|
{
|
||||||
|
return _audioTag.duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns if the sound is playing or not.
|
||||||
|
|
||||||
|
@return BOOL YES if the sound is playing, NO otherwise
|
||||||
|
*/
|
||||||
|
- (BOOL)isPlaying
|
||||||
|
{
|
||||||
|
return (_playBackStatus === CPSoundPlayBackStatePlay);
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
@@ -621,17 +621,20 @@ var CPSplitViewHorizontalImage = nil,
|
|||||||
viewFrame = CGRectMakeCopy(bounds),
|
viewFrame = CGRectMakeCopy(bounds),
|
||||||
isSizable = isVertical ? [view autoresizingMask] & CPViewWidthSizable : [view autoresizingMask] & CPViewHeightSizable;
|
isSizable = isVertical ? [view autoresizingMask] & CPViewWidthSizable : [view autoresizingMask] & CPViewHeightSizable;
|
||||||
|
|
||||||
if (index + 1 == count)
|
if (index + 1 === count)
|
||||||
viewFrame.size[_sizeComponent] = bounds.size[_sizeComponent] - viewFrame.origin[_originComponent];
|
viewFrame.size[_sizeComponent] = bounds.size[_sizeComponent] - viewFrame.origin[_originComponent];
|
||||||
else if (totalSizableSpace && isSizable && lastSizableIndex === index)
|
|
||||||
viewFrame.size[_sizeComponent] = MAX(0, ROUND([view frame].size[_sizeComponent] + remainingFlexibleSpace))
|
else if (totalSizableSpace && isSizable && lastSizableIndex === index)
|
||||||
else if (isSizable || !totalSizableSpace)
|
viewFrame.size[_sizeComponent] = MAX(0, ROUND([view frame].size[_sizeComponent] + remainingFlexibleSpace))
|
||||||
{
|
|
||||||
viewFrame.size[_sizeComponent] = MAX(0, ROUND(ratio * [view frame].size[_sizeComponent]));
|
else if (isSizable || !totalSizableSpace)
|
||||||
remainingFlexibleSpace -= (viewFrame.size[_sizeComponent] - [view frame].size[_sizeComponent]);
|
{
|
||||||
}
|
viewFrame.size[_sizeComponent] = MAX(0, ROUND(ratio * [view frame].size[_sizeComponent]));
|
||||||
else if (totalSizableSpace && !isSizable)
|
remainingFlexibleSpace -= (viewFrame.size[_sizeComponent] - [view frame].size[_sizeComponent]);
|
||||||
viewFrame.size[_sizeComponent] = [view frame].size[_sizeComponent];
|
}
|
||||||
|
|
||||||
|
else if (totalSizableSpace && !isSizable)
|
||||||
|
viewFrame.size[_sizeComponent] = [view frame].size[_sizeComponent];
|
||||||
|
|
||||||
bounds.origin[_originComponent] += viewFrame.size[_sizeComponent] + dividerThickness;
|
bounds.origin[_originComponent] += viewFrame.size[_sizeComponent] + dividerThickness;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,344 @@
|
|||||||
|
/*
|
||||||
|
* CPStepper.j
|
||||||
|
* AppKit
|
||||||
|
*
|
||||||
|
* Created by Antoine Mercadal
|
||||||
|
* Copyright 2009, Antoine Mercadal
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
@import <AppKit/CPControl.j>
|
||||||
|
@import <AppKit/CPButton.j>
|
||||||
|
@import <AppKit/CPTextField.j>
|
||||||
|
|
||||||
|
|
||||||
|
var CPStepperButtonsSize = CPSizeMake(19, 13);
|
||||||
|
|
||||||
|
/*! CPStepper is an implementation of Cocoa NSStepper.
|
||||||
|
|
||||||
|
This control display a two part button that can be used to increase or decrease a value with a given interval.
|
||||||
|
*/
|
||||||
|
@implementation CPStepper: CPControl
|
||||||
|
{
|
||||||
|
BOOL _valueWraps @accessors(property=valueWraps);
|
||||||
|
int _increment @accessors(property=increment);
|
||||||
|
int _maxValue @accessors(property=maxValue);
|
||||||
|
int _minValue @accessors(property=minValue);
|
||||||
|
|
||||||
|
_CPContinuousButton _buttonDown;
|
||||||
|
_CPContinuousButton _buttonUp;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark -
|
||||||
|
#pragma mark Initialization
|
||||||
|
|
||||||
|
/*! Initializes a CPStepper with given values
|
||||||
|
@param aValue the initial value of the CPStepper
|
||||||
|
@param minValue the minimal acceptable value of the stepper
|
||||||
|
@param maxValue the maximal acceptable value of the stepper
|
||||||
|
@return Initialized CPStepper
|
||||||
|
*/
|
||||||
|
+ (CPStepper)stepperWithInitialValue:(float)aValue minValue:(float)aMinValue maxValue:(float)aMaxValue
|
||||||
|
{
|
||||||
|
var stepper = [[CPStepper alloc] initWithFrame:CPRectMake(0, 0, 19, 25)];
|
||||||
|
[stepper setDoubleValue:aValue];
|
||||||
|
[stepper setMinValue:aMinValue];
|
||||||
|
[stepper setMaxValue:aMaxValue];
|
||||||
|
|
||||||
|
return stepper;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! Initializes a CPStepper with default values:
|
||||||
|
- minValue = 0.0
|
||||||
|
- maxValue = 59.0
|
||||||
|
- value = 0.0
|
||||||
|
@return Initialized CPStepper
|
||||||
|
*/
|
||||||
|
+ (CPStepper)stepper
|
||||||
|
{
|
||||||
|
return [CPStepper stepperWithInitialValue:0.0 minValue:0.0 maxValue:59.0];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! Initializes the CPStepper
|
||||||
|
@param aFrame the frame of the control
|
||||||
|
@return initialized CPStepper
|
||||||
|
*/
|
||||||
|
- (id)initWithFrame:(CGRect)aFrame
|
||||||
|
{
|
||||||
|
if (self = [super initWithFrame:aFrame])
|
||||||
|
{
|
||||||
|
_maxValue = 59.0;
|
||||||
|
_minValue = 0.0;
|
||||||
|
_increment = 1.0;
|
||||||
|
_valueWraps = YES;
|
||||||
|
|
||||||
|
[self setDoubleValue:0.0];
|
||||||
|
|
||||||
|
_buttonUp = [[_CPContinuousButton alloc] initWithFrame:CPRectMake(aFrame.size.width - CPStepperButtonsSize.width, 0, CPStepperButtonsSize.width, CPStepperButtonsSize.height)];
|
||||||
|
[_buttonUp setContinuous:YES];
|
||||||
|
[_buttonUp setTarget:self];
|
||||||
|
[_buttonUp setAction:@selector(_buttonDidClick:)];
|
||||||
|
[_buttonUp setAutoresizingMask:CPViewNotSizable];
|
||||||
|
[self addSubview:_buttonUp];
|
||||||
|
|
||||||
|
_buttonDown = [[_CPContinuousButton alloc] initWithFrame:CPRectMake(aFrame.size.width - CPStepperButtonsSize.width, CPStepperButtonsSize.height, CPStepperButtonsSize.width, CPStepperButtonsSize.height - 1)];
|
||||||
|
[_buttonDown setContinuous:YES];
|
||||||
|
[_buttonDown setTarget:self];
|
||||||
|
[_buttonDown setAction:@selector(_buttonDidClick:)];
|
||||||
|
[_buttonDown setAutoresizingMask:CPViewNotSizable];
|
||||||
|
[self addSubview:_buttonDown];
|
||||||
|
|
||||||
|
[self setNeedsLayout];
|
||||||
|
}
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark -
|
||||||
|
#pragma mark Superclass overrides
|
||||||
|
|
||||||
|
/*! set if the CPStepper is enabled or not
|
||||||
|
@param shouldEnabled BOOL that define if stepper is enabled or not.
|
||||||
|
*/
|
||||||
|
- (void)setEnabled:(BOOL)shouldEnabled
|
||||||
|
{
|
||||||
|
[super setEnabled:shouldEnabled];
|
||||||
|
|
||||||
|
[_buttonUp setEnabled:shouldEnabled];
|
||||||
|
[_buttonDown setEnabled:shouldEnabled];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! set the frame of the CPStepper and check if width is not smaller than theme min-size
|
||||||
|
@param aFrame the frame
|
||||||
|
*/
|
||||||
|
- (void)setFrame:(CGRect)aFrame
|
||||||
|
{
|
||||||
|
if (aFrame.size.width >= CGRectGetWidth(aFrame))
|
||||||
|
[super setFrame:aFrame];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @ignore
|
||||||
|
*/
|
||||||
|
- (void)layoutSubviews
|
||||||
|
{
|
||||||
|
[_buttonUp setValue:[self valueForThemeAttribute:@"bezel-color-up-button" inState:CPThemeStateBordered] forThemeAttribute:@"bezel-color" inState:CPThemeStateBordered];
|
||||||
|
[_buttonUp setValue:[self valueForThemeAttribute:@"bezel-color-up-button" inState:CPThemeStateBordered | CPThemeStateDisabled] forThemeAttribute:@"bezel-color" inState:CPThemeStateBordered | CPThemeStateDisabled];
|
||||||
|
[_buttonUp setValue:[self valueForThemeAttribute:@"bezel-color-up-button" inState:CPThemeStateBordered | CPThemeStateHighlighted] forThemeAttribute:@"bezel-color" inState:CPThemeStateBordered | CPThemeStateHighlighted];
|
||||||
|
[_buttonDown setValue:[self valueForThemeAttribute:@"bezel-color-down-button" inState:CPThemeStateBordered] forThemeAttribute:@"bezel-color" inState:CPThemeStateBordered];
|
||||||
|
[_buttonDown setValue:[self valueForThemeAttribute:@"bezel-color-down-button" inState:CPThemeStateBordered | CPThemeStateDisabled] forThemeAttribute:@"bezel-color" inState:CPThemeStateBordered | CPThemeStateDisabled];
|
||||||
|
[_buttonDown setValue:[self valueForThemeAttribute:@"bezel-color-down-button" inState:CPThemeStateBordered | CPThemeStateHighlighted] forThemeAttribute:@"bezel-color" inState:CPThemeStateBordered | CPThemeStateHighlighted];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! set if CPStepper should autorepeat
|
||||||
|
@param shouldAutoRepeat if YES, the first mouse down does one increment (decrement) and, after each delay of 0.5 seconds
|
||||||
|
*/
|
||||||
|
- (void)setAutorepeat:(BOOL)shouldAutoRepeat
|
||||||
|
{
|
||||||
|
[_buttonUp setContinuous:shouldAutoRepeat];
|
||||||
|
[_buttonDown setContinuous:shouldAutoRepeat];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! set the current value of the stepper
|
||||||
|
@param aValue a float contaning the value
|
||||||
|
*/
|
||||||
|
- (void)setDoubleValue:(float)aValue
|
||||||
|
{
|
||||||
|
if (aValue > _maxValue)
|
||||||
|
[super setDoubleValue:_valueWraps ? _minValue : _maxValue];
|
||||||
|
else if (aValue < _minValue)
|
||||||
|
[super setDoubleValue:_valueWraps ? _maxValue : _minValue];
|
||||||
|
else
|
||||||
|
[super setDoubleValue:aValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark -
|
||||||
|
#pragma mark Actions
|
||||||
|
|
||||||
|
/*! @ignore
|
||||||
|
*/
|
||||||
|
- (IBAction)_buttonDidClick:(id)aSender
|
||||||
|
{
|
||||||
|
if (![self isEnabled])
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (aSender == _buttonUp)
|
||||||
|
[self setDoubleValue:([self doubleValue] + _increment)];
|
||||||
|
else
|
||||||
|
[self setDoubleValue:([self doubleValue] - _increment)];
|
||||||
|
|
||||||
|
if (_target && _action && [_target respondsToSelector:_action])
|
||||||
|
[self sendAction:_action to:_target];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @perform a programatic click on up button
|
||||||
|
@param aSender sender of the action
|
||||||
|
*/
|
||||||
|
- (IBAction)performClickUp:(id)aSender
|
||||||
|
{
|
||||||
|
[_buttonUp performClick:aSender];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! @perform a programatic click on down button
|
||||||
|
@param aSender sender of the action
|
||||||
|
*/
|
||||||
|
- (IBAction)performClickDown:(id)aSender
|
||||||
|
{
|
||||||
|
[_buttonDown performClick:aSender];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#pragma mark -
|
||||||
|
#pragma mark Theming
|
||||||
|
|
||||||
|
+ (CPString)defaultThemeClass
|
||||||
|
{
|
||||||
|
return @"stepper";
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (id)themeAttributes
|
||||||
|
{
|
||||||
|
return [CPDictionary dictionaryWithObjects:[[CPNull null], [CPNull null]]
|
||||||
|
forKeys:[@"bezel-color-up-button", @"bezel-color-down-button"]];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@implementation CPStepper (CPCodingCompliance)
|
||||||
|
|
||||||
|
- (id)initWithCoder:(CPCoder)aCoder
|
||||||
|
{
|
||||||
|
if (self = [super initWithCoder:aCoder])
|
||||||
|
{
|
||||||
|
_maxValue = [aCoder decodeObjectForKey:@"_maxValue"];
|
||||||
|
_minValue = [aCoder decodeObjectForKey:@"_minValue"];
|
||||||
|
_increment = [aCoder decodeObjectForKey:@"_increment"];
|
||||||
|
_buttonUp = [aCoder decodeObjectForKey:@"_buttonUp"];
|
||||||
|
_buttonDown = [aCoder decodeObjectForKey:@"_buttonDown"];
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)encodeWithCoder:(CPCoder)aCoder
|
||||||
|
{
|
||||||
|
[super encodeWithCoder:aCoder];
|
||||||
|
|
||||||
|
[aCoder encodeObject:_maxValue forKey:@"_maxValue"];
|
||||||
|
[aCoder encodeObject:_minValue forKey:@"_minValue"];
|
||||||
|
[aCoder encodeObject:_increment forKey:@"_increment"];
|
||||||
|
[aCoder encodeObject:_buttonUp forKey:@"_buttonUp"];
|
||||||
|
[aCoder encodeObject:_buttonDown forKey:@"_buttonDown"];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
/*! This is a subclass of CPButton that allows to send continuous action.
|
||||||
|
This may should be include in CPButton..
|
||||||
|
*/
|
||||||
|
@implementation _CPContinuousButton : CPButton
|
||||||
|
{
|
||||||
|
CPTimer _continuousDelayTimer;
|
||||||
|
CPTimer _continuousTimer;
|
||||||
|
float _periodicDelay;
|
||||||
|
float _periodicInterval;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)initWithFrame:(CGRect)aFrame
|
||||||
|
{
|
||||||
|
if (self = [super initWithFrame:aFrame])
|
||||||
|
{
|
||||||
|
_periodicInterval = 0.05;
|
||||||
|
_periodicDelay = 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setPeriodicDelay:(float)aDelay interval:(float)anInterval
|
||||||
|
{
|
||||||
|
_periodicDelay = aDelay;
|
||||||
|
_periodicInterval = anInterval;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)mouseDown:(CPEvent)anEvent
|
||||||
|
{
|
||||||
|
if ([self isContinuous])
|
||||||
|
{
|
||||||
|
_continuousDelayTimer = [CPTimer scheduledTimerWithTimeInterval:_periodicDelay callback: function()
|
||||||
|
{
|
||||||
|
if (!_continuousTimer)
|
||||||
|
_continuousTimer = [CPTimer scheduledTimerWithTimeInterval:_periodicInterval target:self selector:@selector(onContinousEvent:) userInfo:anEvent repeats:YES];
|
||||||
|
}
|
||||||
|
|
||||||
|
repeats:NO];
|
||||||
|
}
|
||||||
|
|
||||||
|
[super mouseDown:anEvent];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)onContinousEvent:(CPTimer)aTimer
|
||||||
|
{
|
||||||
|
if (_target && _action && [_target respondsToSelector:_action])
|
||||||
|
[_target performSelector:_action withObject:self];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)stopTracking:(CGPoint)lastPoint at:(CGPoint)aPoint mouseIsUp:(BOOL)mouseIsUp
|
||||||
|
{
|
||||||
|
[self invalidateTimers];
|
||||||
|
[super stopTracking:lastPoint at:aPoint mouseIsUp:mouseIsUp];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)invalidateTimers
|
||||||
|
{
|
||||||
|
if (_continuousTimer)
|
||||||
|
{
|
||||||
|
[_continuousTimer invalidate];
|
||||||
|
_continuousTimer = nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_continuousDelayTimer)
|
||||||
|
{
|
||||||
|
[_continuousDelayTimer invalidate];
|
||||||
|
_continuousDelayTimer = nil;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@implementation _CPContinuousButton (CPCodingCompliance)
|
||||||
|
|
||||||
|
- (id)initWithCoder:(CPCoder)aCoder
|
||||||
|
{
|
||||||
|
if (self = [super initWithCoder:aCoder])
|
||||||
|
{
|
||||||
|
_periodicDelay = [aCoder decodeObjectForKey:@"_periodicDelay"];
|
||||||
|
_periodicInterval = [aCoder decodeObjectForKey:@"_periodicInterval"];
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)encodeWithCoder:(CPCoder)aCoder
|
||||||
|
{
|
||||||
|
[super encodeWithCoder:aCoder];
|
||||||
|
|
||||||
|
[self invalidateTimers];
|
||||||
|
[aCoder encodeObject:_periodicDelay forKey:@"_periodicDelay"];
|
||||||
|
[aCoder encodeObject:_periodicInterval forKey:@"_periodicInterval"];
|
||||||
|
}
|
||||||
|
@end
|
||||||
@@ -3,83 +3,66 @@
|
|||||||
@import "CPTabViewItem.j"
|
@import "CPTabViewItem.j"
|
||||||
@import "CPView.j"
|
@import "CPView.j"
|
||||||
|
|
||||||
/*
|
|
||||||
Places tabs on top with a bezeled border.
|
|
||||||
@global
|
|
||||||
@group CPTabViewType
|
|
||||||
*/
|
|
||||||
CPTopTabsBezelBorder = 0;
|
CPTopTabsBezelBorder = 0;
|
||||||
//CPLeftTabsBezelBorder = 1;
|
//CPLeftTabsBezelBorder = 1;
|
||||||
CPBottomTabsBezelBorder = 2;
|
CPBottomTabsBezelBorder = 2;
|
||||||
//CPRightTabsBezelBorder = 3;
|
//CPRightTabsBezelBorder = 3;
|
||||||
/*
|
CPNoTabsBezelBorder = 4; //Displays no tabs and has a bezeled border.
|
||||||
Displays no tabs and has a bezeled border.
|
CPNoTabsLineBorder = 5; //Has no tabs and displays a line border.
|
||||||
@global
|
CPNoTabsNoBorder = 6; //Displays no tabs and no border.
|
||||||
@group CPTabViewType
|
|
||||||
*/
|
|
||||||
CPNoTabsBezelBorder = 4;
|
|
||||||
/*
|
|
||||||
Has no tabs and displays a line border.
|
|
||||||
@global
|
|
||||||
@group CPTabViewType
|
|
||||||
*/
|
|
||||||
CPNoTabsLineBorder = 5;
|
|
||||||
/*
|
|
||||||
Displays no tabs and no border.
|
|
||||||
@global
|
|
||||||
@group CPTabViewType
|
|
||||||
*/
|
|
||||||
CPNoTabsNoBorder = 6;
|
|
||||||
|
|
||||||
var CPTabViewDidSelectTabViewItemSelector = 1,
|
var CPTabViewDidSelectTabViewItemSelector = 1,
|
||||||
CPTabViewShouldSelectTabViewItemSelector = 2,
|
CPTabViewShouldSelectTabViewItemSelector = 2,
|
||||||
CPTabViewWillSelectTabViewItemSelector = 4,
|
CPTabViewWillSelectTabViewItemSelector = 4,
|
||||||
CPTabViewDidChangeNumberOfTabViewItemsSelector = 8;
|
CPTabViewDidChangeNumberOfTabViewItemsSelector = 8;
|
||||||
|
|
||||||
var HEIGHT_OF_SEGMENTED_CONTROL = 24;
|
|
||||||
|
|
||||||
@implementation CPTabView : CPView
|
@implementation CPTabView : CPView
|
||||||
{
|
{
|
||||||
CPArray items;
|
CPArray _items;
|
||||||
|
|
||||||
CPSegmentedControl tabs;
|
CPSegmentedControl _tabs;
|
||||||
CPBox box;
|
CPBox _box;
|
||||||
|
|
||||||
CPNumber selectedIndex;
|
CPNumber _selectedIndex;
|
||||||
|
|
||||||
CPTabViewType type;
|
CPTabViewType _type;
|
||||||
|
|
||||||
id delegate;
|
id _delegate;
|
||||||
unsigned delegateSelectors;
|
unsigned _delegateSelectors;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)initWithFrame:(CGRect)aFrame
|
- (id)initWithFrame:(CGRect)aFrame
|
||||||
{
|
{
|
||||||
self = [super initWithFrame:aFrame];
|
if (self = [super initWithFrame:aFrame])
|
||||||
if (self)
|
|
||||||
{
|
{
|
||||||
items = [CPArray array];
|
_items = [CPArray array];
|
||||||
|
_selectedIndex = CPNotFound;
|
||||||
tabs = [[CPSegmentedControl alloc] initWithFrame:CGRectMake(0, 0, 0, HEIGHT_OF_SEGMENTED_CONTROL)];
|
|
||||||
[tabs setHitTests:NO];
|
|
||||||
|
|
||||||
box = [[CPBox alloc] initWithFrame:CGRectMake(0, HEIGHT_OF_SEGMENTED_CONTROL / 2, CGRectGetWidth(aFrame),
|
|
||||||
CGRectGetHeight(aFrame) - HEIGHT_OF_SEGMENTED_CONTROL)];
|
|
||||||
|
|
||||||
selectedIndex = CPNotFound;
|
|
||||||
|
|
||||||
|
[self _init];
|
||||||
[self setTabViewType:CPTopTabsBezelBorder];
|
[self setTabViewType:CPTopTabsBezelBorder];
|
||||||
[self setBackgroundColor:[CPColor colorWithCalibratedWhite:0.95 alpha:1.0]];
|
|
||||||
|
|
||||||
[self addSubview:box];
|
|
||||||
[self addSubview:tabs];
|
|
||||||
|
|
||||||
[box setAutoresizingMask:CPViewWidthSizable];
|
|
||||||
[tabs setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)_init
|
||||||
|
{
|
||||||
|
_tabs = [[CPSegmentedControl alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
|
||||||
|
[_tabs setHitTests:NO];
|
||||||
|
|
||||||
|
var height = [_tabs valueForThemeAttribute:@"default-height"];
|
||||||
|
[_tabs setFrameSize:CGSizeMake(0, height)];
|
||||||
|
|
||||||
|
_box = [[CPBox alloc] initWithFrame:[self bounds]];
|
||||||
|
[self setBackgroundColor:[CPColor colorWithCalibratedWhite:0.95 alpha:1.0]];
|
||||||
|
|
||||||
|
[_box setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
|
||||||
|
[_tabs setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin];
|
||||||
|
|
||||||
|
[self addSubview:_box];
|
||||||
|
[self addSubview:_tabs];
|
||||||
|
}
|
||||||
|
|
||||||
// Adding and Removing Tabs
|
// Adding and Removing Tabs
|
||||||
/*!
|
/*!
|
||||||
Adds a CPTabViewItem to the tab view.
|
Adds a CPTabViewItem to the tab view.
|
||||||
@@ -87,7 +70,7 @@ var HEIGHT_OF_SEGMENTED_CONTROL = 24;
|
|||||||
*/
|
*/
|
||||||
- (void)addTabViewItem:(CPTabViewItem)aTabViewItem
|
- (void)addTabViewItem:(CPTabViewItem)aTabViewItem
|
||||||
{
|
{
|
||||||
[self insertTabViewItem:aTabViewItem atIndex:[items count]];
|
[self insertTabViewItem:aTabViewItem atIndex:[_items count]];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -98,13 +81,15 @@ var HEIGHT_OF_SEGMENTED_CONTROL = 24;
|
|||||||
*/
|
*/
|
||||||
- (void)insertTabViewItem:(CPTabViewItem)aTabViewItem atIndex:(unsigned)anIndex
|
- (void)insertTabViewItem:(CPTabViewItem)aTabViewItem atIndex:(unsigned)anIndex
|
||||||
{
|
{
|
||||||
[items insertObject:aTabViewItem atIndex:anIndex];
|
[_items insertObject:aTabViewItem atIndex:anIndex];
|
||||||
|
|
||||||
[self _updateItems];
|
[self _updateItems];
|
||||||
[self _repositionTabs];
|
[self _repositionTabs];
|
||||||
|
|
||||||
if (delegateSelectors & CPTabViewDidChangeNumberOfTabViewItemsSelector)
|
[aTabViewItem _setTabView:self];
|
||||||
[delegate tabViewDidChangeNumberOfTabViewItems:self];
|
|
||||||
|
if (_delegateSelectors & CPTabViewDidChangeNumberOfTabViewItemsSelector)
|
||||||
|
[_delegate tabViewDidChangeNumberOfTabViewItems:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -113,19 +98,23 @@ var HEIGHT_OF_SEGMENTED_CONTROL = 24;
|
|||||||
*/
|
*/
|
||||||
- (void)removeTabViewItem:(CPTabViewItem)aTabViewItem
|
- (void)removeTabViewItem:(CPTabViewItem)aTabViewItem
|
||||||
{
|
{
|
||||||
for (var i = 0; i < [items count]; i++)
|
var count = [_items count];
|
||||||
|
for (var i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
if ([items objectAtIndex:i] === aTabViewItem)
|
if ([_items objectAtIndex:i] === aTabViewItem)
|
||||||
{
|
{
|
||||||
[items removeObjectAtIndex:i];
|
[_items removeObjectAtIndex:i];
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[self _updateItems];
|
[self _updateItems];
|
||||||
[self _repositionTabs];
|
[self _repositionTabs];
|
||||||
|
|
||||||
if (delegateSelectors & CPTabViewDidChangeNumberOfTabViewItemsSelector)
|
[aTabViewItem _setTabView:nil];
|
||||||
[delegate tabViewDidChangeNumberOfTabViewItems:self];
|
|
||||||
|
if (_delegateSelectors & CPTabViewDidChangeNumberOfTabViewItemsSelector)
|
||||||
|
[_delegate tabViewDidChangeNumberOfTabViewItems:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Accessing Tabs
|
// Accessing Tabs
|
||||||
@@ -135,7 +124,7 @@ var HEIGHT_OF_SEGMENTED_CONTROL = 24;
|
|||||||
*/
|
*/
|
||||||
- (int)indexOfTabViewItem:(CPTabViewItem)aTabViewItem
|
- (int)indexOfTabViewItem:(CPTabViewItem)aTabViewItem
|
||||||
{
|
{
|
||||||
return [items indexOfObjectIdenticalTo:aTabViewItem];
|
return [_items indexOfObjectIdenticalTo:aTabViewItem];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -144,8 +133,8 @@ var HEIGHT_OF_SEGMENTED_CONTROL = 24;
|
|||||||
*/
|
*/
|
||||||
- (int)indexOfTabViewItemWithIdentifier:(CPString)anIdentifier
|
- (int)indexOfTabViewItemWithIdentifier:(CPString)anIdentifier
|
||||||
{
|
{
|
||||||
for (var index = [items count]; index >= 0; index--)
|
for (var index = [_items count]; index >= 0; index--)
|
||||||
if ([[items[index] identifier] isEqual:anIdentifier])
|
if ([[_items[index] identifier] isEqual:anIdentifier])
|
||||||
return index;
|
return index;
|
||||||
|
|
||||||
return CPNotFound;
|
return CPNotFound;
|
||||||
@@ -156,7 +145,7 @@ var HEIGHT_OF_SEGMENTED_CONTROL = 24;
|
|||||||
*/
|
*/
|
||||||
- (unsigned)numberOfTabViewItems
|
- (unsigned)numberOfTabViewItems
|
||||||
{
|
{
|
||||||
return [items count];
|
return [_items count];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -164,7 +153,7 @@ var HEIGHT_OF_SEGMENTED_CONTROL = 24;
|
|||||||
*/
|
*/
|
||||||
- (CPTabViewItem)tabViewItemAtIndex:(unsigned)anIndex
|
- (CPTabViewItem)tabViewItemAtIndex:(unsigned)anIndex
|
||||||
{
|
{
|
||||||
return [items objectAtIndex:anIndex];
|
return [_items objectAtIndex:anIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -172,7 +161,7 @@ var HEIGHT_OF_SEGMENTED_CONTROL = 24;
|
|||||||
*/
|
*/
|
||||||
- (CPArray)tabViewItems
|
- (CPArray)tabViewItems
|
||||||
{
|
{
|
||||||
return [items copy]; // Copy?
|
return [_items copy]; // Copy?
|
||||||
}
|
}
|
||||||
|
|
||||||
// Selecting a Tab
|
// Selecting a Tab
|
||||||
@@ -182,7 +171,7 @@ var HEIGHT_OF_SEGMENTED_CONTROL = 24;
|
|||||||
*/
|
*/
|
||||||
- (void)selectFirstTabViewItem:(id)aSender
|
- (void)selectFirstTabViewItem:(id)aSender
|
||||||
{
|
{
|
||||||
if ([items count] === 0)
|
if ([_items count] === 0)
|
||||||
return; // throw?
|
return; // throw?
|
||||||
|
|
||||||
[self selectTabViewItemAtIndex:0];
|
[self selectTabViewItemAtIndex:0];
|
||||||
@@ -194,10 +183,10 @@ var HEIGHT_OF_SEGMENTED_CONTROL = 24;
|
|||||||
*/
|
*/
|
||||||
- (void)selectLastTabViewItem:(id)aSender
|
- (void)selectLastTabViewItem:(id)aSender
|
||||||
{
|
{
|
||||||
if ([items count] === 0)
|
if ([_items count] === 0)
|
||||||
return; // throw?
|
return; // throw?
|
||||||
|
|
||||||
[self selectTabViewItemAtIndex:[items count] - 1];
|
[self selectTabViewItemAtIndex:[_items count] - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -206,12 +195,12 @@ var HEIGHT_OF_SEGMENTED_CONTROL = 24;
|
|||||||
*/
|
*/
|
||||||
- (void)selectNextTabViewItem:(id)aSender
|
- (void)selectNextTabViewItem:(id)aSender
|
||||||
{
|
{
|
||||||
if (selectedIndex === CPNotFound)
|
if (_selectedIndex === CPNotFound)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var nextIndex = selectedIndex + 1;
|
var nextIndex = _selectedIndex + 1;
|
||||||
|
|
||||||
if (nextIndex === [items count])
|
if (nextIndex === [_items count])
|
||||||
// does nothing. According to spec at (http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Reference/ApplicationKit/Classes/NSTabView_Class/Reference/Reference.html#//apple_ref/occ/instm/NSTabView/selectNextTabViewItem:)
|
// does nothing. According to spec at (http://developer.apple.com/mac/library/DOCUMENTATION/Cocoa/Reference/ApplicationKit/Classes/NSTabView_Class/Reference/Reference.html#//apple_ref/occ/instm/NSTabView/selectNextTabViewItem:)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -224,10 +213,10 @@ var HEIGHT_OF_SEGMENTED_CONTROL = 24;
|
|||||||
*/
|
*/
|
||||||
- (void)selectPreviousTabViewItem:(id)aSender
|
- (void)selectPreviousTabViewItem:(id)aSender
|
||||||
{
|
{
|
||||||
if (selectedIndex === CPNotFound)
|
if (_selectedIndex === CPNotFound)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var previousIndex = selectedIndex - 1;
|
var previousIndex = _selectedIndex - 1;
|
||||||
|
|
||||||
if (previousIndex < 0)
|
if (previousIndex < 0)
|
||||||
return; // does nothing. See above.
|
return; // does nothing. See above.
|
||||||
@@ -250,24 +239,24 @@ var HEIGHT_OF_SEGMENTED_CONTROL = 24;
|
|||||||
*/
|
*/
|
||||||
- (void)selectTabViewItemAtIndex:(unsigned)anIndex
|
- (void)selectTabViewItemAtIndex:(unsigned)anIndex
|
||||||
{
|
{
|
||||||
var aTabViewItem = [items objectAtIndex:anIndex];
|
var aTabViewItem = [_items objectAtIndex:anIndex];
|
||||||
|
|
||||||
if (anIndex === selectedIndex)
|
if (anIndex === _selectedIndex)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var aTabViewItem = [self tabViewItemAtIndex:anIndex];
|
var aTabViewItem = [self tabViewItemAtIndex:anIndex];
|
||||||
|
|
||||||
if ((delegateSelectors & CPTabViewShouldSelectTabViewItemSelector) && ![delegate tabView:self shouldSelectTabViewItem:aTabViewItem])
|
if ((_delegateSelectors & CPTabViewShouldSelectTabViewItemSelector) && ![_delegate tabView:self shouldSelectTabViewItem:aTabViewItem])
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (delegateSelectors & CPTabViewWillSelectTabViewItemSelector)
|
if (_delegateSelectors & CPTabViewWillSelectTabViewItemSelector)
|
||||||
[delegate tabView:self willSelectTabViewItem:aTabViewItem];
|
[_delegate tabView:self willSelectTabViewItem:aTabViewItem];
|
||||||
|
|
||||||
[tabs selectSegmentWithTag:anIndex];
|
[_tabs selectSegmentWithTag:anIndex];
|
||||||
[self _setSelectedIndex:anIndex];
|
[self _setSelectedIndex:anIndex];
|
||||||
|
|
||||||
if (delegateSelectors & CPTabViewDidSelectTabViewItemSelector)
|
if (_delegateSelectors & CPTabViewDidSelectTabViewItemSelector)
|
||||||
[delegate tabView:self didSelectTabViewItem:aTabViewItem];
|
[_delegate tabView:self didSelectTabViewItem:aTabViewItem];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -275,7 +264,7 @@ var HEIGHT_OF_SEGMENTED_CONTROL = 24;
|
|||||||
*/
|
*/
|
||||||
- (CPTabViewItem)selectedTabViewItem
|
- (CPTabViewItem)selectedTabViewItem
|
||||||
{
|
{
|
||||||
return [items objectAtIndex:selectedIndex];
|
return [_items objectAtIndex:_selectedIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -285,31 +274,40 @@ var HEIGHT_OF_SEGMENTED_CONTROL = 24;
|
|||||||
*/
|
*/
|
||||||
- (void)setTabViewType:(CPTabViewType)aTabViewType
|
- (void)setTabViewType:(CPTabViewType)aTabViewType
|
||||||
{
|
{
|
||||||
if (type === aTabViewType)
|
if (_type === aTabViewType)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if ((type === CPTopTabsBezelBorder || type === CPBottomTabsBezelBorder)
|
_type = aTabViewType;
|
||||||
&& (aTabViewType !== CPTopTabsBezelBorder && aTabViewType !== CPBottomTabsBezelBorder))
|
|
||||||
[tabs removeFromSuperview];
|
|
||||||
|
|
||||||
if ((type === CPNoTabsBezelBorder || type === CPNoTabsLineBorder || type === CPNoTabsNoBorder)
|
if (_type !== CPTopTabsBezelBorder && _type !== CPBottomTabsBezelBorder)
|
||||||
&& (aTabViewType !== CPNoTabsBezelBorder && aTabViewType !== CPNoTabsBezelBorder && aTabViewType !== CPNoTabsNoBorder))
|
{
|
||||||
[self addSubview:tabs];
|
[_box setFrame:[self bounds]];
|
||||||
|
[_tabs removeFromSuperview];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var aFrame = [self frame],
|
||||||
|
segmentedHeight = CGRectGetHeight([_tabs frame]),
|
||||||
|
origin = _type === CPTopTabsBezelBorder ? segmentedHeight / 2 : 0;
|
||||||
|
|
||||||
type = aTabViewType;
|
[_box setFrame:CGRectMake(0, origin, CGRectGetWidth(aFrame),
|
||||||
|
CGRectGetHeight(aFrame) - segmentedHeight / 2)];
|
||||||
|
|
||||||
switch (type)
|
[self addSubview:_tabs];
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (_type)
|
||||||
{
|
{
|
||||||
case CPTopTabsBezelBorder:
|
case CPTopTabsBezelBorder:
|
||||||
case CPBottomTabsBezelBorder:
|
case CPBottomTabsBezelBorder:
|
||||||
case CPNoTabsBezelBorder:
|
case CPNoTabsBezelBorder:
|
||||||
[box setBorderType:CPBezelBorder];
|
[_box setBorderType:CPBezelBorder];
|
||||||
break;
|
break;
|
||||||
case CPNoTabsLineBorder:
|
case CPNoTabsLineBorder:
|
||||||
[box setBorderType:CPLineBorder];
|
[_box setBorderType:CPLineBorder];
|
||||||
break;
|
break;
|
||||||
case CPNoTabsNoBorder:
|
case CPNoTabsNoBorder:
|
||||||
[box setBorderType:CPNoBorder];
|
[_box setBorderType:CPNoBorder];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -319,7 +317,7 @@ var HEIGHT_OF_SEGMENTED_CONTROL = 24;
|
|||||||
*/
|
*/
|
||||||
- (CPTabViewType)tabViewType
|
- (CPTabViewType)tabViewType
|
||||||
{
|
{
|
||||||
return type;
|
return _type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -327,7 +325,7 @@ var HEIGHT_OF_SEGMENTED_CONTROL = 24;
|
|||||||
*/
|
*/
|
||||||
- (id)delegate
|
- (id)delegate
|
||||||
{
|
{
|
||||||
return delegate;
|
return _delegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -336,71 +334,77 @@ var HEIGHT_OF_SEGMENTED_CONTROL = 24;
|
|||||||
*/
|
*/
|
||||||
- (void)setDelegate:(id)aDelegate
|
- (void)setDelegate:(id)aDelegate
|
||||||
{
|
{
|
||||||
if (delegate == aDelegate)
|
if (_delegate == aDelegate)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
delegate = aDelegate;
|
_delegate = aDelegate;
|
||||||
|
|
||||||
delegateSelectors = 0;
|
_delegateSelectors = 0;
|
||||||
|
|
||||||
if ([delegate respondsToSelector:@selector(tabView:shouldSelectTabViewItem:)])
|
if ([_delegate respondsToSelector:@selector(tabView:shouldSelectTabViewItem:)])
|
||||||
delegateSelectors |= CPTabViewShouldSelectTabViewItemSelector;
|
_delegateSelectors |= CPTabViewShouldSelectTabViewItemSelector;
|
||||||
|
|
||||||
if ([delegate respondsToSelector:@selector(tabView:willSelectTabViewItem:)])
|
if ([_delegate respondsToSelector:@selector(tabView:willSelectTabViewItem:)])
|
||||||
delegateSelectors |= CPTabViewWillSelectTabViewItemSelector;
|
_delegateSelectors |= CPTabViewWillSelectTabViewItemSelector;
|
||||||
|
|
||||||
if ([delegate respondsToSelector:@selector(tabView:didSelectTabViewItem:)])
|
if ([_delegate respondsToSelector:@selector(tabView:didSelectTabViewItem:)])
|
||||||
delegateSelectors |= CPTabViewDidSelectTabViewItemSelector;
|
_delegateSelectors |= CPTabViewDidSelectTabViewItemSelector;
|
||||||
|
|
||||||
if ([delegate respondsToSelector:@selector(tabViewDidChangeNumberOfTabViewItems:)])
|
if ([_delegate respondsToSelector:@selector(tabViewDidChangeNumberOfTabViewItems:)])
|
||||||
delegateSelectors |= CPTabViewDidChangeNumberOfTabViewItemsSelector;
|
_delegateSelectors |= CPTabViewDidChangeNumberOfTabViewItemsSelector;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setBackgroundColor:(CPColor)aColor
|
- (void)setBackgroundColor:(CPColor)aColor
|
||||||
{
|
{
|
||||||
[box setBackgroundColor:aColor];
|
[_box setBackgroundColor:aColor];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (CPColor)backgroundColor
|
||||||
|
{
|
||||||
|
return [_box backgroundColor];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)mouseDown:(CPEvent)anEvent
|
- (void)mouseDown:(CPEvent)anEvent
|
||||||
{
|
{
|
||||||
var segmentIndex = [tabs testSegment:[tabs convertPoint:[anEvent locationInWindow] fromView:nil]];
|
var segmentIndex = [_tabs testSegment:[_tabs convertPoint:[anEvent locationInWindow] fromView:nil]];
|
||||||
|
|
||||||
if (segmentIndex != CPNotFound)
|
if (segmentIndex != CPNotFound)
|
||||||
{
|
{
|
||||||
[self selectTabViewItemAtIndex:segmentIndex];
|
[self selectTabViewItemAtIndex:segmentIndex];
|
||||||
[tabs trackSegment:anEvent];
|
[_tabs trackSegment:anEvent];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)_repositionTabs
|
- (void)_repositionTabs
|
||||||
{
|
{
|
||||||
var horizontalCenterOfSelf = CGRectGetWidth([self bounds]) / 2,
|
var horizontalCenterOfSelf = CGRectGetWidth([self bounds]) / 2,
|
||||||
verticalCenterOfTabs = CGRectGetHeight([tabs bounds]) / 2;
|
verticalCenterOfTabs = CGRectGetHeight([_tabs bounds]) / 2;
|
||||||
|
|
||||||
if (type === CPBottomTabsBezelBorder)
|
if (_type === CPBottomTabsBezelBorder)
|
||||||
[tabs setCenter:CGPointMake(horizontalCenterOfSelf, CGRectGetHeight([self bounds]) - verticalCenterOfTabs)];
|
[_tabs setCenter:CGPointMake(horizontalCenterOfSelf, CGRectGetHeight([self bounds]) - verticalCenterOfTabs)];
|
||||||
else
|
else
|
||||||
[tabs setCenter:CGPointMake(horizontalCenterOfSelf, verticalCenterOfTabs)];
|
[_tabs setCenter:CGPointMake(horizontalCenterOfSelf, verticalCenterOfTabs)];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)_setSelectedIndex:(CPNumber)index
|
- (void)_setSelectedIndex:(CPNumber)index
|
||||||
{
|
{
|
||||||
selectedIndex = index;
|
_selectedIndex = index;
|
||||||
|
|
||||||
[box setContentView:[[items objectAtIndex:selectedIndex] view]];
|
[_box setContentView:[[_items objectAtIndex:_selectedIndex] view]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)_updateItems
|
- (void)_updateItems
|
||||||
{
|
{
|
||||||
[tabs setSegmentCount:[items count]];
|
var count = [_items count];
|
||||||
|
[_tabs setSegmentCount:count];
|
||||||
|
|
||||||
for (var i = 0; i < [items count]; i++)
|
for (var i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
[tabs setLabel:[[items objectAtIndex:i] label] forSegment:i];
|
[_tabs setLabel:[[_items objectAtIndex:i] label] forSegment:i];
|
||||||
[tabs setTag:i forSegment:i];
|
[_tabs setTag:i forSegment:i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selectedIndex === CPNotFound)
|
if (_selectedIndex === CPNotFound)
|
||||||
{
|
{
|
||||||
[self selectFirstTabViewItem:self];
|
[self selectFirstTabViewItem:self];
|
||||||
}
|
}
|
||||||
@@ -419,18 +423,20 @@ var CPTabViewItemsKey = "CPTabViewItemsKey",
|
|||||||
{
|
{
|
||||||
if (self = [super initWithCoder:aCoder])
|
if (self = [super initWithCoder:aCoder])
|
||||||
{
|
{
|
||||||
type = [aCoder decodeIntForKey:CPTabViewTypeKey];
|
[self _init];
|
||||||
items = [];
|
|
||||||
|
|
||||||
var encodedItems = [aCoder decodeObjectForKey:CPTabViewItemsKey];
|
_items = [aCoder decodeObjectForKey:CPTabViewItemsKey];
|
||||||
for (var i = 0; encodedItems && i < encodedItems.length; i++)
|
|
||||||
[self insertTabViewItem:encodedItems[i] atIndex:i];
|
[self _updateItems];
|
||||||
|
[self _repositionTabs];
|
||||||
|
|
||||||
var selected = [aCoder decodeObjectForKey:CPTabViewSelectedItemKey];
|
var selected = [aCoder decodeObjectForKey:CPTabViewSelectedItemKey];
|
||||||
if (selected)
|
if (selected)
|
||||||
[self selectTabViewItem:selected];
|
[self selectTabViewItem:selected];
|
||||||
|
|
||||||
[self setDelegate:[aCoder decodeObjectForKey:CPTabViewDelegateKey]];
|
[self setDelegate:[aCoder decodeObjectForKey:CPTabViewDelegateKey]];
|
||||||
|
|
||||||
|
[self setTabViewType:[aCoder decodeIntForKey:CPTabViewTypeKey]];
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
@@ -440,12 +446,12 @@ var CPTabViewItemsKey = "CPTabViewItemsKey",
|
|||||||
{
|
{
|
||||||
[super encodeWithCoder:aCoder];
|
[super encodeWithCoder:aCoder];
|
||||||
|
|
||||||
[aCoder encodeObject:items forKey:CPTabViewItemsKey];;
|
[aCoder encodeObject:_items forKey:CPTabViewItemsKey];
|
||||||
[aCoder encodeObject:[self selectedTabViewItem] forKey:CPTabViewSelectedItemKey];
|
[aCoder encodeObject:[self selectedTabViewItem] forKey:CPTabViewSelectedItemKey];
|
||||||
|
|
||||||
[aCoder encodeInt:type forKey:CPTabViewTypeKey];
|
[aCoder encodeInt:_type forKey:CPTabViewTypeKey];
|
||||||
|
|
||||||
[aCoder encodeConditionalObject:delegate forKey:CPTabViewDelegateKey];
|
[aCoder encodeConditionalObject:_delegate forKey:CPTabViewDelegateKey];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -33,6 +33,14 @@ CPTableColumnNoResizing = 0;
|
|||||||
CPTableColumnAutoresizingMask = 1 << 0;
|
CPTableColumnAutoresizingMask = 1 << 0;
|
||||||
CPTableColumnUserResizingMask = 1 << 1;
|
CPTableColumnUserResizingMask = 1 << 1;
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@class CPTableColumn
|
||||||
|
|
||||||
|
A CPTableColumn contains a dataview to display for its column of the CPTableView.
|
||||||
|
A CPTableColumn determines its own size constrains and resizing behaviour.
|
||||||
|
|
||||||
|
The default dataview is a CPTextField but you can set it to any view you'd like. See -setDataView: for documentaion including theme states.
|
||||||
|
*/
|
||||||
@implementation CPTableColumn : CPObject
|
@implementation CPTableColumn : CPObject
|
||||||
{
|
{
|
||||||
CPTableView _tableView;
|
CPTableView _tableView;
|
||||||
@@ -54,11 +62,23 @@ CPTableColumnUserResizingMask = 1 << 1;
|
|||||||
BOOL _disableResizingPosting @accessors(property=disableResizingPosting);
|
BOOL _disableResizingPosting @accessors(property=disableResizingPosting);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (Class)_binderClassForBinding:(CPString)theBinding
|
||||||
|
{
|
||||||
|
return [CPBinder class];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
- (id)init
|
- (id)init
|
||||||
{
|
{
|
||||||
return [self initWithIdentifier:@""];
|
return [self initWithIdentifier:@""];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Initializes a newly created CPTableColumn with a given identifier.
|
||||||
|
|
||||||
|
*/
|
||||||
- (id)initWithIdentifier:(id)anIdentifier
|
- (id)initWithIdentifier:(id)anIdentifier
|
||||||
{
|
{
|
||||||
self = [super init];
|
self = [super init];
|
||||||
@@ -84,17 +104,50 @@ CPTableColumnUserResizingMask = 1 << 1;
|
|||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Set the columns's parent tableview
|
||||||
|
*/
|
||||||
- (void)setTableView:(CPTableView)aTableView
|
- (void)setTableView:(CPTableView)aTableView
|
||||||
{
|
{
|
||||||
_tableView = aTableView;
|
_tableView = aTableView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Return the column's parent tableview
|
||||||
|
*/
|
||||||
- (CPTableView)tableView
|
- (CPTableView)tableView
|
||||||
{
|
{
|
||||||
return _tableView;
|
return _tableView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
this method tries to resize a column called via the tableview via autoresizing
|
||||||
|
it returns the delta from the actual resize and the proposed resize
|
||||||
|
|
||||||
|
for example if the column should have been resized 50px but the maxWidth was hit only
|
||||||
|
after 25px then the return value would be 25px;
|
||||||
|
|
||||||
|
if no edge has been hit zero will be returned
|
||||||
|
*/
|
||||||
|
- (int)_tryToResizeToWidth:(int)width
|
||||||
|
{
|
||||||
|
var min = [self minWidth],
|
||||||
|
max = [self maxWidth],
|
||||||
|
newWidth = MIN(MAX(width, min), max);
|
||||||
|
|
||||||
|
[self setWidth:newWidth];
|
||||||
|
|
||||||
|
return newWidth - width;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Set the width of the column
|
||||||
|
Default value is: 100
|
||||||
|
|
||||||
|
If the value is greater than the maxWidth the maxWidth will be reset with the supplied width here
|
||||||
|
If the value is less than the minWidth the minWidth will be reset with the supplied width.
|
||||||
|
*/
|
||||||
- (void)setWidth:(float)aWidth
|
- (void)setWidth:(float)aWidth
|
||||||
{
|
{
|
||||||
aWidth = +aWidth;
|
aWidth = +aWidth;
|
||||||
@@ -135,11 +188,18 @@ CPTableColumnUserResizingMask = 1 << 1;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns the column's width
|
||||||
|
*/
|
||||||
- (float)width
|
- (float)width
|
||||||
{
|
{
|
||||||
return _width;
|
return _width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Sets the minimum width of the column.
|
||||||
|
Default value is 10.
|
||||||
|
*/
|
||||||
- (void)setMinWidth:(float)aMinWidth
|
- (void)setMinWidth:(float)aMinWidth
|
||||||
{
|
{
|
||||||
aMinWidth = +aMinWidth;
|
aMinWidth = +aMinWidth;
|
||||||
@@ -156,11 +216,18 @@ CPTableColumnUserResizingMask = 1 << 1;
|
|||||||
[self setWidth:newWidth];
|
[self setWidth:newWidth];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns the minimum width of the column.
|
||||||
|
*/
|
||||||
- (float)minWidth
|
- (float)minWidth
|
||||||
{
|
{
|
||||||
return _minWidth;
|
return _minWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Sets the maximum width of the table column.
|
||||||
|
Default value is: 1000000
|
||||||
|
*/
|
||||||
- (void)setMaxWidth:(float)aMaxWidth
|
- (void)setMaxWidth:(float)aMaxWidth
|
||||||
{
|
{
|
||||||
aMaxWidth = +aMaxWidth;
|
aMaxWidth = +aMaxWidth;
|
||||||
@@ -177,21 +244,42 @@ CPTableColumnUserResizingMask = 1 << 1;
|
|||||||
[self setWidth:newWidth];
|
[self setWidth:newWidth];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns the maximum width of the column
|
||||||
|
*/
|
||||||
- (float)maxWidth
|
- (float)maxWidth
|
||||||
{
|
{
|
||||||
return _maxWidth;
|
return _maxWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
<pre>
|
||||||
|
Set the resizing mask of the column.
|
||||||
|
By default the column can be resized automatically with the tableview and manaully by the user
|
||||||
|
|
||||||
|
Possible masking values are:
|
||||||
|
CPTableColumnNoResizing
|
||||||
|
CPTableColumnAutoresizingMask
|
||||||
|
CPTableColumnUserResizingMask
|
||||||
|
</pre>
|
||||||
|
*/
|
||||||
- (void)setResizingMask:(unsigned)aResizingMask
|
- (void)setResizingMask:(unsigned)aResizingMask
|
||||||
{
|
{
|
||||||
_resizingMask = aResizingMask;
|
_resizingMask = aResizingMask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns the resizing mask of the column
|
||||||
|
*/
|
||||||
- (unsigned)resizingMask
|
- (unsigned)resizingMask
|
||||||
{
|
{
|
||||||
return _resizingMask;
|
return _resizingMask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Sizes the column to fix the column header text.
|
||||||
|
*/
|
||||||
- (void)sizeToFit
|
- (void)sizeToFit
|
||||||
{
|
{
|
||||||
var width = _CGRectGetWidth([_headerView frame]);
|
var width = _CGRectGetWidth([_headerView frame]);
|
||||||
@@ -205,7 +293,11 @@ CPTableColumnUserResizingMask = 1 << 1;
|
|||||||
[self setWidth:width];
|
[self setWidth:width];
|
||||||
}
|
}
|
||||||
|
|
||||||
//Setting Component Cells
|
|
||||||
|
/*!
|
||||||
|
Sets the header view for the column.
|
||||||
|
The headerview handles the display of sort indicators, text, etc
|
||||||
|
*/
|
||||||
- (void)setHeaderView:(CPView)aView
|
- (void)setHeaderView:(CPView)aView
|
||||||
{
|
{
|
||||||
if (!aView)
|
if (!aView)
|
||||||
@@ -219,17 +311,28 @@ CPTableColumnUserResizingMask = 1 << 1;
|
|||||||
[tableHeaderView setNeedsDisplay:YES];
|
[tableHeaderView setNeedsDisplay:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns the headerview for the column
|
||||||
|
*/
|
||||||
- (CPView)headerView
|
- (CPView)headerView
|
||||||
{
|
{
|
||||||
return _headerView;
|
return _headerView;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
This method set's the "prototype" view which will be used to create all table cells in this column.
|
<pre>
|
||||||
|
This method sets the "prototype" view which will be used to create all table cells in this column.
|
||||||
|
|
||||||
It creates a snapshot of aView, using keyed archiving, which is then copied over and over for each
|
It creates a snapshot of aView, using keyed archiving, which is then copied over and over for each
|
||||||
individual cell that is shown. As a result, changes made after calling this method won't be reflected.
|
individual cell that is shown. As a result, changes made after calling this method won't be reflected.
|
||||||
|
|
||||||
|
When you set a dataview and it is added to the tableview the theme state will be set to CPThemeStateTableDataView
|
||||||
|
When the dataview becomes selected the theme state will be set to CPThemeStateSelectedDataView.
|
||||||
|
|
||||||
|
If the dataview shows up in a group row of the tablview the theme state will be set to CPThemeStateGroupRow.
|
||||||
|
|
||||||
|
You should overide setThemeState: and unsetThemeState: to handle these theme state changes in your dataview.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
[tableColumn setDataView:someView]; // snapshot taken
|
[tableColumn setDataView:someView]; // snapshot taken
|
||||||
@@ -239,6 +342,38 @@ CPTableColumnUserResizingMask = 1 << 1;
|
|||||||
|
|
||||||
[someView setSomething:x];
|
[someView setSomething:x];
|
||||||
[tableColumn setDataView:someView];
|
[tableColumn setDataView:someView];
|
||||||
|
|
||||||
|
REMEMBER: you should implement CPKeyedArchiving otherwise you might see unexpected results.
|
||||||
|
This is done by adding the following methods to your class:
|
||||||
|
- (id)initWithCoder(CPCoder)aCoder;
|
||||||
|
- (void)encodeWithCoder:(CPCoder)aCoder;
|
||||||
|
|
||||||
|
Example:
|
||||||
|
Say you have two instance variables in your object that need to be set up each time an object is create.
|
||||||
|
We will call these instance variables "image" and "text".
|
||||||
|
Your CPCoding methods will look like the following:
|
||||||
|
|
||||||
|
- (id)initWithCoder:(CPCoder)aCoder
|
||||||
|
{
|
||||||
|
self = [super initWithCoder:aCoder];
|
||||||
|
|
||||||
|
if (self)
|
||||||
|
{
|
||||||
|
image = [aCoder decodeObjectForKey:"MyDataViewImage"];
|
||||||
|
text = [aCoder decodeObjectForKey:"MyDataViewText"];
|
||||||
|
}
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)encodeWithCoder:(CPCoder)aCoder
|
||||||
|
{
|
||||||
|
[super encodeWithCoder:aCoder];
|
||||||
|
|
||||||
|
[aCoder encodeObject:image forKey:"MyDataViewImage"];
|
||||||
|
[aCoder encodeObject:text forKey:"MyDataViewText"];
|
||||||
|
}
|
||||||
|
</pre>
|
||||||
*/
|
*/
|
||||||
- (void)setDataView:(CPView)aView
|
- (void)setDataView:(CPView)aView
|
||||||
{
|
{
|
||||||
@@ -260,7 +395,7 @@ CPTableColumnUserResizingMask = 1 << 1;
|
|||||||
Returns the CPView object used by the CPTableView to draw values for the receiver.
|
Returns the CPView object used by the CPTableView to draw values for the receiver.
|
||||||
|
|
||||||
By default, this method just calls dataView. Subclassers can override if they need to
|
By default, this method just calls dataView. Subclassers can override if they need to
|
||||||
potentially use different cells for different rows. Subclasses should expect this method
|
potentially use different "cells" or dataViews for different rows. Subclasses should expect this method
|
||||||
to be invoked with row equal to -1 in cases where no actual row is involved but the table
|
to be invoked with row equal to -1 in cases where no actual row is involved but the table
|
||||||
view needs to get some generic cell info.
|
view needs to get some generic cell info.
|
||||||
*/
|
*/
|
||||||
@@ -269,6 +404,9 @@ CPTableColumnUserResizingMask = 1 << 1;
|
|||||||
return [self dataView];
|
return [self dataView];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
- (id)_newDataViewForRow:(int)aRowIndex
|
- (id)_newDataViewForRow:(int)aRowIndex
|
||||||
{
|
{
|
||||||
var dataView = [self dataViewForRow:aRowIndex],
|
var dataView = [self dataViewForRow:aRowIndex],
|
||||||
@@ -294,7 +432,7 @@ CPTableColumnUserResizingMask = 1 << 1;
|
|||||||
|
|
||||||
//Setting the Identifier
|
//Setting the Identifier
|
||||||
|
|
||||||
/*
|
/*!
|
||||||
Sets the receiver identifier to anIdentifier.
|
Sets the receiver identifier to anIdentifier.
|
||||||
*/
|
*/
|
||||||
- (void)setIdentifier:(id)anIdentifier
|
- (void)setIdentifier:(id)anIdentifier
|
||||||
@@ -302,7 +440,7 @@ CPTableColumnUserResizingMask = 1 << 1;
|
|||||||
_identifier = anIdentifier;
|
_identifier = anIdentifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*!
|
||||||
Returns the object used by the data source to identify the attribute corresponding to the receiver.
|
Returns the object used by the data source to identify the attribute corresponding to the receiver.
|
||||||
*/
|
*/
|
||||||
- (id)identifier
|
- (id)identifier
|
||||||
@@ -312,7 +450,7 @@ CPTableColumnUserResizingMask = 1 << 1;
|
|||||||
|
|
||||||
//Controlling Editability
|
//Controlling Editability
|
||||||
|
|
||||||
/*
|
/*!
|
||||||
Controls whether the user can edit cells in the receiver by double-clicking them.
|
Controls whether the user can edit cells in the receiver by double-clicking them.
|
||||||
*/
|
*/
|
||||||
- (void)setEditable:(BOOL)shouldBeEditable
|
- (void)setEditable:(BOOL)shouldBeEditable
|
||||||
@@ -320,7 +458,7 @@ CPTableColumnUserResizingMask = 1 << 1;
|
|||||||
_isEditable = shouldBeEditable;
|
_isEditable = shouldBeEditable;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*!
|
||||||
Returns YES if the user can edit cells associated with the receiver by double-clicking the
|
Returns YES if the user can edit cells associated with the receiver by double-clicking the
|
||||||
column in the NSTableView, NO otherwise.
|
column in the NSTableView, NO otherwise.
|
||||||
*/
|
*/
|
||||||
@@ -329,19 +467,26 @@ CPTableColumnUserResizingMask = 1 << 1;
|
|||||||
return _isEditable;
|
return _isEditable;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Sorting
|
/*!
|
||||||
|
Sets the sort descriptor prototype for the column.
|
||||||
|
*/
|
||||||
- (void)setSortDescriptorPrototype:(CPSortDescriptor)aSortDescriptor
|
- (void)setSortDescriptorPrototype:(CPSortDescriptor)aSortDescriptor
|
||||||
{
|
{
|
||||||
_sortDescriptorPrototype = aSortDescriptor;
|
_sortDescriptorPrototype = aSortDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns the sort descriptor prototype for the column.
|
||||||
|
*/
|
||||||
- (CPSortDescriptor)sortDescriptorPrototype
|
- (CPSortDescriptor)sortDescriptorPrototype
|
||||||
{
|
{
|
||||||
return _sortDescriptorPrototype;
|
return _sortDescriptorPrototype;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Setting Column Visibility
|
/*!
|
||||||
|
If NO the tablecolumn will no longer be visisble in the tableview
|
||||||
|
If YES the tablecolumn will be visible in the tableview.
|
||||||
|
*/
|
||||||
- (void)setHidden:(BOOL)shouldBeHidden
|
- (void)setHidden:(BOOL)shouldBeHidden
|
||||||
{
|
{
|
||||||
shouldBeHidden = !!shouldBeHidden
|
shouldBeHidden = !!shouldBeHidden
|
||||||
@@ -354,6 +499,9 @@ CPTableColumnUserResizingMask = 1 << 1;
|
|||||||
[[self tableView] _tableColumnVisibilityDidChange:self];
|
[[self tableView] _tableColumnVisibilityDidChange:self];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns the visibility status of the column.
|
||||||
|
*/
|
||||||
- (BOOL)isHidden
|
- (BOOL)isHidden
|
||||||
{
|
{
|
||||||
return _isHidden;
|
return _isHidden;
|
||||||
@@ -361,7 +509,7 @@ CPTableColumnUserResizingMask = 1 << 1;
|
|||||||
|
|
||||||
//Setting Tool Tips
|
//Setting Tool Tips
|
||||||
|
|
||||||
/*
|
/*!
|
||||||
Sets the tooltip string that is displayed when the cursor pauses over the
|
Sets the tooltip string that is displayed when the cursor pauses over the
|
||||||
header cell of the receiver.
|
header cell of the receiver.
|
||||||
*/
|
*/
|
||||||
@@ -370,13 +518,21 @@ CPTableColumnUserResizingMask = 1 << 1;
|
|||||||
_headerToolTip = aToolTip;
|
_headerToolTip = aToolTip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Returns the tooltip for the column header
|
||||||
|
*/
|
||||||
- (CPString)headerToolTip
|
- (CPString)headerToolTip
|
||||||
{
|
{
|
||||||
return _headerToolTip;
|
return _headerToolTip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
- (void)_postDidResizeNotificationWithOldWidth:(float)oldWidth
|
- (void)_postDidResizeNotificationWithOldWidth:(float)oldWidth
|
||||||
{
|
{
|
||||||
|
[[self tableView] _didResizeTableColumn:self];
|
||||||
|
|
||||||
[[CPNotificationCenter defaultCenter]
|
[[CPNotificationCenter defaultCenter]
|
||||||
postNotificationName:CPTableViewColumnDidResizeNotification
|
postNotificationName:CPTableViewColumnDidResizeNotification
|
||||||
object:[self tableView]
|
object:[self tableView]
|
||||||
@@ -386,7 +542,6 @@ CPTableColumnUserResizingMask = 1 << 1;
|
|||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation CPTableColumn (Bindings)
|
@implementation CPTableColumn (Bindings)
|
||||||
|
|
||||||
- (void)bind:(CPString)aBinding toObject:(id)anObject withKeyPath:(CPString)aKeyPath options:(CPDictionary)options
|
- (void)bind:(CPString)aBinding toObject:(id)anObject withKeyPath:(CPString)aKeyPath options:(CPDictionary)options
|
||||||
{
|
{
|
||||||
[super bind:aBinding toObject:anObject withKeyPath:aKeyPath options:options];
|
[super bind:aBinding toObject:anObject withKeyPath:aKeyPath options:options];
|
||||||
@@ -397,7 +552,7 @@ CPTableColumnUserResizingMask = 1 << 1;
|
|||||||
|
|
||||||
- (void)prepareDataView:(CPView)aDataView forRow:(unsigned)aRow
|
- (void)prepareDataView:(CPView)aDataView forRow:(unsigned)aRow
|
||||||
{
|
{
|
||||||
var bindingsDictionary = [CPKeyValueBinding allBindingsForObject:self],
|
var bindingsDictionary = [CPBinder allBindingsForObject:self],
|
||||||
keys = [bindingsDictionary allKeys];
|
keys = [bindingsDictionary allKeys];
|
||||||
|
|
||||||
for (var i = 0, count = [keys count]; i < count; i++)
|
for (var i = 0, count = [keys count]; i < count; i++)
|
||||||
@@ -437,9 +592,7 @@ CPTableColumnUserResizingMask = 1 << 1;
|
|||||||
}
|
}
|
||||||
|
|
||||||
value = [binding transformValue:value withOptions:[bindingInfo objectForKey:CPOptionsKey]];
|
value = [binding transformValue:value withOptions:[bindingInfo objectForKey:CPOptionsKey]];
|
||||||
|
[aDataView setValue:value forKey:@"objectValue"];
|
||||||
// console.log(bindingName+" : "+keyPath+" : "+aRow+" : "+[[destination valueForKeyPath:keyPath] objectAtIndex:aRow]);
|
|
||||||
[aDataView setValue:value forKey:bindingPath];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -520,25 +673,25 @@ var CPTableColumnIdentifierKey = @"CPTableColumnIdentifierKey",
|
|||||||
- (void)setHeaderCell:(CPView)aView
|
- (void)setHeaderCell:(CPView)aView
|
||||||
{
|
{
|
||||||
[CPException raise:CPUnsupportedMethodException
|
[CPException raise:CPUnsupportedMethodException
|
||||||
reason:@"setHeaderCell: is not supported. -setHeaderCell:aView instead."];
|
reason:@"setHeaderCell: is not supported. Use -setHeaderView:aView instead."];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (CPView)headerCell
|
- (CPView)headerCell
|
||||||
{
|
{
|
||||||
[CPException raise:CPUnsupportedMethodException
|
[CPException raise:CPUnsupportedMethodException
|
||||||
reason:@"headCell is not supported. -headerView instead."];
|
reason:@"headCell is not supported. Use -headerView instead."];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setDataCell:(CPView)aView
|
- (void)setDataCell:(CPView)aView
|
||||||
{
|
{
|
||||||
[CPException raise:CPUnsupportedMethodException
|
[CPException raise:CPUnsupportedMethodException
|
||||||
reason:@"setDataCell: is not supported. Use -setHeaderCell:aView instead."];
|
reason:@"setDataCell: is not supported. Use -setDataView:aView instead."];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (CPView)dataCell
|
- (CPView)dataCell
|
||||||
{
|
{
|
||||||
[CPException raise:CPUnsupportedMethodException
|
[CPException raise:CPUnsupportedMethodException
|
||||||
reason:@"dataCell is not supported. Use -dataCell instead."];
|
reason:@"dataCell is not supported. Use -dataView instead."];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)dataCellForRow:(int)row
|
- (id)dataCellForRow:(int)row
|
||||||
|
|||||||
@@ -56,7 +56,7 @@
|
|||||||
{
|
{
|
||||||
_textField = [[_CPImageAndTextView alloc] initWithFrame:_CGRectMakeZero()];
|
_textField = [[_CPImageAndTextView alloc] initWithFrame:_CGRectMakeZero()];
|
||||||
|
|
||||||
[_textField setAutoresizingMask:CPViewWidthSizable|CPViewHeightSizable];
|
[_textField setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
|
||||||
|
|
||||||
[_textField setLineBreakMode:CPLineBreakByTruncatingTail];
|
[_textField setLineBreakMode:CPLineBreakByTruncatingTail];
|
||||||
[_textField setAlignment:CPLeftTextAlignment];
|
[_textField setAlignment:CPLeftTextAlignment];
|
||||||
@@ -102,20 +102,20 @@
|
|||||||
|
|
||||||
- (void)setFont:(CPFont)aFont
|
- (void)setFont:(CPFont)aFont
|
||||||
{
|
{
|
||||||
[_textField setFont:aFont];
|
[self setValue:aFont forThemeAttribute:"text-font"];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)_setIndicatorImage:(CPImage)anImage
|
- (void)_setIndicatorImage:(CPImage)anImage
|
||||||
{
|
{
|
||||||
if (anImage)
|
if (anImage)
|
||||||
{
|
{
|
||||||
[_textField setImage:anImage];
|
[_textField setImage:anImage];
|
||||||
[_textField setImagePosition:CPImageRight];
|
[_textField setImagePosition:CPImageRight];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
[_textField setImagePosition:CPNoImage];
|
[_textField setImagePosition:CPNoImage];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -604,7 +604,7 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
|
|||||||
|
|
||||||
[headerView setFrame:frame];
|
[headerView setFrame:frame];
|
||||||
|
|
||||||
if([headerView superview] != self)
|
if ([headerView superview] != self)
|
||||||
[self addSubview:headerView];
|
[self addSubview:headerView];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -634,7 +634,7 @@ var _CPTableColumnHeaderViewStringValueKey = @"_CPTableColumnHeaderViewStringVal
|
|||||||
columnMaxX;
|
columnMaxX;
|
||||||
|
|
||||||
CGContextBeginPath(context);
|
CGContextBeginPath(context);
|
||||||
for(; columnArrayIndex < columnArrayCount; columnArrayIndex++)
|
for (; columnArrayIndex < columnArrayCount; columnArrayIndex++)
|
||||||
{
|
{
|
||||||
// grab each column rect and add vertical lines
|
// grab each column rect and add vertical lines
|
||||||
var columnIndex = columnsArray[columnArrayIndex],
|
var columnIndex = columnsArray[columnArrayIndex],
|
||||||
@@ -669,7 +669,15 @@ var CPTableHeaderViewTableViewKey = @"CPTableHeaderViewTableViewKey",
|
|||||||
{
|
{
|
||||||
[self _init];
|
[self _init];
|
||||||
_tableView = [aCoder decodeObjectForKey:CPTableHeaderViewTableViewKey];
|
_tableView = [aCoder decodeObjectForKey:CPTableHeaderViewTableViewKey];
|
||||||
_drawsColumnLines = [aCoder decodeBoolForKey:CPTableHeaderViewDrawsColumnLines];
|
|
||||||
|
// FIX ME: Take this out before 1.0
|
||||||
|
if ([aCoder containsValueForKey:CPTableHeaderViewDrawsColumnLines])
|
||||||
|
_drawsColumnLines = [aCoder decodeBoolForKey:CPTableHeaderViewDrawsColumnLines];
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_drawsColumnLines = YES;
|
||||||
|
CPLog.warn("The tableview header being decoded is using an old cib. Please run Nib2Cib.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
|||||||
@@ -84,7 +84,6 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
|
|||||||
CPColor _textFieldBackgroundColor;
|
CPColor _textFieldBackgroundColor;
|
||||||
|
|
||||||
id _placeholderString;
|
id _placeholderString;
|
||||||
id _originalPlaceholderString;
|
|
||||||
BOOL _currentValueIsPlaceholder;
|
BOOL _currentValueIsPlaceholder;
|
||||||
|
|
||||||
id _delegate;
|
id _delegate;
|
||||||
@@ -160,6 +159,14 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
|
|||||||
return "textfield";
|
return "textfield";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (Class)_binderClassForBinding:(CPString)theBinding
|
||||||
|
{
|
||||||
|
if (theBinding === CPValueBinding)
|
||||||
|
return [_CPTextFieldValueBinder class];
|
||||||
|
|
||||||
|
return [super _binderClassForBinding:theBinding];
|
||||||
|
}
|
||||||
|
|
||||||
+ (id)themeAttributes
|
+ (id)themeAttributes
|
||||||
{
|
{
|
||||||
return [CPDictionary dictionaryWithObjects:[_CGInsetMakeZero(), _CGInsetMake(2.0, 2.0, 2.0, 2.0), [CPNull null]]
|
return [CPDictionary dictionaryWithObjects:[_CGInsetMakeZero(), _CGInsetMake(2.0, 2.0, 2.0, 2.0), [CPNull null]]
|
||||||
@@ -479,11 +486,15 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
|
|||||||
#if PLATFORM(DOM)
|
#if PLATFORM(DOM)
|
||||||
|
|
||||||
var string = [self stringValue],
|
var string = [self stringValue],
|
||||||
element = [self _inputElement];
|
element = [self _inputElement],
|
||||||
|
font = [self currentValueForThemeAttribute:@"font"];
|
||||||
|
|
||||||
|
// generate the font metric
|
||||||
|
[font _getMetrics];
|
||||||
|
|
||||||
element.value = string;
|
element.value = string;
|
||||||
element.style.color = [[self currentValueForThemeAttribute:@"text-color"] cssString];
|
element.style.color = [[self currentValueForThemeAttribute:@"text-color"] cssString];
|
||||||
element.style.font = [[self currentValueForThemeAttribute:@"font"] cssString];
|
element.style.font = [font cssString];
|
||||||
element.style.zIndex = 1000;
|
element.style.zIndex = 1000;
|
||||||
|
|
||||||
switch ([self alignment])
|
switch ([self alignment])
|
||||||
@@ -495,12 +506,32 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
|
|||||||
default: element.style.textAlign = "left";
|
default: element.style.textAlign = "left";
|
||||||
}
|
}
|
||||||
|
|
||||||
var contentRect = [self contentRectForBounds:[self bounds]];
|
var contentRect = [self contentRectForBounds:[self bounds]],
|
||||||
|
verticalAlign = [self currentValueForThemeAttribute:"vertical-alignment"];
|
||||||
|
|
||||||
element.style.top = _CGRectGetMinY(contentRect) + "px";
|
switch(verticalAlign)
|
||||||
|
{
|
||||||
|
case CPTopVerticalTextAlignment:
|
||||||
|
var topPoint = (_CGRectGetMinY(contentRect) + 1) + "px"; // for the same reason we have a -1 for the left, we also have a + 1 here
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CPCenterVerticalTextAlignment:
|
||||||
|
var topPoint = (_CGRectGetMidY(contentRect) - (font._lineHeight / 2) + 1) + "px";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CPBottomVerticalTextAlignment:
|
||||||
|
var topPoint = (_CGRectGetMaxY(contentRect) - font._lineHeight) + "px";
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
var topPoint = (_CGRectGetMinY(contentRect) + 1) + "px";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
element.style.top = topPoint;
|
||||||
element.style.left = (_CGRectGetMinX(contentRect) - 1) + "px"; // why -1?
|
element.style.left = (_CGRectGetMinX(contentRect) - 1) + "px"; // why -1?
|
||||||
element.style.width = _CGRectGetWidth(contentRect) + "px";
|
element.style.width = _CGRectGetWidth(contentRect) + "px";
|
||||||
element.style.height = _CGRectGetHeight(contentRect) + "px";
|
element.style.height = font._lineHeight + "px"; // private ivar for the line height of the DOM text at this particaulr size
|
||||||
|
|
||||||
_DOMElement.appendChild(element);
|
_DOMElement.appendChild(element);
|
||||||
|
|
||||||
@@ -672,25 +703,87 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
|
|||||||
|
|
||||||
- (void)keyDown:(CPEvent)anEvent
|
- (void)keyDown:(CPEvent)anEvent
|
||||||
{
|
{
|
||||||
if ([anEvent keyCode] === CPReturnKeyCode)
|
if ([anEvent _couldBeKeyEquivalent] && [self performKeyEquivalent:anEvent])
|
||||||
{
|
return;
|
||||||
if (_isEditing)
|
|
||||||
{
|
|
||||||
_isEditing = NO;
|
|
||||||
[self textDidEndEditing:[CPNotification notificationWithName:CPControlTextDidEndEditingNotification object:self userInfo:nil]];
|
|
||||||
}
|
|
||||||
|
|
||||||
[self sendAction:[self action] to:[self target]];
|
// CPTextField uses an HTML input element to take the input so we need to
|
||||||
[self selectText:nil];
|
// propagate the dom event so the element is updated. This has to be done
|
||||||
|
// before interpretKeyEvents: though so individual commands have a chance
|
||||||
|
// to override this (escape to clear the text in a search field for example).
|
||||||
|
[[[self window] platformWindow] _propagateCurrentDOMEvent:YES];
|
||||||
|
|
||||||
[[[self window] platformWindow] _propagateCurrentDOMEvent:NO];
|
[self interpretKeyEvents:[anEvent]];
|
||||||
}
|
|
||||||
else
|
|
||||||
[[[self window] platformWindow] _propagateCurrentDOMEvent:YES];
|
|
||||||
|
|
||||||
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
|
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Invoke the action specified by aSelector on the current responder.
|
||||||
|
|
||||||
|
This is implemented by CPResponder and by default it passes any unrecignized
|
||||||
|
actions on to the next responder but text fields appearently aren't supposed
|
||||||
|
to do that according to this documentation by Apple:
|
||||||
|
|
||||||
|
http://developer.apple.com/mac/library/documentation/cocoa/reference/NSTextInputClient_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/NSTextInputClient/doCommandBySelector:
|
||||||
|
*/
|
||||||
|
- (void)doCommandBySelector:(SEL)aSelector
|
||||||
|
{
|
||||||
|
if ([self respondsToSelector:aSelector])
|
||||||
|
[self performSelector:aSelector];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)insertNewline:(id)sender
|
||||||
|
{
|
||||||
|
if (_isEditing)
|
||||||
|
{
|
||||||
|
_isEditing = NO;
|
||||||
|
[self textDidEndEditing:[CPNotification notificationWithName:CPControlTextDidEndEditingNotification object:self userInfo:nil]];
|
||||||
|
}
|
||||||
|
|
||||||
|
[self sendAction:[self action] to:[self target]];
|
||||||
|
[self selectText:nil];
|
||||||
|
|
||||||
|
[[[self window] platformWindow] _propagateCurrentDOMEvent:NO];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)insertNewlineIgnoringFieldEditor:(id)sender
|
||||||
|
{
|
||||||
|
var oldValue = [self stringValue];
|
||||||
|
|
||||||
|
[self _inputElement].value += CPNewlineCharacter;
|
||||||
|
[self _setStringValue:[self _inputElement].value];
|
||||||
|
|
||||||
|
if (oldValue !== [self stringValue])
|
||||||
|
{
|
||||||
|
if (!_isEditing)
|
||||||
|
{
|
||||||
|
_isEditing = YES;
|
||||||
|
[self textDidBeginEditing:[CPNotification notificationWithName:CPControlTextDidBeginEditingNotification object:self userInfo:nil]];
|
||||||
|
}
|
||||||
|
|
||||||
|
[self textDidChange:[CPNotification notificationWithName:CPControlTextDidChangeNotification object:self userInfo:nil]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)insertTabIgnoringFieldEditor:(id)sender
|
||||||
|
{
|
||||||
|
var oldValue = [self stringValue];
|
||||||
|
|
||||||
|
[self _inputElement].value += CPTabCharacter;
|
||||||
|
[self _setStringValue:[self _inputElement].value];
|
||||||
|
|
||||||
|
if (oldValue !== [self stringValue])
|
||||||
|
{
|
||||||
|
if (!_isEditing)
|
||||||
|
{
|
||||||
|
_isEditing = YES;
|
||||||
|
[self textDidBeginEditing:[CPNotification notificationWithName:CPControlTextDidBeginEditingNotification object:self userInfo:nil]];
|
||||||
|
}
|
||||||
|
|
||||||
|
[self textDidChange:[CPNotification notificationWithName:CPControlTextDidChangeNotification object:self userInfo:nil]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (void)textDidBlur:(CPNotification)note
|
- (void)textDidBlur:(CPNotification)note
|
||||||
{
|
{
|
||||||
// this looks to prevent false propagation of notifications for other objects
|
// this looks to prevent false propagation of notifications for other objects
|
||||||
@@ -728,6 +821,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
@ignore
|
@ignore
|
||||||
|
Sets the internal string value without updating the value in the input element
|
||||||
*/
|
*/
|
||||||
- (void)_setStringValue:(id)aValue
|
- (void)_setStringValue:(id)aValue
|
||||||
{
|
{
|
||||||
@@ -787,34 +881,6 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
|
|||||||
return _placeholderString;
|
return _placeholderString;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)_setCurrentValueIsPlaceholder:(BOOL)isPlaceholder
|
|
||||||
{
|
|
||||||
// The initial _currentValueIsPlaceholder is null so convert it to NO for comparison purposes.
|
|
||||||
if (!!_currentValueIsPlaceholder === isPlaceholder)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (isPlaceholder)
|
|
||||||
{
|
|
||||||
// Save the original placeholder value so we can restore it later
|
|
||||||
// Only do this if the placeholder is not already overridden because the bindings logic might call this method
|
|
||||||
// several times and we don't want the bindings placeholder to ever become the original placeholder
|
|
||||||
if (!_currentValueIsPlaceholder)
|
|
||||||
_originalPlaceholderString = [self placeholderString];
|
|
||||||
|
|
||||||
// Set the current string value as the current placeholder and clear the string value
|
|
||||||
[self setPlaceholderString:[self stringValue]];
|
|
||||||
[self setStringValue:@""];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Restore the original placeholder, the actual textfield value is already correct
|
|
||||||
// because it was set using setValue:forKey:
|
|
||||||
[self setPlaceholderString:_originalPlaceholderString];
|
|
||||||
}
|
|
||||||
|
|
||||||
_currentValueIsPlaceholder = isPlaceholder;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
For non-bezeled text fields (typically a label), sizeToFit has two behaviors, depending
|
For non-bezeled text fields (typically a label), sizeToFit has two behaviors, depending
|
||||||
on the line break mode of the receiver.
|
on the line break mode of the receiver.
|
||||||
@@ -885,21 +951,28 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Select all the text in the CPTextField.
|
Make the receiver the first responder and select all the text in the field.
|
||||||
*/
|
*/
|
||||||
- (void)selectText:(id)sender
|
- (void)selectText:(id)sender
|
||||||
{
|
{
|
||||||
#if PLATFORM(DOM)
|
// FIXME Should this really make the text field the first responder?
|
||||||
var element = [self _inputElement];
|
|
||||||
|
|
||||||
if (([self isEditable] || [self isSelectable]))
|
if (([self isEditable] || [self isSelectable]))
|
||||||
{
|
{
|
||||||
|
#if PLATFORM(DOM)
|
||||||
|
var element = [self _inputElement];
|
||||||
|
|
||||||
if ([[self window] firstResponder] === self)
|
if ([[self window] firstResponder] === self)
|
||||||
window.setTimeout(function() { element.select(); }, 0);
|
window.setTimeout(function() { element.select(); }, 0);
|
||||||
else if ([self window] !== nil && [[self window] makeFirstResponder:self])
|
else if ([self window] !== nil && [[self window] makeFirstResponder:self])
|
||||||
window.setTimeout(function() {[self selectText:sender];}, 0);
|
window.setTimeout(function() {[self selectText:sender];}, 0);
|
||||||
}
|
#else
|
||||||
|
// Even if we can't actually select the text we need to preserve the first
|
||||||
|
// responder side effect.
|
||||||
|
if ([self window] !== nil && [[self window] firstResponder] !== self)
|
||||||
|
[[self window] makeFirstResponder:self];
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)copy:(id)sender
|
- (void)copy:(id)sender
|
||||||
@@ -981,7 +1054,7 @@ CPTextFieldStatePlaceholder = CPThemeState("placeholder");
|
|||||||
// fall through to the return
|
// fall through to the return
|
||||||
}
|
}
|
||||||
|
|
||||||
return CGMakeRange(0, 0);
|
return CPMakeRange(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setSelectedRange:(CPRange)aRange
|
- (void)setSelectedRange:(CPRange)aRange
|
||||||
@@ -1262,18 +1335,6 @@ var CPTextFieldIsEditableKey = "CPTextFieldIsEditableKey",
|
|||||||
[self setAlignment:[aCoder decodeIntForKey:CPTextFieldAlignmentKey]];
|
[self setAlignment:[aCoder decodeIntForKey:CPTextFieldAlignmentKey]];
|
||||||
|
|
||||||
[self setPlaceholderString:[aCoder decodeObjectForKey:CPTextFieldPlaceholderStringKey]];
|
[self setPlaceholderString:[aCoder decodeObjectForKey:CPTextFieldPlaceholderStringKey]];
|
||||||
|
|
||||||
// Make sure the frame is big enough
|
|
||||||
var minSize = [self _minimumFrameSize];
|
|
||||||
minSize.width = MAX(CGRectGetWidth([self frame]), minSize.width);
|
|
||||||
minSize.height = MAX(CGRectGetHeight([self frame]), minSize.height);
|
|
||||||
|
|
||||||
// Only size multiline bezeled textfields if it's to small to fit the content
|
|
||||||
if ([self isBezeled])
|
|
||||||
if ([self lineBreakMode] === CPLineBreakByCharWrapping || [self lineBreakMode] == CPLineBreakByWordWrapping)
|
|
||||||
minSize.height = MAX(CGRectGetHeight([self frame]), minSize.height);
|
|
||||||
|
|
||||||
[self setFrameSize:minSize];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
@@ -1302,3 +1363,48 @@ var CPTextFieldIsEditableKey = "CPTextFieldIsEditableKey",
|
|||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@implementation _CPTextFieldValueBinder : CPBinder
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setValueFor:(CPString)theBinding
|
||||||
|
{
|
||||||
|
var destination = [_info objectForKey:CPObservedObjectKey],
|
||||||
|
keyPath = [_info objectForKey:CPObservedKeyPathKey],
|
||||||
|
options = [_info objectForKey:CPOptionsKey],
|
||||||
|
newValue = [destination valueForKeyPath:keyPath],
|
||||||
|
isPlaceholder = CPIsControllerMarker(newValue);
|
||||||
|
|
||||||
|
if (isPlaceholder)
|
||||||
|
{
|
||||||
|
switch (newValue)
|
||||||
|
{
|
||||||
|
case CPMultipleValuesMarker:
|
||||||
|
newValue = [options objectForKey:CPMultipleValuesPlaceholderBindingOption] || @"Multiple Values";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CPNoSelectionMarker:
|
||||||
|
newValue = [options objectForKey:CPNoSelectionPlaceholderBindingOption] || @"No Selection";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CPNotApplicableMarker:
|
||||||
|
if ([options objectForKey:CPRaisesForNotApplicableKeysBindingOption])
|
||||||
|
[CPException raise:CPGenericException
|
||||||
|
reason:@"can't transform non applicable key on: "+_source+" value: "+newValue];
|
||||||
|
|
||||||
|
newValue = [options objectForKey:CPNotApplicablePlaceholderBindingOption] || @"Not Applicable";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
[_source setPlaceholderString:newValue];
|
||||||
|
[_source setObjectValue:nil];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
newValue = [self transformValue:newValue withOptions:options];
|
||||||
|
[_source setObjectValue:newValue];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
|||||||
@@ -405,6 +405,7 @@ function CPThemeStateName(aState)
|
|||||||
CPThemeStateNames[0] = "normal";
|
CPThemeStateNames[0] = "normal";
|
||||||
CPThemeStateNormal = CPThemeStates["normal"] = 0;
|
CPThemeStateNormal = CPThemeStates["normal"] = 0;
|
||||||
CPThemeStateDisabled = CPThemeState("disabled");
|
CPThemeStateDisabled = CPThemeState("disabled");
|
||||||
|
CPThemeStateHovered = CPThemeState("hovered");
|
||||||
CPThemeStateHighlighted = CPThemeState("highlighted");
|
CPThemeStateHighlighted = CPThemeState("highlighted");
|
||||||
CPThemeStateSelected = CPThemeState("selected");
|
CPThemeStateSelected = CPThemeState("selected");
|
||||||
CPThemeStateTableDataView = CPThemeState("tableDataView");
|
CPThemeStateTableDataView = CPThemeState("tableDataView");
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
@import "CPButton.j"
|
@import "CPButton.j"
|
||||||
@import "CPScrollView.j"
|
@import "CPScrollView.j"
|
||||||
@import "CPTextField.j"
|
@import "CPTextField.j"
|
||||||
|
@import "CPTableView.j"
|
||||||
@import "CPWindow.j"
|
@import "CPWindow.j"
|
||||||
@import "_CPMenuWindow.j"
|
@import "_CPMenuWindow.j"
|
||||||
|
|
||||||
@@ -79,6 +80,7 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting",
|
|||||||
CPEvent _mouseDownEvent;
|
CPEvent _mouseDownEvent;
|
||||||
|
|
||||||
BOOL _preventResign;
|
BOOL _preventResign;
|
||||||
|
BOOL _shouldNotifyTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (CPCharacterSet)defaultTokenizingCharacterSet
|
+ (CPCharacterSet)defaultTokenizingCharacterSet
|
||||||
@@ -208,10 +210,7 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting",
|
|||||||
[self _inputElement].value = @"";
|
[self _inputElement].value = @"";
|
||||||
[self setNeedsLayout];
|
[self setNeedsLayout];
|
||||||
|
|
||||||
var theBinding = [CPKeyValueBinding getBinding:CPValueBinding forObject:self];
|
[self _controlTextDidChange];
|
||||||
|
|
||||||
if (theBinding)
|
|
||||||
[theBinding reverseSetValueFor:@"objectValue"];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)_autocomplete
|
- (void)_autocomplete
|
||||||
@@ -265,12 +264,15 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting",
|
|||||||
|
|
||||||
- (void)_controlTextDidChange
|
- (void)_controlTextDidChange
|
||||||
{
|
{
|
||||||
var theBinding = [CPKeyValueBinding getBinding:CPValueBinding forObject:self];
|
var binderClass = [[self class] _binderClassForBinding:CPValueBinding],
|
||||||
|
theBinding = [binderClass getBinding:CPValueBinding forObject:self];
|
||||||
|
|
||||||
if (theBinding)
|
if (theBinding)
|
||||||
[theBinding reverseSetValueFor:@"objectValue"];
|
[theBinding reverseSetValueFor:@"objectValue"];
|
||||||
|
|
||||||
[self textDidChange:[CPNotification notificationWithName:CPControlTextDidChangeNotification object:self userInfo:nil]];
|
[self textDidChange:[CPNotification notificationWithName:CPControlTextDidChangeNotification object:self userInfo:nil]];
|
||||||
|
|
||||||
|
_shouldNotifyTarget = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)_removeSelectedTokens:(id)sender
|
- (void)_removeSelectedTokens:(id)sender
|
||||||
@@ -401,7 +403,14 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting",
|
|||||||
|
|
||||||
[self setNeedsLayout];
|
[self setNeedsLayout];
|
||||||
|
|
||||||
[self textDidEndEditing:[CPNotification notificationWithName:CPControlTextDidBeginEditingNotification object:self userInfo:nil]];
|
if (_shouldNotifyTarget)
|
||||||
|
{
|
||||||
|
_shouldNotifyTarget = NO;
|
||||||
|
[self textDidEndEditing:[CPNotification notificationWithName:CPControlTextDidEndEditingNotification object:self userInfo:nil]];
|
||||||
|
|
||||||
|
if ([self sendsActionOnEndEditing])
|
||||||
|
[self sendAction:[self action] to:[self target]];
|
||||||
|
}
|
||||||
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
@@ -465,7 +474,7 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting",
|
|||||||
if ([token isKindOfClass:[CPString class]])
|
if ([token isKindOfClass:[CPString class]])
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
[objectValue addObject:[token stringValue]];
|
[objectValue addObject:[token representedObject]];
|
||||||
}
|
}
|
||||||
|
|
||||||
#if PLATFORM(DOM)
|
#if PLATFORM(DOM)
|
||||||
@@ -501,13 +510,14 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting",
|
|||||||
for (var i = 0, count = [aValue count]; i < count; i++)
|
for (var i = 0, count = [aValue count]; i < count; i++)
|
||||||
{
|
{
|
||||||
// Do we have this token among the old ones?
|
// Do we have this token among the old ones?
|
||||||
var tokenValue = aValue[i],
|
var tokenObject = aValue[i],
|
||||||
|
tokenValue = [self tokenField:self displayStringForRepresentedObject:tokenObject],
|
||||||
newToken = nil;
|
newToken = nil;
|
||||||
|
|
||||||
for (var j = 0, oldCount = [oldTokens count]; j < oldCount; j++)
|
for (var j = 0, oldCount = [oldTokens count]; j < oldCount; j++)
|
||||||
{
|
{
|
||||||
var oldToken = oldTokens[j];
|
var oldToken = oldTokens[j];
|
||||||
if ([oldToken stringValue] == tokenValue)
|
if ([oldToken representedObject] == tokenObject)
|
||||||
{
|
{
|
||||||
// Yep. Reuse it.
|
// Yep. Reuse it.
|
||||||
[oldTokens removeObjectAtIndex:j];
|
[oldTokens removeObjectAtIndex:j];
|
||||||
@@ -520,6 +530,7 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting",
|
|||||||
{
|
{
|
||||||
newToken = [[_CPTokenFieldToken alloc] init];
|
newToken = [[_CPTokenFieldToken alloc] init];
|
||||||
[newToken setTokenField:self];
|
[newToken setTokenField:self];
|
||||||
|
[newToken setRepresentedObject:tokenObject];
|
||||||
[newToken setStringValue:tokenValue];
|
[newToken setStringValue:tokenValue];
|
||||||
[contentView addSubview:newToken];
|
[contentView addSubview:newToken];
|
||||||
}
|
}
|
||||||
@@ -552,6 +563,12 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting",
|
|||||||
[self setNeedsDisplay:YES];
|
[self setNeedsDisplay:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)sendAction:(SEL)anAction to:(id)anObject
|
||||||
|
{
|
||||||
|
_shouldNotifyTarget = NO;
|
||||||
|
[super sendAction:anAction to:anObject];
|
||||||
|
}
|
||||||
|
|
||||||
// Incredible hack to disable supers implementation
|
// Incredible hack to disable supers implementation
|
||||||
// so it cannot change our object value and break the tokenfield
|
// so it cannot change our object value and break the tokenfield
|
||||||
- (void)_setStringValue:(id)aValue
|
- (void)_setStringValue:(id)aValue
|
||||||
@@ -1074,7 +1091,7 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting",
|
|||||||
|
|
||||||
- (void)tableView:(CPTableView)tableView objectValueForTableColumn:(CPTableColumn)tableColumn row:(int)row
|
- (void)tableView:(CPTableView)tableView objectValueForTableColumn:(CPTableColumn)tableColumn row:(int)row
|
||||||
{
|
{
|
||||||
return [_cachedCompletions objectAtIndex:row];
|
return [self tokenField:self displayStringForRepresentedObject:[_cachedCompletions objectAtIndex:row]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)tableViewSelectionDidChange:(CPNotification)notification
|
- (void)tableViewSelectionDidChange:(CPNotification)notification
|
||||||
@@ -1111,6 +1128,23 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting",
|
|||||||
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// // Alows the delegate to provide a string to be displayed as a proxy for the given represented object.
|
||||||
|
// // If you return nil or do not implement this method, then representedObject is displayed as the string.
|
||||||
|
- (CPString)tokenField:(CPTokenField)tokenField displayStringForRepresentedObject:(id)representedObject
|
||||||
|
{
|
||||||
|
if ([[self delegate] respondsToSelector:@selector(tokenField:displayStringForRepresentedObject:)])
|
||||||
|
{
|
||||||
|
var stringForRepresentedObject = [[self delegate] tokenField:tokenField displayStringForRepresentedObject:representedObject];
|
||||||
|
if (stringForRepresentedObject !== nil)
|
||||||
|
{
|
||||||
|
return stringForRepresentedObject;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return representedObject;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// // return an array of represented objects you want to add.
|
// // return an array of represented objects you want to add.
|
||||||
// // If you want to reject the add, return an empty array.
|
// // If you want to reject the add, return an empty array.
|
||||||
@@ -1119,7 +1153,6 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting",
|
|||||||
//
|
//
|
||||||
// // If you return nil or don't implement these delegate methods, we will assume
|
// // If you return nil or don't implement these delegate methods, we will assume
|
||||||
// // editing string = display string = represented object
|
// // editing string = display string = represented object
|
||||||
// - (NSString *)tokenField:(NSTokenField *)tokenField displayStringForRepresentedObject:(id)representedObject;
|
|
||||||
// - (NSString *)tokenField:(NSTokenField *)tokenField editingStringForRepresentedObject:(id)representedObject;
|
// - (NSString *)tokenField:(NSTokenField *)tokenField editingStringForRepresentedObject:(id)representedObject;
|
||||||
// - (id)tokenField:(NSTokenField *)tokenField representedObjectForEditingString: (NSString *)editingString;
|
// - (id)tokenField:(NSTokenField *)tokenField representedObjectForEditingString: (NSString *)editingString;
|
||||||
//
|
//
|
||||||
@@ -1143,6 +1176,7 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting",
|
|||||||
{
|
{
|
||||||
_CPTokenFieldTokenCloseButton _deleteButton;
|
_CPTokenFieldTokenCloseButton _deleteButton;
|
||||||
CPTokenField _tokenField;
|
CPTokenField _tokenField;
|
||||||
|
id _representedObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (CPString)defaultThemeClass
|
+ (CPString)defaultThemeClass
|
||||||
@@ -1175,6 +1209,16 @@ var CPThemeStateAutoCompleting = @"CPThemeStateAutoCompleting",
|
|||||||
_tokenField = tokenField;
|
_tokenField = tokenField;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (id)representedObject
|
||||||
|
{
|
||||||
|
return _representedObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setRepresentedObject:(id)representedObject
|
||||||
|
{
|
||||||
|
_representedObject = representedObject;
|
||||||
|
}
|
||||||
|
|
||||||
- (CGSize)_minimumFrameSize
|
- (CGSize)_minimumFrameSize
|
||||||
{
|
{
|
||||||
var size = CGSizeMakeZero(),
|
var size = CGSizeMakeZero(),
|
||||||
|
|||||||
@@ -50,8 +50,8 @@ CPToolbarDisplayModeIconOnly = 2;
|
|||||||
*/
|
*/
|
||||||
CPToolbarDisplayModeLabelOnly = 3;
|
CPToolbarDisplayModeLabelOnly = 3;
|
||||||
|
|
||||||
var CPToolbarsByIdentifier = nil;
|
var CPToolbarsByIdentifier = nil,
|
||||||
var CPToolbarConfigurationsByIdentifier = nil;
|
CPToolbarConfigurationsByIdentifier = nil;
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ingroup appkit
|
@ingroup appkit
|
||||||
@@ -667,7 +667,7 @@ var _CPToolbarItemInfoMake = function(anIndex, aView, aLabel, aMinWidth)
|
|||||||
|
|
||||||
// Determine all the items that have flexible width.
|
// Determine all the items that have flexible width.
|
||||||
// Also determine the height of the toolbar.
|
// Also determine the height of the toolbar.
|
||||||
var count = _visibleItems.length
|
var count = _visibleItems.length,
|
||||||
flexibleItemIndexes = [CPIndexSet indexSet];
|
flexibleItemIndexes = [CPIndexSet indexSet];
|
||||||
|
|
||||||
while (count--)
|
while (count--)
|
||||||
@@ -799,10 +799,11 @@ var _CPToolbarItemInfoMake = function(anIndex, aView, aLabel, aMinWidth)
|
|||||||
|
|
||||||
hasNonSeparatorItem = YES;
|
hasNonSeparatorItem = YES;
|
||||||
|
|
||||||
var menuItem = [[CPMenuItem alloc] initWithTitle:[item label] action:[item action] keyEquivalent:nil];
|
var menuItem = [[CPMenuItem alloc] initWithTitle:[item label] action:@selector(didSelectMenuItem:) keyEquivalent:nil];
|
||||||
|
|
||||||
|
[menuItem setRepresentedObject:item];
|
||||||
[menuItem setImage:[item image]];
|
[menuItem setImage:[item image]];
|
||||||
[menuItem setTarget:[item target]];
|
[menuItem setTarget:self];
|
||||||
[menuItem setEnabled:[item isEnabled]];
|
[menuItem setEnabled:[item isEnabled]];
|
||||||
|
|
||||||
[_additionalItemsButton addItem:menuItem];
|
[_additionalItemsButton addItem:menuItem];
|
||||||
@@ -812,6 +813,18 @@ var _CPToolbarItemInfoMake = function(anIndex, aView, aLabel, aMinWidth)
|
|||||||
[_additionalItemsButton removeFromSuperview];
|
[_additionalItemsButton removeFromSuperview];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Used privately.
|
||||||
|
@ignore
|
||||||
|
*/
|
||||||
|
|
||||||
|
- (void)didSelectMenuItem:(id)aSender
|
||||||
|
{
|
||||||
|
var toolbarItem = [aSender representedObject];
|
||||||
|
|
||||||
|
[CPApp sendAction:[toolbarItem action] to:[toolbarItem target] from:toolbarItem];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)reloadToolbarItems
|
- (void)reloadToolbarItems
|
||||||
{
|
{
|
||||||
// Get rid of all our current subviews.
|
// Get rid of all our current subviews.
|
||||||
|
|||||||
@@ -386,7 +386,7 @@ CPToolbarPrintItemIdentifier = @"CPToolbarPrintItem";
|
|||||||
*/
|
*/
|
||||||
- (void)setMinSize:(CGSize)aMinSize
|
- (void)setMinSize:(CGSize)aMinSize
|
||||||
{
|
{
|
||||||
if(!aMinSize.height || !aMinSize.width)
|
if (!aMinSize.height || !aMinSize.width)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_minSize = CGSizeMakeCopy(aMinSize);
|
_minSize = CGSizeMakeCopy(aMinSize);
|
||||||
@@ -409,7 +409,7 @@ CPToolbarPrintItemIdentifier = @"CPToolbarPrintItem";
|
|||||||
*/
|
*/
|
||||||
- (void)setMaxSize:(CGSize)aMaxSize
|
- (void)setMaxSize:(CGSize)aMaxSize
|
||||||
{
|
{
|
||||||
if(!aMaxSize.height || !aMaxSize.width)
|
if (!aMaxSize.height || !aMaxSize.width)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_maxSize = CGSizeMakeCopy(aMaxSize);
|
_maxSize = CGSizeMakeCopy(aMaxSize);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
@import <Foundation/CPObject.j>
|
@import <Foundation/CPObject.j>
|
||||||
|
@import <Foundation/CPIndexPath.j>
|
||||||
|
|
||||||
|
|
||||||
@implementation CPTreeNode : CPObject
|
@implementation CPTreeNode : CPObject
|
||||||
@@ -87,6 +88,18 @@
|
|||||||
[_childNodes[count] sortWithSortDescriptors:sortDescriptors recursively:YES];
|
[_childNodes[count] sortWithSortDescriptors:sortDescriptors recursively:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (CPTreeNode)descendantNodeAtIndexPath:(CPIndexPath)indexPath
|
||||||
|
{
|
||||||
|
var index = 0,
|
||||||
|
count = [indexPath length],
|
||||||
|
node = self;
|
||||||
|
|
||||||
|
for (; index < count; ++index)
|
||||||
|
node = [node objectInChildNodesAtIndex:[indexPath indexAtPosition:index]];
|
||||||
|
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
var CPTreeNodeRepresentedObjectKey = @"CPTreeNodeRepresentedObjectKey",
|
var CPTreeNodeRepresentedObjectKey = @"CPTreeNodeRepresentedObjectKey",
|
||||||
|
|||||||
@@ -1566,6 +1566,16 @@ var CPViewFlags = { },
|
|||||||
return CGPointApplyAffineTransform(aPoint, _CPViewGetTransform(aView, self));
|
return CGPointApplyAffineTransform(aPoint, _CPViewGetTransform(aView, self));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Converts the point from the base coordinate system to the receiver’s coordinate system.
|
||||||
|
@param aPoint A point specifying a location in the base coordinate system
|
||||||
|
@return The point converted to the receiver’s base coordinate system
|
||||||
|
*/
|
||||||
|
- (CGPoint)convertPointFromBase:(CGPoint)aPoint
|
||||||
|
{
|
||||||
|
return CGPointApplyAffineTransform(aPoint, _CPViewGetTransform(nil, self));
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Converts \c aPoint from the receiver's coordinate space to the coordinate space of \c aView.
|
Converts \c aPoint from the receiver's coordinate space to the coordinate space of \c aView.
|
||||||
@param aPoint the point to convert
|
@param aPoint the point to convert
|
||||||
@@ -1577,6 +1587,16 @@ var CPViewFlags = { },
|
|||||||
return CGPointApplyAffineTransform(aPoint, _CPViewGetTransform(self, aView));
|
return CGPointApplyAffineTransform(aPoint, _CPViewGetTransform(self, aView));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Converts the point from the receiver’s coordinate system to the base coordinate system.
|
||||||
|
@param aPoint A point specifying a location in the coordinate system of the receiver
|
||||||
|
@return The point converted to the base coordinate system
|
||||||
|
*/
|
||||||
|
- (CGPoint)convertPointToBase:(CGPoint)aPoint
|
||||||
|
{
|
||||||
|
return CGPointApplyAffineTransform(aPoint, _CPViewGetTransform(self, nil));
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Convert's \c aSize from \c aView's coordinate space to the receiver's coordinate space.
|
Convert's \c aSize from \c aView's coordinate space to the receiver's coordinate space.
|
||||||
@param aSize the size to convert
|
@param aSize the size to convert
|
||||||
@@ -1610,6 +1630,16 @@ var CPViewFlags = { },
|
|||||||
return CGRectApplyAffineTransform(aRect, _CPViewGetTransform(aView, self));
|
return CGRectApplyAffineTransform(aRect, _CPViewGetTransform(aView, self));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Converts the rectangle from the base coordinate system to the receiver’s coordinate system.
|
||||||
|
@param aRect A rectangle specifying a location in the base coordinate system
|
||||||
|
@return The rectangle converted to the receiver’s base coordinate system
|
||||||
|
*/
|
||||||
|
- (CGRect)convertRectFromBase:(CGRect)aRect
|
||||||
|
{
|
||||||
|
return CGRectApplyAffineTransform(aRect, _CPViewGetTransform(nil, self));
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Converts \c aRect from the receiver's coordinate space to \c aView's coordinate space.
|
Converts \c aRect from the receiver's coordinate space to \c aView's coordinate space.
|
||||||
@param aRect the rectangle to convert
|
@param aRect the rectangle to convert
|
||||||
@@ -1621,6 +1651,16 @@ var CPViewFlags = { },
|
|||||||
return CGRectApplyAffineTransform(aRect, _CPViewGetTransform(self, aView));
|
return CGRectApplyAffineTransform(aRect, _CPViewGetTransform(self, aView));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Converts the rectangle from the receiver’s coordinate system to the base coordinate system.
|
||||||
|
@param aRect A rectangle specifying a location in the coordinate system of the receiver
|
||||||
|
@return The rectangle converted to the base coordinate system
|
||||||
|
*/
|
||||||
|
- (CGRect)convertRectToBase:(CGRect)aRect
|
||||||
|
{
|
||||||
|
return CGRectApplyAffineTransform(aRect, _CPViewGetTransform(self, nil));
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Sets whether the receiver posts a CPViewFrameDidChangeNotification notification
|
Sets whether the receiver posts a CPViewFrameDidChangeNotification notification
|
||||||
to the default notification center when its frame is changed. The default is \c NO.
|
to the default notification center when its frame is changed. The default is \c NO.
|
||||||
@@ -2105,11 +2145,18 @@ setBoundsOrigin:
|
|||||||
|
|
||||||
- (CPView)nextValidKeyView
|
- (CPView)nextValidKeyView
|
||||||
{
|
{
|
||||||
var result = [self nextKeyView];
|
var result = [self nextKeyView],
|
||||||
|
firstResult = result;
|
||||||
|
|
||||||
while (result && ![result canBecomeKeyView])
|
while (result && ![result canBecomeKeyView])
|
||||||
|
{
|
||||||
result = [result nextKeyView];
|
result = [result nextKeyView];
|
||||||
|
|
||||||
|
// Cycled.
|
||||||
|
if (result === firstResult)
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2213,6 +2260,10 @@ setBoundsOrigin:
|
|||||||
|
|
||||||
- (BOOL)hasThemeState:(CPThemeState)aState
|
- (BOOL)hasThemeState:(CPThemeState)aState
|
||||||
{
|
{
|
||||||
|
// Because CPThemeStateNormal is defined as 0 we need to check for it explicitly here
|
||||||
|
if (aState === CPThemeStateNormal && _themeState === CPThemeStateNormal)
|
||||||
|
return YES;
|
||||||
|
|
||||||
return !!(_themeState & ((typeof aState === "string") ? CPThemeState(aState) : aState));
|
return !!(_themeState & ((typeof aState === "string") ? CPThemeState(aState) : aState));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2469,7 +2520,7 @@ setBoundsOrigin:
|
|||||||
|
|
||||||
var frame = [self rectForEphemeralSubviewNamed:aViewName];
|
var frame = [self rectForEphemeralSubviewNamed:aViewName];
|
||||||
|
|
||||||
if (frame && !_CGRectIsEmpty(frame))
|
if (frame)
|
||||||
{
|
{
|
||||||
if (!_ephemeralSubviewsForNames[aViewName])
|
if (!_ephemeralSubviewsForNames[aViewName])
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -23,13 +23,13 @@
|
|||||||
@import "CPAnimation.j"
|
@import "CPAnimation.j"
|
||||||
|
|
||||||
|
|
||||||
CPViewAnimationTargetKey = @"CPViewAnimationTarget";
|
CPViewAnimationTargetKey = @"CPViewAnimationTargetKey";
|
||||||
CPViewAnimationStartFrameKey = @"CPViewAnimationStartFrame";
|
CPViewAnimationStartFrameKey = @"CPViewAnimationStartFrameKey";
|
||||||
CPViewAnimationEndFrameKey = @"CPViewAnimationEndFrame";
|
CPViewAnimationEndFrameKey = @"CPViewAnimationEndFrameKey";
|
||||||
CPViewAnimationEffectKey = @"CPViewAnimationEffect";
|
CPViewAnimationEffectKey = @"CPViewAnimationEffectKey";
|
||||||
|
|
||||||
CPViewAnimationFadeInEffect = @"CPViewAnimationFadeIn";
|
CPViewAnimationFadeInEffect = @"CPViewAnimationFadeInEffect";
|
||||||
CPViewAnimationFadeOutEffect = @"CPViewAnimationFadeOut";
|
CPViewAnimationFadeOutEffect = @"CPViewAnimationFadeOutEffect";
|
||||||
|
|
||||||
@implementation CPViewAnimation : CPAnimation
|
@implementation CPViewAnimation : CPAnimation
|
||||||
{
|
{
|
||||||
@@ -61,7 +61,7 @@ CPViewAnimationFadeOutEffect = @"CPViewAnimationFadeOut";
|
|||||||
if (effect === CPViewAnimationFadeInEffect)
|
if (effect === CPViewAnimationFadeInEffect)
|
||||||
{
|
{
|
||||||
[view setAlphaValue:0.0];
|
[view setAlphaValue:0.0];
|
||||||
[view setHidden:NO];
|
[self _targetView:view setHidden:NO];
|
||||||
}
|
}
|
||||||
else if (effect === CPViewAnimationFadeOutEffect)
|
else if (effect === CPViewAnimationFadeOutEffect)
|
||||||
[view setAlphaValue:1.0];
|
[view setAlphaValue:1.0];
|
||||||
@@ -104,7 +104,7 @@ CPViewAnimationFadeOutEffect = @"CPViewAnimationFadeOut";
|
|||||||
[view setAlphaValue:1.0 + ( 0.0 - 1.0 ) * progress];
|
[view setAlphaValue:1.0 + ( 0.0 - 1.0 ) * progress];
|
||||||
|
|
||||||
if (progress === 1.0)
|
if (progress === 1.0)
|
||||||
[view setHidden:_CGRectIsNull(endFrame) || [view alphaValue] === 0.0];
|
[self _targetView:view setHidden:_CGRectIsNull(endFrame) || [view alphaValue] === 0.0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,12 +125,25 @@ CPViewAnimationFadeOutEffect = @"CPViewAnimationFadeOut";
|
|||||||
else if (effect === CPViewAnimationFadeOutEffect)
|
else if (effect === CPViewAnimationFadeOutEffect)
|
||||||
[view setAlphaValue:0.0];
|
[view setAlphaValue:0.0];
|
||||||
|
|
||||||
[view setHidden:_CGRectIsNull(endFrame) || [view alphaValue] === 0.0];
|
[self _targetView:view setHidden:_CGRectIsNull(endFrame) || [view alphaValue] === 0.0];
|
||||||
}
|
}
|
||||||
|
|
||||||
[super stopAnimation];
|
[super stopAnimation];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)_targetView:(id)theView setHidden:(BOOL)isHidden
|
||||||
|
{
|
||||||
|
if ([theView isKindOfClass:[CPWindow class]])
|
||||||
|
{
|
||||||
|
if (isHidden)
|
||||||
|
[theView orderOut:self];
|
||||||
|
else
|
||||||
|
[theView orderFront:self];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
[theView setHidden:isHidden];
|
||||||
|
}
|
||||||
|
|
||||||
- (id)_targetView:(CPDictionary)dictionary
|
- (id)_targetView:(CPDictionary)dictionary
|
||||||
{
|
{
|
||||||
var targetView = [dictionary valueForKey:CPViewAnimationTargetKey];
|
var targetView = [dictionary valueForKey:CPViewAnimationTargetKey];
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ CPWebViewScrollNative = 2;
|
|||||||
_ignoreLoadEnd = YES;
|
_ignoreLoadEnd = YES;
|
||||||
|
|
||||||
_iframe = document.createElement("iframe");
|
_iframe = document.createElement("iframe");
|
||||||
_iframe.name = "iframe_" + Math.floor(Math.random()*10000);
|
_iframe.name = "iframe_" + FLOOR(RAND() * 10000);
|
||||||
_iframe.style.width = "100%";
|
_iframe.style.width = "100%";
|
||||||
_iframe.style.height = "100%";
|
_iframe.style.height = "100%";
|
||||||
_iframe.style.borderWidth = "0px";
|
_iframe.style.borderWidth = "0px";
|
||||||
@@ -116,47 +116,46 @@ CPWebViewScrollNative = 2;
|
|||||||
[self setDrawsBackground:YES];
|
[self setDrawsBackground:YES];
|
||||||
|
|
||||||
_loadCallback = function() {
|
_loadCallback = function() {
|
||||||
// HACK: this block handles the case where we don't know about loads initiated by the user clicking a link
|
// HACK: this block handles the case where we don't know about loads initiated by the user clicking a link
|
||||||
if (!_ignoreLoadStart)
|
if (!_ignoreLoadStart)
|
||||||
{
|
{
|
||||||
// post the start load notification
|
// post the start load notification
|
||||||
[self _startedLoading];
|
[self _startedLoading];
|
||||||
|
|
||||||
if (_mainFrameURL)
|
if (_mainFrameURL)
|
||||||
[_backwardStack addObject:_mainFrameURL];
|
[_backwardStack addObject:_mainFrameURL];
|
||||||
|
|
||||||
// FIXME: this doesn't actually get the right URL for different domains. Not possible due to browser security restrictions.
|
// FIXME: this doesn't actually get the right URL for different domains. Not possible due to browser security restrictions.
|
||||||
_mainFrameURL = _iframe.src;
|
_mainFrameURL = _iframe.src;
|
||||||
_mainFrameURL = _iframe.src;
|
_mainFrameURL = _iframe.src;
|
||||||
|
|
||||||
// clear the forward
|
// clear the forward
|
||||||
[_forwardStack removeAllObjects];
|
[_forwardStack removeAllObjects];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
_ignoreLoadStart = NO;
|
_ignoreLoadStart = NO;
|
||||||
|
|
||||||
if (!_ignoreLoadEnd)
|
if (!_ignoreLoadEnd)
|
||||||
{
|
{
|
||||||
[self _finishedLoading];
|
[self _finishedLoading];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
_ignoreLoadEnd = NO;
|
_ignoreLoadEnd = NO;
|
||||||
|
|
||||||
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
|
[[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_iframe.addEventListener)
|
|
||||||
_iframe.addEventListener("load", _loadCallback, false);
|
|
||||||
else if (_iframe.attachEvent)
|
|
||||||
_iframe.attachEvent("onload", _loadCallback);
|
|
||||||
|
|
||||||
|
if (_iframe.addEventListener)
|
||||||
|
_iframe.addEventListener("load", _loadCallback, false);
|
||||||
|
else if (_iframe.attachEvent)
|
||||||
|
_iframe.attachEvent("onload", _loadCallback);
|
||||||
|
|
||||||
_frameView = [[CPView alloc] initWithFrame:[self bounds]];
|
_frameView = [[CPView alloc] initWithFrame:[self bounds]];
|
||||||
[_frameView setAutoresizingMask:CPViewWidthSizable|CPViewHeightSizable];
|
[_frameView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
|
||||||
|
|
||||||
_scrollView = [[CPScrollView alloc] initWithFrame:[self bounds]];
|
_scrollView = [[CPScrollView alloc] initWithFrame:[self bounds]];
|
||||||
[_scrollView setAutohidesScrollers:YES];
|
[_scrollView setAutohidesScrollers:YES];
|
||||||
[_scrollView setAutoresizingMask:CPViewWidthSizable|CPViewHeightSizable];
|
[_scrollView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
|
||||||
[_scrollView setDocumentView:_frameView];
|
[_scrollView setDocumentView:_frameView];
|
||||||
|
|
||||||
_frameView._DOMElement.appendChild(_iframe);
|
_frameView._DOMElement.appendChild(_iframe);
|
||||||
|
|||||||
@@ -197,6 +197,21 @@ var CPWindowSaveImage = nil,
|
|||||||
|
|
||||||
var CPWindowResizeTime = 0.2;
|
var CPWindowResizeTime = 0.2;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Keys for which action messages will be sent by default when unhandled, e.g. complete:.
|
||||||
|
*/
|
||||||
|
var CPWindowActionMessageKeys = [
|
||||||
|
CPLeftArrowFunctionKey,
|
||||||
|
CPRightArrowFunctionKey,
|
||||||
|
CPUpArrowFunctionKey,
|
||||||
|
CPDownArrowFunctionKey,
|
||||||
|
CPPageUpFunctionKey,
|
||||||
|
CPPageDownFunctionKey,
|
||||||
|
CPHomeFunctionKey,
|
||||||
|
CPEndFunctionKey,
|
||||||
|
CPEscapeFunctionKey
|
||||||
|
];
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ingroup appkit
|
@ingroup appkit
|
||||||
@class CPWindow
|
@class CPWindow
|
||||||
@@ -388,6 +403,7 @@ CPTexturedBackgroundWindowMask
|
|||||||
_registeredDraggedTypes = [CPSet set];
|
_registeredDraggedTypes = [CPSet set];
|
||||||
_registeredDraggedTypesArray = [];
|
_registeredDraggedTypesArray = [];
|
||||||
_isSheet = NO;
|
_isSheet = NO;
|
||||||
|
_acceptsMouseMovedEvents = YES;
|
||||||
|
|
||||||
// Set up our window number.
|
// Set up our window number.
|
||||||
_windowNumber = [CPApp._windows count];
|
_windowNumber = [CPApp._windows count];
|
||||||
@@ -937,7 +953,7 @@ CPTexturedBackgroundWindowMask
|
|||||||
/*!
|
/*!
|
||||||
Sets the window's minimum size. If the provided
|
Sets the window's minimum size. If the provided
|
||||||
size is the same as the current minimum size, the method simply returns.
|
size is the same as the current minimum size, the method simply returns.
|
||||||
@aSize the new minimum size for the window
|
@param aSize the new minimum size for the window
|
||||||
*/
|
*/
|
||||||
- (void)setMinSize:(CGSize)aSize
|
- (void)setMinSize:(CGSize)aSize
|
||||||
{
|
{
|
||||||
@@ -1223,10 +1239,10 @@ CPTexturedBackgroundWindowMask
|
|||||||
if (_firstResponder === aResponder)
|
if (_firstResponder === aResponder)
|
||||||
return YES;
|
return YES;
|
||||||
|
|
||||||
if(![_firstResponder resignFirstResponder])
|
if (![_firstResponder resignFirstResponder])
|
||||||
return NO;
|
return NO;
|
||||||
|
|
||||||
if(!aResponder || ![aResponder acceptsFirstResponder] || ![aResponder becomeFirstResponder])
|
if (!aResponder || ![aResponder acceptsFirstResponder] || ![aResponder becomeFirstResponder])
|
||||||
{
|
{
|
||||||
_firstResponder = self;
|
_firstResponder = self;
|
||||||
|
|
||||||
@@ -2155,7 +2171,7 @@ CPTexturedBackgroundWindowMask
|
|||||||
aSheet._isSheet = YES;
|
aSheet._isSheet = YES;
|
||||||
aSheet._parentView = self;
|
aSheet._parentView = self;
|
||||||
|
|
||||||
var originx = frame.origin.x + FLOOR((frame.size.width - sheetFrame.size.width)/2),
|
var originx = frame.origin.x + FLOOR((frame.size.width - sheetFrame.size.width) / 2),
|
||||||
originy = frame.origin.y + [[self contentView] frame].origin.y,
|
originy = frame.origin.y + [[self contentView] frame].origin.y,
|
||||||
startFrame = CGRectMake(originx, originy, sheetFrame.size.width, 0),
|
startFrame = CGRectMake(originx, originy, sheetFrame.size.width, 0),
|
||||||
endFrame = CGRectMake(originx, originy, sheetFrame.size.width, sheetFrame.size.height);
|
endFrame = CGRectMake(originx, originy, sheetFrame.size.width, sheetFrame.size.height);
|
||||||
@@ -2323,59 +2339,15 @@ CPTexturedBackgroundWindowMask
|
|||||||
@ignore
|
@ignore
|
||||||
Interprets the key event for action messages and sends the action message down the responder chain
|
Interprets the key event for action messages and sends the action message down the responder chain
|
||||||
Cocoa only sends moveDown:, moveUp:, moveLeft:, moveRight:, pageUp:, pageDown: and complete: messages.
|
Cocoa only sends moveDown:, moveUp:, moveLeft:, moveRight:, pageUp:, pageDown: and complete: messages.
|
||||||
We deviate from this by sending (the default) scrollPageUp: scrollPageDown: for pageUp and pageDown keys.
|
We deviate from this by sending (the default) scrollPageUp:, scrollPageDown:, scrollToBeginningOfDocument: and scrollToEndOfDocument: for pageUp, pageDown, home and end keys.
|
||||||
@param anEvent the event to handle.
|
@param anEvent the event to handle.
|
||||||
@return YES if the key event was handled, NO if no responder handled the key event
|
@return YES if the key event was handled, NO if no responder handled the key event
|
||||||
*/
|
*/
|
||||||
- (BOOL)_processKeyboardUIKey:(CPEvent)anEvent
|
- (BOOL)_processKeyboardUIKey:(CPEvent)anEvent
|
||||||
{
|
{
|
||||||
var character = [anEvent charactersIgnoringModifiers],
|
var character = [anEvent charactersIgnoringModifiers];
|
||||||
uiKeys = [CPLeftArrowFunctionKey, CPRightArrowFunctionKey, CPUpArrowFunctionKey, CPDownArrowFunctionKey, CPPageUpFunctionKey, CPPageDownFunctionKey, CPEscapeFunctionKey];
|
|
||||||
|
|
||||||
if (![uiKeys containsObject:character])
|
if (![CPWindowActionMessageKeys containsObject:character])
|
||||||
return NO;
|
|
||||||
|
|
||||||
var selectors = [CPKeyBinding selectorsForKey:character modifierFlags:0];
|
|
||||||
|
|
||||||
if ([selectors count] <= 0)
|
|
||||||
return NO;
|
|
||||||
|
|
||||||
if (character !== CPEscapeFunctionKey)
|
|
||||||
{
|
|
||||||
var selector = [selectors objectAtIndex:0];
|
|
||||||
return [[self firstResponder] tryToPerform:selector with:self];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Cocoa sends complete: for the escape key (in stead of the default cancelOperation:)
|
|
||||||
// This is also the only action that is not sent directly to the first responder, but through doCommandBySelector.
|
|
||||||
// The difference is that doCommandBySelector: will also send the action to the window and application delegates.
|
|
||||||
[[self firstResponder] doCommandBySelector:@selector(complete:)];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
@ignore
|
|
||||||
Interprets the key event for action messages and sends the action message down the responder chain
|
|
||||||
Cocoa only sends moveDown:, moveUp:, moveLeft:, moveRight:, pageUp:, pageDown: and complete: messages.
|
|
||||||
We deviate from this by sending (the default) scrollPageUp: scrollPageDown: for pageUp and pageDown keys.
|
|
||||||
@param anEvent the event to handle.
|
|
||||||
@return YES if the key event was handled, NO if no responder handled the key event
|
|
||||||
*/
|
|
||||||
- (BOOL)_processKeyboardUIKey:(CPEvent)anEvent
|
|
||||||
{
|
|
||||||
var character = [anEvent charactersIgnoringModifiers],
|
|
||||||
uiKeys = [
|
|
||||||
CPLeftArrowFunctionKey,
|
|
||||||
CPRightArrowFunctionKey,
|
|
||||||
CPUpArrowFunctionKey,
|
|
||||||
CPDownArrowFunctionKey,
|
|
||||||
CPPageUpFunctionKey,
|
|
||||||
CPPageDownFunctionKey,
|
|
||||||
CPEscapeFunctionKey
|
|
||||||
];
|
|
||||||
|
|
||||||
if (![uiKeys containsObject:character])
|
|
||||||
return NO;
|
return NO;
|
||||||
|
|
||||||
var selectors = [CPKeyBinding selectorsForKey:character modifierFlags:0];
|
var selectors = [CPKeyBinding selectorsForKey:character modifierFlags:0];
|
||||||
@@ -2405,45 +2377,31 @@ CPTexturedBackgroundWindowMask
|
|||||||
|
|
||||||
- (BOOL)_hasKeyViewLoop
|
- (BOOL)_hasKeyViewLoop
|
||||||
{
|
{
|
||||||
var subviews = [];
|
var views = allViews(self),
|
||||||
|
index = [views count];
|
||||||
|
|
||||||
[self _appendSubviewsOf:_contentView toArray:subviews];
|
while (index--)
|
||||||
|
if ([views[index] nextKeyView])
|
||||||
for (var i = 0, count = [subviews count]; i<count; i++)
|
|
||||||
{
|
|
||||||
if (subviews[i]._nextKeyView)
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
|
||||||
|
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)recalculateKeyViewLoop
|
- (void)recalculateKeyViewLoop
|
||||||
{
|
{
|
||||||
var subviews = [];
|
var views = allViews(self);
|
||||||
|
|
||||||
[self _appendSubviewsOf:_contentView toArray:subviews];
|
[views sortUsingFunction:keyViewComparator context:nil];
|
||||||
|
|
||||||
var keyViewOrder = [subviews sortedArrayUsingFunction:keyViewComparator context:_contentView],
|
var index = 0,
|
||||||
count = [keyViewOrder count];
|
count = [views count];
|
||||||
|
|
||||||
for (var i=0; i<count; i++)
|
for (; index < count; ++index)
|
||||||
[keyViewOrder[i] setNextKeyView:keyViewOrder[(i+1)%count]];
|
[views[index] setNextKeyView:views[(index + 1) % count]];
|
||||||
|
|
||||||
_keyViewLoopIsDirty = NO;
|
_keyViewLoopIsDirty = NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)_appendSubviewsOf:(CPView)aView toArray:(CPArray)anArray
|
|
||||||
{
|
|
||||||
var subviews = [aView subviews],
|
|
||||||
count = [subviews count];
|
|
||||||
|
|
||||||
while (count--)
|
|
||||||
[self _appendSubviewsOf:subviews[count] toArray:anArray];
|
|
||||||
|
|
||||||
[anArray addObject:aView];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setAutorecalculatesKeyViewLoop:(BOOL)shouldRecalculate
|
- (void)setAutorecalculatesKeyViewLoop:(BOOL)shouldRecalculate
|
||||||
{
|
{
|
||||||
if (_autorecalculatesKeyViewLoop === shouldRecalculate)
|
if (_autorecalculatesKeyViewLoop === shouldRecalculate)
|
||||||
@@ -2541,19 +2499,46 @@ CPTexturedBackgroundWindowMask
|
|||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
var keyViewComparator = function(a, b, context)
|
var allViews = function(aWindow)
|
||||||
{
|
{
|
||||||
var viewBounds = [a convertRect:[a bounds] toView:nil],
|
var views = [[aWindow contentView] subviews],
|
||||||
otherBounds = [b convertRect:[b bounds] toView:nil];
|
index = 0;
|
||||||
|
|
||||||
if (CGRectGetMinY(viewBounds) < CGRectGetMinY(otherBounds))
|
for (; index < views.length; ++index)
|
||||||
return -1;
|
views = views.concat([views[index] subviews]);
|
||||||
else if (CGRectGetMinY(viewBounds) == CGRectGetMinY(otherBounds) && CGRectGetMinX(viewBounds) < CGRectGetMinX(otherBounds))
|
|
||||||
return -1;
|
return views;
|
||||||
else if (CGRectGetMinX(viewBounds) == CGRectGetMinX(otherBounds) && CGRectGetMinX(viewBounds) == CGRectGetMinX(otherBounds))
|
}
|
||||||
return 0;
|
|
||||||
else
|
var keyViewComparator = function(lhs, rhs, context)
|
||||||
return 1;
|
{
|
||||||
|
var lhsBounds = [lhs convertRect:[lhs bounds] toView:nil],
|
||||||
|
rhsBounds = [rhs convertRect:[rhs bounds] toView:nil],
|
||||||
|
lhsY = _CGRectGetMinY(lhsBounds),
|
||||||
|
rhsY = _CGRectGetMinY(rhsBounds),
|
||||||
|
lhsX = _CGRectGetMinX(lhsBounds),
|
||||||
|
rhsX = _CGRectGetMinX(rhsBounds),
|
||||||
|
intersectsVertically = MIN(_CGRectGetMaxY(lhsBounds), _CGRectGetMaxY(rhsBounds)) - MAX(lhsY, rhsY);
|
||||||
|
|
||||||
|
// If two views are "on the same line" (intersect vertically), then rely on the x comparison.
|
||||||
|
if (intersectsVertically > 0)
|
||||||
|
{
|
||||||
|
if (lhsX < rhsX)
|
||||||
|
return CPOrderedAscending;
|
||||||
|
|
||||||
|
if (lhsX === rhsX)
|
||||||
|
return CPOrderedSame;
|
||||||
|
|
||||||
|
return CPOrderedDescending;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (lhsY < rhsY)
|
||||||
|
return CPOrderedAscending;
|
||||||
|
|
||||||
|
if (lhsY === rhsY)
|
||||||
|
return CPOrderedSame;
|
||||||
|
|
||||||
|
return CPOrderedDescending;
|
||||||
}
|
}
|
||||||
|
|
||||||
@implementation CPWindow (MenuBar)
|
@implementation CPWindow (MenuBar)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ var _CPStandardWindowViewBodyBackgroundColor = nil;
|
|||||||
@implementation _CPDocModalWindowView : _CPWindowView
|
@implementation _CPDocModalWindowView : _CPWindowView
|
||||||
{
|
{
|
||||||
CPView _bodyView;
|
CPView _bodyView;
|
||||||
|
CPView _shadowView;
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (CPColor)bodyBackgroundColor
|
+ (CPColor)bodyBackgroundColor
|
||||||
@@ -25,13 +26,19 @@ var _CPStandardWindowViewBodyBackgroundColor = nil;
|
|||||||
var theClass = [self class],
|
var theClass = [self class],
|
||||||
bounds = [self bounds];
|
bounds = [self bounds];
|
||||||
|
|
||||||
_bodyView = [[CPView alloc] initWithFrame:CGRectMake(0.0, 0.0, CGRectGetWidth(bounds), CGRectGetHeight(bounds))];
|
_bodyView = [[CPView alloc] initWithFrame:_CGRectMake(0.0, 0.0, _CGRectGetWidth(bounds), _CGRectGetHeight(bounds))];
|
||||||
|
|
||||||
[_bodyView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
|
[_bodyView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
|
||||||
[_bodyView setBackgroundColor:[theClass bodyBackgroundColor]];
|
[_bodyView setBackgroundColor:[theClass bodyBackgroundColor]];
|
||||||
[_bodyView setHitTests:NO];
|
[_bodyView setHitTests:NO];
|
||||||
|
|
||||||
[self addSubview:_bodyView];
|
[self addSubview:_bodyView];
|
||||||
|
|
||||||
|
var bundle = [CPBundle bundleForClass:[CPWindow class]];
|
||||||
|
_shadowView = [[CPView alloc] initWithFrame:CGRectMake(0, 0, _CGRectGetWidth(bounds), 8)];
|
||||||
|
[_shadowView setAutoresizingMask:CPViewWidthSizable];
|
||||||
|
[_shadowView setBackgroundColor:[CPColor colorWithPatternImage:[[CPImage alloc] initWithContentsOfFile:[bundle pathForResource:@"CPWindow/CPWindowAttachedSheetShadow.png"] size:CGSizeMake(9,8)]]];
|
||||||
|
[self addSubview:_shadowView];
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
|||||||
@@ -20,6 +20,8 @@
|
|||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@import "CPTextField.j"
|
||||||
|
|
||||||
var _CPHUDWindowViewBackgroundColor = nil,
|
var _CPHUDWindowViewBackgroundColor = nil,
|
||||||
|
|
||||||
CPHUDCloseButtonImage = nil;
|
CPHUDCloseButtonImage = nil;
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@import "CPTextField.j"
|
||||||
@import "_CPWindowView.j"
|
@import "_CPWindowView.j"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ var _CPWindowViewResizeIndicatorImage = nil;
|
|||||||
CGSize _toolbarOffset;
|
CGSize _toolbarOffset;
|
||||||
// BOOL _isAnimatingToolbar;
|
// BOOL _isAnimatingToolbar;
|
||||||
|
|
||||||
|
|
||||||
CGRect _resizeFrame;
|
CGRect _resizeFrame;
|
||||||
CGPoint _mouseDraggedPoint;
|
CGPoint _mouseDraggedPoint;
|
||||||
|
|
||||||
@@ -138,12 +137,12 @@ var _CPWindowViewResizeIndicatorImage = nil;
|
|||||||
|
|
||||||
else if (type === CPLeftMouseDragged)
|
else if (type === CPLeftMouseDragged)
|
||||||
{
|
{
|
||||||
var newSize = CGSizeMake(CGRectGetWidth(_resizeFrame) + location.x - CGRectGetMinX(_resizeFrame), CGRectGetHeight(_resizeFrame) + location.y - CGRectGetMinY(_resizeFrame));
|
var newSize = CGSizeMake(CGRectGetWidth(_resizeFrame) + location.x - CGRectGetMinX(_resizeFrame), CGRectGetHeight(_resizeFrame) + location.y - CGRectGetMinY(_resizeFrame));
|
||||||
|
|
||||||
if (theWindow._isSheet && theWindow._parentView && (theWindow._frame.size.width !== newSize.width))
|
if (theWindow._isSheet && theWindow._parentView && (theWindow._frame.size.width !== newSize.width))
|
||||||
[theWindow._parentView _setAttachedSheetFrameOrigin];
|
[theWindow._parentView _setAttachedSheetFrameOrigin];
|
||||||
|
|
||||||
[theWindow setFrameSize:newSize];
|
[theWindow setFrameSize:newSize];
|
||||||
}
|
}
|
||||||
|
|
||||||
[CPApp setTarget:self selector:@selector(trackResizeWithEvent:) forNextEventMatchingMask:CPLeftMouseDraggedMask | CPLeftMouseUpMask untilDate:nil inMode:nil dequeue:YES];
|
[CPApp setTarget:self selector:@selector(trackResizeWithEvent:) forNextEventMatchingMask:CPLeftMouseDraggedMask | CPLeftMouseUpMask untilDate:nil inMode:nil dequeue:YES];
|
||||||
|
|||||||
@@ -276,6 +276,10 @@
|
|||||||
[self setViewController:viewController];
|
[self setViewController:viewController];
|
||||||
|
|
||||||
[self synchronizeWindowTitleWithDocumentName];
|
[self synchronizeWindowTitleWithDocumentName];
|
||||||
|
|
||||||
|
// Change of document means toolbar items may no longer make sense.
|
||||||
|
// FIXME: DOCUMENT ARCHITECTURE Should we setToolbar: as well?
|
||||||
|
[[[self window] toolbar] validateVisibleItems];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setSupportsMultipleDocuments:(BOOL)shouldSupportMultipleDocuments
|
- (void)setSupportsMultipleDocuments:(BOOL)shouldSupportMultipleDocuments
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* CPCibBindingConnector.j
|
||||||
|
* AppKit
|
||||||
|
*
|
||||||
|
* Created by Ross Boucher.
|
||||||
|
* Copyright 2010, 280 North, Inc.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
@import "CPCibConnector.j"
|
||||||
|
|
||||||
|
var CPCibBindingConnectorBindingKey = @"CPCibBindingConnectorBindingKey",
|
||||||
|
CPCibBindingConnectorKeyPathKey = @"CPCibBindingConnectorKeyPathKey",
|
||||||
|
CPCibBindingConnectorOptionsKey = @"CPCibBindingConnectorOptionsKey";
|
||||||
|
|
||||||
|
@implementation CPCibBindingConnector : CPCibConnector
|
||||||
|
{
|
||||||
|
id _binding;
|
||||||
|
id _keyPath;
|
||||||
|
id _options;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id)initWithCoder:(CPCoder)aCoder
|
||||||
|
{
|
||||||
|
if (self = [super initWithCoder:aCoder])
|
||||||
|
{
|
||||||
|
_binding = [aCoder decodeObjectForKey:CPCibBindingConnectorBindingKey];
|
||||||
|
_keyPath = [aCoder decodeObjectForKey:CPCibBindingConnectorKeyPathKey];
|
||||||
|
_options = [aCoder decodeObjectForKey:CPCibBindingConnectorOptionsKey];
|
||||||
|
}
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)encodeWithCoder:(CPCoder)aCoder
|
||||||
|
{
|
||||||
|
[super encodeWithCoder:aCoder];
|
||||||
|
|
||||||
|
[aCoder encodeObject:_binding forKey:CPCibBindingConnectorBindingKey];
|
||||||
|
[aCoder encodeObject:_keyPath forKey:CPCibBindingConnectorKeyPathKey];
|
||||||
|
[aCoder encodeObject:_options forKey:CPCibBindingConnectorOptionsKey];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)establishConnection
|
||||||
|
{
|
||||||
|
[_source bind:_binding toObject:_destination withKeyPath:_keyPath options:_options];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
@@ -28,6 +28,7 @@
|
|||||||
@import "CPCibConnector.j"
|
@import "CPCibConnector.j"
|
||||||
@import "CPCibControlConnector.j"
|
@import "CPCibControlConnector.j"
|
||||||
@import "CPCibOutletConnector.j"
|
@import "CPCibOutletConnector.j"
|
||||||
|
@import "CPCibBindingConnector.j"
|
||||||
|
|
||||||
|
|
||||||
@implementation _CPCibObjectData : CPObject
|
@implementation _CPCibObjectData : CPObject
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ function CGColorCreateCopyWithAlpha(aColor, anAlpha)
|
|||||||
var components = aColor.components;
|
var components = aColor.components;
|
||||||
|
|
||||||
if (!aColor || anAlpha == components[components.length - 1])
|
if (!aColor || anAlpha == components[components.length - 1])
|
||||||
return aColor;
|
return aColor;
|
||||||
|
|
||||||
if (aColor.pattern)
|
if (aColor.pattern)
|
||||||
var copy = CGColorCreateWithPattern(aColor.colorspace, aColor.pattern, components);
|
var copy = CGColorCreateWithPattern(aColor.colorspace, aColor.pattern, components);
|
||||||
@@ -275,11 +275,11 @@ function CGColorGetPattern(aColor)
|
|||||||
/* var components = aColor.components;
|
/* var components = aColor.components;
|
||||||
|
|
||||||
case : _CGCSSForColor[CFGetHash(aColor)] = "rgba(" + ROUND(components[0] * 255.0) + ',' + ROUND(components[0] * 255.0) + ',' ROUND(components[0] * 255.0) + ',' + ROUND(components[0] * 255.0);
|
case : _CGCSSForColor[CFGetHash(aColor)] = "rgba(" + ROUND(components[0] * 255.0) + ',' + ROUND(components[0] * 255.0) + ',' ROUND(components[0] * 255.0) + ',' + ROUND(components[0] * 255.0);
|
||||||
_cssString = (hasAlpha ? "rgba(" : "rgb(") +
|
_cssString = (hasAlpha ? "rgba(" : "rgb(") +
|
||||||
parseInt(_components[0] * 255.0) + ", " +
|
parseInt(_components[0] * 255.0) + ", " +
|
||||||
parseInt(_components[1] * 255.0) + ", " +
|
parseInt(_components[1] * 255.0) + ", " +
|
||||||
parseInt(_components[2] * 255.0) +
|
parseInt(_components[2] * 255.0) +
|
||||||
(hasAlpha ? (", " + _components[3]) : "") + ")";
|
(hasAlpha ? (", " + _components[3]) : "") + ")";
|
||||||
|
|
||||||
function CFStringFromColor()
|
function CFStringFromColor()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -535,6 +535,7 @@ function CGContextEOFillPath(aContext)
|
|||||||
function CGContextFillPath(aContext)
|
function CGContextFillPath(aContext)
|
||||||
{
|
{
|
||||||
CGContextDrawPath(aContext, kCGPathFill);
|
CGContextDrawPath(aContext, kCGPathFill);
|
||||||
|
CGContextClosePath(aContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
var KAPPA = 4.0 * ((SQRT2 - 1.0) / 3.0);
|
var KAPPA = 4.0 * ((SQRT2 - 1.0) / 3.0);
|
||||||
@@ -588,6 +589,7 @@ function CGContextStrokeEllipseInRect(aContext, aRect)
|
|||||||
function CGContextStrokePath(aContext)
|
function CGContextStrokePath(aContext)
|
||||||
{
|
{
|
||||||
CGContextDrawPath(aContext, kCGPathStroke);
|
CGContextDrawPath(aContext, kCGPathStroke);
|
||||||
|
CGContextClosePath(aContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
@@ -255,8 +255,6 @@ function CGContextDrawPath(aContext, aMode)
|
|||||||
|
|
||||||
vml.push("</cg_vml_:shape>");
|
vml.push("</cg_vml_:shape>");
|
||||||
|
|
||||||
aContext.path = NULL;
|
|
||||||
|
|
||||||
if (aContext.buffer != nil)
|
if (aContext.buffer != nil)
|
||||||
aContext.buffer += vml.join("");
|
aContext.buffer += vml.join("");
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -268,20 +268,20 @@ function CGPathWithEllipseInRect(aRect)
|
|||||||
{
|
{
|
||||||
var path = CGPathCreateMutable();
|
var path = CGPathCreateMutable();
|
||||||
|
|
||||||
if (_CGRectGetWidth(aRect) == _CGRectGetHeight(aRect))
|
if (_CGRectGetWidth(aRect) == _CGRectGetHeight(aRect))
|
||||||
CGPathAddArc(path, nil, _CGRectGetMidX(aRect), _CGRectGetMidY(aRect), _CGRectGetWidth(aRect) / 2.0, 0.0, 2 * PI, YES);
|
CGPathAddArc(path, nil, _CGRectGetMidX(aRect), _CGRectGetMidY(aRect), _CGRectGetWidth(aRect) / 2.0, 0.0, 2 * PI, YES);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var axis = _CGSizeMake(_CGRectGetWidth(aRect) / 2.0, _CGRectGetHeight(aRect) / 2.0),
|
var axis = _CGSizeMake(_CGRectGetWidth(aRect) / 2.0, _CGRectGetHeight(aRect) / 2.0),
|
||||||
center = _CGPointMake(_CGRectGetMinX(aRect) + axis.width, _CGRectGetMinY(aRect) + axis.height);
|
center = _CGPointMake(_CGRectGetMinX(aRect) + axis.width, _CGRectGetMinY(aRect) + axis.height);
|
||||||
|
|
||||||
CGPathMoveToPoint(path, nil, center.x, center.y - axis.height);
|
CGPathMoveToPoint(path, nil, center.x, center.y - axis.height);
|
||||||
|
|
||||||
CGPathAddCurveToPoint(path, nil, center.x + (KAPPA * axis.width), center.y - axis.height, center.x + axis.width, center.y - (KAPPA * axis.height), center.x + axis.width, center.y);
|
CGPathAddCurveToPoint(path, nil, center.x + (KAPPA * axis.width), center.y - axis.height, center.x + axis.width, center.y - (KAPPA * axis.height), center.x + axis.width, center.y);
|
||||||
CGPathAddCurveToPoint(path, nil, center.x + axis.width, center.y + (KAPPA * axis.height), center.x + (KAPPA * axis.width), center.y + axis.height, center.x, center.y + axis.height);
|
CGPathAddCurveToPoint(path, nil, center.x + axis.width, center.y + (KAPPA * axis.height), center.x + (KAPPA * axis.width), center.y + axis.height, center.x, center.y + axis.height);
|
||||||
CGPathAddCurveToPoint(path, nil, center.x - (KAPPA * axis.width), center.y + axis.height, center.x - axis.width, center.y + (KAPPA * axis.height), center.x - axis.width, center.y);
|
CGPathAddCurveToPoint(path, nil, center.x - (KAPPA * axis.width), center.y + axis.height, center.x - axis.width, center.y + (KAPPA * axis.height), center.x - axis.width, center.y);
|
||||||
CGPathAddCurveToPoint(path, nil, center.x - axis.width, center.y - (KAPPA * axis.height), center.x - (KAPPA * axis.width), center.y - axis.height, center.x, center.y - axis.height);
|
CGPathAddCurveToPoint(path, nil, center.x - axis.width, center.y - (KAPPA * axis.height), center.x - (KAPPA * axis.width), center.y - axis.height, center.x, center.y - axis.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
CGPathCloseSubpath(path);
|
CGPathCloseSubpath(path);
|
||||||
|
|
||||||
@@ -298,36 +298,37 @@ function CGPathWithRoundedRectangleInRect(aRect, xRadius, yRadius/*not currently
|
|||||||
|
|
||||||
CGPathMoveToPoint(path, nil, xMin + xRadius, yMin);
|
CGPathMoveToPoint(path, nil, xMin + xRadius, yMin);
|
||||||
|
|
||||||
if (ne)
|
if (ne)
|
||||||
{
|
{
|
||||||
CGPathAddLineToPoint(path, nil, xMax - xRadius, yMin);
|
CGPathAddLineToPoint(path, nil, xMax - xRadius, yMin);
|
||||||
CGPathAddCurveToPoint(path, nil, xMax - xRadius, yMin, xMax, yMin, xMax, yMin + xRadius);
|
CGPathAddCurveToPoint(path, nil, xMax - xRadius, yMin, xMax, yMin, xMax, yMin + xRadius);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
CGPathAddLineToPoint(path, nil, xMax, yMin);
|
CGPathAddLineToPoint(path, nil, xMax, yMin);
|
||||||
|
|
||||||
if (se)
|
if (se)
|
||||||
{
|
{
|
||||||
CGPathAddLineToPoint(path, nil, xMax, yMax - xRadius);
|
CGPathAddLineToPoint(path, nil, xMax, yMax - xRadius);
|
||||||
CGPathAddCurveToPoint(path, nil, xMax, yMax - xRadius, xMax, yMax, xMax - xRadius, yMax);
|
CGPathAddCurveToPoint(path, nil, xMax, yMax - xRadius, xMax, yMax, xMax - xRadius, yMax);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
CGPathAddLineToPoint(path, nil, xMax, yMax);
|
CGPathAddLineToPoint(path, nil, xMax, yMax);
|
||||||
|
|
||||||
if (sw)
|
if (sw)
|
||||||
{
|
{
|
||||||
CGPathAddLineToPoint(path, nil, xMin + xRadius, yMax);
|
CGPathAddLineToPoint(path, nil, xMin + xRadius, yMax);
|
||||||
CGPathAddCurveToPoint(path, nil, xMin + xRadius, yMax, xMin, yMax, xMin, yMax - xRadius);
|
CGPathAddCurveToPoint(path, nil, xMin + xRadius, yMax, xMin, yMax, xMin, yMax - xRadius);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
CGPathAddLineToPoint(path, nil, xMin, yMax);
|
CGPathAddLineToPoint(path, nil, xMin, yMax);
|
||||||
|
|
||||||
if (nw)
|
if (nw)
|
||||||
{
|
{
|
||||||
CGPathAddLineToPoint(path, nil, xMin, yMin + xRadius);
|
CGPathAddLineToPoint(path, nil, xMin, yMin + xRadius);
|
||||||
CGPathAddCurveToPoint(path, nil, xMin, yMin + xRadius, xMin, yMin, xMin + xRadius, yMin);
|
CGPathAddCurveToPoint(path, nil, xMin, yMin + xRadius, xMin, yMin, xMin + xRadius, yMin);
|
||||||
} else
|
}
|
||||||
CGPathAddLineToPoint(path, nil, xMin, yMin);
|
else
|
||||||
|
CGPathAddLineToPoint(path, nil, xMin, yMin);
|
||||||
|
|
||||||
CGPathCloseSubpath(path);
|
CGPathCloseSubpath(path);
|
||||||
|
|
||||||
|
|||||||
@@ -168,6 +168,8 @@ KeyCodesToUnicodeMap[CPKeyCodes.LEFT] = CPLeftArrowFunctionKey
|
|||||||
KeyCodesToUnicodeMap[CPKeyCodes.UP] = CPUpArrowFunctionKey;
|
KeyCodesToUnicodeMap[CPKeyCodes.UP] = CPUpArrowFunctionKey;
|
||||||
KeyCodesToUnicodeMap[CPKeyCodes.RIGHT] = CPRightArrowFunctionKey;
|
KeyCodesToUnicodeMap[CPKeyCodes.RIGHT] = CPRightArrowFunctionKey;
|
||||||
KeyCodesToUnicodeMap[CPKeyCodes.DOWN] = CPDownArrowFunctionKey;
|
KeyCodesToUnicodeMap[CPKeyCodes.DOWN] = CPDownArrowFunctionKey;
|
||||||
|
KeyCodesToUnicodeMap[CPKeyCodes.HOME] = CPHomeFunctionKey;
|
||||||
|
KeyCodesToUnicodeMap[CPKeyCodes.END] = CPEndFunctionKey;
|
||||||
KeyCodesToUnicodeMap[CPKeyCodes.SEMICOLON] = ";";
|
KeyCodesToUnicodeMap[CPKeyCodes.SEMICOLON] = ";";
|
||||||
KeyCodesToUnicodeMap[CPKeyCodes.DASH] = "-";
|
KeyCodesToUnicodeMap[CPKeyCodes.DASH] = "-";
|
||||||
KeyCodesToUnicodeMap[CPKeyCodes.EQUALS] = "=";
|
KeyCodesToUnicodeMap[CPKeyCodes.EQUALS] = "=";
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 106 B |
|
Before Width: | Height: | Size: 106 B |
|
Before Width: | Height: | Size: 118 B |
|
Before Width: | Height: | Size: 121 B |
|
Before Width: | Height: | Size: 142 B |
|
Before Width: | Height: | Size: 245 B |
|
Before Width: | Height: | Size: 241 B |
|
Before Width: | Height: | Size: 126 B |
|
Before Width: | Height: | Size: 180 B |
|
Before Width: | Height: | Size: 181 B |
|
Before Width: | Height: | Size: 146 B |
|
Before Width: | Height: | Size: 322 B |
|
Before Width: | Height: | Size: 339 B |
|
After Width: | Height: | Size: 183 B |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 1.3 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 2.2 KiB |
|
After Width: | Height: | Size: 1.0 KiB |
|
After Width: | Height: | Size: 1023 B |
|
After Width: | Height: | Size: 1.4 KiB |