aboutsummaryrefslogtreecommitdiffstats
path: root/art/malehead.png
blob: ada9545c8577726df9a5568f315b1580810cda18 (plain) (blame)
ofshex dumpascii
0000 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 00 30 00 00 00 30 08 06 00 00 00 57 02 f9 .PNG........IHDR...0...0.....W..
0020 87 00 00 00 04 67 41 4d 41 00 00 b1 8f 0b fc 61 05 00 00 00 06 62 4b 47 44 00 ff 00 ff 00 ff a0 .....gAMA......a.....bKGD.......
0040 bd a7 93 00 00 00 09 70 48 59 73 00 00 2e 22 00 00 2e 22 01 aa e2 dd 92 00 00 00 07 74 49 4d 45 .......pHYs..."...".........tIME
0060 07 d0 04 0c 0d 01 1f fd 77 00 10 00 00 0f f9 49 44 41 54 78 da bd 9a 79 94 5c 75 95 c7 3f 6f ad ........w......IDATx...y.\u..?o.
0080 b5 bb ba bb 7a df d3 dd 49 77 96 ee 84 10 0c 22 a0 81 40 06 46 10 74 18 0c 2a 8e 8e a0 c7 0c a3 ....z...Iw....."..@.F.t..*......
00a0 83 b8 8d e3 8c 3a 80 9e 83 cb 38 1e 17 5c 80 c0 c8 80 20 ae 41 18 11 06 06 30 82 40 42 12 92 4e .....:....8..\......A....0.@B..N
00c0 77 d2 fb de d5 b5 bf 7a f5 d6 f9 23 af 9c 37 45 77 12 94 63 9d f3 ce ab e5 2d f7 7b ef f7 de ef w......z...#..7Ew..c.....-.{....
00e0 bd bf 57 12 af cf 2b 00 ac 06 6a 80 34 e0 f0 67 7a 09 7f e2 f9 9b 81 4b 81 35 de 67 db db 44 40 ..W...+...j.4..gz......K.5.g..D@
0100 01 8e 01 2f 02 fb 81 31 0f e8 c5 c0 99 1e c8 41 ef b7 61 c0 fa 73 02 a8 07 ae 03 ba 01 59 55 24 .../...1.......A..a..s.......YU$
0120 fb 9d 97 5f 28 c9 92 ec de f3 e3 47 05 d3 b6 5d ef da a5 eb bb c0 9d c0 3a 60 93 0f a0 eb bd d7 ..._(......G...]........:`......
0140 80 87 81 3d af 15 88 f0 1a 8f 15 81 2e e0 26 40 0e 07 94 d0 ce 2b 2f 96 77 fd dd 47 a2 f7 7e ff ...=..........&@.....+/.w..G..~.
0160 df 6b eb aa 23 2d 7b 9f 7b 31 34 31 b3 58 8d 0b a2 20 a0 28 12 c5 a2 89 e1 32 b9 aa a5 41 93 02 .k..#-{.{141.X.....(.....2...A..
0180 c1 b9 9d d7 be 2f bf aa 77 a0 a0 6b 5a e1 5b df f8 9a 7b ef cf 7e 23 7a 11 99 07 be 0f 0c 79 9f ...../..w..kZ.[...{..~#z......y.
01a0 1d 9f 03 fe 24 00 25 e3 5b 80 cf 2a b2 14 ea 6c ae 55 77 ff e0 bb 51 2b 3b b7 a6 2e 5e d1 3d 3d ....$.%.[..*...l.Uw...Q+;...^.==
01c0 31 c2 9d 77 dd c3 d1 91 39 c2 41 05 d7 71 c9 eb 26 02 2e b2 24 61 3b 27 6c 11 04 81 cf dc f4 7e 1..w....9.A..q..&...$a;'l......~
01e0 0c 83 d4 77 ee fe f1 cc 63 2f 8c 94 e8 63 7b f9 13 f2 22 f1 10 60 7a c6 bb 2b 81 90 5e 83 f1 51 ...w....c/...c{..."..`z..+..^..Q
0200 e0 73 aa 22 c5 b6 bf 69 93 7a f7 dd 77 d5 2f 1e 7b fe 4d bd eb 37 d4 7f e6 e3 1f e7 81 5f 3c 46 .s."...i.z..w./.{.M..7......._<F
0220 63 4d 8c fa 9a 28 93 73 29 4c d3 26 1c 0e 60 9a 36 b6 e3 62 58 0e 8e 20 a1 9b 16 b6 96 21 ac 8a cM...(.s)L.&..`.6..bX........!..
0240 c1 8f 7d f2 13 75 d7 ed 7c 6b 87 96 5c c8 ee 1f 1c 2f 7a 39 62 7b 8e 1a f0 f2 a3 78 b2 28 08 a7 ..}..u..|k..\..../z9b{.....x.(..
0260 61 bc e0 01 bd 45 91 a4 b6 8d 6b 3b a5 1b 6f f8 60 65 43 c4 da 11 af ab e7 fa 5d 9f c0 b1 5d be a....E....k;..o.`eC.......]...].
0280 f0 8f 1f 66 76 7a 8a 6f dd f9 53 00 9a eb ab 98 9e 4f 01 10 0a a9 4c 2d 64 11 44 81 40 20 40 32 ...fvz.o..S......O....L-d.D.@.@2
02a0 9d 23 16 56 51 65 91 a6 9a 30 1b d6 74 30 b6 64 bc f8 d4 4b c3 d3 f3 c9 9c 05 e8 c0 61 af 08 3c .#.VQe...0..t0.d...K........a..<
02c0 e0 81 72 96 03 21 9e a6 f7 af 56 64 a9 ed 0d 1b 7b a4 f7 5d bb 53 a9 56 b4 f3 c7 8e 0f b1 eb 86 ..r..!....Vd....{..].S.V........
02e0 4f 81 0b bb ef f8 06 0d 2d 6d ec be ef e1 13 17 15 85 3f 18 5f 19 0e 92 c9 e9 20 40 24 1c 26 91 O.......-m........?._......@$.&.
0300 d6 08 04 02 64 75 93 4d 6b 3b 79 c3 e6 b5 d8 ae c3 e8 b1 e3 9b 6d a3 d8 ee dd 2f 08 c4 80 17 00 ....du.Mk;y..........m..../.....
0320 d9 fb 4e 5c ce e1 d2 69 18 5f 03 ec ba e4 fc 2d b2 24 89 ca 25 6f 3e 6b a3 ad 67 ea 77 ff f0 a7 ..N\...i._.....-.$..%o>k..g.w...
0340 d8 b6 c3 5d 77 7c 93 85 99 09 3e 72 d3 e7 09 05 14 8a 86 45 34 a4 12 0a 2a 58 b6 43 c1 30 30 6d ...]w|....>r.......E4...*X.C.00m
0360 07 cb 76 a9 ad ad c1 b2 1c 2e b9 e0 8d 44 43 2a bf 7b 79 98 97 8f 4e 12 8b 04 79 cf 55 3b 68 ac ..v..........DC*.{y...N...y.U;h.
0380 10 1a f6 0f cf 1d 30 6d d7 00 ea 80 a4 17 85 15 f3 40 3a 0d ea 5c a3 2a 72 73 36 97 0b dd f0 a1 ......0m.........@:..\.*rs6.....
03a0 eb 94 e4 e4 e1 4d f7 3d f8 4b 39 97 2f f2 d3 47 1f e5 91 07 77 73 cb 57 7e c0 79 67 f5 72 c9 f6 .....M.=.K9./..G....ws.W~.yg.r..
03c0 73 11 1d 83 b6 a6 38 47 47 e6 70 5c 17 cb 3e c1 ff 55 6d 4d 1c 3e 3e c5 ea ce 56 1a 1b e2 74 75 s.....8GG.p\..>..UmM.>>...V...tu
03e0 b4 b0 b6 a7 8d a2 5e e4 c5 23 e3 3c f5 dc 21 ea ab 22 34 54 06 5a 27 12 85 3d 96 ed c8 40 3f 90 ......^..#.<..!.."4T.Z'..=...@?.
0400 00 a6 7c 14 72 4f 17 40 c9 fb ef ef 6c 89 87 be f2 a5 9b d5 af dc 76 5b db d8 c8 48 5b 22 ad f1 ..|.rO.@....l.........v[...H["..
0420 a3 07 ee e5 ce af df ca dd 0f fe 86 1d e7 0f 70 cd 7b fe 86 bd 4f 3f 43 6d bc 8a 3d 4f bc 84 28 ...............p.{...O?Cm..=O..(
0440 80 e5 b8 e8 a6 45 24 1c 22 99 d1 b0 6d 87 cb 2e 79 0b a1 80 8a 22 0b b8 ae 40 47 7b 33 7d 3d 6d .....E$."...m...y...."...@G{3}=m
0460 1c 3c 72 9c b9 54 1e 59 14 02 13 8b b9 a0 e3 32 ee d1 27 e9 09 de 69 03 f0 7b ff 1c 60 e3 d7 be .<r..T.Y.......2..'...i..{..`...
0480 f8 cf 81 cf fc cb 2d 4a 6d 44 ea cb e6 0a d1 db 6e fd 38 7b 1e bc 8f 87 1f 7f 9e 2b 76 6c e5 da ......-JmD......n.8{.......+vl..
04a0 eb 6f e0 4b 37 ff 2b eb d7 ae 66 f7 83 8f 03 2e aa a2 90 d6 8a 08 a2 88 a2 06 48 a4 73 5c ff 9e .o.K7.+...f...............H.s\..
04c0 77 d0 d7 d7 cb 9a ee 2e 44 1c 32 b9 1c 96 65 13 0e 05 69 ad af 66 70 64 0a 45 55 71 6c 3b 9f d5 w.......D.2...e...i..fpd.EUql;..
04e0 2d 05 f8 ad 97 d0 c7 ca 12 d9 5d 09 80 e0 f3 be 0c 5c ac 2a b2 3a 3f 33 59 bd 7f 70 4c 8d aa 52 -.........]......\.*.:?3Y..pL..R
0500 f3 f9 5b 7a 22 35 b1 0a 26 a7 a6 d9 d0 d7 c9 07 3f 79 0b 6f bb ec ed bc ff dd 57 f2 cd 3b 1e c2 ..[z"5..&.......?y.o......W..;..
0520 71 5d 24 51 24 91 2d a0 aa 2a bd ab 57 71 f8 d8 04 ef 7e c7 a5 6c db f6 16 da db 3b 68 ac ab a6 q]$Q$.-..*..Wq....~..l.....;h...
0540 26 16 41 95 44 f4 a2 81 61 da c4 aa 2a d0 72 1a 92 24 d3 5c 17 cb 0d 4f 2d 25 81 5f 00 33 40 c6 &.A.D...a...*.r..$.\...O-%._.3@.
0560 d3 8a 57 89 9b 78 12 ef cb 40 dc b6 ed aa ff f9 fd 2b e3 80 12 0d 8a f5 e7 9c 7d 16 df db fd 13 ..W..x...@.......+........}.....
0580 12 4b 19 76 7d f6 ab 5c b1 63 07 57 5e fc 06 7e b9 e7 d7 58 b6 83 e3 b8 a4 b5 22 e1 70 98 ab de .K.v}..\.c.W^..~...X......".p...
05a0 b6 9d 17 0e 0c b1 a6 ab 9d 0b 2e dc 46 55 55 15 6b 56 b5 13 89 44 08 05 43 34 d4 55 33 d0 d7 45 ............FUU.kV...D..C4.U3..E
05c0 75 55 25 c5 a2 c1 99 67 ac 23 10 54 d9 bc 71 5d a7 e7 f9 88 d7 66 28 be 6a 24 f8 25 40 5c c1 78 uU%....g.#.T..q].....f(.j$.%@\.x
05e0 09 50 de f7 97 5b c3 57 6f eb df 1a 56 e5 46 40 e9 5f dd c2 9e 47 9e a0 77 55 13 9f ff f2 37 d8 .P...[.Wo...V.F@._...G..wU....7.
0600 f9 d6 8b 90 65 91 a6 96 26 0e 0e cf 60 58 36 39 dd a4 be b6 86 77 be fd 62 9e fa ed 3e 2c d7 e5 ....e...&...`X69.....w..b...>,..
0620 bd ef ba 8a ba da 5a 7a bb db 09 06 64 54 09 54 59 44 55 54 2a 23 41 56 b5 d6 23 0a 02 86 61 d2 ......Zz....dT.TYDUT*#AV..#...a.
0640 de da cc c2 52 16 4f 95 1b 3c 71 53 3c 9b 84 b2 1e 0b b9 cc f8 12 00 05 08 dc 7e db 27 df 3d 3e ....R.O..<qS<.............~.'.=>
0660 3a d1 24 b8 b7 77 fe e4 e9 c1 83 c7 c6 17 90 44 81 ab ff fa 72 3e 7b e3 2e e6 97 72 7c e0 9a 4b :.$..w.........D....r>{....r|..K
0680 f9 fa f7 1e a2 68 da 98 96 c3 96 8d bd 0c 6c e8 63 70 78 8c 83 43 e3 5c 78 ee 16 d6 ad 5d c3 ba .....h........l.cpx..C.\x....]..
06a0 9e 76 02 01 15 6c 13 c9 a3 73 24 a4 90 2e e6 89 06 65 42 41 95 a5 74 8e d9 85 64 89 1d 0d 9e 3d .v...l...s$......eBA..t...d....=
06c0 25 ef 4b cb 69 81 bc 4c e5 f9 03 80 6c de 68 5a d4 1c 3e 7d e3 ae 48 4f d7 9e 8e 83 af 0c 12 8d %.K.i..L....l.hZ..>}..HO........
06e0 04 69 69 5d c5 d0 e8 2c 97 6f 3f 93 9f 3f fa 14 05 c3 a2 68 3a 6c ee 5f c3 da be d5 1c 3d 3e c1 .ii]...,.o?..?.....h:l._.....=>.
0700 c3 4f 3c 4f ff da 6e de 75 d5 65 f4 ad 6a 41 92 44 70 6c 5c 4b 47 70 6d 04 d7 46 d7 0b e8 ba c1 .O<O..n.u.e..jA.Dpl\KGpm..F.....
0720 d0 d8 14 d9 7c 81 ac a6 13 0a 05 39 3e 36 0d f0 0a 90 2d a3 cf 8a 00 ca b9 af 02 21 59 96 f8 ce ....|......9>6....-........!Y...
0740 7d 8f 50 13 8b b2 a1 ab bb 71 f8 d8 08 e7 9f 73 06 0f fc e7 7f b0 7e 75 33 b1 ca 2a 26 e6 b3 14 }.P......q.....s......~u3..*&...
0760 0c 9b ca 8a 0a ba bb 3a 78 e6 f7 87 d8 bb 6f 90 78 75 8c 68 65 25 b7 ff f0 67 68 7a 91 ad 9b 07 .......:x.....o.xu.he%...ghz....
0780 a8 88 04 28 16 0a 24 93 49 46 c6 27 f9 f5 d3 2f 71 e4 d8 38 43 e3 b3 2c 24 b3 14 74 83 f6 a6 38 ...(..$.IF.'.../q..8C..,$..t...8
07a0 9d cd b5 25 0a 49 3e cf bf 8a ff a7 8c 40 26 9b c7 34 2d 06 7a 3b 79 f6 b9 97 38 3c 3a cb fa 9e ...%.I>......@&..4-.z;y...8<:...
07c0 39 34 bd 88 a6 1b 3c f1 ec 3e 34 dd c4 72 04 5a 5a 9a b8 fd fe c7 48 e7 0b 00 a4 67 96 98 cf be 94....<..>4..r.ZZ.....H....g....
07e0 c2 da b5 6b 79 e4 f1 67 a9 8c 84 a9 af af e5 53 5f fc 36 d7 5e fe 66 9e 7a fe 00 0f fe fa 79 b2 ...ky..g.......S_.6.^.f.z.....y.
0800 b9 3c 52 24 ce 85 17 5c c2 fc c8 01 70 2c 5c d7 1d f7 19 5d ee f5 93 46 c0 1f 85 40 22 95 3d 12 .<R$...\....p,\....]...F...@".=.
0820 8b 86 fb 5e 38 38 44 ae 60 b0 98 2e b0 77 df 20 f3 4b 59 ba db 1b 18 9e 4c 20 48 32 5b fa 3b 99 ...^88D.`....w...KY.....L.H2[.;.
0840 cf 14 e8 ea e9 a6 aa a9 9b 43 93 59 6c a3 c0 e5 e7 ad 63 e7 15 97 b2 e7 fe ef 91 ca e6 50 83 01 .........C.Yl.....c..........P..
0860 9e fc dd 7e d2 e9 0c eb 56 b7 73 f5 d5 57 73 f7 8f 7f 45 5d c7 5a a6 27 27 28 e4 75 2a 42 72 c9 ...~....V.s..Ws...E].Z.''(.u*Br.
0880 46 a1 cc e3 cb 36 9e f2 49 34 40 1e 9f 9c 19 3a 67 53 77 df 0f 1e 78 8c ad 03 3d 58 b6 4b 4e b7 F....6..I4@....:gSw...x...=X.KN.
08a0 c9 16 0c 26 66 93 34 d4 57 b3 75 f3 7a 6a 6b 6a 18 1c 9d e6 c5 a1 59 c6 8e 1e 42 0d c4 71 a3 b5 ...&f.4.W.u.zjkj......Y...B..q..
08c0 c4 62 55 7c e1 d6 2f b2 ba a9 92 ea 9a 5a 9a ea e2 a8 aa ca a1 e1 71 c2 01 19 7b 26 83 93 9d 23 .bU|../......Z........q...{&...#
08e0 39 98 a0 f7 cc 01 a2 0d 5d 68 f9 2c d2 ab 47 ea 53 ce 03 a2 8f 3e aa d7 0d 46 e7 16 93 a9 0f bc 9.......]h.,..G.S....>...F......
0900 63 db 5b 25 49 c4 b1 6d 0e 0e 8e d2 50 1b 63 62 36 49 30 18 e0 6f 77 5e 46 43 5d 0d 6d 8d d5 9c c.[%I..m....P.cb6I0..ow^FC].m...
0920 7d 46 1f ab 3b 5a 59 ca 6a a4 66 47 b1 53 e3 8c 1d 3f 4a 73 6d 15 37 5e bf 93 d6 c6 7a 82 41 95 }F..;ZY.j.fG.S...?Jsm.7^....z.A.
0940 87 7e f5 24 33 f3 4b f4 76 34 d1 d5 d1 cc b9 5b fa 39 f7 ac 7e 1a e2 95 04 54 15 bd 68 90 cb e7 .~.$3.K.v4.....[.9..~....T..h...
0960 f6 1f 9f 5c 18 03 52 5e 2e e4 3c 3d 28 fa 04 cd 2d 8f 80 5b 86 d6 79 fc 77 07 17 f7 1d 19 7d e2 ...\..R^..<=(...-..[..y.w.....}.
0980 a2 37 6e d8 36 31 b3 c8 c4 d4 46 22 41 99 83 43 13 5c b6 fd 8d 28 b2 48 4b 7d 15 5b cf 58 8f 23 .7n.61....F"A..C.\...(.HK}.[.X.#
09a0 05 e8 ee 95 d9 be ed bc 13 89 aa 99 54 d7 c4 09 06 43 a8 aa 0a 66 01 d1 d5 b9 eb b6 8f 71 ce 5f ............T....C...f.......q._
09c0 fd 03 43 13 73 f4 f7 af 27 1a 52 89 84 03 68 05 03 ad 50 c4 b2 2c 44 41 70 7d 0b 04 ce 32 b3 80 ..C.s...'.R...h...P..,DAp}...2..
09e0 5b 4e 21 bf f1 8e 77 a2 05 18 3b 6f fa fa 8f ee bc e5 43 e1 d6 86 f8 d6 6d e7 9c 41 38 a8 92 4d [N!...w...;o......C.....m..A8..M
0a00 25 d9 76 f6 00 b5 f1 6a 7a 3a 5b 41 52 11 d4 28 b2 18 c0 b1 6d 9c ca 2a 6a 04 09 07 09 51 56 4e %.v....jz:[AR..(....m..*j....QVN
0a20 84 57 15 41 b7 d8 b4 a6 8d 96 86 1a 46 26 e7 b1 2c 0b 49 0c 22 08 02 ae eb 62 da 2e 45 5d 63 78 .W.A........F&..,.I."....b..E]cx
0a40 7c 6e c6 07 a0 bc 07 5a b6 99 13 96 a9 42 25 2a 05 7f f6 f8 ef a7 e7 12 e9 64 ff ea d6 c6 96 fa |n.....Z.....B%*.........d......
0a60 aa d0 8e 37 9f 4d 6f 57 0b 75 b5 35 20 48 20 4a 08 52 00 49 94 11 24 15 41 92 11 45 19 59 56 50 ...7.MoW.u.5.H.J.R.I..$.A..E.YVP
0a80 04 07 59 74 11 45 f1 c4 bd ad 3c 1b bb 1a b8 e7 97 cf 50 34 0c 7a bb da 70 00 c3 b0 58 4c a4 c8 ..Yt.E....<.......P4.z..p...XL..
0aa0 a4 53 bc 70 78 f4 19 af 0b 4d fa 28 54 00 8c f2 e9 4c 2c a7 8d 77 80 e9 f1 4d f3 4e ce fe d7 33 .S.px....M.(T....L,..w...M.N...3
0ac0 2f 0f 5d fb e9 6f ff bc b1 b6 9a e6 86 38 02 a2 77 96 8d 6b 19 b8 66 1e 17 1b 51 70 90 25 01 45 /.]..o.......8..w..k..f...Qp.%.E
0ae0 16 90 05 1b c1 35 4f dc c0 b1 c1 2e 92 4e a5 58 d7 d3 c2 c0 9a 36 0e 1c 39 4e 3e 9b c5 75 1c 1c .....5O......N.X.....6..9N>..u..
0b00 c7 21 95 cd 22 4b 52 d2 8b be e9 1b f6 ed 95 da 69 b1 8c 57 4e 89 3a 5e 33 95 f7 d4 30 5d 4a a8 .!.."KR.........i..WN.:^3...0]J.
0b20 f9 a5 8c 66 98 26 96 eb 62 16 0b 38 a6 01 ee 09 03 1e 7b fc 49 b4 6c 02 c7 d2 71 0c 0d d7 d4 70 ...f.&..b..8......{.I.l...q....p
0b40 1c 1b c7 c8 e3 16 33 7c f9 f6 7b 69 3c ef 3a da 2f fa 28 2f 1f 9d c0 b2 1d 66 17 93 04 55 99 82 ......3|..{i<.:./.(/.....f...U..
0b60 61 a2 eb 3a a2 28 68 9e 0d fe ad 3c 17 96 6d a7 85 65 34 c1 5f 9d 64 40 ee 6c 8e f7 74 36 c5 ab a..:.(h....<..m..e4._.d@.l..t6..
0b80 25 01 6c db 41 10 04 24 45 c5 c5 e1 b1 67 f7 f3 de 9b be 4c 5d 2c 44 63 5d 0c 49 56 90 5c 13 d7 %.l.A..$E....g.....L],Dc].IV.\..
0ba0 d4 70 0d 8d 58 50 24 91 ca 10 0a a8 54 55 86 d9 ba a1 9b 2d eb ba b0 05 99 f9 44 8a c5 85 05 6c .p..XP$.....TU.....-......D....l
0bc0 db 39 38 32 b5 30 ea d1 a7 54 85 34 cf a1 66 39 88 95 e6 01 a1 4c 9d ff a0 0d 8d f1 aa f0 f4 42 .982.0...T.4..f9.....L.........B
0be0 aa 2f 5e 55 81 24 89 38 8e 8b 6b 17 11 1c 93 2d eb 3a b1 91 f8 e8 cd df e5 c5 03 83 f4 76 36 52 ./^U.$.8..k....-.:...........v6R
0c00 19 92 91 31 71 2d 83 78 54 e5 b2 b7 6c 62 e7 5f 9c cd 40 6f 1b 03 3d ad fc f7 73 87 d8 bb ef 30 ...1q-.xT...lb._..@o..=...s....0
0c20 82 6d 52 d0 0d 72 5a e1 d0 f4 42 6a 0a 58 f2 00 64 3d 26 14 3d 00 b6 7f ed 55 58 61 94 94 fd 7a .mR..rZ...Bj.X..d=&.=....UXa...z
0c40 00 54 01 b5 40 23 d0 7c c3 35 17 ff d3 86 9e b6 68 67 73 2d 1d 4d 71 a2 91 20 01 55 45 55 64 66 .T..@#.|.5......hgs-.Mq....UEUdf
0c60 17 53 bc 74 64 84 0f df bc 1b c3 b4 b8 72 fb 56 aa 2b 43 d4 54 86 10 11 d0 8a 06 f3 89 0c 7b 0f .S.td........r.V.+C.T.........{.
0c80 1c e3 e8 e8 2c b2 24 52 19 0d b1 b9 af 83 9c a6 f3 f4 be a1 3b 80 09 60 dc db cf 79 60 72 5e 14 ....,.$R............;..`...y`r^.
0ca0 4a 94 7a 95 0e f8 73 a1 94 c8 a2 2f 17 02 de aa 59 24 9d d3 7e 3b bb 98 bc 28 14 90 71 1c 87 55 J.z...s..../....Y$..~;...(..q..U
0cc0 ad 0d b8 08 e0 3a a8 b2 c8 a6 de 0e 1e fa ea df f3 89 7f bb 9f 7b 7e fe e4 49 d7 6d 3a 9a e3 6c .....:...............{~..I.m:..l
0ce0 ee eb 60 7a 3e 45 40 91 67 7c 05 a4 b8 4c 0e 9c f6 50 7f b2 29 4d d9 3f 38 9e a9 ab aa e8 54 15 ..`z>E@.g|...L...P..)M.?8.....T.
0d00 a5 5a 14 45 f4 62 91 70 50 25 a8 2a 28 8a 84 6e 58 48 82 c0 59 1b 56 d1 d5 5c 47 7d bc 92 86 9a .Z.E.b.pP%.*(..nXH..Y.V..\G}....
0d20 18 cd 75 55 b4 35 d6 b0 a1 a7 95 b3 fb bb d9 da df 45 6d 55 05 4b e9 1c 99 5c 81 50 40 1d 1d 99 ..uU.5...........EmU.K...\.P@...
0d40 5e 3c e6 79 3c 59 a6 c2 46 39 7d 4e 16 01 96 29 a9 05 5f 55 9a df 7b 60 f8 99 ea 58 a4 21 95 cd ^<.y<Y..F9}N...).._U..{`...X.!..
0d60 47 7a 3b 9b 30 2d 9b fa 9a 18 ad 0d 35 54 57 84 d0 b4 02 b6 e3 d0 d1 5c 4b ac 32 8c 65 d9 e0 9e Gz;.0-......5TW........\K.2.e...
0d80 b8 b4 ed b8 14 0d 93 d1 e9 45 2c db 21 af 15 51 64 89 e1 c9 b9 51 cf d0 52 25 34 7d 74 71 ca 04 .........E,.!..Qd....Q..R%4}tq..
0da0 f7 94 cb 2a fe bd 58 96 cc 4a 26 57 c8 cd 2c a6 cc 8e e6 da 8e a9 b9 a4 e2 ba 80 eb 92 cd 17 c8 ...*..X..J&W..,.................
0dc0 e5 75 62 d1 30 e1 a0 ca cc 42 0a c7 75 b0 ed ff 73 9c e3 b8 a4 72 1a a6 69 a1 1b 26 b9 42 11 20 .ub.0....B..u...s....r..i..&.B..
0de0 73 e8 f8 f4 cb 9e f7 97 ca fa 20 bd 0c 8c fb 5a 28 b4 9c 52 4b 80 9c cd eb b9 a9 b9 a4 d4 de 58 s..............Z(..RK..........X
0e00 d3 bc 90 ca 28 0b 4b 19 6c c7 c1 05 74 c3 24 9d d5 70 5d 97 70 30 40 24 14 20 14 54 89 86 83 a4 ....(.K.l...t.$..p].p0@$...T....
0e20 73 05 52 19 0d c3 30 99 9c 4f 92 cb 17 98 9c 5b 9a c9 17 8c 41 8f 3a cb 55 a0 ff 97 bc a7 0b e0 s.R...0..O.....[....A.:.U.......
0e40 64 da 20 02 62 be 50 4c cf 26 d2 52 28 a0 56 14 0d 33 9c ca 17 c8 6b 3a d9 bc 4e 32 93 67 21 99 d...b.PL.&.R(.V..3....k:..N2.g!.
0e60 25 9b 2f a0 17 0d 0a 45 83 f1 d9 04 73 89 34 c9 8c c6 f8 6c 82 42 d1 a0 50 34 b3 63 33 4b 53 c0 %./....E....s.4....l.B..P4.c3KS.
0e80 34 b0 e8 d3 80 ac 47 5d 3f 80 3f 6a 79 7d 39 9d 28 81 11 34 dd 48 8f 4e 2f ba ba 61 1a 21 55 09 4.....G]?.?jy}9.(..4.H.N/..a.!U.
0ea0 66 f3 7a 60 74 7a 91 b9 a5 0c 00 a9 ac c6 e8 74 82 63 13 73 4c cc 2e 91 cd 17 58 ca e4 b1 1d 87 f.z`tz.........t.c.sL.....X.....
0ec0 c5 54 ae b8 90 cc 4c ea 86 35 05 cc fa 00 f8 e9 53 02 f0 aa 2a 24 9f c2 78 77 99 16 43 f2 ad 12 .T....L..5......S...*$..xw..C...
0ee0 94 86 6d 17 b0 c6 a6 13 fa d8 74 22 55 5d 19 8e 35 d7 55 45 a3 a1 60 6c 62 26 21 c4 a2 21 04 01 ..m.......t"U]..5.UE..`lb&!..!..
0f00 c1 75 4f a0 5e 48 e5 8a c9 4c de 9d 4b 64 ac 5c a1 b8 e0 51 26 ef 79 5d 2b e3 bc 73 b2 c5 5d f9 .uO.^H...L..Kd.\...Q&.y]+..s..].
0f20 34 22 50 02 20 78 20 8a be 39 55 5c a6 09 ec 4a 66 b4 ce 64 46 cb 79 9e b4 3d 4f 2a be a8 57 7b 4"P..x...9U\...Jf..dF.y..=O*..W{
0f40 c7 e6 bd 2d 0d 8c 7a 94 d1 3c da e8 be 4a e4 ac 34 91 9d 2e 00 7c 51 28 6f 35 1c df 6f a6 77 f3 ...-..z..<...J..4....|Q(o5..o.w.
0f60 19 a0 13 68 f2 9e 7b f9 a3 85 a7 ae 11 0f 5c 02 98 5c 81 f7 e6 c9 44 ec 74 01 f8 a3 c0 32 4f 11 ...h..{.......\..\....D.t....2O.
0f80 4b de 37 7c 00 4a 5e 3d e6 a9 77 c0 6b 4d a4 65 40 a7 bc b5 cf 94 ef 7d 79 e5 59 f1 b9 f3 e9 02 K.7|.J^=..w.kM.e@......}y.Y.....
0fa0 28 07 e1 2e 33 43 94 64 bf e0 9b 23 22 de 16 5c 66 75 ad d4 b2 17 ca 5a f6 12 80 c2 4a b5 ff 8f (...3C.d...#"..\fu.....Z....J...
0fc0 05 b0 52 24 ca 29 a4 fb a2 10 f6 22 10 2a 09 a0 67 7c a9 df 2a 29 7c ce a7 f2 a5 3c 30 cb 06 f8 ..R$.).....".*..g|..*)|....<0...
0fe0 d7 05 00 65 b2 ee df 6c 1f 08 c3 33 22 e8 6d aa 47 23 c9 07 c0 29 03 ac 79 20 f4 b2 d2 e9 bc 1e ...e...l...3".m.G#...)..y.......
1000 cf 89 4f a5 ce 62 d9 b2 a4 e2 33 ba f4 5e 2e 2b bb b6 af aa 19 be d2 59 f4 f5 43 76 d9 33 81 d7 ..O..b....3..^.+.......Y..Cv.3..
1020 fd bf 12 fe 19 c2 bf 34 2f fb 28 23 f9 f6 a2 4f 3c 6d 5f e9 2d 45 ce 2c ab 3c ce a9 fe 38 f2 7a .......4/.(#...O<m_.-E.,.<...8.z
1040 00 38 59 ab 21 97 2d ce 8a 65 ff 9f f0 e7 8f bf d7 f1 e7 17 7f 0e 00 27 6d 35 7c fb e5 ee 67 fb .8Y.!.-..e.............'m5|...g.
1060 f6 ee a9 92 b6 fc f5 bf cc c5 9e 5e 11 48 6f ba 00 00 00 00 49 45 4e 44 ae 42 60 82 ...........^.Ho.....IEND.B`.
href='#n835'>835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */

/*
 * Authors :
 *  Damon Chaplin <damon@ximian.com>
 *  Rodrigo Moya <rodrigo@ximian.com>
 *
 * Copyright 1999, Ximian, Inc.
 * Copyright 2001, Ximian, Inc.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of version 2 of the GNU General Public
 * License as published by the Free Software Foundation.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 */

/*
 * EWeekView - displays the Week & Month views of the calendar.
 */

#include <config.h>

#include "e-week-view.h"

#include <math.h>
#include <gdk/gdkkeysyms.h>
#include <gtk/gtkinvisible.h>
#include <gtk/gtkselection.h>
#include <gtk/gtksignal.h>
#include <gtk/gtkvscrollbar.h>
#include <gtk/gtkwindow.h>
#include <gtk/gtkmain.h>
#include <libgnome/gnome-defs.h>
#include <libgnome/gnome-i18n.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gdk-pixbuf/gnome-canvas-pixbuf.h>
#include <gal/e-text/e-text.h>
#include <gal/widgets/e-popup-menu.h>
#include <gal/widgets/e-canvas-utils.h>
#include <gal/widgets/e-unicode.h>
#include "dialogs/delete-comp.h"
#include "comp-util.h"
#include "cal-util/timeutil.h"
#include "calendar-commands.h"
#include "calendar-config.h"
#include "goto.h"
#include "e-week-view-event-item.h"
#include "e-week-view-layout.h"
#include "e-week-view-main-item.h"
#include "e-week-view-titles-item.h"
#include "misc.h"

/* Images */
#include "art/bell.xpm"
#include "art/recur.xpm"
#include "art/timezone-16.xpm"
#include "art/jump.xpm"

#define E_WEEK_VIEW_SMALL_FONT  \
    "-adobe-utopia-regular-r-normal-*-*-100-*-*-p-*-iso8859-*"
#define E_WEEK_VIEW_SMALL_FONT_FALLBACK \
    "-adobe-helvetica-medium-r-normal-*-*-80-*-*-p-*-iso8859-*"

#define E_WEEK_VIEW_JUMP_BUTTON_WIDTH   16
#define E_WEEK_VIEW_JUMP_BUTTON_HEIGHT  8

#define E_WEEK_VIEW_JUMP_BUTTON_X_PAD   3
#define E_WEEK_VIEW_JUMP_BUTTON_Y_PAD   3

/* The timeout before we do a layout, so we don't do a layout for each event
   we get from the server. */
#define E_WEEK_VIEW_LAYOUT_TIMEOUT  100

/* Used for the status bar messages */
#define EVOLUTION_CALENDAR_PROGRESS_IMAGE "evolution-calendar-mini.png"
static GdkPixbuf *progress_icon[2] = { NULL, NULL };

/* Signal IDs */
enum {
    SELECTION_CHANGED,
    LAST_SIGNAL
};
static guint e_week_view_signals[LAST_SIGNAL] = { 0 };


static void e_week_view_class_init (EWeekViewClass *class);
static void e_week_view_init (EWeekView *week_view);
static void e_week_view_destroy (GtkObject *object);
static void e_week_view_realize (GtkWidget *widget);
static void e_week_view_unrealize (GtkWidget *widget);
static void e_week_view_style_set (GtkWidget *widget,
                   GtkStyle  *previous_style);
static void e_week_view_size_allocate (GtkWidget *widget,
                       GtkAllocation *allocation);
static void e_week_view_recalc_cell_sizes (EWeekView *week_view);
static gint e_week_view_focus_in (GtkWidget *widget,
                  GdkEventFocus *event);
static gint e_week_view_focus_out (GtkWidget *widget,
                   GdkEventFocus *event);
static gint e_week_view_expose_event (GtkWidget *widget,
                      GdkEventExpose *event);
static void e_week_view_draw (GtkWidget    *widget,
                  GdkRectangle *area);
static void e_week_view_draw_shadow (EWeekView *week_view);

static gboolean e_week_view_on_button_press (GtkWidget *widget,
                         GdkEventButton *event,
                         EWeekView *week_view);
static gboolean e_week_view_on_button_release (GtkWidget *widget,
                           GdkEventButton *event,
                           EWeekView *week_view);
static gboolean e_week_view_on_motion (GtkWidget *widget,
                       GdkEventMotion *event,
                       EWeekView *week_view);
static gint e_week_view_convert_position_to_day (EWeekView *week_view,
                         gint x,
                         gint y);
static void e_week_view_update_selection (EWeekView *week_view,
                      gint day);

static void e_week_view_free_events (EWeekView *week_view);
static gboolean e_week_view_add_event (CalComponent *comp,
                       time_t     start,
                       time_t     end,
                       gpointer   data);
static void e_week_view_check_layout (EWeekView *week_view);
static void e_week_view_ensure_events_sorted (EWeekView *week_view);
static void e_week_view_reshape_events (EWeekView *week_view);
static void e_week_view_reshape_event_span (EWeekView *week_view,
                        gint event_num,
                        gint span_num);
static void e_week_view_recalc_day_starts (EWeekView *week_view,
                       time_t lower);
static void e_week_view_on_adjustment_changed (GtkAdjustment *adjustment,
                           EWeekView *week_view);
static void e_week_view_on_editing_started (EWeekView *week_view,
                        GnomeCanvasItem *item);
static void e_week_view_on_editing_stopped (EWeekView *week_view,
                        GnomeCanvasItem *item);
static gboolean e_week_view_find_event_from_item (EWeekView   *week_view,
                          GnomeCanvasItem *item,
                          gint        *event_num,
                          gint        *span_num);
static gboolean e_week_view_find_event_from_uid (EWeekView    *week_view,
                         const gchar      *uid,
                         gint         *event_num_return);
typedef gboolean (* EWeekViewForeachEventCallback) (EWeekView *week_view,
                            gint event_num,
                            gpointer data);

static void e_week_view_foreach_event_with_uid (EWeekView *week_view,
                        const gchar *uid,
                        EWeekViewForeachEventCallback callback,
                        gpointer data);
static gboolean e_week_view_on_text_item_event (GnomeCanvasItem *item,
                        GdkEvent *event,
                        EWeekView *week_view);
static gboolean e_week_view_on_jump_button_event (GnomeCanvasItem *item,
                          GdkEvent *event,
                          EWeekView *week_view);
static gint e_week_view_key_press (GtkWidget *widget, GdkEventKey *event);
static void e_week_view_on_new_appointment (GtkWidget *widget,
                        gpointer data);
static void e_week_view_on_new_event       (GtkWidget *widget,
                       gpointer data);
static void e_week_view_on_goto_today      (GtkWidget *widget,
                       gpointer data);
static void e_week_view_on_goto_date       (GtkWidget *widget,
                       gpointer data);
static void e_week_view_on_edit_appointment (GtkWidget *widget,
                         gpointer data);
static void e_week_view_on_delete_occurrence (GtkWidget *widget,
                          gpointer data);
static void e_week_view_on_delete_appointment (GtkWidget *widget,
                           gpointer data);
static void e_week_view_on_cut (GtkWidget *widget, gpointer data);
static void e_week_view_on_copy (GtkWidget *widget, gpointer data);
static void e_week_view_on_paste (GtkWidget *widget, gpointer data);
static void e_week_view_on_unrecur_appointment (GtkWidget *widget,
                        gpointer data);

static gboolean e_week_view_update_event_cb (EWeekView *week_view,
                         gint event_num,
                         gpointer data);
static gboolean e_week_view_remove_event_cb (EWeekView *week_view,
                         gint event_num,
                         gpointer data);
static gboolean e_week_view_recalc_display_start_day    (EWeekView  *week_view);

static void invisible_destroyed   (GtkWidget *invisible, EWeekView *week_view);
static void selection_get         (GtkWidget *invisible,
                   GtkSelectionData *selection_data,
                   guint info,
                   guint time_stamp,
                   EWeekView *week_view);
static void selection_clear_event (GtkWidget *invisible,
                   GdkEventSelection *event,
                   EWeekView *week_view);
static void selection_received    (GtkWidget *invisible,
                   GtkSelectionData *selection_data,
                   guint time,
                   EWeekView *week_view);

static void e_week_view_queue_layout (EWeekView *week_view);
static void e_week_view_cancel_layout (EWeekView *week_view);
static gboolean e_week_view_layout_timeout_cb (gpointer data);


static GtkTableClass *parent_class;
static GdkAtom clipboard_atom = GDK_NONE;


GtkType
e_week_view_get_type (void)
{
    static GtkType e_week_view_type = 0;

    if (!e_week_view_type){
        GtkTypeInfo e_week_view_info = {
            "EWeekView",
            sizeof (EWeekView),
            sizeof (EWeekViewClass),
            (GtkClassInitFunc) e_week_view_class_init,
            (GtkObjectInitFunc) e_week_view_init,
            NULL, /* reserved 1 */
            NULL, /* reserved 2 */
            (GtkClassInitFunc) NULL
        };

        parent_class = gtk_type_class (GTK_TYPE_TABLE);
        e_week_view_type = gtk_type_unique (GTK_TYPE_TABLE,
                            &e_week_view_info);
    }

    return e_week_view_type;
}


static void
e_week_view_class_init (EWeekViewClass *class)
{
    GtkObjectClass *object_class;
    GtkWidgetClass *widget_class;

    object_class = (GtkObjectClass *) class;
    widget_class = (GtkWidgetClass *) class;

    e_week_view_signals[SELECTION_CHANGED] =
        gtk_signal_new ("selection_changed",
                GTK_RUN_LAST,
                object_class->type,
                GTK_SIGNAL_OFFSET (EWeekViewClass, selection_changed),
                gtk_marshal_NONE__NONE,
                GTK_TYPE_NONE, 0);

    gtk_object_class_add_signals (object_class, e_week_view_signals, LAST_SIGNAL);

    /* Method override */
    object_class->destroy       = e_week_view_destroy;

    widget_class->realize       = e_week_view_realize;
    widget_class->unrealize     = e_week_view_unrealize;
    widget_class->style_set     = e_week_view_style_set;
    widget_class->size_allocate = e_week_view_size_allocate;
    widget_class->focus_in_event    = e_week_view_focus_in;
    widget_class->focus_out_event   = e_week_view_focus_out;
    widget_class->key_press_event   = e_week_view_key_press;
    widget_class->expose_event  = e_week_view_expose_event;
    widget_class->draw      = e_week_view_draw;

    class->selection_changed = NULL;

    /* clipboard atom */
    if (!clipboard_atom)
        clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE);
}


static void
e_week_view_init (EWeekView *week_view)
{
    GnomeCanvasGroup *canvas_group;
    GtkObject *adjustment;
    GdkPixbuf *pixbuf;
    gint i;

    GTK_WIDGET_SET_FLAGS (week_view, GTK_CAN_FOCUS);

    week_view->calendar = NULL;
    week_view->client = NULL;
    week_view->sexp = g_strdup ("#t"); /* match all by default */
    week_view->query = NULL;

    week_view->events = g_array_new (FALSE, FALSE,
                     sizeof (EWeekViewEvent));
    week_view->events_sorted = TRUE;
    week_view->events_need_layout = FALSE;
    week_view->events_need_reshape = FALSE;

    week_view->layout_timeout_id = 0;

    week_view->spans = NULL;

    week_view->zone = NULL;
    week_view->multi_week_view = FALSE;
    week_view->weeks_shown = 6;
    week_view->rows = 6;
    week_view->columns = 2;
    week_view->compress_weekend = TRUE;
    week_view->show_event_end_times = TRUE;
    week_view->week_start_day = 0;      /* Monday. */
    week_view->display_start_day = 0;   /* Monday. */

    g_date_clear (&week_view->base_date, 1);
    g_date_clear (&week_view->first_day_shown, 1);

    week_view->row_height = 10;
    week_view->rows_per_cell = 1;

    week_view->selection_start_day = -1;
    week_view->selection_drag_pos = E_WEEK_VIEW_DRAG_NONE;

    week_view->pressed_event_num = -1;
    week_view->editing_event_num = -1;

    week_view->main_gc = NULL;

    week_view->default_category = NULL;

    /* Create the small font. */
    week_view->use_small_font = TRUE;
    week_view->small_font = gdk_font_load (E_WEEK_VIEW_SMALL_FONT);
    if (!week_view->small_font)
        week_view->small_font = gdk_font_load (E_WEEK_VIEW_SMALL_FONT_FALLBACK);
    if (!week_view->small_font)
        g_warning ("Couldn't load font");

    /* String to use in 12-hour time format for times in the morning. */
    week_view->am_string = _("am");

    /* String to use in 12-hour time format for times in the afternoon. */
    week_view->pm_string = _("pm");


    /*
     * Titles Canvas. Note that we don't show it is only shown in the
     * Month view.
     */
    week_view->titles_canvas = e_canvas_new ();
    gtk_table_attach (GTK_TABLE (week_view), week_view->titles_canvas,
              1, 2, 0, 1, GTK_EXPAND | GTK_FILL, GTK_FILL, 0, 0);

    canvas_group = GNOME_CANVAS_GROUP (GNOME_CANVAS (week_view->titles_canvas)->root);

    week_view->titles_canvas_item =
        gnome_canvas_item_new (canvas_group,
                       e_week_view_titles_item_get_type (),
                       "EWeekViewTitlesItem::week_view", week_view,
                       NULL);

    /*
     * Main Canvas
     */
    week_view->main_canvas = e_canvas_new ();
    gtk_table_attach (GTK_TABLE (week_view), week_view->main_canvas,
              1, 2, 1, 2,
              GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 1, 1);
    gtk_widget_show (week_view->main_canvas);

    canvas_group = GNOME_CANVAS_GROUP (GNOME_CANVAS (week_view->main_canvas)->root);

    week_view->main_canvas_item =
        gnome_canvas_item_new (canvas_group,
                       e_week_view_main_item_get_type (),
                       "EWeekViewMainItem::week_view", week_view,
                       NULL);

    gtk_signal_connect_after (GTK_OBJECT (week_view->main_canvas),
                  "button_press_event",
                  GTK_SIGNAL_FUNC (e_week_view_on_button_press),
                  week_view);
    gtk_signal_connect_after (GTK_OBJECT (week_view->main_canvas),
                  "button_release_event",
                  GTK_SIGNAL_FUNC (e_week_view_on_button_release),
                  week_view);
    gtk_signal_connect_after (GTK_OBJECT (week_view->main_canvas),
                  "motion_notify_event",
                  GTK_SIGNAL_FUNC (e_week_view_on_motion),
                  week_view);

    /* Create the buttons to jump to each days. */
    pixbuf = gdk_pixbuf_new_from_xpm_data ((const char**) jump_xpm);

    for (i = 0; i < E_WEEK_VIEW_MAX_WEEKS * 7; i++) {
        week_view->jump_buttons[i] = gnome_canvas_item_new
            (canvas_group,
             gnome_canvas_pixbuf_get_type (),
             "GnomeCanvasPixbuf::pixbuf", pixbuf,
             NULL);

        gtk_signal_connect (GTK_OBJECT (week_view->jump_buttons[i]),
                    "event",
                    GTK_SIGNAL_FUNC (e_week_view_on_jump_button_event),
                    week_view);
    }
    gdk_pixbuf_unref (pixbuf);

    /*
     * Scrollbar.
     */
    adjustment = gtk_adjustment_new (0, -52, 52, 1, 1, 1);
    gtk_signal_connect (adjustment, "value_changed",
                GTK_SIGNAL_FUNC (e_week_view_on_adjustment_changed),
                week_view);

    week_view->vscrollbar = gtk_vscrollbar_new (GTK_ADJUSTMENT (adjustment));
    gtk_table_attach (GTK_TABLE (week_view), week_view->vscrollbar,
              2, 3, 1, 2, 0, GTK_EXPAND | GTK_FILL, 0, 0);
    gtk_widget_show (week_view->vscrollbar);

    /* Create the cursors. */
    week_view->normal_cursor = gdk_cursor_new (GDK_LEFT_PTR);
    week_view->move_cursor = gdk_cursor_new (GDK_FLEUR);
    week_view->resize_width_cursor = gdk_cursor_new (GDK_SB_H_DOUBLE_ARROW);
    week_view->last_cursor_set = NULL;

    /* Set up the inivisible widget for the clipboard selections */
    week_view->invisible = gtk_invisible_new ();
    gtk_selection_add_target (week_view->invisible,
                  clipboard_atom,
                  GDK_SELECTION_TYPE_STRING,
                  0);
    gtk_signal_connect (GTK_OBJECT (week_view->invisible),
                "selection_get",
                GTK_SIGNAL_FUNC (selection_get),
                (gpointer) week_view);
    gtk_signal_connect (GTK_OBJECT (week_view->invisible),
                "selection_clear_event",
                GTK_SIGNAL_FUNC (selection_clear_event),
                (gpointer) week_view);
    gtk_signal_connect (GTK_OBJECT (week_view->invisible),
                "selection_received",
                GTK_SIGNAL_FUNC (selection_received),
                (gpointer) week_view);
    gtk_signal_connect (GTK_OBJECT (week_view->invisible),
                "destroy",
                GTK_SIGNAL_FUNC (invisible_destroyed),
                (gpointer) week_view);
    week_view->clipboard_selection = NULL;

    week_view->activity = NULL;
}


/**
 * e_week_view_new:
 * @Returns: a new #EWeekView.
 *
 * Creates a new #EWeekView.
 **/
GtkWidget *
e_week_view_new (void)
{
    GtkWidget *week_view;

    week_view = GTK_WIDGET (gtk_type_new (e_week_view_get_type ()));

    return week_view;
}


static void
e_week_view_destroy (GtkObject *object)
{
    EWeekView *week_view;

    week_view = E_WEEK_VIEW (object);

    e_week_view_cancel_layout (week_view);

    e_week_view_free_events (week_view);
    g_array_free (week_view->events, TRUE);
    week_view->events = NULL;

    if (week_view->client) {
        gtk_signal_disconnect_by_data (GTK_OBJECT (week_view->client), week_view);
        gtk_object_unref (GTK_OBJECT (week_view->client));
        week_view->client = NULL;
    }

    if (week_view->sexp) {
        g_free (week_view->sexp);
        week_view->sexp = NULL;
    }

    if (week_view->query) {
        gtk_signal_disconnect_by_data (GTK_OBJECT (week_view->query), week_view);
        gtk_object_unref (GTK_OBJECT (week_view->query));
        week_view->query = NULL;
    }

    if (week_view->small_font) {
        gdk_font_unref (week_view->small_font);
        week_view->small_font = NULL;
    }

    if (week_view->default_category) {
        g_free (week_view->default_category);
        week_view->default_category = NULL;
    }

    gdk_cursor_destroy (week_view->normal_cursor);
    gdk_cursor_destroy (week_view->move_cursor);
    gdk_cursor_destroy (week_view->resize_width_cursor);

    if (week_view->invisible)
        gtk_widget_destroy (week_view->invisible);
    if (week_view->clipboard_selection) {
        g_free (week_view->clipboard_selection);
        week_view->clipboard_selection = NULL;
    }

    if (week_view->activity) {
        gtk_object_unref (GTK_OBJECT (week_view->activity));
        week_view->activity = NULL;
    }

    GTK_OBJECT_CLASS (parent_class)->destroy (object);
}


static void
e_week_view_realize (GtkWidget *widget)
{
    EWeekView *week_view;
    GdkColormap *colormap;
    gboolean success[E_WEEK_VIEW_COLOR_LAST];
    gint nfailed;

    if (GTK_WIDGET_CLASS (parent_class)->realize)
        (*GTK_WIDGET_CLASS (parent_class)->realize)(widget);

    week_view = E_WEEK_VIEW (widget);
    week_view->main_gc = gdk_gc_new (widget->window);

    colormap = gtk_widget_get_colormap (widget);

    /* Allocate the colors. */
    week_view->colors[E_WEEK_VIEW_COLOR_EVEN_MONTHS].red   = 0xe0e0;
    week_view->colors[E_WEEK_VIEW_COLOR_EVEN_MONTHS].green = 0xe0e0;
    week_view->colors[E_WEEK_VIEW_COLOR_EVEN_MONTHS].blue  = 0xe0e0;

    week_view->colors[E_WEEK_VIEW_COLOR_ODD_MONTHS].red   = 65535;
    week_view->colors[E_WEEK_VIEW_COLOR_ODD_MONTHS].green = 65535;
    week_view->colors[E_WEEK_VIEW_COLOR_ODD_MONTHS].blue  = 65535;

    week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BACKGROUND].red   = 213 * 257;
    week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BACKGROUND].green = 213 * 257;
    week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BACKGROUND].blue  = 213 * 257;

    week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BORDER].red   = 0;
    week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BORDER].green = 0;
    week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BORDER].blue  = 0;

    week_view->colors[E_WEEK_VIEW_COLOR_EVENT_TEXT].red   = 0;
    week_view->colors[E_WEEK_VIEW_COLOR_EVENT_TEXT].green = 0;
    week_view->colors[E_WEEK_VIEW_COLOR_EVENT_TEXT].blue  = 0;

    week_view->colors[E_WEEK_VIEW_COLOR_GRID].red   = 0 * 257;
    week_view->colors[E_WEEK_VIEW_COLOR_GRID].green = 0 * 257;
    week_view->colors[E_WEEK_VIEW_COLOR_GRID].blue  = 0 * 257;

    week_view->colors[E_WEEK_VIEW_COLOR_SELECTED].red   = 0 * 257;
    week_view->colors[E_WEEK_VIEW_COLOR_SELECTED].green = 0 * 257;
    week_view->colors[E_WEEK_VIEW_COLOR_SELECTED].blue  = 156 * 257;

    week_view->colors[E_WEEK_VIEW_COLOR_DATES].red   = 0 * 257;
    week_view->colors[E_WEEK_VIEW_COLOR_DATES].green = 0 * 257;
    week_view->colors[E_WEEK_VIEW_COLOR_DATES].blue  = 0 * 257;

    week_view->colors[E_WEEK_VIEW_COLOR_DATES_SELECTED].red   = 65535;
    week_view->colors[E_WEEK_VIEW_COLOR_DATES_SELECTED].green = 65535;
    week_view->colors[E_WEEK_VIEW_COLOR_DATES_SELECTED].blue  = 65535;

    nfailed = gdk_colormap_alloc_colors (colormap, week_view->colors,
                         E_WEEK_VIEW_COLOR_LAST, FALSE,
                         TRUE, success);
    if (nfailed)
        g_warning ("Failed to allocate all colors");


    /* Create the pixmaps. */
    week_view->reminder_icon = gdk_pixmap_colormap_create_from_xpm_d (NULL, colormap, &week_view->reminder_mask, NULL, bell_xpm);
    week_view->recurrence_icon = gdk_pixmap_colormap_create_from_xpm_d (NULL, colormap, &week_view->recurrence_mask, NULL, recur_xpm);
    week_view->timezone_icon = gdk_pixmap_colormap_create_from_xpm_d (NULL, colormap, &week_view->timezone_mask, NULL, timezone_16_xpm);
}


static void
e_week_view_unrealize (GtkWidget *widget)
{
    EWeekView *week_view;
    GdkColormap *colormap;
    gint i;

    week_view = E_WEEK_VIEW (widget);

    gdk_gc_unref (week_view->main_gc);
    week_view->main_gc = NULL;

    colormap = gtk_widget_get_colormap (widget);
    for (i = 0; i < E_WEEK_VIEW_COLOR_LAST; i++)
        gdk_colors_free (colormap, &week_view->colors[i].pixel, 1, 0);

    gdk_pixmap_unref (week_view->reminder_icon);
    week_view->reminder_icon = NULL;
    gdk_pixmap_unref (week_view->recurrence_icon);
    week_view->recurrence_icon = NULL;

    if (GTK_WIDGET_CLASS (parent_class)->unrealize)
        (*GTK_WIDGET_CLASS (parent_class)->unrealize)(widget);
}


static void
e_week_view_style_set (GtkWidget *widget,
              GtkStyle  *previous_style)
{
    EWeekView *week_view;
    EWeekViewEventSpan *span;
    GdkFont *font;
    gint day, day_width, max_day_width, max_abbr_day_width;
    gint month, month_width, max_month_width, max_abbr_month_width;
    gint span_num;
    GDate date;
    gchar buffer[128];

    if (GTK_WIDGET_CLASS (parent_class)->style_set)
        (*GTK_WIDGET_CLASS (parent_class)->style_set)(widget, previous_style);

    week_view = E_WEEK_VIEW (widget);
    font = widget->style->font;

    /* Recalculate the height of each row based on the font size. */
    week_view->row_height = font->ascent + font->descent + E_WEEK_VIEW_EVENT_BORDER_HEIGHT * 2 + E_WEEK_VIEW_EVENT_TEXT_Y_PAD * 2;
    week_view->row_height = MAX (week_view->row_height, E_WEEK_VIEW_ICON_HEIGHT + E_WEEK_VIEW_ICON_Y_PAD + E_WEEK_VIEW_EVENT_BORDER_HEIGHT * 2);

    /* Check that the small font is smaller than the default font.
       If it isn't, we won't use it. */
    if (week_view->small_font) {
        if (font->ascent + font->descent <= week_view->small_font->ascent + week_view->small_font->descent)
            week_view->use_small_font = FALSE;
    }

    /* Set the height of the top canvas. */
    gtk_widget_set_usize (week_view->titles_canvas, -1,
                  font->ascent + font->descent + 5);

    /* Save the sizes of various strings in the font, so we can quickly
       decide which date formats to use. */
    g_date_clear (&date, 1);
    g_date_set_dmy (&date, 27, 3, 2000);    /* Must be a Monday. */

    max_day_width = 0;
    max_abbr_day_width = 0;
    for (day = 0; day < 7; day++) {
        g_date_strftime (buffer, 128, "%A", &date);
        day_width = gdk_string_width (font, buffer);
        week_view->day_widths[day] = day_width;
        max_day_width = MAX (max_day_width, day_width);

        g_date_strftime (buffer, 128, "%a", &date);
        day_width = gdk_string_width (font, buffer);
        week_view->abbr_day_widths[day] = day_width;
        max_abbr_day_width = MAX (max_abbr_day_width, day_width);

        g_date_add_days (&date, 1);
    }

    max_month_width = 0;
    max_abbr_month_width = 0;
    for (month = 0; month < 12; month++) {
        g_date_set_month (&date, month + 1);

        g_date_strftime (buffer, 128, "%B", &date);
        month_width = gdk_string_width (font, buffer);
        week_view->month_widths[month] = month_width;
        max_month_width = MAX (max_month_width, month_width);

        g_date_strftime (buffer, 128, "%b", &date);
        month_width = gdk_string_width (font, buffer);
        week_view->abbr_month_widths[month] = month_width;
        max_abbr_month_width = MAX (max_abbr_month_width, month_width);
    }

    week_view->space_width = gdk_string_width (font, " ");
    week_view->colon_width = gdk_string_width (font, ":");
    week_view->slash_width = gdk_string_width (font, "/");
    week_view->digit_width = gdk_string_width (font, "5");
    if (week_view->small_font)
        week_view->small_digit_width = gdk_string_width (week_view->small_font, "5");
    week_view->max_day_width = max_day_width;
    week_view->max_abbr_day_width = max_abbr_day_width;
    week_view->max_month_width = max_month_width;
    week_view->max_abbr_month_width = max_abbr_month_width;

    week_view->am_string_width = gdk_string_width (font,
                               week_view->am_string);
    week_view->pm_string_width = gdk_string_width (font,
                               week_view->pm_string);

    /* Set the font of all the EText items. */
    if (week_view->spans) {
        for (span_num = 0; span_num < week_view->spans->len;
             span_num++) {
            span = &g_array_index (week_view->spans,
                           EWeekViewEventSpan, span_num);
            if (span->text_item)
                gnome_canvas_item_set (span->text_item,
                               "font_gdk", font,
                               NULL);
        }
    }
}


/* This recalculates the sizes of each column. */
static void
e_week_view_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
{
    EWeekView *week_view;
    gdouble old_x2, old_y2, new_x2, new_y2;

    week_view = E_WEEK_VIEW (widget);

    (*GTK_WIDGET_CLASS (parent_class)->size_allocate) (widget, allocation);

    e_week_view_recalc_cell_sizes (week_view);

    /* Set the scroll region of the top canvas to its allocated size. */
    gnome_canvas_get_scroll_region (GNOME_CANVAS (week_view->titles_canvas),
                    NULL, NULL, &old_x2, &old_y2);
    new_x2 = week_view->titles_canvas->allocation.width - 1;
    new_y2 = week_view->titles_canvas->allocation.height - 1;
    if (old_x2 != new_x2 || old_y2 != new_y2)
        gnome_canvas_set_scroll_region (GNOME_CANVAS (week_view->titles_canvas),
                        0, 0, new_x2, new_y2);


    /* Set the scroll region of the main canvas to its allocated width,
       but with the height depending on the number of rows needed. */
    gnome_canvas_get_scroll_region (GNOME_CANVAS (week_view->main_canvas),
                    NULL, NULL, &old_x2, &old_y2);
    new_x2 = week_view->main_canvas->allocation.width - 1;
    new_y2 = week_view->main_canvas->allocation.height - 1;
    if (old_x2 != new_x2 || old_y2 != new_y2)
        gnome_canvas_set_scroll_region (GNOME_CANVAS (week_view->main_canvas),
                        0, 0, new_x2, new_y2);

    /* Flag that we need to reshape the events. */
    if (old_x2 != new_x2 || old_y2 != new_y2) {
        week_view->events_need_reshape = TRUE;
        e_week_view_check_layout (week_view);
    }
}


static void
e_week_view_recalc_cell_sizes (EWeekView *week_view)
{
    gfloat canvas_width, canvas_height, offset;
    gint row, col;
    GtkWidget *widget;
    GdkFont *font;
    gint width, height, time_width;

    if (week_view->multi_week_view) {
        week_view->rows = week_view->weeks_shown * 2;
        week_view->columns = week_view->compress_weekend ? 6 : 7;
    } else {
        week_view->rows = 6;
        week_view->columns = 2;
    }

    /* Calculate the column sizes, using floating point so that pixels
       get divided evenly. Note that we use one more element than the
       number of columns, to make it easy to get the column widths.
       We also add one to the width so that the right border of the last
       column is off the edge of the displayed area. */
    canvas_width = week_view->main_canvas->allocation.width + 1;
    canvas_width /= week_view->columns;
    offset = 0;
    for (col = 0; col <= week_view->columns; col++) {
        week_view->col_offsets[col] = floor (offset + 0.5);
        offset += canvas_width;
    }

    /* Calculate the cell widths based on the offsets. */
    for (col = 0; col < week_view->columns; col++) {
        week_view->col_widths[col] = week_view->col_offsets[col + 1]
            - week_view->col_offsets[col];
    }

    /* Now do the same for the row heights. */
    canvas_height = week_view->main_canvas->allocation.height + 1;
    canvas_height /= week_view->rows;
    offset = 0;
    for (row = 0; row <= week_view->rows; row++) {
        week_view->row_offsets[row] = floor (offset + 0.5);
        offset += canvas_height;
    }

    /* Calculate the cell heights based on the offsets. */
    for (row = 0; row < week_view->rows; row++) {
        week_view->row_heights[row] = week_view->row_offsets[row + 1]
            - week_view->row_offsets[row];
    }


    /* If the font hasn't been set yet just return. */
    widget = GTK_WIDGET (week_view);
    if (!widget->style || ! widget->style->font)
        return;

    font = widget->style->font;

    /* Calculate the number of rows of events in each cell, for the large
       cells and the compressed weekend cells. */
    if (week_view->multi_week_view) {
        week_view->events_y_offset = E_WEEK_VIEW_DATE_T_PAD
            + font->ascent + font->descent
            + E_WEEK_VIEW_DATE_B_PAD;
    } else {
        week_view->events_y_offset = E_WEEK_VIEW_DATE_T_PAD
            + font->ascent + font->descent
            + E_WEEK_VIEW_DATE_LINE_T_PAD + 1
            + E_WEEK_VIEW_DATE_LINE_B_PAD;
    }

    height = week_view->row_heights[0];
    week_view->rows_per_cell = (height * 2 - week_view->events_y_offset)
        / (week_view->row_height + E_WEEK_VIEW_EVENT_Y_SPACING);
    week_view->rows_per_cell = MIN (week_view->rows_per_cell,
                    E_WEEK_VIEW_MAX_ROWS_PER_CELL);

    week_view->rows_per_compressed_cell =
        (height - week_view->events_y_offset)
        / (week_view->row_height + E_WEEK_VIEW_EVENT_Y_SPACING);
    week_view->rows_per_compressed_cell = MIN (week_view->rows_per_compressed_cell,
                           E_WEEK_VIEW_MAX_ROWS_PER_CELL);

    /* Determine which time format to use, based on the width of the cells.
       We only allow the time to take up about half of the width. */
    width = week_view->col_widths[0];

    time_width = e_week_view_get_time_string_width (week_view);

    week_view->time_format = E_WEEK_VIEW_TIME_NONE;
    if (week_view->use_small_font && week_view->small_font) {
        if (week_view->show_event_end_times
            && width / 2 > time_width * 2 + E_WEEK_VIEW_EVENT_TIME_SPACING)
            week_view->time_format = E_WEEK_VIEW_TIME_BOTH_SMALL_MIN;
        else if (width / 2 > time_width)
            week_view->time_format = E_WEEK_VIEW_TIME_START_SMALL_MIN;
    } else {
        if (week_view->show_event_end_times
            && width / 2 > time_width * 2 + E_WEEK_VIEW_EVENT_TIME_SPACING)
            week_view->time_format = E_WEEK_VIEW_TIME_BOTH;
        else if (width / 2 > time_width)
            week_view->time_format = E_WEEK_VIEW_TIME_START;
    }
}


static gint
e_week_view_focus_in (GtkWidget *widget, GdkEventFocus *event)
{
    EWeekView *week_view;

    g_return_val_if_fail (widget != NULL, FALSE);
    g_return_val_if_fail (E_IS_WEEK_VIEW (widget), FALSE);
    g_return_val_if_fail (event != NULL, FALSE);

    week_view = E_WEEK_VIEW (widget);

    GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS);

    gtk_widget_queue_draw (week_view->main_canvas);

    return FALSE;
}


static gint
e_week_view_focus_out (GtkWidget *widget, GdkEventFocus *event)
{
    EWeekView *week_view;

    g_return_val_if_fail (widget != NULL, FALSE);
    g_return_val_if_fail (E_IS_WEEK_VIEW (widget), FALSE);
    g_return_val_if_fail (event != NULL, FALSE);

    week_view = E_WEEK_VIEW (widget);

    GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS);

    gtk_widget_queue_draw (week_view->main_canvas);

    return FALSE;
}


/* This draws a shadow around the top display and main display. */
static gint
e_week_view_expose_event (GtkWidget *widget,
              GdkEventExpose *event)
{
    EWeekView *week_view;

    week_view = E_WEEK_VIEW (widget);

    e_week_view_draw_shadow (week_view);

    if (GTK_WIDGET_CLASS (parent_class)->expose_event)
        (*GTK_WIDGET_CLASS (parent_class)->expose_event)(widget, event);

    return FALSE;
}


static void
e_week_view_draw (GtkWidget    *widget,
          GdkRectangle *area)
{
    EWeekView *week_view;

    week_view = E_WEEK_VIEW (widget);

    e_week_view_draw_shadow (week_view);

    if (GTK_WIDGET_CLASS (parent_class)->draw)
        (*GTK_WIDGET_CLASS (parent_class)->draw)(widget, area);
}


static void
e_week_view_draw_shadow (EWeekView *week_view)
{
    gint x1, y1, x2, y2;
    GtkStyle *style;
    GdkGC *light_gc, *dark_gc;
    GdkWindow *window;

    /* Draw the shadow around the graphical displays. */
    x1 = week_view->main_canvas->allocation.x - 1;
    y1 = week_view->main_canvas->allocation.y - 1;
    x2 = x1 + week_view->main_canvas->allocation.width + 2;
    y2 = y1 + week_view->main_canvas->allocation.height + 2;

    style = GTK_WIDGET (week_view)->style;
    dark_gc = style->dark_gc[GTK_STATE_NORMAL];
    light_gc = style->light_gc[GTK_STATE_NORMAL];

    window = GTK_WIDGET (week_view)->window;
    gdk_draw_line (window, dark_gc, x1, y1, x1, y2);
    gdk_draw_line (window, dark_gc, x1, y1, x2, y1);
    gdk_draw_line (window, light_gc, x2, y1, x2, y2);
    gdk_draw_line (window, light_gc, x1, y2, x2, y2);
}


void
e_week_view_set_calendar    (EWeekView  *week_view,
                 GnomeCalendar  *calendar)
{
    g_return_if_fail (E_IS_WEEK_VIEW (week_view));

    week_view->calendar = calendar;
}


/* Callback used when a component is updated in the live query */
static void
query_obj_updated_cb (CalQuery *query, const char *uid,
              gboolean query_in_progress, int n_scanned, int total,
              gpointer data)
{
    EWeekView *week_view;
    EWeekViewEvent *event;
    gint event_num, num_days;
    CalComponent *comp;
    CalClientGetStatus status;

    week_view = E_WEEK_VIEW (data);

    /* If we don't have a valid date set yet, just return. */
    if (!g_date_valid (&week_view->first_day_shown))
        return;

    /* Get the event from the server. */
    status = cal_client_get_object (week_view->client, uid, &comp);

    switch (status) {
    case CAL_CLIENT_GET_SUCCESS:
        /* Everything is fine */
        break;

    case CAL_CLIENT_GET_SYNTAX_ERROR:
        g_message ("obj_updated_cb(): Syntax error when getting object `%s'", uid);
        return;

    case CAL_CLIENT_GET_NOT_FOUND:
        /* The object is no longer in the server, so do nothing */
        return;
    }

    /* If the event already exists and the dates didn't change, we can
       update the event fairly easily without changing the events arrays
       or computing a new layout. */
    if (e_week_view_find_event_from_uid (week_view, uid, &event_num)) {
        event = &g_array_index (week_view->events, EWeekViewEvent,
                    event_num);

        if (!cal_component_has_recurrences (comp)
            && !cal_component_has_recurrences (event->comp)
            && cal_component_event_dates_match (comp, event->comp)) {
#if 0
            g_print ("updated object's dates unchanged\n");
#endif
            e_week_view_foreach_event_with_uid (week_view, uid, e_week_view_update_event_cb, comp);
            gtk_object_unref (GTK_OBJECT (comp));
            gtk_widget_queue_draw (week_view->main_canvas);
            return;
        }

        /* The dates have changed, so we need to remove the
           old occurrrences before adding the new ones. */
#if 0
        g_print ("dates changed - removing occurrences\n");
#endif
        e_week_view_foreach_event_with_uid (week_view, uid,
                            e_week_view_remove_event_cb,
                            NULL);
    }

    /* Add the occurrences of the event. */
    num_days = week_view->multi_week_view ? week_view->weeks_shown * 7 : 7;

    cal_recur_generate_instances (comp,
                      week_view->day_starts[0],
                      week_view->day_starts[num_days],
                      e_week_view_add_event, week_view,
                      cal_client_resolve_tzid_cb, week_view->client,
                      week_view->zone);

    gtk_object_unref (GTK_OBJECT (comp));

    e_week_view_queue_layout (week_view);
}

/* Callback used when a component is removed from the live query */
static void
query_obj_removed_cb (CalClient *client, const char *uid, gpointer data)
{
    EWeekView *week_view;

    week_view = E_WEEK_VIEW (data);

    e_week_view_foreach_event_with_uid (week_view, uid,
                        e_week_view_remove_event_cb, NULL);

    gtk_widget_queue_draw (week_view->main_canvas);
    e_week_view_check_layout (week_view);
}

/* Callback used when a query ends */
static void
query_query_done_cb (CalQuery *query, CalQueryDoneStatus status, const char *error_str, gpointer data)
{
    EWeekView *week_view;

    week_view = E_WEEK_VIEW (data);

    /* FIXME */

    e_week_view_set_status_message (week_view, NULL);

    if (status != CAL_QUERY_DONE_SUCCESS)
        fprintf (stderr, "query done: %s\n", error_str);

    gtk_widget_queue_draw (week_view->main_canvas);
}

/* Callback used when an evaluation error occurs when running a query */
static void
query_eval_error_cb (CalQuery *query, const char *error_str, gpointer data)
{
    EWeekView *week_view;

    week_view = E_WEEK_VIEW (data);

    /* FIXME */

    e_week_view_set_status_message (week_view, NULL);

    fprintf (stderr, "eval error: %s\n", error_str);

    gtk_widget_queue_draw (week_view->main_canvas);
}

/* Builds a complete query sexp for the week view by adding the predicates to
 * filter only for VEVENTS that fit in the week view's time range.
 */
static char *
adjust_query_sexp (EWeekView *week_view, const char *sexp)
{
    int num_days;
    char *start, *end;
    char *new_sexp;

    /* If the dates have not been set yet, we just want an empty query. */
    if (!g_date_valid (&week_view->first_day_shown))
        return NULL;

    num_days = week_view->multi_week_view ? week_view->weeks_shown * 7 : 7;

    start = isodate_from_time_t (week_view->day_starts[0]);
    end = isodate_from_time_t (week_view->day_starts[num_days]);

    new_sexp = g_strdup_printf ("(and (= (get-vtype) \"VEVENT\")"
                    "     (occur-in-time-range? (make-time \"%s\")"
                    "                           (make-time \"%s\"))"
                    "     %s)",
                    start, end,
                    sexp);

    g_free (start);
    g_free (end);

    return new_sexp;
}

/* Restarts a query for the week view */
static void
update_query (EWeekView *week_view)
{
    CalQuery *old_query;
    char *real_sexp;

    gtk_widget_queue_draw (week_view->main_canvas);
    e_week_view_free_events (week_view);
    e_week_view_queue_layout (week_view);

    if (!(week_view->client
          && cal_client_get_load_state (week_view->client) == CAL_CLIENT_LOAD_LOADED))
        return;

    old_query = week_view->query;
    week_view->query = NULL;

    if (old_query) {
        gtk_signal_disconnect_by_data (GTK_OBJECT (old_query), week_view);
        gtk_object_unref (GTK_OBJECT (old_query));
    }

    g_assert (week_view->sexp != NULL);

    real_sexp = adjust_query_sexp (week_view, week_view->sexp);
    if (!real_sexp) {
        return; /* No time range is set, so don't start a query */
    }

    e_week_view_set_status_message (week_view, _("Searching"));
    week_view->query = cal_client_get_query (week_view->client, real_sexp);
    g_free (real_sexp);

    if (!week_view->query) {
        g_message ("update_query(): Could not create the query");
        return;
    }

    gtk_signal_connect (GTK_OBJECT (week_view->query), "obj_updated",
                GTK_SIGNAL_FUNC (query_obj_updated_cb), week_view);
    gtk_signal_connect (GTK_OBJECT (week_view->query), "obj_removed",
                GTK_SIGNAL_FUNC (query_obj_removed_cb), week_view);
    gtk_signal_connect (GTK_OBJECT (week_view->query), "query_done",
                GTK_SIGNAL_FUNC (query_query_done_cb), week_view);
    gtk_signal_connect (GTK_OBJECT (week_view->query), "eval_error",
                GTK_SIGNAL_FUNC (query_eval_error_cb), week_view);
}

/* Callback used when the calendar client finishes opening */
static void
cal_opened_cb (CalClient *client, CalClientOpenStatus status, gpointer data)
{
    EWeekView *week_view;

    week_view = E_WEEK_VIEW (data);

    if (status != CAL_CLIENT_OPEN_SUCCESS)
        return;

    update_query (week_view);
}

/**
 * e_week_view_set_cal_client:
 * @week_view: A week view.
 * @client: A calendar client interface object.
 *
 * Sets the calendar client interface object that a week view will monitor.
 **/
void
e_week_view_set_cal_client  (EWeekView  *week_view,
                 CalClient  *client)
{
    g_return_if_fail (week_view != NULL);
    g_return_if_fail (E_IS_WEEK_VIEW (week_view));

    if (client == week_view->client)
        return;

    if (client)
        g_return_if_fail (IS_CAL_CLIENT (client));

    if (client)
        gtk_object_ref (GTK_OBJECT (client));

    if (week_view->client) {
        gtk_signal_disconnect_by_data (GTK_OBJECT (week_view->client), week_view);
        gtk_object_unref (GTK_OBJECT (week_view->client));
    }

    week_view->client = client;

    if (week_view->client) {
        if (cal_client_get_load_state (week_view->client) == CAL_CLIENT_LOAD_LOADED)
            update_query (week_view);
        else
            gtk_signal_connect (GTK_OBJECT (week_view->client), "cal_opened",
                        GTK_SIGNAL_FUNC (cal_opened_cb), week_view);
    }
}

/**
 * e_week_view_set_query:
 * @week_view: A week view.
 * @sexp: S-expression that defines the query.
 *
 * Sets the query sexp that the week view will use for filtering the displayed
 * events.
 **/
void
e_week_view_set_query (EWeekView *week_view, const char *sexp)
{
    g_return_if_fail (week_view != NULL);
    g_return_if_fail (E_IS_WEEK_VIEW (week_view));
    g_return_if_fail (sexp != NULL);

    if (week_view->sexp)
        g_free (week_view->sexp);

    week_view->sexp = g_strdup (sexp);

    update_query (week_view);
}


/**
 * e_week_view_set_default_category:
 * @week_view: A week view.
 * @category: Default category name or NULL for no category.
 *
 * Sets the default category that will be used when creating new calendar
 * components from the week view.
 **/
void
e_week_view_set_default_category (EWeekView *week_view, const char *category)
{
    g_return_if_fail (week_view != NULL);
    g_return_if_fail (E_IS_WEEK_VIEW (week_view));

    if (week_view->default_category)
        g_free (week_view->default_category);

    week_view->default_category = g_strdup (category);
}


/* This sets the selected time range. The EWeekView will show the corresponding
   month and the days between start_time and end_time will be selected.
   To select a single day, use the same value for start_time & end_time. */
void
e_week_view_set_selected_time_range (EWeekView  *week_view,
                     time_t      start_time,
                     time_t      end_time)
{
    GDate date, base_date, end_date;
    gint day_offset, weekday, week_start_offset, num_days;
    gboolean update_adjustment_value = FALSE;

    g_return_if_fail (E_IS_WEEK_VIEW (week_view));

    time_to_gdate_with_zone (&date, start_time, week_view->zone);

    if (week_view->multi_week_view) {
        /* Find the number of days since the start of the month. */
        day_offset = g_date_day (&date) - 1;

        /* Find the 1st week which starts at or before the start of
           the month. */
        base_date = date;
        g_date_set_day (&base_date, 1);

        /* Calculate the weekday of the 1st of the month, 0 = Mon. */
        weekday = g_date_weekday (&base_date) - 1;

        /* Convert it to an offset from the start of the display. */
        week_start_offset = (weekday + 7 - week_view->display_start_day) % 7;

        /* Add it to the day offset so we go back to the 1st week at
           or before the start of the month. */
        day_offset += week_start_offset;
    } else {
        /* Calculate the weekday of the given date, 0 = Mon. */
        weekday = g_date_weekday (&date) - 1;

        /* Convert it to an offset from the start of the display. */
        week_start_offset = (weekday + 7 - week_view->display_start_day) % 7;

        /* Set the day_offset to the result, so we move back to the
           start of the week. */
        day_offset = week_start_offset;
    }

    /* Calculate the base date, i.e. the first day shown when the
       scrollbar adjustment value is 0. */
    base_date = date;
    g_date_subtract_days (&base_date, day_offset);

    /* See if we need to update the base date. */
    if (!g_date_valid (&week_view->base_date)
        || g_date_compare (&week_view->base_date, &base_date)) {
        week_view->base_date = base_date;
        update_adjustment_value = TRUE;
    }

    /* See if we need to update the first day shown. */
    if (!g_date_valid (&week_view->first_day_shown)
        || g_date_compare (&week_view->first_day_shown, &base_date)) {
        week_view->first_day_shown = base_date;
        start_time = time_add_day_with_zone (start_time, -day_offset,
                             week_view->zone);
        start_time = time_day_begin_with_zone (start_time,
                               week_view->zone);
        e_week_view_recalc_day_starts (week_view, start_time);
        update_query (week_view);
    }

    /* Set the selection to the given days. */
    week_view->selection_start_day = g_date_julian (&date)
        - g_date_julian (&base_date);
    if (end_time == start_time
        || end_time <= time_add_day_with_zone (start_time, 1,
                           week_view->zone))
        week_view->selection_end_day = week_view->selection_start_day;
    else {
        time_to_gdate_with_zone (&end_date, end_time - 60, week_view->zone);
        week_view->selection_end_day = g_date_julian (&end_date)
            - g_date_julian (&base_date);
    }

    /* Make sure the selection is valid. */
    num_days = week_view->multi_week_view ? week_view->weeks_shown * 7 : 7;
    num_days--;
    week_view->selection_start_day = CLAMP (week_view->selection_start_day,
                        0, num_days);
    week_view->selection_end_day = CLAMP (week_view->selection_end_day,
                          week_view->selection_start_day,
                          num_days);

    /* Reset the adjustment value to 0 if the base address has changed.
       Note that we do this after updating first_day_shown so that our
       signal handler will not try to reload the events. */
    if (update_adjustment_value)
        gtk_adjustment_set_value (GTK_RANGE (week_view->vscrollbar)->adjustment, 0);

    gtk_widget_queue_draw (week_view->main_canvas);
}


/* Returns the selected time range. */
void
e_week_view_get_selected_time_range (EWeekView  *week_view,
                     time_t     *start_time,
                     time_t     *end_time)
{
    gint start_day, end_day;

    start_day = week_view->selection_start_day;
    end_day = week_view->selection_end_day;

    if (start_day == -1) {
        start_day = 0;
        end_day = 0;
    }

    if (start_time)
        *start_time = week_view->day_starts[start_day];

    if (end_time)
        *end_time = week_view->day_starts[end_day + 1];
}


/* Note that the returned date may be invalid if no date has been set yet. */
void
e_week_view_get_first_day_shown     (EWeekView  *week_view,
                     GDate      *date)
{
    *date = week_view->first_day_shown;
}


/* This sets the first day shown in the view. It will be rounded down to the
   nearest week. */
void
e_week_view_set_first_day_shown     (EWeekView  *week_view,
                     GDate      *date)
{
    GDate base_date;
    gint weekday, day_offset, num_days;
    gboolean update_adjustment_value = FALSE;
    guint32 old_selection_start_julian = 0, old_selection_end_julian = 0;
    struct icaltimetype start_tt = icaltime_null_time ();
    time_t start_time;

    g_return_if_fail (E_IS_WEEK_VIEW (week_view));

    /* Calculate the old selection range. */
    if (week_view->selection_start_day != -1) {
        old_selection_start_julian =
            g_date_julian (&week_view->base_date)
            + week_view->selection_start_day;
        old_selection_end_julian =
            g_date_julian (&week_view->base_date)
            + week_view->selection_end_day;
    }

    /* Calculate the weekday of the given date, 0 = Mon. */
    weekday = g_date_weekday (date) - 1;

    /* Convert it to an offset from the start of the display. */
    day_offset = (weekday + 7 - week_view->display_start_day) % 7;

    /* Calculate the base date, i.e. the first day shown when the
       scrollbar adjustment value is 0. */
    base_date = *date;
    g_date_subtract_days (&base_date, day_offset);

    /* See if we need to update the base date. */
    if (!g_date_valid (&week_view->base_date)
        || g_date_compare (&week_view->base_date, &base_date)) {
        week_view->base_date = base_date;
        update_adjustment_value = TRUE;
    }

    /* See if we need to update the first day shown. */
    if (!g_date_valid (&week_view->first_day_shown)
        || g_date_compare (&week_view->first_day_shown, &base_date)) {
        week_view->first_day_shown = base_date;

        start_tt.year = g_date_year (&base_date);
        start_tt.month = g_date_month (&base_date);
        start_tt.day = g_date_day (&base_date);

        start_time = icaltime_as_timet_with_zone (start_tt,
                              week_view->zone);

        e_week_view_recalc_day_starts (week_view, start_time);
        update_query (week_view);
    }

    /* Try to keep the previous selection, but if it is no longer shown
       just select the first day. */
    if (week_view->selection_start_day != -1) {
        week_view->selection_start_day = old_selection_start_julian
            - g_date_julian (&base_date);
        week_view->selection_end_day = old_selection_end_julian
            - g_date_julian (&base_date);

        /* Make sure the selection is valid. */
        num_days = week_view->multi_week_view
            ? week_view->weeks_shown * 7 : 7;
        num_days--;
        week_view->selection_start_day =
            CLAMP (week_view->selection_start_day, 0, num_days);
        week_view->selection_end_day =
            CLAMP (week_view->selection_end_day,
                   week_view->selection_start_day,
                   num_days);
    }

    /* Reset the adjustment value to 0 if the base address has changed.
       Note that we do this after updating first_day_shown so that our
       signal handler will not try to reload the events. */
    if (update_adjustment_value)
        gtk_adjustment_set_value (GTK_RANGE (week_view->vscrollbar)->adjustment, 0);

    gtk_widget_queue_draw (week_view->main_canvas);
}


/* Recalculates the time_t corresponding to the start of each day. */
static void
e_week_view_recalc_day_starts (EWeekView *week_view,
                   time_t lower)
{
    gint num_days, day;
    time_t tmp_time;

    num_days = week_view->multi_week_view ? week_view->weeks_shown * 7 : 7;

    tmp_time = lower;
    week_view->day_starts[0] = tmp_time;
    for (day = 1; day <= num_days; day++) {
        tmp_time = time_add_day_with_zone (tmp_time, 1,
                           week_view->zone);
        week_view->day_starts[day] = tmp_time;
    }
}


gboolean
e_week_view_get_multi_week_view (EWeekView  *week_view)
{
    g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), FALSE);

    return week_view->multi_week_view;
}


void
e_week_view_set_multi_week_view (EWeekView  *week_view,
                 gboolean    multi_week_view)
{
    GtkAdjustment *adjustment;
    gint page_increment, page_size;

    g_return_if_fail (E_IS_WEEK_VIEW (week_view));

    if (week_view->multi_week_view == multi_week_view)
        return;

    week_view->multi_week_view = multi_week_view;

    if (multi_week_view) {
        gtk_widget_show (week_view->titles_canvas);
        page_increment = 4;
        page_size = 5;
    } else {
        gtk_widget_hide (week_view->titles_canvas);
        page_increment = page_size = 1;
    }

    adjustment = GTK_RANGE (week_view->vscrollbar)->adjustment;
    adjustment->page_increment = page_increment;
    adjustment->page_size = page_size;
    gtk_adjustment_changed (adjustment);

    e_week_view_recalc_cell_sizes (week_view);

    if (g_date_valid (&week_view->first_day_shown))
        e_week_view_set_first_day_shown (week_view,
                         &week_view->first_day_shown);
}


gint
e_week_view_get_weeks_shown (EWeekView  *week_view)
{
    g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), 1);

    return week_view->weeks_shown;
}


void
e_week_view_set_weeks_shown (EWeekView  *week_view,
                 gint        weeks_shown)
{
    GtkAdjustment *adjustment;
    gint page_increment, page_size;

    g_return_if_fail (E_IS_WEEK_VIEW (week_view));

    weeks_shown = MIN (weeks_shown, E_WEEK_VIEW_MAX_WEEKS);

    if (week_view->weeks_shown == weeks_shown)
        return;

    week_view->weeks_shown = weeks_shown;

    if (week_view->multi_week_view) {
        page_increment = 4;
        page_size = 5;

        adjustment = GTK_RANGE (week_view->vscrollbar)->adjustment;
        adjustment->page_increment = page_increment;
        adjustment->page_size = page_size;
        gtk_adjustment_changed (adjustment);

        e_week_view_recalc_cell_sizes (week_view);

        if (g_date_valid (&week_view->first_day_shown))
            e_week_view_set_first_day_shown (week_view, &week_view->first_day_shown);

        update_query (week_view);
    }
}


gboolean
e_week_view_get_compress_weekend    (EWeekView  *week_view)
{
    g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), FALSE);

    return week_view->compress_weekend;
}


void
e_week_view_set_compress_weekend    (EWeekView  *week_view,
                     gboolean    compress)
{
    gboolean need_reload = FALSE;

    g_return_if_fail (E_IS_WEEK_VIEW (week_view));

    if (week_view->compress_weekend == compress)
        return;

    week_view->compress_weekend = compress;

    /* The option only affects the month view. */
    if (!week_view->multi_week_view)
        return;

    e_week_view_recalc_cell_sizes (week_view);

    need_reload = e_week_view_recalc_display_start_day (week_view);

    /* If the display_start_day has changed we need to recalculate the
       date range shown and reload all events, otherwise we only need to
       do a reshape. */
    if (need_reload) {
        /* Recalculate the days shown and reload if necessary. */
        if (g_date_valid (&week_view->first_day_shown))
            e_week_view_set_first_day_shown (week_view, &week_view->first_day_shown);
    } else {
        week_view->events_need_reshape = TRUE;
        e_week_view_check_layout (week_view);
    }
}


/* Whether we display event end times. */
gboolean
e_week_view_get_show_event_end_times    (EWeekView  *week_view)
{
    g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), TRUE);

    return week_view->show_event_end_times;
}


void
e_week_view_set_show_event_end_times    (EWeekView  *week_view,
                     gboolean    show)
{
    g_return_if_fail (E_IS_WEEK_VIEW (week_view));

    if (week_view->show_event_end_times != show) {
        week_view->show_event_end_times = show;
        e_week_view_recalc_cell_sizes (week_view);
        week_view->events_need_reshape = TRUE;
        e_week_view_check_layout (week_view);
    }
}


/* The first day of the week, 0 (Monday) to 6 (Sunday). */
gint
e_week_view_get_week_start_day  (EWeekView  *week_view)
{
    g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), 0);

    return week_view->week_start_day;
}


void
e_week_view_set_week_start_day  (EWeekView  *week_view,
                 gint        week_start_day)
{
    g_return_if_fail (E_IS_WEEK_VIEW (week_view));
    g_return_if_fail (week_start_day >= 0);
    g_return_if_fail (week_start_day < 7);

    if (week_view->week_start_day == week_start_day)
        return;

    week_view->week_start_day = week_start_day;

    e_week_view_recalc_display_start_day (week_view);

    /* Recalculate the days shown and reload if necessary. */
    if (g_date_valid (&week_view->first_day_shown))
        e_week_view_set_first_day_shown (week_view,
                         &week_view->first_day_shown);
}


/* Whether we use 12-hour or 24-hour format. */
gboolean
e_week_view_get_24_hour_format  (EWeekView  *week_view)
{
    g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), FALSE);

    return week_view->use_24_hour_format;
}


void
e_week_view_set_24_hour_format  (EWeekView  *week_view,
                 gboolean    use_24_hour)
{
    g_return_if_fail (E_IS_WEEK_VIEW (week_view));

    if (week_view->use_24_hour_format == use_24_hour)
        return;

    week_view->use_24_hour_format = use_24_hour;

    /* We need to re-layout the events since the time format affects the
       sizes. */
    e_week_view_recalc_cell_sizes (week_view);
    week_view->events_need_reshape = TRUE;
    e_week_view_check_layout (week_view);
    gtk_widget_queue_draw (week_view->main_canvas);
}


/* The current timezone. */
icaltimezone*
e_week_view_get_timezone        (EWeekView  *week_view)
{
    g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), NULL);

    return week_view->zone;
}


