OSDN Git Service

チャットのリンク表示実装
[nlite/nlite.git] / nlite / nlite_commentview.cpp
index 50acbd8..cef2a2b 100644 (file)
@@ -1,6 +1,6 @@
 #include "stdafx.h"
 #include "nlite_include.h"
-
+using namespace std::tr1;
 
 namespace nlite{
 
@@ -10,13 +10,56 @@ namespace nlite{
        //\83R\83\81\83\93\83g\83r\83\85\81[\93à\82Ì\83R\83\93\83g\83\8d\81[\83\8b\83N\83\89\83X
        ///////////////////////////////////////////////////////////////////
 
-       BOOL CChatReadEdit::SetWindowText(LPCTSTR str){
+       BOOL CChatReadEdit::SetWindowText(const CChatData &chat){
+
+               BOOL rslt = FALSE;
+               try{
+                       
+                       tstring viewString(regex_replace(tstring(chat.chatBuf),nliteregex::TAGSTRING,nliteregex::NUTHINGSTRING));
+                       rslt = __super::SetWindowText(viewString.c_str());
+                       linkStringBeside(viewString,nliteregex::URL);
+                       linkStringBeside(viewString,nliteregex::VIDEOID);
+                       linkStringBeside(viewString,nliteregex::LIVEID);
+                       
+                       
+
+               } catch(std::exception &e){
+                       e;
+                       rslt =  FALSE;
+
+               }
 
-               return __super::SetWindowText(str);
+               return rslt;
                
        }
 
-       
+       VOID CChatReadEdit::linkStringBeside(const tstring &target,const nliteregex::tregex &re){
+
+               match_results<tstring::const_iterator> regexRslt;
+               tstring::const_iterator beginStr = target.begin();
+               tstring::const_iterator endstr = target.end();
+               CHARFORMAT2 cf;
+               cf.cbSize = sizeof(cf);
+               cf.dwMask = CFM_LINK;
+               cf.dwEffects = CFE_LINK;
+               INT_PTR basePosition = 0;
+               while(regex_search(beginStr,endstr,regexRslt,re)){
+                       basePosition += regexRslt.position(0);
+                       this->SetSel(basePosition,basePosition + regexRslt.length());
+                       this->SetCharFormat(cf,SCF_SELECTION);
+                       basePosition += regexRslt.length();
+                               
+                       beginStr = regexRslt[0].second;
+               }
+
+       }
+
+       VOID CChatReadEdit::Reset(){
+
+               __super::SetWindowText(TEXT(""));
+
+               return;
+       }
 
        HWND CChatReadEdit::GeneralCreate(HWND hParent,DWORD eventMask,UINT id){
 
@@ -83,7 +126,7 @@ namespace nlite{
        VOID CChatChildCtrls::SetCtrl(HDWP hdwp,const RECT  &rc,CCommentList::reference comment,BOOL mulutiLineFlag){
 
                
-               chatDispCtrl.SetWindowText(comment.chatBuf);
+               chatDispCtrl.SetWindowText(comment);
                RECT chatRect = rc;
                
                
@@ -477,7 +520,7 @@ namespace nlite{
 
                if(vScrollInfo.nPos + static_cast<INT_PTR>(vScrollInfo.nPage) >= vScrollInfo.nMax - static_cast<INT_PTR>(vScrollInfo.nPage)){
                        m_commentListWindow.Invalidate();
-
+                       
                        this->PostMessage(UM_COMMENTVIEW_SETCTRL,NULL,NULL);
                }
 
@@ -580,21 +623,7 @@ namespace nlite{
 
                return 0;
        }
-       /*
-       LRESULT CCommentView::OnHeaderItemChanged(LPNMHDR lParam){
-
-               if(lParam->hwndFrom == m_header.m_hWnd){
-                       
-
-                       m_commentListWindow.Invalidate();
-                       this->m_commentListWindow.SendMessage(UM_COMMENTVIEW_SETCTRL,NULL,NULL);
-                       
 
-               }
-
-               return 0;
-       }
-       */
        VOID CCommentView::OnHScroll(INT_PTR loWParam,SHORT hiWParam,HWND lParam){
 
 
@@ -1221,7 +1250,6 @@ end:
        VOID CCommentListWindow::CalcItemHeight(CChatData &chatData){
                
                if(chatData.viewData.height == 0){
-               //      dumpln(TEXT("viewdataupdate"));
                        RECT drowSize;
                        self.m_header.GetItemRect(CCommentView::COMMENT,&drowSize);
                
@@ -1230,12 +1258,13 @@ end:
                        CChatReadEdit cedit;
                
                        cedit.GeneralCreate(*this,ENM_REQUESTRESIZE,CALCEDIT_ID);
-                       cedit.SetWindowText(TEXT(""));
+                       cedit.Reset();
                        cedit.SetWindowPos(NULL,0,0,drowSize.right - drowSize.left,drowSize.bottom - drowSize.top,SWP_NOZORDER | SWP_NOMOVE | SWP_NOREDRAW);
-                       cedit.SetWindowText(chatData.chatBuf);
+                       cedit.SetWindowText(chatData);
                        cedit.GetClientRect(&drowSize);
                        cedit.DestroyWindow();
-                       if(drowSize.bottom - drowSize.top > 70)drowSize.bottom = drowSize.top + 70;
+                       drowSize.bottom += 12;
+                       if(drowSize.bottom - drowSize.top > 120)drowSize.bottom = drowSize.top + 120;
                        chatData.viewData.height = drowSize.bottom - drowSize.top;
                }
 
@@ -1280,10 +1309,6 @@ end:
                self.m_header.GetItemRect(index,&rc);
                BOOL rslt = FALSE;
 
-               //dumpln(TEXT("index:%d"),index);
-               //dumpln(TEXT("rc.left:%d"),rc.left);
-               //dumpln(TEXT("rc.right:%d"),rc.right);
-               //dumpln(TEXT("point.x:%d"),point.x);
                if((point.x >= rc.left && point.x <= rc.right) && (point.y < static_cast<INT_PTR>(viewSellHeight))){
 
                        INT_PTR heightsum = 0;
@@ -1299,9 +1324,8 @@ end:
                                        
                                        rc.top = heightsum -= clickData->viewData.height;
                                        RECT calcRect = {0};
-                                       //rc.bottom = rc.bottom;
                                        cdc.SelectFont(linkFont);
-                                       //::GetTextExtentPoint32(cdc,clickData->chatBuf,clickData->chatBuf.Length(),&stringSize);
+
 
                                        if(index == CCommentView::USERNAME){
                                                LPCTSTR viewStr = clickData->listenerData->userName.Length() == 0 ? clickData->listenerData->user_id : clickData->listenerData->userName;
@@ -1315,11 +1339,6 @@ end:
                                        }
                                        rc.bottom = rc.top +  calcRect.bottom - calcRect.top;
                                        rc.right = rc.right > rc.left + calcRect.right - calcRect.left ? rc.left + calcRect.right - calcRect.left : rc.right;
-                                       
-                                       //dumpln(TEXT("stringSize.cy:%d"),stringSize.cy);
-                                       //dumpln(TEXT("stringSize.cx:%d"),stringSize.cx);
-                                       dumpln(TEXT("rc.left:%d"),rc.left);
-                                       dumpln(TEXT("rc.right :%d"),rc.right);
                                        rslt = (point.y >= rc.top && point.y <= rc.bottom && point.x >= rc.left && point.x <= rc.right);
                                        
                                        break;
@@ -1454,6 +1473,7 @@ end:
 
        LRESULT CCommentListWindow::OnSetCursor(HWND wparam,UINT loLparam,UINT hiLparam){
 
+               
                POINT mousePoint = {0};
        
                GetCursorPos(&mousePoint);