OSDN Git Service

2012/01/04 16:56:06
[nlite/nlite.git] / nlite / nlite_commentview.cpp
1 #include "stdafx.h"
2 #include "nlite_include.h"
3
4
5
6
7 VOID CCommentView::CommentLineSet(CChatData &chat,UINT_PTR count){
8
9         
10         
11         CDC cdc = listBox.GetDC();
12         
13         RECT drowSize;
14         header.GetItemRect(COMMENT,&drowSize);
15         drowSize.left += 2;
16         drowSize.top +=  2;
17         drowSize.right -= 2;
18         drowSize.bottom = 0;
19         
20         SelectObject(cdc,AtlGetDefaultGuiFont());
21
22         
23         cdc.DrawTextW(chat.chatBuf.c_str(),chat.chatBuf.length(),&drowSize, DT_CALCRECT | DT_WORDBREAK);
24         
25         drowSize.top -= 2;
26         drowSize.bottom += 2;
27
28         
29         listBox.SetItemHeight(listBox.GetCount() -1,drowSize.bottom - drowSize.top);
30         
31
32         return;
33 }
34
35
36 VOID CCommentView::OnHeaderTrack(){
37
38         
39         Lock();
40         INT_PTR curSel = listBox.GetCurSel();
41         listBox.ShowWindow(SW_HIDE);
42
43         UINT_PTR commentCount = commentlist.Size();
44
45         timer_set(resize);
46         timer_start(resize);
47         for(UINT_PTR index =0;index < commentCount;index++){
48
49                 CommentLineSet(commentlist.GetChatAt(index),index);
50
51         }
52         timer_end(resize);
53         
54         
55         listBox.ShowWindow(SW_SHOW);
56         listBox.SetRedraw(TRUE);
57         listBox.SetCurSel(curSel);
58
59         Unlock();
60         
61
62 }
63
64 VOID CCommentView::OnChatReceve(NicoLiveChat_P chat,UINT_PTR count){
65         
66
67         
68         Lock();
69         commentlist.OnChatReceve(chat,count);
70         listBox.AddString(NULL);
71         CommentLineSet(commentlist.back(),count);
72         Unlock();
73
74         
75         
76
77 }
78
79 VOID CCommentView::OnChatReceveSettle(UINT_PTR commentCount,UINT_PTR commentCountSum){
80
81         listBox.SetRedraw(TRUE);
82
83         return;
84 }
85
86 static UCHAR getrgb(){
87
88         
89         UCHAR rgb = 160 + rand() % 92;
90         return rgb;
91 }
92
93 VOID CCommentView::OnListBoxDoubleClick(){
94         INT_PTR cursel = listBox.GetCurSel();
95         if(cursel == LB_ERR)return;
96         
97         auto chatData = commentlist.GetChatAt(cursel);
98         COLORREF bkColor;
99         if(chatData.listenerData->originBkFlag == FALSE){
100                 CListenerColorCollector colorCollector;
101                 listenerList.BkColorCollect(colorCollector);
102                 UCHAR red;
103                 UCHAR green;
104                 UCHAR blue;
105                 
106                 srand((unsigned int)time(NULL));
107                 do{
108
109                         red = getrgb();
110                         green = getrgb();
111                         blue = getrgb();
112                         bkColor = RGB(red,green,blue);
113
114                 }while(colorCollector.Find(bkColor));
115         } else {
116
117                 bkColor = viewproperty.backColor;
118         }
119
120         
121         
122
123         chatData.listenerData->SetBkColor(bkColor);
124
125         listBox.Invalidate(TRUE);
126
127         return;
128 }
129
130 VOID CCommentView::OnDrawList(LPDRAWITEMSTRUCT lpDrawItemStruct){
131
132
133         RECT noViewRect;
134         RECT userNameViewRect;
135         RECT timeViewRect;
136         RECT chatViewRect;
137         RECT infoViewRect;
138
139            
140
141         CChatData &chatData = commentlist.GetChatAt(lpDrawItemStruct->itemID);
142
143         time_t chatTime = (time_t)difftime(chatData.date,streamStatus.start_time);
144         tm ct = *gmtime(&chatTime);
145                 
146                 
147         TCHAR noString[sizeof(chatData.no) * 8]; 
148         TCHAR dateString[LENGTH_16];
149         _stprintf(noString,TEXT("%u"),chatData.no);
150
151         _tcsftime(dateString,ARRAY_LENGTH(dateString),ct.tm_hour != 0 ? TEXT("%H:%M:%S") : TEXT("%M:%S"),&ct);
152
153         
154         
155         //\91I\91ð\8fó\91Ô\82©\83`\83F\83b\83N
156         if ((lpDrawItemStruct->itemState) & (ODS_SELECTED))
157         {
158
159                 SelectObject(lpDrawItemStruct->hDC,bkBurushSelect);
160                 SelectObject(lpDrawItemStruct->hDC,outLinePenSelect);   
161                 SetBkColor(lpDrawItemStruct->hDC,RGB(255,240,240)) ;
162         }
163         else  
164         {
165                 SelectObject(lpDrawItemStruct->hDC,outLinePenNomal);
166
167                 if(chatData.listenerData->originBkFlag == TRUE){
168                         
169                         SelectObject(lpDrawItemStruct->hDC,chatData.listenerData->baseBkBrush);
170                         SetBkColor(lpDrawItemStruct->hDC,chatData.listenerData->bkColor) ;
171
172                 } else {
173
174                         SelectObject(lpDrawItemStruct->hDC,bkBurushNomal);
175                         SetBkColor(lpDrawItemStruct->hDC,viewproperty.backColor) ;
176                         
177                 }
178         }
179                 
180         
181         //\83e\83L\83X\83g\82Ì\83J\83\89\81[\82ð\90Ý\92è
182         SetTextColor(lpDrawItemStruct->hDC,viewproperty.baseStringColor);
183
184         
185         
186         Rectangle(lpDrawItemStruct->hDC,lpDrawItemStruct->rcItem.left,lpDrawItemStruct->rcItem.top,lpDrawItemStruct->rcItem.right,lpDrawItemStruct->rcItem.bottom);
187
188
189
190
191
192
193
194         //\95`\89æ\83T\83C\83Y\82ð\8cv\8eZ
195
196         header.GetItemRect(NO,&noViewRect);
197         header.GetItemRect(USERNAME,&userNameViewRect);
198         header.GetItemRect(COMMENT,&chatViewRect);
199         header.GetItemRect(TIME,&timeViewRect);
200         header.GetItemRect(INFO,&infoViewRect);
201
202         SelectObject(lpDrawItemStruct->hDC,colLinePen);
203         
204         MoveToEx(lpDrawItemStruct->hDC,noViewRect.right,lpDrawItemStruct->rcItem.top,NULL);
205         LineTo(lpDrawItemStruct->hDC,noViewRect.right,lpDrawItemStruct->rcItem.bottom);
206         MoveToEx(lpDrawItemStruct->hDC,userNameViewRect.right,lpDrawItemStruct->rcItem.top,NULL);
207         LineTo(lpDrawItemStruct->hDC,userNameViewRect.right,lpDrawItemStruct->rcItem.bottom);
208         MoveToEx(lpDrawItemStruct->hDC,chatViewRect.right,lpDrawItemStruct->rcItem.top,NULL);
209         LineTo(lpDrawItemStruct->hDC,chatViewRect.right,lpDrawItemStruct->rcItem.bottom);
210         MoveToEx(lpDrawItemStruct->hDC,timeViewRect.right,lpDrawItemStruct->rcItem.top,NULL);
211         LineTo(lpDrawItemStruct->hDC,timeViewRect.right,lpDrawItemStruct->rcItem.bottom);
212         MoveToEx(lpDrawItemStruct->hDC,infoViewRect.right,lpDrawItemStruct->rcItem.top,NULL);
213         LineTo(lpDrawItemStruct->hDC,infoViewRect.right,lpDrawItemStruct->rcItem.bottom);
214
215         noViewRect.left += 2;
216         userNameViewRect.left += 2;
217         timeViewRect.left += 2;
218         chatViewRect.left += 2;
219         infoViewRect.left += 2;
220
221         noViewRect.right += 2;
222         userNameViewRect.right += 2;
223         timeViewRect.right += 2;
224         chatViewRect.right += 2;
225         infoViewRect.right += 2;
226
227         noViewRect.top = lpDrawItemStruct->rcItem.top + 2;
228         userNameViewRect.top = lpDrawItemStruct->rcItem.top + 2;
229         timeViewRect.top = lpDrawItemStruct->rcItem.top + 2;
230         chatViewRect.top = lpDrawItemStruct->rcItem.top + 2;
231         infoViewRect.top = lpDrawItemStruct->rcItem.top + 2;
232
233         noViewRect.bottom = lpDrawItemStruct->rcItem.bottom - 2;
234         userNameViewRect.bottom = lpDrawItemStruct->rcItem.bottom - 2;
235         timeViewRect.bottom = lpDrawItemStruct->rcItem.bottom - 2;
236         chatViewRect.bottom = lpDrawItemStruct->rcItem.bottom - 2;
237         infoViewRect.bottom = lpDrawItemStruct->rcItem.bottom - 2;
238
239
240
241         
242
243         ::DrawText(lpDrawItemStruct->hDC,noString,_tcslen(noString),&noViewRect,DT_WORD_ELLIPSIS);
244
245         ::DrawText(lpDrawItemStruct->hDC,chatData.listenerData->user_id.c_str(),chatData.listenerData->user_id.length(),&userNameViewRect,DT_WORD_ELLIPSIS);
246
247         ::DrawText(lpDrawItemStruct->hDC,chatData.chatBuf.c_str(),chatData.chatBuf.length(),&chatViewRect,DT_WORDBREAK);
248
249         ::DrawText(lpDrawItemStruct->hDC,dateString,_tcslen(dateString),&timeViewRect,DT_WORD_ELLIPSIS);
250
251         return;
252 }
253
254
255
256
257
258
259
260
261