void
e_week_view_set_timezone        (EWeekView  *week_view,
                     icaltimezone   *zone)
{
    icaltimezone *old_zone;
    struct icaltimetype tt = icaltime_null_time ();
    time_t lower;

    g_return_if_fail (E_IS_WEEK_VIEW (week_view));

    old_zone = week_view->zone;
    if (old_zone == zone)
        return;

    week_view->zone = zone;

    /* If we don't have a valid date set yet, just return. */
    if (!g_date_valid (&week_view->first_day_shown))
        return;

    /* Recalculate the new start of the first week. We just use exactly
       the same time, but with the new timezone. */
    tt.year = g_date_year (&week_view->first_day_shown);
    tt.month = g_date_month (&week_view->first_day_shown);
    tt.day = g_date_day (&week_view->first_day_shown);

    lower = icaltime_as_timet_with_zone (tt, zone);

    e_week_view_recalc_day_starts (week_view, lower);
    update_query (week_view);
}


void
e_week_view_cut_clipboard (EWeekView *week_view)
{
    EWeekViewEvent *event;
    const char *uid;

    g_return_if_fail (E_IS_WEEK_VIEW (week_view));

    if (week_view->editing_event_num == -1)
        return;

    event = &g_array_index (week_view->events, EWeekViewEvent,
                week_view->editing_event_num);
    if (event == NULL)
        return;

    e_week_view_set_status_message (week_view, _("Deleting selected objects"));

    e_week_view_copy_clipboard (week_view);
    cal_component_get_uid (event->comp, &uid);
    cal_client_remove_object (week_view->client, uid);

    e_week_view_set_status_message (week_view, NULL);
}

