OSDN Git Service

チャットのリンク表示実装
authorqwerty2501 <riot313@gmail.com>
Fri, 3 Feb 2012 16:11:52 +0000 (01:11 +0900)
committerqwerty2501 <riot313@gmail.com>
Fri, 3 Feb 2012 16:11:52 +0000 (01:11 +0900)
nlite.suo
nlite/nlite.h
nlite/nlite_commentview.cpp
nlite/nlite_commentview.h
nlite/stdafx.h
nlite_stub/nlib_stub.h
nlite_stub/nlite_stub.cpp

index e3293b2..8599cfa 100644 (file)
Binary files a/nlite.suo and b/nlite.suo differ
index 0ca0989..fd44598 100644 (file)
@@ -1,7 +1,7 @@
 #pragma once
 
 
-
+#include "nlite_string.h"
 namespace nlite{
 
        //\83N\83\89\83X\90æ\8ds\90é\8c¾
@@ -22,6 +22,15 @@ namespace nlite{
 
        };
 
+       namespace nliteregex{
+               typedef std::tr1::basic_regex<TCHAR> tregex;
+               const static tregex URL(TEXT("(https?|ftp)(://[-_.!~*\'()a-zA-Z0-9;/?:@&=+$,%#]+)"));
+               const static tregex TAGSTRING(TEXT("<[/a-zA-Z0-9= ]*>"));
+               const static tregex VIDEOID(TEXT("(sm|nm)([0-9])+"));
+               const static tregex LIVEID(TEXT("(lv)([0-9])+"));
+               const static tstring NUTHINGSTRING(TEXT(""));
+       }
+
        ///
        ///\90Ý\92è\83t\83@\83C\83\8b\82Ìxml\93Ç\82Ý\8eæ\82è\97p\83N\83\89\83X
        ///
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);
index f7d31c2..8431b45 100644 (file)
@@ -37,7 +37,12 @@ namespace nlite{
 
                END_MSG_MAP()
 
-               BOOL SetWindowText(LPCTSTR str);
+               BOOL SetWindowText(const CChatData &str);
+
+               VOID Reset();
+
+               VOID linkStringBeside(const tstring &target,const nliteregex::tregex &re);
+               
 
                HWND GeneralCreate(HWND hParent,DWORD eventMask,UINT id);
        };
index d06f16b..46540fd 100644 (file)
@@ -41,6 +41,7 @@
 #include <deque>
 #include <algorithm>
 #include <set>
+#include <regex>
 #include <map>
 #include <list>
 
index c592a17..036bddf 100644 (file)
@@ -30,6 +30,6 @@ typedef struct nicolivestream_t{
 
 #define STARTRECEVECOUNT 1000
 
-#define RECEVECOUNT 65536
+#define RECEVECOUNT 1
 
 #define ONERECEVECHATCOUNT 3
\ No newline at end of file
index 60861f0..9b8d424 100644 (file)
@@ -211,7 +211,7 @@ unsigned int WINAPI commentthread(VOID *usadata){
 
                for(index2 = 0;index2 < ONERECEVECHATCOUNT;index2++){
 
-                       liveChat.chatBuf = commentcount % 2 == 0 ? TEXT("http://live.nicovideo.jp/watch/lv79715214?alert=1 254 http://live.nicovideo.jp/") : TEXT("test");
+                       liveChat.chatBuf = commentcount % 2 == 0 ? TEXT("http://live.nicovideo.jp/watch/lv79715214?alert=1 254 http://live.nicovideo.jp/") : TEXT("<font color=FF0000>sm552447 nm6655447 lv25447 </font >");
                        _stprintf((LPTSTR)liveChat.user_id,user_id_format,rand() % 15);
                        commentcount++;
                        _stprintf((LPTSTR)liveChat.no,TEXT("%u"),commentcount);