2 #include "nlite_include.h"
6 CCommentView::CCommentView():
9 hScrollInfo.fMask = SIF_ALL;
10 hScrollInfo.cbSize = sizeof(hScrollInfo);
13 lf.lfCharSet = SHIFTJIS_CHARSET;
16 hHeaderFontNew = CreateFontIndirect(&lf);
18 colLinePen.CreatePen(PS_SOLID,1,RGB(224,224,224));
19 outLinePenNomal.CreatePen(PS_SOLID,1,RGB(127,127,127));
20 outLinePenSelect.CreatePen(PS_SOLID,1,RGB(255,0,0));
21 bkBurushSelect.CreateSolidBrush(RGB(255,240,240));
26 CCommentView::~CCommentView(){
28 colLinePen.DeleteObject();
29 outLinePenNomal.DeleteObject();
30 outLinePenSelect.DeleteObject();
31 bkBurushSelect.DeleteObject();
32 DeleteObject(hHeaderFontNew);
39 VOID CCommentView::Lock(){
43 VOID CCommentView::Unlock(){
48 VOID CCommentView::OnConnect(){
49 commentlist.OnConnect();
50 m_listBox.SetRedraw(FALSE);
51 m_listBox.ResetContent();
55 UINT_PTR CCommentView::GetColumnHolSizeSum(){
57 return hScrollInfo.nMax;
60 VOID CCommentView::SetProperty(CommentViewProperty &setProperty){
62 viewproperty = setProperty;
64 if(bkBurushNomal.IsNull() == FALSE){
65 bkBurushNomal.DeleteObject();
67 bkBurushNomal.CreateSolidBrush(viewproperty.backColor);
71 CommentViewProperty &CCommentView::GetProperty(){
77 VOID CCommentView::OnMeasureItem(UINT wParam,LPMEASUREITEMSTRUCT lpMersureItemStruct){
79 if(lpMersureItemStruct->CtlID == commentViewConstant::LISTBOX_ID){
81 auto &chat = *(CChatData*)lpMersureItemStruct->itemData;
83 CDC cdc = m_listBox.GetDC();
86 m_header.GetItemRect(COMMENT,&drowSize);
92 SelectObject(cdc,AtlGetDefaultGuiFont());
95 cdc.DrawTextW(chat.chatBuf.c_str(),chat.chatBuf.length(),&drowSize, DT_CALCRECT | DT_WORDBREAK);
100 lpMersureItemStruct->itemHeight = drowSize.bottom - drowSize.top;
110 HWND CCommentView::Create(HWND hWndParent){
114 HWND rslt = __super::Create(hWndParent,0,commentViewConstant::NLITE_COMMENTVIEW,WS_VISIBLE | WS_CHILD | WS_HSCROLL | WS_BORDER,0,commentViewConstant::MENU_OR_ID);
117 HDC hdc = m_header.BeginPaint(&ps);
120 HFONT hOld = (HFONT)SelectObject(hdc,hHeaderFontNew);
122 LPTSTR columns[] = {TEXT("
\83R
\83\81\94Ô"),TEXT("
\83\86\81[
\83U
\81[
\96¼"),TEXT("
\83R
\83\81\83\93\83g"),TEXT("
\8e\9e\8aÔ"),TEXT("
\8fî
\95ñ")};
123 UINT_PTR holizenSize[] = {0,0,100,0,0};
125 for(UINT_PTR index = 0;index < ARRAY_LENGTH(columns) ;++index){
127 GetTextExtentPoint32(hdc , columns[index] , _tcslen(columns[index]) , &size);
128 UINT_PTR holsize = holizenSize[index] + size.cx + 15;
129 holizenSize[index] = viewproperty.headerholSize[index] >= 0 ? viewproperty.headerholSize[index] : holsize;
132 SelectObject(hdc,hOld);
134 m_header.EndPaint(&ps);
137 HEADERSINFO headersinfo = {columns,holizenSize,ARRAY_LENGTH(columns)};
139 AddHeader(&headersinfo);
141 m_header.SetOrderArray(ARRAY_LENGTH(viewproperty.headerOraderArray),viewproperty.headerOraderArray);
152 LRESULT CCommentView::OnheaderItemChanged(LPNMHDR lParam){
155 if(lParam->hwndFrom == m_header.m_hWnd){
157 INT_PTR curSel = m_listBox.GetCurSel();
159 SCROLLINFO scrollInfo = {0};
160 scrollInfo.fMask = SIF_PAGE | SIF_POS | SIF_RANGE;
161 m_listBox.GetScrollInfo(SB_VERT,&scrollInfo);
163 BOOL scrollFlag = scrollInfo.nPos + (int)scrollInfo.nPage >= scrollInfo.nMax;
164 UINT_PTR commentCount = commentlist.Size();
167 m_listBox.SetRedraw(FALSE);
168 m_listBox.ResetContent();
169 for(UINT_PTR index =0;index < commentCount;index++){
170 m_listBox.AddString((LPCTSTR)&commentlist.GetChatAt(index));
176 m_listBox.SetCurSel(curSel);
180 m_listBox.SetRedraw(TRUE);
181 m_listBox.Invalidate();
184 if(scrollFlag == TRUE){
186 m_listBox.SendMessageW(WM_VSCROLL,SB_BOTTOM,0);
189 INT_PTR itemCount = m_header.GetItemCount();
191 hScrollInfo.nMax = 0;
192 for(INT_PTR imtemIndex = 0;imtemIndex < itemCount;imtemIndex++){
193 m_header.GetItemRect(imtemIndex,&itemSizeRect);
194 hScrollInfo.nMax += itemSizeRect.right - itemSizeRect.left;
198 this->SetScrollInfo(SB_HORZ,&hScrollInfo,TRUE);
206 VOID CCommentView::OnChatReceve(NicoLiveChat_P chat,UINT_PTR count){
211 commentlist.OnChatReceve(chat,count);
212 m_listBox.AddString((LPCTSTR)&commentlist.back());
214 SCROLLINFO scrollInfo = {0};
215 scrollInfo.fMask = SIF_PAGE | SIF_POS | SIF_RANGE;
216 m_listBox.GetScrollInfo(SB_VERT,&scrollInfo);
219 if(scrollInfo.nPos + (int)scrollInfo.nPage >= scrollInfo.nMax == TRUE){
220 m_listBox.SendMessageW(WM_VSCROLL,SB_BOTTOM,0);
226 VOID CCommentView::SetStreamStatus(StreamStatus &st){
228 streamStatus.SetStreamStatus(st);
231 VOID CCommentView::OnChatReceveSettle(UINT_PTR commentCount,UINT_PTR commentCountSum){
233 m_listBox.SetRedraw(TRUE);
239 static UCHAR getrgb(){
242 UCHAR rgb = 160 + rand() % 92;
246 LRESULT CCommentView::OnListBoxDoubleClick(UINT uNotifyCode, int nID, CWindow wndCtl){
250 if(wndCtl.m_hWnd == m_listBox.m_hWnd){
252 INT_PTR cursel = m_listBox.GetCurSel();
253 if(cursel == LB_ERR)return 0;
255 auto chatData = commentlist.GetChatAt(cursel);
257 if(chatData.listenerData->originBkFlag == FALSE){
258 CListenerColorCollector colorCollector;
259 listenerList.BkColorCollect(colorCollector);
264 srand((unsigned int)time(NULL));
270 bkColor = RGB(red,green,blue);
272 }while(colorCollector.Find(bkColor));
274 chatData.listenerData->originBkFlag = TRUE;
278 bkColor = viewproperty.backColor;
279 chatData.listenerData->originBkFlag = FALSE;
285 chatData.listenerData->SetBkColor(bkColor);
287 m_listBox.Invalidate(TRUE);
293 VOID CCommentView::OnDrawItem(UINT wParam,LPDRAWITEMSTRUCT lpDrawItemStruct){
295 if((lpDrawItemStruct->hwndItem == m_listBox.m_hWnd) && ((UINT)m_listBox.GetCount() > lpDrawItemStruct->itemID)){
298 RECT userNameViewRect;
305 CChatData &chatData = *(CChatData*)lpDrawItemStruct->itemData;
309 time_t chatTime = (time_t)difftime(chatData.date,streamStatus.start_time);
310 tm ct = *gmtime(&chatTime);
313 TCHAR noString[sizeof(chatData.no) * 8];
314 TCHAR dateString[LENGTH_16];
315 _stprintf(noString,TEXT("%u"),chatData.no);
317 _tcsftime(dateString,ARRAY_LENGTH(dateString),ct.tm_hour != 0 ? TEXT("%H:%M:%S") : TEXT("%M:%S"),&ct);
321 //
\91I
\91ð
\8fó
\91Ô
\82©
\83`
\83F
\83b
\83N
322 if ((lpDrawItemStruct->itemState) & (ODS_SELECTED))
325 SelectObject(lpDrawItemStruct->hDC,bkBurushSelect);
326 SelectObject(lpDrawItemStruct->hDC,outLinePenSelect);
327 SetBkColor(lpDrawItemStruct->hDC,RGB(255,240,240)) ;
331 SelectObject(lpDrawItemStruct->hDC,outLinePenNomal);
333 if(chatData.listenerData->originBkFlag == TRUE){
335 SelectObject(lpDrawItemStruct->hDC,chatData.listenerData->baseBkBrush);
336 SetBkColor(lpDrawItemStruct->hDC,chatData.listenerData->bkColor) ;
340 SelectObject(lpDrawItemStruct->hDC,bkBurushNomal);
341 SetBkColor(lpDrawItemStruct->hDC,viewproperty.backColor) ;
347 //
\83e
\83L
\83X
\83g
\82Ì
\83J
\83\89\81[
\82ð
\90Ý
\92è
348 SetTextColor(lpDrawItemStruct->hDC,viewproperty.baseStringColor);
352 Rectangle(lpDrawItemStruct->hDC,lpDrawItemStruct->rcItem.left,lpDrawItemStruct->rcItem.top,lpDrawItemStruct->rcItem.right,lpDrawItemStruct->rcItem.bottom);
360 //
\95`
\89æ
\83T
\83C
\83Y
\82ð
\8cv
\8eZ
362 m_header.GetItemRect(NO,&noViewRect);
363 m_header.GetItemRect(USERNAME,&userNameViewRect);
364 m_header.GetItemRect(COMMENT,&chatViewRect);
365 m_header.GetItemRect(TIME,&timeViewRect);
366 m_header.GetItemRect(INFO,&infoViewRect);
368 SelectObject(lpDrawItemStruct->hDC,colLinePen);
370 MoveToEx(lpDrawItemStruct->hDC,noViewRect.right,lpDrawItemStruct->rcItem.top,NULL);
371 LineTo(lpDrawItemStruct->hDC,noViewRect.right,lpDrawItemStruct->rcItem.bottom);
372 MoveToEx(lpDrawItemStruct->hDC,userNameViewRect.right,lpDrawItemStruct->rcItem.top,NULL);
373 LineTo(lpDrawItemStruct->hDC,userNameViewRect.right,lpDrawItemStruct->rcItem.bottom);
374 MoveToEx(lpDrawItemStruct->hDC,chatViewRect.right,lpDrawItemStruct->rcItem.top,NULL);
375 LineTo(lpDrawItemStruct->hDC,chatViewRect.right,lpDrawItemStruct->rcItem.bottom);
376 MoveToEx(lpDrawItemStruct->hDC,timeViewRect.right,lpDrawItemStruct->rcItem.top,NULL);
377 LineTo(lpDrawItemStruct->hDC,timeViewRect.right,lpDrawItemStruct->rcItem.bottom);
378 MoveToEx(lpDrawItemStruct->hDC,infoViewRect.right,lpDrawItemStruct->rcItem.top,NULL);
379 LineTo(lpDrawItemStruct->hDC,infoViewRect.right,lpDrawItemStruct->rcItem.bottom);
381 noViewRect.left += 2;
382 userNameViewRect.left += 2;
383 timeViewRect.left += 2;
384 chatViewRect.left += 2;
385 infoViewRect.left += 2;
387 noViewRect.right += 2;
388 userNameViewRect.right += 2;
389 timeViewRect.right += 2;
390 chatViewRect.right += 2;
391 infoViewRect.right += 2;
393 noViewRect.top = lpDrawItemStruct->rcItem.top + 2;
394 userNameViewRect.top = lpDrawItemStruct->rcItem.top + 2;
395 timeViewRect.top = lpDrawItemStruct->rcItem.top + 2;
396 chatViewRect.top = lpDrawItemStruct->rcItem.top + 2;
397 infoViewRect.top = lpDrawItemStruct->rcItem.top + 2;
399 noViewRect.bottom = lpDrawItemStruct->rcItem.bottom - 2;
400 userNameViewRect.bottom = lpDrawItemStruct->rcItem.bottom - 2;
401 timeViewRect.bottom = lpDrawItemStruct->rcItem.bottom - 2;
402 chatViewRect.bottom = lpDrawItemStruct->rcItem.bottom - 2;
403 infoViewRect.bottom = lpDrawItemStruct->rcItem.bottom - 2;
409 ::DrawText(lpDrawItemStruct->hDC,noString,_tcslen(noString),&noViewRect,DT_WORD_ELLIPSIS);
411 ::DrawText(lpDrawItemStruct->hDC,chatData.listenerData->user_id.c_str(),chatData.listenerData->user_id.length(),&userNameViewRect,DT_WORD_ELLIPSIS);
413 ::DrawText(lpDrawItemStruct->hDC,chatData.chatBuf.c_str(),chatData.chatBuf.length(),&chatViewRect,DT_WORDBREAK);
415 ::DrawText(lpDrawItemStruct->hDC,dateString,_tcslen(dateString),&timeViewRect,DT_WORD_ELLIPSIS);
424 VOID CCommentView::OnPaint(HDC wParam){
425 PAINTSTRUCT paintStruct;
426 HDC paintDC = this->BeginPaint(&paintStruct);
427 HPEN hPen = (HPEN)GetStockPen(NULL_PEN);
428 HPEN oldPen = (HPEN)::SelectObject(paintDC,hPen);
429 HBRUSH brush = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
430 HBRUSH oldBrush = (HBRUSH)::SelectObject(paintDC,brush);
432 ::Rectangle(paintDC,paintStruct.rcPaint.left,paintStruct.rcPaint.top,paintStruct.rcPaint.right,paintStruct.rcPaint.bottom);
433 this->EndPaint(&paintStruct);
434 ::SelectObject(paintDC,oldBrush);
435 ::SelectObject(paintDC,oldPen);
441 VOID CCommentView::OnSizing(UINT wParam,LPRECT lParam){
444 ChangeSize( _WTYPES_NS::CSize(lParam->right - lParam->left,lParam->bottom - lParam->top));
453 LRESULT CCommentView::OnSize(UINT wParam,SIZE lParam){
460 VOID CCommentView::ChangeSize(const SIZE& client){
464 HDWP hDwp = BeginDeferWindowPos(2);
466 RECT commentViewPosRect;
469 m_header.GetWindowRect(&headerPosRect);
470 this->GetWindowRect(&commentViewPosRect);
472 INT_PTR movePos = (client.cx - hScrollInfo.nPage);
473 idumpln(TEXT("movePos:%d"),movePos);
474 m_header.DeferWindowPos(hDwp,m_header.m_hWnd,movePos,0,0,0,SWP_NOSIZE | SWP_NOZORDER);
475 m_listBox.DeferWindowPos(hDwp,m_listBox.m_hWnd,movePos,commentViewConstant::HEADER_HAIGHT,hScrollInfo.nMax,client.cy - commentViewConstant::HEADER_HAIGHT,SWP_NOZORDER);
477 EndDeferWindowPos(hDwp);
478 // m_listBox.MoveWindow(0,commentViewConstant::HEADER_HAIGHT,hScrollInfo.nMax,client.cy - commentViewConstant::HEADER_HAIGHT);
479 hScrollInfo.nPage = client.cx;
480 this->SetScrollInfo(SB_HORZ,&hScrollInfo);
482 bkRect.right = client.cx - hScrollInfo.nMax;
483 bkRect.bottom = client.cy;
484 this->InvalidateRect(&bkRect);
490 LRESULT CCommentView::OnEraseBkgnd(HDC wParam){
496 VOID CCommentView::OnDestroy(){
497 m_header.GetOrderArray(ARRAY_LENGTH(viewproperty.headerOraderArray),viewproperty.headerOraderArray);
498 INT_PTR headerItemcount = m_header.GetItemCount();
500 for(INT_PTR itemindex = 0;itemindex < headerItemcount;itemindex++){
502 m_header.GetItemRect(itemindex,&headerItemRect);
503 viewproperty.headerholSize[itemindex] = headerItemRect.right - headerItemRect.left;
505 commentlist.OnDestroy();
506 m_header.DestroyWindow();
507 m_listBox.DestroyWindow();
512 LRESULT CCommentView::OnHeaderEndDrag(LPNMHDR lParam){
514 if(lParam->hwndFrom == m_header.m_hWnd){
516 m_listBox.Invalidate();
524 VOID CCommentView::OnHScroll(INT_PTR loWParam,SHORT hiWParam,HWND lParam){
530 case SB_THUMBPOSITION:
532 dy = hiWParam - hScrollInfo.nPos;
538 dy = -1 * hScrollInfo.nPage;
545 dy = hScrollInfo.nPage + hScrollInfo.nPos > (UINT_PTR)hScrollInfo.nMax ? 0 :(UINT_PTR) (hScrollInfo.nMax - ( hScrollInfo.nPage + hScrollInfo.nPos)) < hScrollInfo.nPage ? (hScrollInfo.nMax - ( hScrollInfo.nPage + hScrollInfo.nPos)) : hScrollInfo.nPage;
555 dy = max(-1 * hScrollInfo.nPos, min(dy, hScrollInfo.nMax - hScrollInfo.nPos));
559 hScrollInfo.nPos += dy;
562 m_header.GetWindowRect(&headerPosRect);
563 m_listBox.GetWindowRect(&listBoxPosRect);
564 INT_PTR moveRange = -(hScrollInfo.nPos);
565 headerPosRect.bottom -= headerPosRect.top;
566 headerPosRect.top = 0;
567 headerPosRect.right += moveRange - headerPosRect.left;
568 headerPosRect.left = moveRange;
570 listBoxPosRect.bottom -= (listBoxPosRect.top - commentViewConstant::HEADER_HAIGHT);
571 listBoxPosRect.top = commentViewConstant::HEADER_HAIGHT;
572 listBoxPosRect.right += moveRange - listBoxPosRect.left;
573 listBoxPosRect.left = moveRange;
575 m_header.MoveWindow(&headerPosRect);
576 m_listBox.MoveWindow(&listBoxPosRect);
581 HDWP hDwp = BeginDeferWindowPos(2);
583 m_header.DeferWindowPos(hDwp,m_header.m_hWnd,moveRange,0,0,0,SWP_NOSIZE | SWP_NOZORDER);
584 m_listBox.DeferWindowPos(hDwp,m_listBox.m_hWnd,moveRange,commentViewConstant::HEADER_HAIGHT,0,0,SWP_NOSIZE | SWP_NOZORDER);
586 EndDeferWindowPos(hDwp);
589 this->SetScrollInfo(SB_HORZ,&hScrollInfo);
595 LRESULT CCommentView::OnCreate(LPCREATESTRUCT lpcs){
596 m_header.Create(m_hWnd,0,WC_HEADER,WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | HDS_BUTTONS | HDS_HOTTRACK |HDS_DRAGDROP | HDS_FULLDRAG ,0,commentViewConstant::HEADER_ID);
597 m_listBox.Create(m_hWnd,0,WC_LISTBOX,WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_CLIPCHILDREN | LBS_OWNERDRAWVARIABLE | LBS_NOTIFY | LBS_NOREDRAW ,0,commentViewConstant::LISTBOX_ID);
598 m_listBox.SetFont(AtlGetDefaultGuiFont());
604 VOID CCommentView::AddHeader(LPHEADERSINFO infos){
607 m_header.SetFont(hHeaderFontNew);
610 item.mask = HDI_FORMAT | HDI_TEXT | HDI_WIDTH;
611 item.fmt = HDF_CENTER | HDF_STRING;
614 for(UINT_PTR index = 0;index < infos->count ;++index){
616 item.pszText = infos->columns[index];
618 item.cxy = infos->holizensize[index];
619 hScrollInfo.nMax += infos->holizensize[index];
620 m_header.InsertItem(index,&item);
623 this->SetScrollInfo(SB_HORZ,&hScrollInfo,TRUE);
628 VOID CCommentView::DecisionHorzSize(){
630 HDWP hWindowPosInfo = BeginDeferWindowPos(2);
632 this->GetClientRect(&bkWindowRect);
633 m_header.DeferWindowPos(hWindowPosInfo,m_header.m_hWnd,0,0,hScrollInfo.nMax,commentViewConstant::HEADER_HAIGHT,SWP_NOZORDER | SWP_NOMOVE);
634 m_listBox.DeferWindowPos(hWindowPosInfo,m_header.m_hWnd,0,0,hScrollInfo.nMax,bkWindowRect.bottom - commentViewConstant::HEADER_HAIGHT,SWP_NOZORDER | SWP_NOMOVE);
636 EndDeferWindowPos(hWindowPosInfo);
637 bkWindowRect.left = hScrollInfo.nMax;
639 this->InvalidateRect(&bkWindowRect);