void
e_week_view_copy_clipboard (EWeekView *week_view)
{
    EWeekViewEvent *event;
    char *comp_str;

    g_return_if_fail (E_IS_WEEK_VIEW (week_view));

    event = &g_array_index (week_view->events, EWeekViewEvent,
                week_view->editing_event_num);
    if (event == NULL)
        return;

    comp_str = cal_component_get_as_string (event->comp);
    if (week_view->clipboard_selection != NULL)
        g_free (week_view->clipboard_selection);
    week_view->clipboard_selection = comp_str;
    gtk_selection_owner_set (week_view->invisible, clipboard_atom, GDK_CURRENT_TIME);
}

void
e_week_view_paste_clipboard (EWeekView *week_view)
{
    g_return_if_fail (E_IS_WEEK_VIEW (week_view));

    gtk_selection_convert (week_view->invisible,
                   clipboard_atom,
                   GDK_SELECTION_TYPE_STRING,
                   GDK_CURRENT_TIME);
}


static gboolean
e_week_view_recalc_display_start_day    (EWeekView  *week_view)
{
    gint display_start_day;

    /* The display start day defaults to week_start_day, but we have
       to use Saturday if the weekend is compressed and week_start_day
       is Sunday. */
    display_start_day = week_view->week_start_day;

    if (display_start_day == 6
        && (!week_view->multi_week_view || week_view->compress_weekend))
        display_start_day = 5;

    if (week_view->display_start_day != display_start_day) {
        week_view->display_start_day = display_start_day;
        return TRUE;
    }

    return FALSE;
}


