OSDN Git Service

2012/01/17 13:38:45
authorunknown <qwerty2501@users.sourceforge.jp>
Tue, 17 Jan 2012 04:38:46 +0000 (13:38 +0900)
committerunknown <qwerty2501@users.sourceforge.jp>
Tue, 17 Jan 2012 04:38:46 +0000 (13:38 +0900)
nlite.suo
nlite/nlite_commentview.cpp
nlite/nlite_commentview.h

index f41766b..e8a7cd6 100644 (file)
Binary files a/nlite.suo and b/nlite.suo differ
index fc50288..aa95a07 100644 (file)
@@ -26,7 +26,7 @@ CCommentView::CCommentView():
 
 CCommentView::~CCommentView(){
 
-       
+
        DeleteObject(hHeaderFontNew);
 
        return;
@@ -42,7 +42,9 @@ VOID CCommentView::OnConnect(){
        SCROLLINFO vScrollInfo = {0};
        vScrollInfo.cbSize = sizeof(vScrollInfo);
        vScrollInfo.fMask = SIF_RANGE;
+
        this->SetScrollInfo(SB_VERT,&vScrollInfo,TRUE);
+
        viewStartHeight = 0;
        m_commentListWindow.SetRedraw(TRUE);
        
@@ -126,10 +128,12 @@ LRESULT CCommentView::OnHeaderEndTrack(LPNMHDR lParam){
                m_commentListWindow.SetRedraw(FALSE);
                SCROLLINFO vScrollInfo = {0};
                vScrollInfo.fMask = SIF_PAGE | SIF_POS | SIF_RANGE;
+
                this->GetScrollInfo(SB_VERT,&vScrollInfo);
                vScrollInfo.nPage = m_commentListWindow.CalcScrollPage();
                vScrollInfo.fMask = SIF_PAGE;
                this->SetScrollInfo(SB_VERT,&vScrollInfo);
+
                BOOL scrollFlag = vScrollInfo.nPos + (int)vScrollInfo.nPage + 1>= vScrollInfo.nMax;
                UINT_PTR commentCount = commentlist.Size();
                LPNMHEADER  lpNmHdr = (LPNMHEADER )lParam;
@@ -172,7 +176,10 @@ LRESULT CCommentView::OnHeaderEndTrack(LPNMHDR lParam){
                }
 
                m_commentListWindow.SetRedraw(TRUE);
-               m_commentListWindow.Invalidate();
+               if(TryEnterCriticalSection(&m_commentListWindow.m_sec) == TRUE){
+                       m_commentListWindow.Invalidate();
+                       m_commentListWindow.Unlock();
+               }
                        
        }
 
@@ -180,7 +187,9 @@ LRESULT CCommentView::OnHeaderEndTrack(LPNMHDR lParam){
 }
 
 VOID CCommentView::OnChatReceve(NicoLiveChat_P chat,UINT_PTR commnetCountSum){
+
        commentlist.OnChatReceve(chat,commnetCountSum,this->m_commentListWindow);
+
        return;
 }
 
@@ -198,6 +207,7 @@ VOID CCommentView::OnChatReceveSettle(UINT_PTR chatNo,UINT_PTR commentCountSum){
        //vScrollCcs.Lock();
 
        vScrollInfo.fMask = SIF_ALL;
+
        this->GetScrollInfo(SB_VERT,&vScrollInfo);
        BOOL scrollFlag = vScrollInfo.nPos + (int)vScrollInfo.nPage >= vScrollInfo.nMax;
        
@@ -210,13 +220,17 @@ VOID CCommentView::OnChatReceveSettle(UINT_PTR chatNo,UINT_PTR commentCountSum){
        
        
        this->SetScrollInfo(SB_VERT,&vScrollInfo);
-       
 
+       
 
+       
        if(scrollFlag == TRUE){
                this->SendMessageW(WM_VSCROLL,MAKEWORD(SB_BOTTOM,0),0);
        }
-       m_commentListWindow.Invalidate();
+       if(TryEnterCriticalSection(&m_commentListWindow.m_sec) == TRUE){
+               m_commentListWindow.Invalidate();
+               m_commentListWindow.Unlock();
+       }
        
        return;
 }
@@ -250,10 +264,13 @@ VOID CCommentView::ChangeSize(const SIZE& client){
        hScrollInfo.cbSize = sizeof(hScrollInfo);
        hScrollInfo.fMask = SIF_PAGE;
        hScrollInfo.nPage = client.cx;
+       
        this->SetScrollInfo(SB_HORZ,&hScrollInfo);
        hScrollInfo.fMask = SIF_ALL;
        this->GetScrollInfo(SB_HORZ,&hScrollInfo);
 
+       
+
        HDWP hDwp = BeginDeferWindowPos(2);
        
 
@@ -272,7 +289,7 @@ VOID CCommentView::ChangeSize(const SIZE& client){
        bkRect.top = 0;
        bkRect.right = client.cx ;
        bkRect.bottom = client.cy;
-       this->InvalidateRect(&bkRect);
+       
 
        return;
 }
@@ -303,8 +320,11 @@ VOID CCommentView::OnDestroy(){
 LRESULT CCommentView::OnHeaderEndDrag(LPNMHDR lParam){
 
        if(lParam->hwndFrom == m_header.m_hWnd){
-
-               m_commentListWindow.Invalidate();
+               if(TryEnterCriticalSection(&m_commentListWindow.m_sec) == TRUE){
+               
+                       m_commentListWindow.Invalidate();
+                       m_commentListWindow.Unlock();
+               }
 
        }
 
@@ -376,7 +396,6 @@ VOID CCommentView::OnVScroll(INT_PTR loWParam,SHORT hiWParam,HWND lParam){
        vScrollInfo.fMask = SIF_ALL;
 
        
-
        this->GetScrollInfo(SB_VERT,&vScrollInfo);
 
        switch(loWParam){
@@ -421,7 +440,7 @@ VOID CCommentView::OnVScroll(INT_PTR loWParam,SHORT hiWParam,HWND lParam){
 
        case SB_BOTTOM:
 
-               dy = vScrollInfo.nMax + 1;
+               dy = vScrollInfo.nMax;
 
                break;
 
@@ -439,12 +458,15 @@ VOID CCommentView::OnVScroll(INT_PTR loWParam,SHORT hiWParam,HWND lParam){
        if(dy != 0){
 
                vScrollInfo.nPos += dy;
-               viewStartHeight = vScrollInfo.nPos + 1;
+               viewStartHeight = vScrollInfo.nPos;
                this->SetScrollInfo(SB_VERT,&vScrollInfo);
-               
-               m_commentListWindow.Invalidate();
+               if(TryEnterCriticalSection(&m_commentListWindow.m_sec) == TRUE){
+                       m_commentListWindow.Invalidate();
+                       m_commentListWindow.Unlock();
+               }
        }
 
+
                
        return;
 }
@@ -522,6 +544,7 @@ CCommentListWindow::~CCommentListWindow(){
        
 }
 
+
 VOID CCommentListWindow::OnPaint(HDC hdc){
 
        
@@ -550,36 +573,39 @@ VOID CCommentListWindow::OnPaint(HDC hdc){
        
        if(commentList.Size() > (UINT_PTR)self.viewStartHeight){
 
-               CCommentList::iterator chatData = commentList.begin();
+       
                
+               CCommentList::iterator chatData = commentList.begin();
                std::advance(chatData,self.viewStartHeight);
+               
+
+
                CBrush baseBkBrush;
                baseBkBrush.CreateSolidBrush(self.viewproperty.backColor);
                m_memoryDC.FillRect(&listRect,baseBkBrush);
                baseBkBrush.DeleteObject();
                CCommentList::iterator endData = commentList.end();
                listRect.bottom = 0;
-               for(;chatData != endData;++chatData){
-                       listRect.bottom += this->CalcItemHeight(*chatData);
+               for(;chatData != endData && listRect.top < clientRect.bottom;++chatData){
+                       listRect.bottom += chatData->height;
+
                        
                        this->DrawItem(m_memoryDC,listRect,*chatData);
-                       listRect.top = listRect.bottom;
-
-                       if(listRect.top >= clientRect.bottom)break;
                        
+                       
+                       
+                       listRect.top = listRect.bottom;
                }
 
                
-
        }
-       //\83R\83\81\83\93\83g\83\8a\83X\83g\83\8d\83b\83N\89ð\8f\9c
-//     commentList.Unlock();
+
        
        
        
        PAINTSTRUCT ps;
        HDC selfDC = this->BeginPaint(&ps);
-       ::BitBlt(selfDC,0,0,windowRect.right,windowRect.bottom,m_memoryDC,0,0,SRCCOPY);
+       BOOL rslt = ::BitBlt(selfDC,0,0,windowRect.right,windowRect.bottom,m_memoryDC,0,0,SRCCOPY);
        this->EndPaint(&ps);
 
        
@@ -590,16 +616,21 @@ VOID CCommentListWindow::OnSize(UINT wParam, _WTYPES_NS::CSize &windowSize){
 
        SCROLLINFO vScrollInfo = {0};
        vScrollInfo.fMask = SIF_ALL;
+
+
        self.GetScrollInfo(SB_VERT,&vScrollInfo);
        BOOL scrollFlag = (UINT)(vScrollInfo.nPage + vScrollInfo.nPos + 1) >= (UINT)vScrollInfo.nMax;
        vScrollInfo.nPage = CalcScrollPage();
        
        vScrollInfo.fMask = SIF_PAGE;
        self.SetScrollInfo(SB_VERT,&vScrollInfo);
+
+       
        
        if(scrollFlag == TRUE){
                self.SendMessageW(WM_VSCROLL,MAKELONG(SB_BOTTOM,0),0);
        }
+       
        return;
 }
 
@@ -619,13 +650,13 @@ UINT_PTR CCommentListWindow::CalcScrollPage(){
                for(;rbegin != rend;++rbegin){
 
                        height += rbegin->height;
-                       rslt++;
-                       if(height > clientRect.bottom)goto overclientrect;
                        
+                       if(height > clientRect.bottom)goto overclientrect;
+                       rslt++;
                }
        }
        
-       vScrollInfo.fMask = SIF_ALL;
+       vScrollInfo.fMask = SIF_RANGE;
        self.GetScrollInfo(SB_VERT,&vScrollInfo);
        rslt = vScrollInfo.nMax + 1;
 
@@ -788,7 +819,9 @@ LRESULT CCommentListWindow::OnCreate(LPCREATESTRUCT lpCreateStruct){
 INT_PTR CCommentListWindow::CalcClickLine(INT_PTR height){
        SCROLLINFO vScrollInfo = {0};
        vScrollInfo.fMask = SIF_POS;
+
        self.GetScrollInfo(SB_VERT,&vScrollInfo);
+
        INT_PTR heightSum = 0;
        INT_PTR lineNo = vScrollInfo.nPos;
        CCommentList::iterator chatData = self.commentlist.begin();
@@ -816,9 +849,6 @@ end:
 
 VOID CCommentListWindow::OnLButtonDown(UINT wParam, _WTYPES_NS::CPoint &point){
 
-       
-
-       
 
        
        this->SetFocus();
@@ -828,8 +858,10 @@ VOID CCommentListWindow::OnLButtonDown(UINT wParam, _WTYPES_NS::CPoint &point){
                curselItem->selectFlag = FALSE;
        }
        self.commentlist.SetCurSel(CalcClickLine(point.y));
-
-       this->Invalidate();
+       if(TryEnterCriticalSection(&this->m_sec) == TRUE){
+               this->Invalidate();
+               this->Unlock();
+       }
        return;
 }
 
@@ -874,8 +906,10 @@ VOID CCommentListWindow::OnLButtonDbClk(UINT wParam, _WTYPES_NS::CPoint &point){
 
        chatData.listenerData->SetBkColor(bkColor);
 
-       this->Invalidate(TRUE);
-               
+       if(TryEnterCriticalSection(&this->m_sec) == TRUE){
+               this->Invalidate(TRUE);
+               this->Unlock();
+       }
        
        
        
@@ -892,7 +926,8 @@ LRESULT CCommentListWindow::OnMouseWheel(UINT loWparam,SHORT hiWparam,CPoint &po
 
        
        self.SendMessageW(WM_VSCROLL,MAKELONG(hiWparam < 0 ? SB_PAGEDOWN : SB_PAGEUP ,0),0);
-       
+
+
        return 0;
 }
 
index 8effa0b..e5b5ce6 100644 (file)
@@ -20,7 +20,7 @@ namespace nlite{
 
        class CCommentView;
        //\83R\83\81\83\93\83g\95\\8e¦\97p\83E\83B\83\93\83h\83E
-       class CCommentListWindow:public CWindowImpl<CCommentListWindow>{
+       class CCommentListWindow:public CWindowImpl<CCommentListWindow>,public CComAutoCriticalSection{
 
                //\83\81\83\93\83o
        private:
@@ -162,13 +162,15 @@ namespace nlite{
 
                CHeaderCtrl m_header;
                CCommentListWindow  m_commentListWindow;
-               CComAutoCriticalSection vScrollCS;
+               
                CStreamStatus streamStatus;
                CCommentList commentlist;
                CommentViewProperty viewproperty;
                INT_PTR viewStartHeight;
                HFONT hHeaderFontNew;
 
+               
+