Revisión | 691196ad7e6aaf1afab0f7a38fadfa237beed25b (tree) |
---|---|
Tiempo | 2011-01-19 16:59:00 |
Autor | azyobuzin <azyobuzin@user...> |
Commiter | azyobuzin |
・StatusesListViewでオーナードローするように
・正規表現不具合を直した
@@ -54,7 +54,7 @@ namespace Azyobuzi.Twirunrun | ||
54 | 54 | .RegexReplace(@"https?://[\w\d/%#$&?()~_.=+\-!]+", (match) => |
55 | 55 | string.Format(@"<a href=""{0}"">{1}</a>", |
56 | 56 | match.ToString().HtmlAttributeEncode(), match.ToString().HtmlEncode())) |
57 | - .RegexReplace(@"[@@]\w+", (match) => | |
57 | + .RegexReplace(@"[@@][a-zA-Z0-9_]+"/*\wだとうまく認識しない*/, (match) => | |
58 | 58 | string.Format(@"{0}<a href=""https://twitter.com/{1}"">{1}</a>", match.ToString()[0], match.ToString().Substring(1))) |
59 | 59 | .RegexReplace(@"(^|\W)([##][a-zA-Z0-9_\-]+)", (match) => |
60 | 60 | string.Format(@"{0}<a href=""https://twitter.com/search?q={1}"">{2}</a>", match.Groups[1].ToString(), Uri.EscapeDataString(match.Groups[2].ToString()).HtmlAttributeEncode(), match.Groups[2].ToString())); |
@@ -1,7 +1,5 @@ | ||
1 | -using System; | |
2 | -using System.Collections.Generic; | |
3 | -using System.Linq; | |
4 | -using System.Text; | |
1 | +using System.Collections.Generic; | |
2 | +using System.Drawing; | |
5 | 3 | using System.Windows.Forms; |
6 | 4 | |
7 | 5 | namespace Azyobuzi.Twirunrun |
@@ -18,10 +16,10 @@ namespace Azyobuzi.Twirunrun | ||
18 | 16 | this.Columns.Add("名前", Settings.Instance.NameWidth); |
19 | 17 | this.Columns.Add("投稿"); |
20 | 18 | this.SizeChanged += (sender, e) => this.AutoResizeColumn(1, ColumnHeaderAutoResizeStyle.ColumnContent); |
19 | + this.OwnerDraw = true; | |
20 | + this.DrawSubItem += this_DrawSubItem; | |
21 | 21 | } |
22 | - | |
23 | - public const string NAME_SUBITEM = "NameSubItem";//SubItem識別用 | |
24 | - | |
22 | + | |
25 | 23 | private IList<StatusInfo> statuses; |
26 | 24 | public IList<StatusInfo> Statuses |
27 | 25 | { |
@@ -59,9 +57,70 @@ namespace Azyobuzi.Twirunrun | ||
59 | 57 | |
60 | 58 | lvi.SubItems.Add(item.Text.Replace('\n', ' ')); |
61 | 59 | |
62 | - lvi.SubItems[0].Tag = NAME_SUBITEM; | |
63 | - | |
64 | 60 | e.Item = lvi; |
65 | 61 | } |
62 | + | |
63 | + //ラベルは保留 | |
64 | + private void this_DrawSubItem(object sender, DrawListViewSubItemEventArgs e) | |
65 | + { | |
66 | + if (e.ItemIndex < 0 || e.ColumnIndex < 0) return; | |
67 | + | |
68 | + using (var b = new SolidBrush( | |
69 | + (e.ItemState & ListViewItemStates.Selected) == ListViewItemStates.Selected ? | |
70 | + SystemColors.Highlight : e.SubItem.BackColor)) | |
71 | + { | |
72 | + e.Graphics.FillRectangle(b, e.Bounds); | |
73 | + } | |
74 | + | |
75 | + var foreColor = (e.ItemState & ListViewItemStates.Selected) == ListViewItemStates.Selected ? | |
76 | + SystemColors.HighlightText : e.SubItem.ForeColor; | |
77 | + | |
78 | + e.ColumnIndex.SelectCase() | |
79 | + .Case(0, () =>//名前部 | |
80 | + { | |
81 | + const int LEFT_SPACE = 2; | |
82 | + var itemPoint = e.Bounds.Location; | |
83 | + var post = Statuses[e.ItemIndex]; | |
84 | + //アイコン描画 | |
85 | + int iconsize = e.Bounds.Height - 1; | |
86 | + var icon = Icons.GetItem(post.ProfileImageUri); | |
87 | + if (icon == null) | |
88 | + { | |
89 | + Icons.AddAsync(post.ProfileImageUri); | |
90 | + } | |
91 | + else | |
92 | + { | |
93 | + e.Graphics.DrawImage(icon, itemPoint.X + LEFT_SPACE, itemPoint.Y, iconsize, iconsize); | |
94 | + } | |
95 | + //名前描画 | |
96 | + TextRenderer.DrawText(e.Graphics, | |
97 | + e.SubItem.Text, | |
98 | + e.SubItem.Font, | |
99 | + new Rectangle( | |
100 | + itemPoint.X + LEFT_SPACE + iconsize + LEFT_SPACE, | |
101 | + itemPoint.Y, | |
102 | + e.Bounds.Width - LEFT_SPACE - iconsize - LEFT_SPACE, | |
103 | + e.Bounds.Height | |
104 | + ), | |
105 | + foreColor, | |
106 | + TextFormatFlags.NoPrefix | | |
107 | + TextFormatFlags.VerticalCenter | | |
108 | + TextFormatFlags.EndEllipsis | | |
109 | + TextFormatFlags.SingleLine | |
110 | + ); | |
111 | + }) | |
112 | + .Case(1, () =>//投稿内容部 | |
113 | + { | |
114 | + TextRenderer.DrawText(e.Graphics, | |
115 | + e.SubItem.Text, | |
116 | + e.SubItem.Font, | |
117 | + e.Bounds, | |
118 | + foreColor, | |
119 | + TextFormatFlags.NoPrefix | | |
120 | + TextFormatFlags.VerticalCenter | | |
121 | + TextFormatFlags.WordEllipsis | | |
122 | + TextFormatFlags.SingleLine); | |
123 | + }); | |
124 | + } | |
66 | 125 | } |
67 | 126 | } |
@@ -39,10 +39,16 @@ namespace Azyobuzi.Twirunrun | ||
39 | 39 | { |
40 | 40 | try |
41 | 41 | { |
42 | - var result = CreateIcon(uri); | |
42 | + var _uri = e.Argument.ToString(); | |
43 | + Image result; | |
44 | + using (var wc = new WebClient()) | |
45 | + { | |
46 | + result = wc.DownloadImage(_uri); | |
47 | + } | |
48 | + | |
43 | 49 | lock (LockObj) |
44 | 50 | { |
45 | - Icons.Add(uri, result); | |
51 | + Icons.Add(_uri, result); | |
46 | 52 | } |
47 | 53 | } |
48 | 54 | catch { } |
@@ -55,7 +61,7 @@ namespace Azyobuzi.Twirunrun | ||
55 | 61 | AddCompleted(); |
56 | 62 | } |
57 | 63 | }; |
58 | - bw.RunWorkerAsync(); | |
64 | + bw.RunWorkerAsync(uri); | |
59 | 65 | } |
60 | 66 | |
61 | 67 | private static int RunnningCount = 0; |
@@ -67,45 +73,45 @@ namespace Azyobuzi.Twirunrun | ||
67 | 73 | |
68 | 74 | |
69 | 75 | |
70 | - /// <summary> | |
71 | - /// 指定したURIからアイコンを作成する | |
72 | - /// </summary> | |
73 | - public static Bitmap CreateIcon(string uri) | |
74 | - { | |
75 | - const int RESULT_SIZE = 48; | |
76 | - | |
77 | - Image img; | |
78 | - | |
79 | - using (var wc = new WebClient()) | |
80 | - { | |
81 | - img = wc.DownloadImage(uri); | |
82 | - } | |
83 | - | |
84 | - if (img.Width == img.Height) | |
85 | - return new Bitmap(img, RESULT_SIZE, RESULT_SIZE); | |
86 | - | |
87 | - int size = Math.Min(img.Width, img.Height); | |
88 | - using (Bitmap temp = new Bitmap(size, size)) | |
89 | - { | |
90 | - if (img.Width > img.Height) | |
91 | - { | |
92 | - int left = img.Width / 2 - ((/*img.Width - */img.Height) / 2); | |
93 | - using (var g = Graphics.FromImage(temp)) | |
94 | - { | |
95 | - g.DrawImage(img, 0, 0, new Rectangle(left, 0, size, size), GraphicsUnit.Pixel); | |
96 | - } | |
97 | - } | |
98 | - else if (img.Width < img.Height) | |
99 | - { | |
100 | - int top = img.Height / 2 - ((/*img.Height - */img.Width) / 2); | |
101 | - using (var g = Graphics.FromImage(temp)) | |
102 | - { | |
103 | - g.DrawImage(img, 0, 0, new Rectangle(0, top, size, size), GraphicsUnit.Pixel); | |
104 | - } | |
105 | - } | |
106 | - | |
107 | - return new Bitmap(temp, RESULT_SIZE, RESULT_SIZE); | |
108 | - } | |
109 | - } | |
76 | + ///// <summary> | |
77 | + ///// 指定したURIからアイコンを作成する | |
78 | + ///// </summary> | |
79 | + //public static Bitmap CreateIcon(string uri) | |
80 | + //{ | |
81 | + // const int RESULT_SIZE = 48; | |
82 | + | |
83 | + // Image img; | |
84 | + | |
85 | + // using (var wc = new WebClient()) | |
86 | + // { | |
87 | + // img = wc.DownloadImage(uri); | |
88 | + // } | |
89 | + | |
90 | + // if (img.Width == img.Height) | |
91 | + // return new Bitmap(img, RESULT_SIZE, RESULT_SIZE); | |
92 | + | |
93 | + // int size = Math.Min(img.Width, img.Height); | |
94 | + // using (Bitmap temp = new Bitmap(size, size)) | |
95 | + // { | |
96 | + // if (img.Width > img.Height) | |
97 | + // { | |
98 | + // int left = img.Width / 2 - ((/*img.Width - */img.Height) / 2); | |
99 | + // using (var g = Graphics.FromImage(temp)) | |
100 | + // { | |
101 | + // g.DrawImage(img, 0, 0, new Rectangle(left, 0, size, size), GraphicsUnit.Pixel); | |
102 | + // } | |
103 | + // } | |
104 | + // else if (img.Width < img.Height) | |
105 | + // { | |
106 | + // int top = img.Height / 2 - ((/*img.Height - */img.Width) / 2); | |
107 | + // using (var g = Graphics.FromImage(temp)) | |
108 | + // { | |
109 | + // g.DrawImage(img, 0, 0, new Rectangle(0, top, size, size), GraphicsUnit.Pixel); | |
110 | + // } | |
111 | + // } | |
112 | + | |
113 | + // return new Bitmap(temp, RESULT_SIZE, RESULT_SIZE); | |
114 | + // } | |
115 | + //} | |
110 | 116 | } |
111 | 117 | } |