static gboolean
e_week_view_update_event_cb (EWeekView *week_view,
                 gint event_num,
                 gpointer data)
{
    EWeekViewEvent *event;
    EWeekViewEventSpan *span;
    gint span_num;
    gchar *text;
    CalComponent *comp;

    comp = data;

    event = &g_array_index (week_view->events, EWeekViewEvent, event_num);

    gtk_object_unref (GTK_OBJECT (event->comp));
    event->comp = comp;
    gtk_object_ref (GTK_OBJECT (comp));

    for (span_num = 0; span_num < event->num_spans; span_num++) {
        span = &g_array_index (week_view->spans, EWeekViewEventSpan,
                       event->spans_index + span_num);

        if (span->text_item) {
            CalComponentText t;

            cal_component_get_summary (event->comp, &t);
            text = (char*) t.value;
            gnome_canvas_item_set (span->text_item,
                           "text", text ? text : "",
                           NULL);

            e_week_view_reshape_event_span (week_view, event_num,
                            span_num);
        }
    }

    return TRUE;
}


/* This calls a given function for each event instance that matches the given
   uid. Note that it is safe for the callback to remove the event (since we
   step backwards through the arrays). */
static void
e_week_view_foreach_event_with_uid (EWeekView *week_view,
                    const gchar *uid,
                    EWeekViewForeachEventCallback callback,
                    gpointer data)
{
    EWeekViewEvent *event;
    gint event_num;

    for (event_num = week_view->events->len - 1;
         event_num >= 0;
         event_num--) {
        const char *u;

        event = &g_array_index (week_view->events, EWeekViewEvent,
                    event_num);

        cal_component_get_uid (event->comp, &u);
        if (u && !strcmp (uid, u)) {
            if (!(*callback) (week_view, event_num, data))
                return;
        }
    }
}


