OSDN Git Service

2011/12/29 22:40:16
[nlite/nlite.git] / nlite / nlite_commentview.cpp
1 #include "stdafx.h"
2 #include "nlite_include.h"
3
4
5
6
7 VOID CCommentView::CommentLineSet(LPCTSTR chat,UINT_PTR count){
8
9         
10         
11         CDC cdc = listBox.GetDC();
12         
13         RECT drowSize = {0};
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         cdc.DrawTextW(chat,-1,&drowSize, DT_CALCRECT | DT_WORDBREAK);
22         drowSize.top -= 2;
23         drowSize.left -= 2;
24         drowSize.right += 2;
25         drowSize.bottom += 2;
26
27         listBox.SetItemHeight(listBox.GetCount() -1,drowSize.bottom - drowSize.top);
28
29         return;
30 }
31
32
33 VOID CCommentView::OnHeaderTrack(){
34
35         Lock();
36
37         listBox.ShowWindow(SW_HIDE);
38
39         UINT_PTR commentCount = commentlist.Size();
40         listBox.ResetContent();
41         for(UINT_PTR index =0;index < commentCount;index++){
42                 listBox.AddString(NULL);
43                 CommentLineSet(commentlist.GetChatAt(index).chatBuf.c_str(),index);
44
45         }
46
47         listBox.ShowWindow(SW_SHOW);
48
49         Unlock();
50
51         //listBox.InvalidateRect(NULL,TRUE);
52
53         
54
55 }
56
57 VOID CCommentView::OnChatReceve(NicoLiveChat_P chat,UINT_PTR count){
58         
59
60         
61         Lock();
62         commentlist.OnChatReceve(chat,count);
63         listBox.AddString(NULL);
64         Unlock();
65
66         CommentLineSet(chat->chatBuf,count);
67         
68
69 }
70
71 VOID CCommentView::OnChatReceveSettle(UINT_PTR commentCount,UINT_PTR commentCountSum){
72
73         return;
74 }
75
76
77 VOID CCommentView::OnDrawList(LPDRAWITEMSTRUCT lpDrawItemStruct){
78
79
80
81         //Lock();
82
83         RECT noViewRect;
84         RECT userNameViewRect;
85         RECT timeViewRect;
86         RECT chatViewRect;
87         RECT infoViewRect;
88
89         header.GetItemRect(NO,&noViewRect);
90         header.GetItemRect(USERNAME,&userNameViewRect);
91         header.GetItemRect(TIME,&timeViewRect);
92         header.GetItemRect(COMMENT,&chatViewRect);
93         header.GetItemRect(INFO,&infoViewRect);
94
95         noViewRect.left += 2;
96         userNameViewRect.left += 2;
97         timeViewRect.left += 2;
98         chatViewRect.left += 2;
99         infoViewRect.left += 2;
100
101         noViewRect.right += 2;
102         userNameViewRect.right += 2;
103         timeViewRect.right += 2;
104         chatViewRect.right += 2;
105         infoViewRect.right += 2;
106
107         noViewRect.top = lpDrawItemStruct->rcItem.top + 2;
108         userNameViewRect.top = lpDrawItemStruct->rcItem.top + 2;
109         timeViewRect.top = lpDrawItemStruct->rcItem.top + 2;
110         chatViewRect.top = lpDrawItemStruct->rcItem.top + 2;
111         infoViewRect.top = lpDrawItemStruct->rcItem.top + 2;
112
113         noViewRect.bottom = lpDrawItemStruct->rcItem.bottom - 2;
114         userNameViewRect.bottom = lpDrawItemStruct->rcItem.bottom - 2;
115         timeViewRect.bottom = lpDrawItemStruct->rcItem.bottom - 2;
116         chatViewRect.bottom = lpDrawItemStruct->rcItem.bottom - 2;
117         infoViewRect.bottom = lpDrawItemStruct->rcItem.bottom - 2;
118
119         CChatData &chatData = commentlist.GetChatAt(lpDrawItemStruct->itemID);
120
121         time_t chatTime = (time_t)difftime(chatData.date,streamStatus.start_time);
122         tm ct = *gmtime(&chatTime);
123                 
124                 
125         TCHAR noString[sizeof(chatData.no) * 8]; 
126         TCHAR dateString[LENGTH_16];
127         _stprintf(noString,TEXT("%u"),chatData.no);
128
129         _tcsftime(dateString,ARRAY_LENGTH(dateString),ct.tm_hour != 0 ? TEXT("%H:%M:%S") : TEXT("%M:%S"),&ct);
130
131         CBrush bkBurush;
132         CPen outLinePen;
133         CPen colLinePen;
134         //\91I\91ð\8fó\91Ô\82©\83`\83F\83b\83N
135         if ((lpDrawItemStruct->itemState) & (ODS_SELECTED))
136         {
137                         
138                 //\83u\83\89\83V\8dì\90¬
139                 bkBurush=CreateSolidBrush(RGB(255,240,240));
140 //              outLinePen = CreatePen(PS_SOLID,3,RGB(255,0,0));
141                 //\83e\83L\83X\83g\82Ì\94w\8ci\90F\82ð\8ew\92è
142                 SetBkColor(lpDrawItemStruct->hDC,RGB(255,240,240)) ;
143         }
144         else  
145         {
146                 //\83u\83\89\83V\8dì\90¬
147                 bkBurush=CreateSolidBrush(viewproperty.backColor);
148                         
149                 
150                 //\83e\83L\83X\83g\82Ì\94w\8ci\90F\82ð\8ew\92è
151                 SetBkColor(lpDrawItemStruct->hDC,viewproperty.backColor) ;
152         }
153                 
154         outLinePen = CreatePen(PS_SOLID,1,RGB(127,127,127));    
155         //\83e\83L\83X\83g\82Ì\83J\83\89\81[\82ð\90Ý\92è
156         SetTextColor(lpDrawItemStruct->hDC,viewproperty.baseStringColor);
157
158         SelectObject(lpDrawItemStruct->hDC,bkBurush);
159         SelectObject(lpDrawItemStruct->hDC,outLinePen);
160         Rectangle(lpDrawItemStruct->hDC,lpDrawItemStruct->rcItem.left,lpDrawItemStruct->rcItem.top,lpDrawItemStruct->rcItem.right,lpDrawItemStruct->rcItem.bottom);
161         DeleteObject(outLinePen);
162         DeleteObject(colLinePen);
163         DeleteObject(bkBurush);
164
165         ::DrawText(lpDrawItemStruct->hDC,noString,_tcslen(noString),&noViewRect,DT_WORD_ELLIPSIS);
166
167         ::DrawText(lpDrawItemStruct->hDC,chatData.user_id.c_str(),chatData.user_id.length(),&userNameViewRect,DT_WORD_ELLIPSIS);
168
169         ::DrawText(lpDrawItemStruct->hDC,chatData.chatBuf.c_str(),chatData.chatBuf.length(),&chatViewRect,DT_WORDBREAK);
170
171         ::DrawText(lpDrawItemStruct->hDC,dateString,_tcslen(dateString),&timeViewRect,DT_WORD_ELLIPSIS);
172
173                 
174         //Unlock();
175
176
177
178
179         return;
180 }
181
182
183
184 VOID CCommentList::OnChatReceve(NicoLiveChat_P chatData_in, UINT_PTR count){
185
186         
187         CChatData chatData;
188         chatData.SetChat(*chatData_in);
189         
190
191         
192         chatList.push_back(chatData);
193         return;
194 }
195
196
197
198 VOID CChatData::SetChat(NicoLiveChat &chat_in){
199         
200         
201         this->anonymity = _ttol(chat_in.anonymity);
202         this->premium = _ttol(chat_in.premium);
203         this->chatBuf = chat_in.chatBuf;
204         this->no = _ttol(chat_in.no);
205
206         if(_tcscmp(chat_in.locale,TEXT("jp")) == 0){
207                 this->locale = cuntry::jp;
208         } else {
209                 this->locale = cuntry::unknown;
210         }
211         this->mail.reserve(chat_in.mailCount);
212         for(UINT_PTR index = 0;index < chat_in.mailCount ;index++){
213
214                 this->mail.push_back(chat_in.mail[index]);
215         }
216
217         this->name = chat_in.name;
218         
219         this->user_id = chat_in.user_id;
220         
221
222         
223         this->vpos = _ttol(chat_in.vpos);
224         this->thread = _ttol(chat_in.thread);
225         this->date = _ttol(chat_in.date);
226         
227
228
229         return;
230 }
231
232
233