2 #include "nlite_include.h"
8 //
\83R
\83\81\83\93\83g
\83r
\83\85\81[
\83N
\83\89\83X
\83\81\83\
\83b
\83h
9 ///////////////////////////////////////////////////////
11 CCommentView::CCommentView():
13 m_commentListWindow(*this)
15 hScrollInfo.fMask = SIF_ALL;
16 hScrollInfo.cbSize = sizeof(hScrollInfo);
19 lf.lfCharSet = SHIFTJIS_CHARSET;
22 hHeaderFontNew = CreateFontIndirect(&lf);
24 colLinePen.CreatePen(PS_SOLID,1,RGB(224,224,224));
25 outLinePenNomal.CreatePen(PS_SOLID,1,RGB(127,127,127));
26 outLinePenSelect.CreatePen(PS_SOLID,1,RGB(255,0,0));
27 bkBurushSelect.CreateSolidBrush(RGB(255,240,240));
32 CCommentView::~CCommentView(){
34 colLinePen.DeleteObject();
35 outLinePenNomal.DeleteObject();
36 outLinePenSelect.DeleteObject();
37 bkBurushSelect.DeleteObject();
38 DeleteObject(hHeaderFontNew);
45 VOID CCommentView::Lock(){
49 VOID CCommentView::Unlock(){
54 VOID CCommentView::OnConnect(){
55 commentlist.OnConnect();
56 // m_commentListWindow.SetRedraw(FALSE);
61 UINT_PTR CCommentView::GetColumnHolSizeSum(){
63 return hScrollInfo.nMax;
66 VOID CCommentView::SetProperty(CommentViewProperty &setProperty){
68 viewproperty = setProperty;
70 if(bkBurushNomal.IsNull() == FALSE){
71 bkBurushNomal.DeleteObject();
73 bkBurushNomal.CreateSolidBrush(viewproperty.backColor);
77 CommentViewProperty &CCommentView::GetProperty(){
83 VOID CCommentView::OnMeasureItem(UINT wParam,LPMEASUREITEMSTRUCT lpMersureItemStruct){
85 if(lpMersureItemStruct->CtlID == commentViewConstant::LISTBOX_ID){
87 auto &chat = *(CChatData*)lpMersureItemStruct->itemData;
89 CDC cdc = this->GetDC();
92 m_header.GetItemRect(COMMENT,&drowSize);
98 SelectObject(cdc,AtlGetDefaultGuiFont());
101 cdc.DrawTextW(chat.chatBuf.c_str(),chat.chatBuf.length(),&drowSize, DT_CALCRECT | DT_WORDBREAK);
104 drowSize.bottom += 2;
106 lpMersureItemStruct->itemHeight = drowSize.bottom - drowSize.top;
116 HWND CCommentView::Create(HWND hWndParent){
120 HWND rslt = __super::Create(hWndParent,0,commentViewConstant::NLITE_COMMENTVIEW,WS_VISIBLE | WS_CHILD | WS_HSCROLL | WS_BORDER,0,commentViewConstant::MENU_OR_ID);
123 HDC hdc = m_header.BeginPaint(&ps);
126 HFONT hOld = (HFONT)SelectObject(hdc,hHeaderFontNew);
128 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ñ")};
129 UINT_PTR holizenSize[] = {0,0,100,0,0};
131 for(UINT_PTR index = 0;index < ARRAY_LENGTH(columns) ;++index){
133 GetTextExtentPoint32(hdc , columns[index] , _tcslen(columns[index]) , &size);
134 UINT_PTR holsize = holizenSize[index] + size.cx + 15;
135 holizenSize[index] = viewproperty.headerholSize[index] >= 0 ? viewproperty.headerholSize[index] : holsize;
138 SelectObject(hdc,hOld);
140 m_header.EndPaint(&ps);
143 HEADERSINFO headersinfo = {columns,holizenSize,ARRAY_LENGTH(columns)};
145 AddHeader(&headersinfo);
147 m_header.SetOrderArray(ARRAY_LENGTH(viewproperty.headerOraderArray),viewproperty.headerOraderArray);
158 LRESULT CCommentView::OnheaderItemChanged(LPNMHDR lParam){
161 if(lParam->hwndFrom == m_header.m_hWnd){
163 //INT_PTR curSel = commentlist.GetCurSel();
165 SCROLLINFO scrollInfo = {0};
166 scrollInfo.fMask = SIF_PAGE | SIF_POS | SIF_RANGE;
167 this->GetScrollInfo(SB_VERT,&scrollInfo);
169 BOOL scrollFlag = scrollInfo.nPos + (int)scrollInfo.nPage >= scrollInfo.nMax;
170 UINT_PTR commentCount = commentlist.Size();
173 // m_commentListWindow.SetRedraw(FALSE);
174 //m_commentListWindow.ResetContent();
176 for(UINT_PTR index =0;index < commentCount;index++){
177 m_commentListWindow.AddString((LPCTSTR)&commentlist.GetChatAt(index));
183 //m_commentListWindow.SetCurSel(curSel);
187 // m_commentListWindow.SetRedraw(TRUE);
188 // m_commentListWindow.Invalidate();
191 if(scrollFlag == TRUE){
193 // m_commentListWindow.SendMessageW(WM_VSCROLL,SB_BOTTOM,0);
196 INT_PTR itemCount = m_header.GetItemCount();
198 hScrollInfo.nMax = 0;
199 for(INT_PTR imtemIndex = 0;imtemIndex < itemCount;imtemIndex++){
200 m_header.GetItemRect(imtemIndex,&itemSizeRect);
201 hScrollInfo.nMax += itemSizeRect.right - itemSizeRect.left;
205 this->SetScrollInfo(SB_HORZ,&hScrollInfo,TRUE);
213 VOID CCommentView::OnChatReceve(NicoLiveChat_P chat,UINT_PTR count){
218 // m_commentListWindow.SetRedraw(FALSE);
219 commentlist.OnChatReceve(chat,count);
220 //m_commentListWindow.AddString((LPCTSTR)&commentlist.back());
222 SCROLLINFO scrollInfo = {0};
223 scrollInfo.fMask = SIF_PAGE | SIF_POS | SIF_RANGE;
224 // m_commentListWindow.GetScrollInfo(SB_VERT,&scrollInfo);
228 if(scrollInfo.nPos + (int)scrollInfo.nPage >= scrollInfo.nMax == TRUE){
229 // m_commentListWindow.SendMessageW(WM_VSCROLL,MAKEWORD(SB_BOTTOM,0),0);
235 VOID CCommentView::SetStreamStatus(StreamStatus &st){
237 streamStatus.SetStreamStatus(st);
240 VOID CCommentView::OnChatReceveSettle(UINT_PTR commentCount,UINT_PTR commentCountSum){
242 // m_commentListWindow.SetRedraw(TRUE);
248 static UCHAR getrgb(){
250 UCHAR rgb = 160 + rand() % 92;
254 LRESULT CCommentView::OnListBoxDoubleClick(UINT uNotifyCode, int nID, CWindow wndCtl){
258 if(wndCtl.m_hWnd == m_commentListWindow.m_hWnd){
260 //INT_PTR cursel = m_commentListWindow.GetCurSel();
262 if(cursel == LB_ERR)return 0;
264 auto chatData = commentlist.GetChatAt(cursel);
266 if(chatData.listenerData->originBkFlag == FALSE){
267 CListenerColorCollector colorCollector;
268 listenerList.BkColorCollect(colorCollector);
273 srand((unsigned int)time(NULL));
279 bkColor = RGB(red,green,blue);
281 }while(colorCollector.Find(bkColor));
283 chatData.listenerData->originBkFlag = TRUE;
287 bkColor = viewproperty.backColor;
288 chatData.listenerData->originBkFlag = FALSE;
294 chatData.listenerData->SetBkColor(bkColor);
296 m_commentListWindow.Invalidate(TRUE);
302 VOID CCommentView::OnDrawItem(UINT wParam,LPDRAWITEMSTRUCT lpDrawItemStruct){
304 //if((lpDrawItemStruct->hwndItem == m_commentListWindow.m_hWnd)/* &&/* ((UINT)m_commentListWindow.GetCount() > lpDrawItemStruct->itemID)*/){
307 RECT userNameViewRect;
314 CChatData &chatData = *(CChatData*)lpDrawItemStruct->itemData;
318 time_t chatTime = (time_t)difftime(chatData.date,streamStatus.start_time);
319 tm ct = *gmtime(&chatTime);
322 TCHAR noString[sizeof(chatData.no) * 8];
323 TCHAR dateString[LENGTH_16];
324 _stprintf(noString,TEXT("%u"),chatData.no);
326 _tcsftime(dateString,ARRAY_LENGTH(dateString),ct.tm_hour != 0 ? TEXT("%H:%M:%S") : TEXT("%M:%S"),&ct);
330 //
\91I
\91ð
\8fó
\91Ô
\82©
\83`
\83F
\83b
\83N
331 if ((lpDrawItemStruct->itemState) & (ODS_SELECTED))
334 SelectObject(lpDrawItemStruct->hDC,bkBurushSelect);
335 SelectObject(lpDrawItemStruct->hDC,outLinePenSelect);
336 SetBkColor(lpDrawItemStruct->hDC,RGB(255,240,240)) ;
340 SelectObject(lpDrawItemStruct->hDC,outLinePenNomal);
342 if(chatData.listenerData->originBkFlag == TRUE){
344 SelectObject(lpDrawItemStruct->hDC,chatData.listenerData->baseBkBrush);
345 SetBkColor(lpDrawItemStruct->hDC,chatData.listenerData->bkColor) ;
349 SelectObject(lpDrawItemStruct->hDC,bkBurushNomal);
350 SetBkColor(lpDrawItemStruct->hDC,viewproperty.backColor) ;
356 //
\83e
\83L
\83X
\83g
\82Ì
\83J
\83\89\81[
\82ð
\90Ý
\92è
357 SetTextColor(lpDrawItemStruct->hDC,viewproperty.baseStringColor);
361 Rectangle(lpDrawItemStruct->hDC,lpDrawItemStruct->rcItem.left,lpDrawItemStruct->rcItem.top,lpDrawItemStruct->rcItem.right,lpDrawItemStruct->rcItem.bottom);
369 //
\95`
\89æ
\83T
\83C
\83Y
\82ð
\8cv
\8eZ
371 m_header.GetItemRect(NO,&noViewRect);
372 m_header.GetItemRect(USERNAME,&userNameViewRect);
373 m_header.GetItemRect(COMMENT,&chatViewRect);
374 m_header.GetItemRect(TIME,&timeViewRect);
375 m_header.GetItemRect(INFO,&infoViewRect);
377 SelectObject(lpDrawItemStruct->hDC,colLinePen);
379 MoveToEx(lpDrawItemStruct->hDC,noViewRect.right,lpDrawItemStruct->rcItem.top,NULL);
380 LineTo(lpDrawItemStruct->hDC,noViewRect.right,lpDrawItemStruct->rcItem.bottom);
381 MoveToEx(lpDrawItemStruct->hDC,userNameViewRect.right,lpDrawItemStruct->rcItem.top,NULL);
382 LineTo(lpDrawItemStruct->hDC,userNameViewRect.right,lpDrawItemStruct->rcItem.bottom);
383 MoveToEx(lpDrawItemStruct->hDC,chatViewRect.right,lpDrawItemStruct->rcItem.top,NULL);
384 LineTo(lpDrawItemStruct->hDC,chatViewRect.right,lpDrawItemStruct->rcItem.bottom);
385 MoveToEx(lpDrawItemStruct->hDC,timeViewRect.right,lpDrawItemStruct->rcItem.top,NULL);
386 LineTo(lpDrawItemStruct->hDC,timeViewRect.right,lpDrawItemStruct->rcItem.bottom);
387 MoveToEx(lpDrawItemStruct->hDC,infoViewRect.right,lpDrawItemStruct->rcItem.top,NULL);
388 LineTo(lpDrawItemStruct->hDC,infoViewRect.right,lpDrawItemStruct->rcItem.bottom);
390 noViewRect.left += 2;
391 userNameViewRect.left += 2;
392 timeViewRect.left += 2;
393 chatViewRect.left += 2;
394 infoViewRect.left += 2;
396 noViewRect.right += 2;
397 userNameViewRect.right += 2;
398 timeViewRect.right += 2;
399 chatViewRect.right += 2;
400 infoViewRect.right += 2;
402 noViewRect.top = lpDrawItemStruct->rcItem.top + 2;
403 userNameViewRect.top = lpDrawItemStruct->rcItem.top + 2;
404 timeViewRect.top = lpDrawItemStruct->rcItem.top + 2;
405 chatViewRect.top = lpDrawItemStruct->rcItem.top + 2;
406 infoViewRect.top = lpDrawItemStruct->rcItem.top + 2;
408 noViewRect.bottom = lpDrawItemStruct->rcItem.bottom - 2;
409 userNameViewRect.bottom = lpDrawItemStruct->rcItem.bottom - 2;
410 timeViewRect.bottom = lpDrawItemStruct->rcItem.bottom - 2;
411 chatViewRect.bottom = lpDrawItemStruct->rcItem.bottom - 2;
412 infoViewRect.bottom = lpDrawItemStruct->rcItem.bottom - 2;
418 ::DrawText(lpDrawItemStruct->hDC,noString,_tcslen(noString),&noViewRect,DT_WORD_ELLIPSIS);
420 ::DrawText(lpDrawItemStruct->hDC,chatData.listenerData->user_id.c_str(),chatData.listenerData->user_id.length(),&userNameViewRect,DT_WORD_ELLIPSIS);
422 ::DrawText(lpDrawItemStruct->hDC,chatData.chatBuf.c_str(),chatData.chatBuf.length(),&chatViewRect,DT_WORDBREAK);
424 ::DrawText(lpDrawItemStruct->hDC,dateString,_tcslen(dateString),&timeViewRect,DT_WORD_ELLIPSIS);
434 VOID CCommentView::OnSizing(UINT wParam,LPRECT lParam){
437 ChangeSize( _WTYPES_NS::CSize(lParam->right - lParam->left,lParam->bottom - lParam->top));
446 LRESULT CCommentView::OnSize(UINT wParam,SIZE lParam){
453 VOID CCommentView::ChangeSize(const SIZE& client){
455 SCROLLINFO scrollInfoTmp = {0};
456 scrollInfoTmp.cbSize = sizeof(scrollInfoTmp);
457 scrollInfoTmp.fMask = SIF_PAGE;
458 scrollInfoTmp.nPage = client.cx;
459 this->SetScrollInfo(SB_HORZ,&scrollInfoTmp);
461 this->GetScrollInfo(SB_HORZ,&hScrollInfo);
463 HDWP hDwp = BeginDeferWindowPos(2);
466 INT_PTR movePos = -1 * hScrollInfo.nPos;
468 m_header.DeferWindowPos(hDwp,m_header.m_hWnd,movePos,0,0,0,SWP_NOSIZE | SWP_NOZORDER);
469 m_commentListWindow.DeferWindowPos(hDwp,m_commentListWindow.m_hWnd,movePos,commentViewConstant::HEADER_HAIGHT,::GetSystemMetrics(SM_CXFULLSCREEN),client.cy - commentViewConstant::HEADER_HAIGHT,SWP_NOZORDER);
471 EndDeferWindowPos(hDwp);
476 m_header.GetWindowRect(&headerRectSize);
477 bkRect.left = headerRectSize.right - headerRectSize.left - hScrollInfo.nPos;
479 bkRect.right = client.cx ;
480 bkRect.bottom = client.cy;
481 this->InvalidateRect(&bkRect);
487 LRESULT CCommentView::OnEraseBkgnd(HDC wParam){
493 VOID CCommentView::OnDestroy(){
494 m_header.GetOrderArray(ARRAY_LENGTH(viewproperty.headerOraderArray),viewproperty.headerOraderArray);
495 INT_PTR headerItemcount = m_header.GetItemCount();
497 for(INT_PTR itemindex = 0;itemindex < headerItemcount;itemindex++){
499 m_header.GetItemRect(itemindex,&headerItemRect);
500 viewproperty.headerholSize[itemindex] = headerItemRect.right - headerItemRect.left;
502 commentlist.OnDestroy();
503 m_header.DestroyWindow();
504 // m_commentListWindow.DestroyWindow();
509 LRESULT CCommentView::OnHeaderEndDrag(LPNMHDR lParam){
511 if(lParam->hwndFrom == m_header.m_hWnd){
513 // m_commentListWindow.Invalidate();
521 VOID CCommentView::OnHScroll(INT_PTR loWParam,SHORT hiWParam,HWND lParam){
527 case SB_THUMBPOSITION:
529 dy = hiWParam - hScrollInfo.nPos;
535 dy = -1 * hScrollInfo.nPage;
542 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;
552 dy = max(-1 * hScrollInfo.nPos, min(dy, hScrollInfo.nMax - hScrollInfo.nPos));
556 hScrollInfo.nPos += dy;
557 //RECT headerPosRect;
558 //RECT listBoxPosRect;
559 //m_header.GetWindowRect(&headerPosRect);
560 //m_commentListWindow.GetWindowRect(&listBoxPosRect);
561 INT_PTR moveRange = -(hScrollInfo.nPos);
564 headerPosRect.bottom -= headerPosRect.top;
565 headerPosRect.top = 0;
566 headerPosRect.right += moveRange - headerPosRect.left;
567 headerPosRect.left = moveRange;
569 listBoxPosRect.bottom -= (listBoxPosRect.top - commentViewConstant::HEADER_HAIGHT);
570 listBoxPosRect.top = commentViewConstant::HEADER_HAIGHT;
571 listBoxPosRect.right += moveRange - listBoxPosRect.left;
572 listBoxPosRect.left = moveRange;
574 m_header.MoveWindow(&headerPosRect);
575 m_commentListWindow.MoveWindow(&listBoxPosRect);
580 HDWP hDwp = BeginDeferWindowPos(2);
582 m_header.DeferWindowPos(hDwp,m_header.m_hWnd,moveRange,0,0,0,SWP_NOSIZE | SWP_NOZORDER);
583 m_commentListWindow.DeferWindowPos(hDwp,m_commentListWindow.m_hWnd,moveRange,commentViewConstant::HEADER_HAIGHT,0,0,SWP_NOSIZE | SWP_NOZORDER);
585 EndDeferWindowPos(hDwp);
588 this->SetScrollInfo(SB_HORZ,&hScrollInfo);
594 LRESULT CCommentView::OnCreate(LPCREATESTRUCT lpcs){
595 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);
596 m_commentListWindow.Create(m_hWnd,0,WC_LISTBOX,WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN , 0,commentViewConstant::LISTBOX_ID);
597 m_commentListWindow.SetFont(AtlGetDefaultGuiFont());
601 m_subListBox.SubclassWindow(m_commentListWindow);
602 m_subListBox.CreateMemoryDC();
607 VOID CCommentView::AddHeader(LPHEADERSINFO infos){
610 m_header.SetFont(hHeaderFontNew);
613 item.mask = HDI_FORMAT | HDI_TEXT | HDI_WIDTH;
614 item.fmt = HDF_CENTER | HDF_STRING;
617 for(UINT_PTR index = 0;index < infos->count ;++index){
619 item.pszText = infos->columns[index];
621 item.cxy = infos->holizensize[index];
622 m_header.AddItem(&item);
626 hScrollInfo.nMax = 0;
627 UINT_PTR itemCount = m_header.GetItemCount();
628 for(UINT_PTR u_index = 0;u_index < itemCount;++u_index){
630 m_header.GetItemRect(u_index,&itemRect);
631 hScrollInfo.nMax += itemRect.right - itemRect.left;
635 this->SetScrollInfo(SB_HORZ,&hScrollInfo,TRUE);
640 VOID CCommentView::DecisionHorzSize(){
642 HDWP hWindowPosInfo = BeginDeferWindowPos(2);
644 this->GetClientRect(&bkWindowRect);
645 m_header.DeferWindowPos(hWindowPosInfo,m_header.m_hWnd,0,0,::GetSystemMetrics(SM_CXFULLSCREEN),commentViewConstant::HEADER_HAIGHT,SWP_NOZORDER | SWP_NOMOVE);
646 m_commentListWindow.DeferWindowPos(hWindowPosInfo,m_header.m_hWnd,0,0,::GetSystemMetrics(SM_CXFULLSCREEN),bkWindowRect.bottom - commentViewConstant::HEADER_HAIGHT,SWP_NOZORDER | SWP_NOMOVE);
648 EndDeferWindowPos(hWindowPosInfo);
649 bkWindowRect.left = hScrollInfo.nMax;
651 this->InvalidateRect(&bkWindowRect);
658 //
\83R
\83\81\83\93\83g
\83r
\83\85\81[
\83N
\83\89\83X
\93à
\95\94\83\8a\83X
\83g
\83N
\83\89\83X
659 ////////////////////////////////////////////////////////////////////
661 CCommentListWindow::CCommentListWindow(CCommentView &in_self):self(in_self){}
665 VOID CCommentListWindow::OnPaint(HDC hdc){
669 m_bitmap.GetSize(bitmapSize);
670 RECT bitmapRect = {0};
672 bitmapRect.right = bitmapSize.cx;
673 bitmapRect.bottom = bitmapSize.cy;
674 this->GetWindowRect(&windowRect);
675 m_memoryDC.FillRect(&bitmapRect,self.viewproperty.backColor);
678 HDC selfDC = this->BeginPaint(&ps);
679 ::BitBlt(selfDC,0,0,windowRect.right - windowRect.left,windowRect.bottom - windowRect.top,m_memoryDC,0,0,SRCCOPY);
687 LRESULT CCommentListWindow::OnCreate(LPCREATESTRUCT lpCreateStruct){
688 LRESULT lRet = this->DefWindowProc();
690 HDC hdc = this->GetDC();
691 m_memoryDC.CreateCompatibleDC(hdc);
693 m_bitmap.CreateCompatibleBitmap(hdc,::GetSystemMetrics(SM_CXFULLSCREEN),::GetSystemMetrics(SM_CYFULLSCREEN));
694 m_memoryDC.SelectBitmap(m_bitmap);
695 this->ReleaseDC(hdc);
700 VOID CCommentListWindow::OnLButtonDown(UINT wParam, _WTYPES_NS::CPoint &point){
706 VOID CCommentListWindow::OnLButtonDbClk(UINT wParam, _WTYPES_NS::CPoint &point){
711 LRESULT CCommentListWindow::OnEraseBkGnd(HDC lparam){