static gboolean
e_week_view_remove_event_cb (EWeekView *week_view,
                 gint event_num,
                 gpointer data)
{
    EWeekViewEvent *event;
    EWeekViewEventSpan *span;
    gint span_num;

    event = &g_array_index (week_view->events, EWeekViewEvent, event_num);

    /* If we were editing this event, set editing_event_num to -1 so
       on_editing_stopped doesn't try to update the event. */
    if (week_view->editing_event_num == event_num)
        week_view->editing_event_num = -1;

    /* We leave the span elements in the array, but set the canvas item
       pointers to NULL. */
    for (span_num = 0; span_num < event->num_spans; span_num++) {
        span = &g_array_index (week_view->spans, EWeekViewEventSpan,
                       event->spans_index + span_num);

        if (span->text_item) {
            gtk_object_destroy (GTK_OBJECT (span->text_item));
            span->text_item = NULL;
        }
        if (span->background_item) {
            gtk_object_destroy (GTK_OBJECT (span->background_item));
            span->background_item = NULL;
        }
    }

    gtk_object_unref (GTK_OBJECT (event->comp));

    g_array_remove_index (week_view->events, event_num);
    week_view->events_need_layout = TRUE;

    return TRUE;
}


void
e_week_view_get_day_position    (EWeekView  *week_view,
                 gint        day,
                 gint       *day_x,
                 gint       *day_y,
                 gint       *day_w,
                 gint       *day_h)
{
    gint cell_x, cell_y, cell_h;

    e_week_view_layout_get_day_position (day,
                         week_view->multi_week_view,
                         week_view->weeks_shown,
                         week_view->display_start_day,
                         week_view->compress_weekend,
                         &cell_x, &cell_y, &cell_h);

    *day_x = week_view->col_offsets[cell_x];
    *day_y = week_view->row_offsets[cell_y];

    *day_w = week_view->col_widths[cell_x];
    *day_h = week_view->row_heights[cell_y];
    if (cell_h == 2)
        *day_h += week_view->row_heights[cell_y + 1];
}


/* Returns the bounding box for a span of an event. Usually this can easily
   be determined by the start & end days and row of the span, which are set in
   e_week_view_layout_event(). Though we need a special case for the weekends
   when they are compressed, since the span may not fit.
   The bounding box includes the entire width of the days in the view (but
   not the vertical line down the right of the last day), though the displayed
   event doesn't normally extend to the edges of the day.
   It returns FALSE if the span isn't visible. */
gboolean
e_week_view_get_span_position   (EWeekView  *week_view,
                 gint        event_num,
                 gint        span_num,
                 gint       *span_x,
                 gint       *span_y,
                 gint       *span_w)
{
    EWeekViewEvent *event;
    EWeekViewEventSpan *span;
    gint num_days;
    gint start_x, start_y, start_w, start_h;
    gint end_x, end_y, end_w, end_h;

    g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), FALSE);
    g_return_val_if_fail (event_num < week_view->events->len, FALSE);

    event = &g_array_index (week_view->events, EWeekViewEvent, event_num);

    g_return_val_if_fail (span_num < event->num_spans, FALSE);

    span = &g_array_index (week_view->spans, EWeekViewEventSpan,
                   event->spans_index + span_num);

    if (!e_week_view_layout_get_span_position (event, span,
                           week_view->rows_per_cell,
                           week_view->rows_per_compressed_cell,
                           week_view->display_start_day,
                           week_view->multi_week_view,
                           week_view->compress_weekend,
                           &num_days)) {
        return FALSE;
    }

    e_week_view_get_day_position (week_view, span->start_day,
                      &start_x, &start_y, &start_w, &start_h);
    *span_y = start_y + week_view->events_y_offset
        + span->row * (week_view->row_height
                   + E_WEEK_VIEW_EVENT_Y_SPACING);
    if (num_days == 1) {
        *span_x = start_x;
        *span_w = start_w - 1;
    } else {
        e_week_view_get_day_position (week_view,
                          span->start_day + num_days - 1,
                          &end_x, &end_y, &end_w, &end_h);
        *span_x = start_x;
        *span_w = end_x + end_w - start_x - 1;
    }

    return TRUE;
}



static gboolean
e_week_view_on_button_press (GtkWidget *widget,
                 GdkEventButton *event,
                 EWeekView *week_view)
{
    gint x, y, day;

#if 0
    g_print ("In e_week_view_on_button_press\n");
    if (event->type == GDK_2BUTTON_PRESS)
        g_print (" is a double-click\n");
    if (week_view->pressed_event_num != -1)
        g_print (" item is pressed\n");
#endif

    /* Handle scroll wheel events */
    if (event->button == 4 || event->button == 5) {
        GtkAdjustment *adj = GTK_RANGE (week_view->vscrollbar)->adjustment;
        gfloat new_value;

        new_value = adj->value + ((event->button == 4) ?
                      -adj->page_increment:
                      adj->page_increment);
        new_value = CLAMP (new_value, adj->lower, adj->upper - adj->page_size);
        gtk_adjustment_set_value (adj, new_value);

        return TRUE;
    }

    /* Convert the mouse position to a week & day. */
    x = event->x;
    y = event->y;
    day = e_week_view_convert_position_to_day (week_view, x, y);
    if (day == -1)
        return FALSE;

    /* If an event is pressed just return. */
    if (week_view->pressed_event_num != -1)
        return FALSE;

    if (event->button == 1 && event->type == GDK_2BUTTON_PRESS) {
        time_t dtstart, dtend;

        dtstart = week_view->day_starts[day];
        dtend = week_view->day_starts[day + 1];
        gnome_calendar_new_appointment_for (week_view->calendar,
                            dtstart, dtend,
                            TRUE);
        return TRUE;
    }

    if (event->button == 1) {
        /* Start the selection drag. */
        if (!GTK_WIDGET_HAS_FOCUS (week_view))
            gtk_widget_grab_focus (GTK_WIDGET (week_view));

        if (gdk_pointer_grab (GTK_LAYOUT (widget)->bin_window, FALSE,
                      GDK_POINTER_MOTION_MASK
                      | GDK_BUTTON_RELEASE_MASK,
                      FALSE, NULL, event->time) == 0) {
            week_view->selection_start_day = day;
            week_view->selection_end_day = day;
            week_view->selection_drag_pos = E_WEEK_VIEW_DRAG_END;

            /* FIXME: Optimise? */
            gtk_widget_queue_draw (week_view->main_canvas);
        }
    } else if (event->button == 3) {
        if (!GTK_WIDGET_HAS_FOCUS (week_view))
            gtk_widget_grab_focus (GTK_WIDGET (week_view));
        e_week_view_show_popup_menu (week_view, event, -1);
    }

    return FALSE;
}


static gboolean
e_week_view_on_button_release (GtkWidget *widget,
                   GdkEventButton *event,
                   EWeekView *week_view)
{
    time_t start, end;

#if 0
    g_print ("In e_week_view_on_button_release\n");
#endif

    if (week_view->selection_drag_pos != E_WEEK_VIEW_DRAG_NONE) {
        week_view->selection_drag_pos = E_WEEK_VIEW_DRAG_NONE;
        gdk_pointer_ungrab (event->time);
        start = week_view->day_starts[week_view->selection_start_day];
        end = week_view->day_starts[week_view->selection_end_day + 1];

        if (week_view->calendar)
            gnome_calendar_set_selected_time_range (week_view->calendar, start, end);
    }

    return FALSE;
}


static gboolean
e_week_view_on_motion (GtkWidget *widget,
               GdkEventMotion *mevent,
               EWeekView *week_view)
{
    gint x, y, day;

#if 0
    g_print ("In e_week_view_on_motion\n");
#endif

    /* Convert the mouse position to a week & day. */
    x = mevent->x;
    y = mevent->y;
    day = e_week_view_convert_position_to_day (week_view, x, y);
    if (day == -1)
        return FALSE;

    if (week_view->selection_drag_pos != E_WEEK_VIEW_DRAG_NONE) {
        e_week_view_update_selection (week_view, day);
        return TRUE;
    }

    return FALSE;
}


/* Converts a position in the canvas window to a day offset from the first
   day displayed. Returns -1 if the position is outside the grid. */
static gint
e_week_view_convert_position_to_day (EWeekView *week_view,
                     gint x,
                     gint y)
{
    gint col, row, grid_x = -1, grid_y = -1, week, day;
    gint weekend_col, box, weekend_box;

    /* First we convert it to a grid position. */
    for (col = 0; col <= week_view->columns; col++) {
        if (x < week_view->col_offsets[col]) {
            grid_x = col - 1;
            break;
        }
    }

    for (row = 0; row <= week_view->rows; row++) {
        if (y < week_view->row_offsets[row]) {
            grid_y = row - 1;
            break;
        }
    }

    /* If the mouse is outside the grid return FALSE. */
    if (grid_x == -1 || grid_y == -1)
        return -1;

    /* Now convert the grid position to a week and day. */
    if (week_view->multi_week_view) {
        week = grid_y / 2;
        day = grid_x;

        if (week_view->compress_weekend) {
            weekend_col = (5 + 7 - week_view->display_start_day) % 7;
            if (grid_x > weekend_col
                || (grid_x == weekend_col && grid_y % 2 == 1))
                day++;
        }
    } else {
        week = 0;

        box = grid_x * 3 + grid_y / 2;
        weekend_box = (5 + 7 - week_view->display_start_day) % 7;
        day = box;
        if (box > weekend_box
            ||( box == weekend_box && grid_y % 2 == 1))
            day++;
    }

    return week * 7 + day;
}


static void
e_week_view_update_selection (EWeekView *week_view,
                  gint day)
{
    gint tmp_day;
    gboolean need_redraw = FALSE;

#if 0
    g_print ("Updating selection %i,%i\n", week, day);
#endif

    if (week_view->selection_drag_pos == E_WEEK_VIEW_DRAG_START) {
        if (day != week_view->selection_start_day) {
            need_redraw = TRUE;
            week_view->selection_start_day = day;
        }
    } else {
        if (day != week_view->selection_end_day) {
            need_redraw = TRUE;
            week_view->selection_end_day = day;
        }
    }

    /* Switch the drag position if necessary. */
    if (week_view->selection_start_day > week_view->selection_end_day) {
        tmp_day = week_view->selection_start_day;
        week_view->selection_start_day = week_view->selection_end_day;
        week_view->selection_end_day = tmp_day;
        if (week_view->selection_drag_pos == E_WEEK_VIEW_DRAG_START)
            week_view->selection_drag_pos = E_WEEK_VIEW_DRAG_END;
        else
            week_view->selection_drag_pos = E_WEEK_VIEW_DRAG_START;
    }

    /* FIXME: Optimise? */
    if (need_redraw) {
        gtk_widget_queue_draw (week_view->main_canvas);
    }
}


static void
e_week_view_free_events (EWeekView *week_view)
{
    EWeekViewEvent *event;
    EWeekViewEventSpan *span;
    gint event_num, span_num, num_days, day;

    /* Reset all our indices. */
    week_view->pressed_event_num = -1;
    week_view->pressed_span_num = -1;
    week_view->editing_event_num = -1;
    week_view->editing_span_num = -1;
    week_view->popup_event_num = -1;

    for (event_num = 0; event_num < week_view->events->len; event_num++) {
        event = &g_array_index (week_view->events, EWeekViewEvent,
                    event_num);
        gtk_object_unref (GTK_OBJECT (event->comp));
    }

    g_array_set_size (week_view->events, 0);

    /* Destroy all the old canvas items. */
    if (week_view->spans) {
        for (span_num = 0; span_num < week_view->spans->len;
             span_num++) {
            span = &g_array_index (week_view->spans,
                           EWeekViewEventSpan, span_num);
            if (span->background_item)
                gtk_object_destroy (GTK_OBJECT (span->background_item));
            if (span->text_item)
                gtk_object_destroy (GTK_OBJECT (span->text_item));
        }
        g_array_free (week_view->spans, TRUE);
        week_view->spans = NULL;
    }

    /* Clear the number of rows used per day. */
    num_days = week_view->multi_week_view ? week_view->weeks_shown * 7 : 7;
    for (day = 0; day <= num_days; day++) {
        week_view->rows_per_day[day] = 0;
    }

    /* Hide all the jump buttons. */
    for (day = 0; day < E_WEEK_VIEW_MAX_WEEKS * 7; day++) {
        gnome_canvas_item_hide (week_view->jump_buttons[day]);
    }
}


/* This adds one event to the view, adding it to the appropriate array. */
static gboolean
e_week_view_add_event (CalComponent *comp,
               time_t     start,
               time_t     end,
               gpointer   data)

{
    EWeekView *week_view;
    EWeekViewEvent event;
    gint num_days;
    struct icaltimetype start_tt, end_tt;

    week_view = E_WEEK_VIEW (data);

    /* Check that the event times are valid. */
    num_days = week_view->multi_week_view ? week_view->weeks_shown * 7 : 7;

#if 0
    g_print ("View start:%li end:%li  Event start:%li end:%li\n",
         week_view->day_starts[0], week_view->day_starts[num_days],
         start, end);
#endif

    g_return_val_if_fail (start <= end, TRUE);
    g_return_val_if_fail (start < week_view->day_starts[num_days], TRUE);
    g_return_val_if_fail (end > week_view->day_starts[0], TRUE);

    start_tt = icaltime_from_timet_with_zone (start, FALSE,
                          week_view->zone);
    end_tt = icaltime_from_timet_with_zone (end, FALSE,
                        week_view->zone);

    event.comp = comp;
    gtk_object_ref (GTK_OBJECT (event.comp));
    event.start = start;
    event.end = end;
    event.spans_index = 0;
    event.num_spans = 0;

    event.start_minute = start_tt.hour * 60 + start_tt.minute;
    event.end_minute = end_tt.hour * 60 + end_tt.minute;
    if (event.end_minute == 0 && start != end)
        event.end_minute = 24 * 60;

    event.different_timezone = FALSE;
    if (!cal_comp_util_compare_event_timezones (comp, week_view->client,
                            week_view->zone))
        event.different_timezone = TRUE;

    g_array_append_val (week_view->events, event);
    week_view->events_sorted = FALSE;
    week_view->events_need_layout = TRUE;

    return TRUE;
}


/* This lays out the events, or reshapes them, as necessary. */
static void
e_week_view_check_layout (EWeekView *week_view)
{
    /* Don't bother if we aren't visible. */
    if (!GTK_WIDGET_VISIBLE (week_view))
        return;

    /* Make sure the events are sorted (by start and size). */
    e_week_view_ensure_events_sorted (week_view);

    if (week_view->events_need_layout)
        week_view->spans = e_week_view_layout_events
            (week_view->events, week_view->spans,
             week_view->multi_week_view,
             week_view->weeks_shown,
             week_view->compress_weekend,
             week_view->display_start_day,
             week_view->day_starts,
             week_view->rows_per_day);

    if (week_view->events_need_layout || week_view->events_need_reshape)
        e_week_view_reshape_events (week_view);

    week_view->events_need_layout = FALSE;
    week_view->events_need_reshape = FALSE;
}


static void
e_week_view_ensure_events_sorted (EWeekView *week_view)
{
    if (!week_view->events_sorted) {
        qsort (week_view->events->data,
               week_view->events->len,
               sizeof (EWeekViewEvent),
               e_week_view_event_sort_func);
        week_view->events_sorted = TRUE;
    }
}


gint
e_week_view_event_sort_func (const void *arg1,
                 const void *arg2)
{
    EWeekViewEvent *event1, *event2;

    event1 = (EWeekViewEvent*) arg1;
    event2 = (EWeekViewEvent*) arg2;

    if (event1->start < event2->start)
        return -1;
    if (event1->start > event2->start)
        return 1;

    if (event1->end > event2->end)
        return -1;
    if (event1->end < event2->end)
        return 1;

    return 0;
}


static void
e_week_view_reshape_events (EWeekView *week_view)
{
    EWeekViewEvent *event;
    gint event_num, span_num;
    gint num_days, day, day_x, day_y, day_w, day_h, max_rows;
    gboolean is_weekend;

    for (event_num = 0; event_num < week_view->events->len; event_num++) {
        event = &g_array_index (week_view->events, EWeekViewEvent,
                    event_num);
        for (span_num = 0; span_num < event->num_spans; span_num++) {
            e_week_view_reshape_event_span (week_view, event_num,
                            span_num);
        }
    }

    /* Reshape the jump buttons and show/hide them as appropriate. */
    num_days = week_view->multi_week_view ? week_view->weeks_shown * 7 : 7;
    for (day = 0; day < num_days; day++) {

        is_weekend = ((week_view->display_start_day + day) % 7 >= 5) ? TRUE : FALSE;
        if (!is_weekend || (week_view->multi_week_view
                    && !week_view->compress_weekend))
            max_rows = week_view->rows_per_cell;
        else
            max_rows = week_view->rows_per_compressed_cell;

        /* Determine whether the jump button should be shown. */
        if (week_view->rows_per_day[day] <= max_rows) {
            gnome_canvas_item_hide (week_view->jump_buttons[day]);
        } else {
            e_week_view_get_day_position (week_view, day,
                              &day_x, &day_y,
                              &day_w, &day_h);