OSDN Git Service

コメント書き込み時のマウス砂時計処理を実装
[nlite/nlite.git] / nlite / nlite_commentWrite.cpp
index 69c83c9..9843313 100644 (file)
@@ -8,10 +8,13 @@ const static SIZE commentColorBoxSize = {35,0};
 
 const static LPCTSTR ANONYMOUS_MAILCOMMAND = TEXT("184");
 const static LPCTSTR ANONYMOUS_BOTTONSTRING = ANONYMOUS_MAILCOMMAND;
-
+const static LPCTSTR OWNERMODE_BOTTONSTRING = TEXT("\8eå\83R\83\81");
 const static LPCTSTR WRITE_BOTTONSTRING = TEXT("\8f\91\82«\8d\9e\82Ý");
 const static LPCTSTR CHECKBUTTON_HIDDENSTRING = TEXT(" ");
 
+
+const static COLORREF OWNEREDITCOLOR = RGB(255,192,192);
+const static COLORREF NORMALEDITCOLOR = RGB(255,255,255);
 const static RECT COMMENTWRITEWINDOW_SEPARATEFSIZE = {0,5,0,5};
 const static UINT_PTR COMMENTWRITEWINDOW_SIDESEPARATESIZE = 5;
 const static UINT_PTR INIT_COMMENTWRITE_MAXLENGTH = 60;
@@ -124,6 +127,12 @@ streamTime(0)
 {}
 
 
+BOOL CCommentWriteWindow::IsWrighthing(){
+
+       return this->commentSubEdit.untilConnectingFlag;
+
+}
+
 UINT_PTR CCommentWriteWindow::GetHeight(){
 
        return commentWriteHeight + infoDispHeight - COMMENTWRITEWINDOW_SEPARATEFSIZE.top;
@@ -136,17 +145,16 @@ LRESULT CCommentWriteWindow::OnCreate(LPCREATESTRUCT lpReateStruct){
 
        commentPosBox.Create(m_hWnd,0,WC_COMBOBOX,WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST ,0,COMMENTPOS_BOX);
        commentSizeBox.Create(m_hWnd,0,WC_COMBOBOX,WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST,0,COMMENTSIZE_BOX);
-       commentColorBox.Create(m_hWnd,0,WC_COMBOBOX,WS_CHILD | WS_VISIBLE  | CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED        ,0,COMMENTCOLOR_BOX);
-       anonymousButton.Create(m_hWnd,0,WC_BUTTON,WS_CHILD | WS_VISIBLE | BS_CHECKBOX | BS_AUTOCHECKBOX ,0,ANONYMOUS_BUTTON);
+       commentColorBox.Create(m_hWnd,0,WC_COMBOBOX,WS_CHILD | WS_VISIBLE  | CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED ,0,COMMENTCOLOR_BOX);
+       anonymousButton.Create(m_hWnd,0,WC_BUTTON,WS_CHILD | WS_VISIBLE |  BS_AUTOCHECKBOX | BS_PUSHLIKE,0,ANONYMOUS_BUTTON);
+       ownerModeButton.Create(m_hWnd,0,WC_BUTTON,WS_CHILD |BS_AUTOCHECKBOX | BS_PUSHLIKE,0,OWNERMODE_BUTTON);
        commentSubEdit.Create(m_hWnd,0,WC_EDIT,WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL,0,COMMENT_EDIT);
-       
        commentWriteButton.Create(m_hWnd,0,WC_BUTTON,WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,0,COMMENTWRITE_BOTTON);
        commentPosBox.SetFont(AtlGetDefaultGuiFont());
        commentSizeBox.SetFont(AtlGetDefaultGuiFont());
        commentColorBox.SetFont(AtlGetDefaultGuiFont());
-
        
-       anonymousButton.SetWindowTextW(CHECKBUTTON_HIDDENSTRING);
+       
        anonymousButton.SetFont(AtlGetDefaultGuiFont());
        commentSubEdit.SetFont(AtlGetDefaultGuiFont());
        commentSubEdit.SetLimitText(commentWriteMaxLength);
@@ -160,14 +168,14 @@ LRESULT CCommentWriteWindow::OnCreate(LPCREATESTRUCT lpReateStruct){
        commentColorBox.SetCurSel(0);
        commentSizeBox.SetCurSel(0);
        commentPosBox.SetCurSel(0);
-       CFont font;
+       CFontHandle font;
        font = AtlGetDefaultGuiFont();
        CPaintDC pdc(*this);
        SIZE thisSize;
        LPCTSTR sample = TEXT(" ");
 
        GetTextExtentPoint32(pdc,sample,_tcslen(sample),&thisSize);
-       commentWriteHeight = thisSize.cy + (CHECKBUTTON_SUBSCRIPT_HEIGHT / 2) + COMMENTWRITEWINDOW_SEPARATEFSIZE.top + COMMENTWRITEWINDOW_SEPARATEFSIZE.bottom;
+       commentWriteHeight = thisSize.cy  + COMMENTWRITEWINDOW_SEPARATEFSIZE.top + COMMENTWRITEWINDOW_SEPARATEFSIZE.bottom;
        infoDispHeight = commentWriteHeight;
        commentWriteInternalHeight = commentWriteHeight - (COMMENTWRITEWINDOW_SEPARATEFSIZE.top + COMMENTWRITEWINDOW_SEPARATEFSIZE.bottom);
 
@@ -175,8 +183,9 @@ LRESULT CCommentWriteWindow::OnCreate(LPCREATESTRUCT lpReateStruct){
        anonymousLogFont.lfHeight = CHECKBUTTON_SUBSCRIPT_HEIGHT;
        anonymousLogFont.lfCharSet = SHIFTJIS_CHARSET;
 
-       anonymousFont.CreateFontIndirect(&anonymousLogFont);
-
+       checkButtonFont.CreateFontIndirect(&anonymousLogFont);
+       anonymousButton.SetFont(checkButtonFont);
+       ownerModeButton.SetFont(checkButtonFont);
        CFontHandle f = AtlGetDefaultGuiFont();
        LOGFONT timeLogFont;
        f.GetLogFont(timeLogFont);
@@ -184,8 +193,8 @@ LRESULT CCommentWriteWindow::OnCreate(LPCREATESTRUCT lpReateStruct){
        timeLogFont.lfWeight = FW_BOLD;
        
        timeFont.CreateFontIndirectW(&timeLogFont);
-
-
+       anonymousButton.SetWindowTextW(ANONYMOUS_MAILCOMMAND);
+       ownerModeButton.SetWindowText(OWNERMODE_BOTTONSTRING);
        return 0;
 }
 
@@ -267,76 +276,47 @@ VOID CCommentWriteWindow::OnPaint(HDC hdc){
        }
 
 
-       RECT anonymousRect;
-       SIZE anonymousStringSize;
-
-       anonymousButton.GetWindowRect(&anonymousRect);
-       CPoint anonymousPoint(anonymousRect.left,anonymousRect.top);
-       ::ScreenToClient(*this,&anonymousPoint);
-       anonymousRect.right -= anonymousRect.left;
-       anonymousRect.bottom -= anonymousRect.top;
-       anonymousRect.left = anonymousPoint.x;
-       anonymousRect.top = anonymousPoint.y + anonymousRect.bottom;
-
-
-       ::GetTextExtentPoint32(pdc,ANONYMOUS_BOTTONSTRING,_tcslen(ANONYMOUS_BOTTONSTRING),&anonymousStringSize);
-       anonymousRect.right = anonymousRect.left + anonymousStringSize.cx;
-       anonymousRect.bottom = anonymousRect.top + anonymousStringSize.cy;
-
        
-       pdc.SelectFont(anonymousFont);
-       
-       pdc.DrawText(ANONYMOUS_BOTTONSTRING,_tcslen(ANONYMOUS_BOTTONSTRING),&anonymousRect,0);
        
        return;
 }
 
-static VOID EnterChatBox(LPVOID userData){
-
-       
-       ((CSubChatEdit*)userData)->SetReadOnly(TRUE);
-       Sleep(3000);
-       ((CSubChatEdit*)userData)->AgreeEnter();
-
-       _endthread();
-       return;
-}
+VOID CSubChatEdit::EnterChatBox(LPVOID userData){
 
-BOOL CCommentWriteWindow::SendChat(){
 
-       _beginthread(EnterChatBox,0,this);
-       
+       auto owner = ((CSubChatEdit*)userData)->self;
+       auto &self = *((CSubChatEdit*)userData);
        CCommentMaker commentMaker;
-       std::vector<TCHAR> chat(commentSubEdit.GetWindowTextLengthW() + 1);
+       std::vector<TCHAR> chat(owner.commentSubEdit.GetWindowTextLengthW() + 1);
 
 
-       commentSubEdit.GetWindowTextW(&chat[0],chat.size());
+       owner.commentSubEdit.GetWindowTextW(&chat[0],chat.size());
        commentMaker.SetChatString(&chat[0]);
-       if(this->anonymousButton.GetCheck() == BST_CHECKED){
+       if(owner.anonymousButton.GetCheck() == BST_CHECKED){
 
                commentMaker.AddMail(ANONYMOUS_MAILCOMMAND);
        }
-       INT_PTR sizeIndex = commentSizeBox.GetCurSel();
+       INT_PTR sizeIndex = owner.commentSizeBox.GetCurSel();
        if(sizeIndex == CB_ERR)sizeIndex = 0;
-       auto &rCommentSizeInfo = *(CommentSizeInfo*)commentSizeBox.GetItemDataPtr(sizeIndex);
+       auto &rCommentSizeInfo = *(CommentSizeInfo*)owner.commentSizeBox.GetItemDataPtr(sizeIndex);
 
        if(_tcscmp(rCommentSizeInfo.userData,DEFAULT_COMMENTSIZE) != 0){
 
                commentMaker.AddMail(rCommentSizeInfo.userData);
 
        }
-       INT_PTR posIndex = commentPosBox.GetCurSel();
+       INT_PTR posIndex = owner.commentPosBox.GetCurSel();
        if(posIndex == CB_ERR)posIndex = 0;
-       auto &rCommentPosInfo = *(CommentPosInfo*)commentPosBox.GetItemDataPtr(posIndex);
+       auto &rCommentPosInfo = *(CommentPosInfo*)owner.commentPosBox.GetItemDataPtr(posIndex);
 
        if(_tcscmp(rCommentPosInfo.userData,DEFAULT_COMMENTPOS) != 0){
 
                commentMaker.AddMail(rCommentPosInfo.userData);
        }
 
-       INT_PTR colorIndex = commentColorBox.GetCurSel();
+       INT_PTR colorIndex = owner.commentColorBox.GetCurSel();
        if(colorIndex == CB_ERR)colorIndex = 0;
-       auto &rCommentColorInfo = *(CommentColorInfo*)commentColorBox.GetItemDataPtr(colorIndex);
+       auto &rCommentColorInfo = *(CommentColorInfo*)owner.commentColorBox.GetItemDataPtr(colorIndex);
 
        if(_tcscmp(rCommentColorInfo.name,DEFAULT_COMMENTCOLOR) != 0){
 
@@ -344,38 +324,80 @@ BOOL CCommentWriteWindow::SendChat(){
        }
 
 
-       BOOL rslt = FALSE;
-       NLIB_RESULT code = nicoLiveStream.SendChat(commentMaker);
+       NLIB_RESULT code = NLIB_ERR_CODE_NOTSET;
+
+       if(owner.nicoLiveStream.IsOwner() ==TRUE && owner.ownerModeButton.GetCheck() == BST_CHECKED){
+               
+               code = owner.nicoLiveStream.SendOwnerChat(commentMaker);
+
+       } else {
+
+               code = owner.nicoLiveStream.SendChat(commentMaker);
+
+       }
 
        switch(code){
 
        case NLIB_ERR_OK:
 
-               rslt = TRUE;
-               this->commentSubEdit.SetWindowText(TEXT(""));
+
+               owner.commentSubEdit.SetWindowText(TEXT(""));
                goto end;
 
        case NLIB_ERR_NOT_LIVECONNECT:
-               
-               ::MessageBox(*this,NLIB_GetErrorMessage(code),TEXT("\83R\83\81\83\93\83g\8f\91\82«\8d\9e\82Ý\83G\83\89\81["),MB_ICONERROR | MB_OK);
-               commentSubEdit.AgreeEnter();
+       case NLIB_FAILED_CONNECT:       
+               ::MessageBox(owner,NLIB_GetErrorMessage(code),TEXT("\83R\83\81\83\93\83g\8f\91\82«\8d\9e\82Ý\83G\83\89\81["),MB_ICONERROR | MB_OK);
+               owner.commentSubEdit.AgreeEnter();
                break;
 
+       
+
+
+
        default:
                UnexpectedErrorMessageShow(TEXT("\83R\83\81\83\93\83g\8f\91\82«\8d\9e\82Ý\92\86\82É"),NLIB_GetErrorMessage(code),__LINE__,TEXT(__FILE__),TEXT(__FUNCTION__));
-               commentSubEdit.AgreeEnter();
+               owner.commentSubEdit.AgreeEnter();
                break;
 
        }
 
 
-       rslt = FALSE;
+end:
+
+
 
        
-end:
+       self.AgreeEnter();
+
+       _endthread();
+       return;
+}
 
+BOOL CCommentWriteWindow::SendChat(){
+       this->commentSubEdit.untilConnectingFlag = TRUE;
+       this->commentSubEdit.SetReadOnly(TRUE);
+       _beginthread(CSubChatEdit::EnterChatBox,0,&this->commentSubEdit);
+       
+       
 
-       return rslt;
+       
+
+
+
+       return TRUE;
+}
+
+
+BOOL CCommentWriteWindow::SetText(LPCTSTR lpStr){
+       
+       BOOL rslt = this->commentSubEdit.SetWindowText(lpStr);
+       if(rslt == TRUE){
+               commentSubEdit.SetFocus();
+               int cursor = commentSubEdit.GetWindowTextLength();
+               commentSubEdit.SetSel(cursor,cursor);
+               //commentSubEdit.ShowCaret();
+       }
+       return rslt; 
 }
 
 VOID CCommentWriteWindow::OnChatReceveStart(CNicoLiveStream &nicoLiveStream,NicoLiveThreadComment_P threadComment){
@@ -406,8 +428,30 @@ VOID CCommentWriteWindow::OnChatReceveStart(CNicoLiveStream &nicoLiveStream,Nico
        this->ShowWindow(SW_SHOW);
        this->streamTime = threadComment->server_time;
        this->SetTimer(TIMER_ID,1000,NULL);
-       
+       if(nicoLiveStream.IsOwner() == TRUE){
+
+               this->ownerModeButton.ShowWindow(SW_SHOW);
+               ownerModeButton.SetCheck(BST_CHECKED);
+               editBkColor = OWNEREDITCOLOR;
+                
+       } else {
 
+               this->ownerModeButton.ShowWindow(SW_HIDE);
+               editBkColor = NORMALEDITCOLOR;
+
+       }
+
+       if(this->editBkBrush.IsNull() ==FALSE){
+               editBkBrush.DeleteObject();
+       }
+
+       editBkBrush.CreateSolidBrush(editBkColor);
+       SIZE size;
+       RECT windowRect;
+       this->GetClientRect(&windowRect);
+       size.cx = windowRect.right - windowRect.left;
+       size.cy = windowRect.bottom - windowRect.top;
+       ChangeSize(size);
 
        return;
 }
@@ -418,14 +462,14 @@ VOID CCommentWriteWindow::ChangeSize(SIZE &size){
        SIZE commentWriteButtonSize;
        commentWriteButton.GetIdealSize(&commentWriteButtonSize);
        anonymousButton.GetIdealSize(&commentAnonymousButtonSize);
-
+       UINT_PTR defwindowCount = 0;
        RECT commentPosBoxRect;
        RECT commentSizeBoxRect;
        RECT commentColorBoxRect;
        RECT anonymousButtonRect;
        RECT commentEditRect;
        RECT commentWriteButtonRect;
-
+       RECT ownerModeButtonRect;
        RECT thisWindowRect;
 
        UINT_PTR writeSpaceHeight = COMMENTWRITEWINDOW_SEPARATEFSIZE.top * 2 + commentWriteInternalHeight;
@@ -444,14 +488,25 @@ VOID CCommentWriteWindow::ChangeSize(SIZE &size){
        commentColorBoxRect.left = commentSizeBoxRect.right + COMMENTWRITEWINDOW_SIDESEPARATESIZE;
        commentColorBoxRect.right = commentColorBoxRect.left + commentColorBoxSize.cx;
 
-       CDC cdc(anonymousButton.GetDC());
-       SIZE anonymousStringSize;
-       ::GetTextExtentPoint32(cdc,CHECKBUTTON_HIDDENSTRING,_tcslen(CHECKBUTTON_HIDDENSTRING),&anonymousStringSize);
+
        
        anonymousButtonRect.left = commentColorBoxRect.right + COMMENTWRITEWINDOW_SIDESEPARATESIZE;
-       anonymousButtonRect.right = anonymousButtonRect.left + commentAnonymousButtonSize.cx - anonymousStringSize.cx;
+       anonymousButtonRect.right = anonymousButtonRect.left + commentAnonymousButtonSize.cx;
+
+       if(ownerModeButton.IsWindowVisible() == TRUE){
 
-       commentEditRect.left = anonymousButtonRect.right + COMMENTWRITEWINDOW_SIDESEPARATESIZE;
+               
+               SIZE ownerModeButtonSize;
+               ownerModeButton.GetIdealSize(&ownerModeButtonSize);
+               ownerModeButtonRect.left = anonymousButtonRect.right + COMMENTWRITEWINDOW_SIDESEPARATESIZE;
+               ownerModeButtonRect.right = ownerModeButtonRect.left + ownerModeButtonSize.cx;
+               commentEditRect.left = ownerModeButtonRect.right + COMMENTWRITEWINDOW_SIDESEPARATESIZE;
+               defwindowCount = 7;
+       } else {
+
+               commentEditRect.left = anonymousButtonRect.right + COMMENTWRITEWINDOW_SIDESEPARATESIZE;
+               defwindowCount = 6;
+       }
        
        commentWriteButtonRect.right = size.cx - COMMENTWRITEWINDOW_SIDESEPARATESIZE;
        commentWriteButtonRect.left = commentWriteButtonRect.right - commentWriteButtonSize.cx;
@@ -461,7 +516,7 @@ VOID CCommentWriteWindow::ChangeSize(SIZE &size){
        
 
        //\88Ú\93®\8f\88\97\9d
-       HDWP hDwp = BeginDeferWindowPos(6);
+       HDWP hDwp = BeginDeferWindowPos(defwindowCount);
        
        commentPosBox.DeferWindowPos(hDwp,*this,
                commentPosBoxRect.left,writeSpaceHeight,commentPosBoxRect.right - commentPosBoxRect.left,commentWriteInternalHeight,
@@ -476,9 +531,15 @@ VOID CCommentWriteWindow::ChangeSize(SIZE &size){
                SWP_NOZORDER);
 
        anonymousButton.DeferWindowPos(hDwp,*this,
-               anonymousButtonRect.left,writeSpaceHeight,anonymousButtonRect.right - anonymousButtonRect.left,commentWriteInternalHeight - CHECKBUTTON_SUBSCRIPT_HEIGHT,
+               anonymousButtonRect.left,writeSpaceHeight,anonymousButtonRect.right - anonymousButtonRect.left,commentWriteInternalHeight,
                SWP_NOZORDER);
 
+       if(ownerModeButton.IsWindowVisible() == TRUE){
+               ownerModeButton.DeferWindowPos(hDwp,*this,
+                       ownerModeButtonRect.left,writeSpaceHeight,ownerModeButtonRect.right - ownerModeButtonRect.left,commentWriteInternalHeight,
+               SWP_NOZORDER);
+
+       }
        commentSubEdit.DeferWindowPos(hDwp,*this,
                commentEditRect.left,writeSpaceHeight,commentEditRect.right - commentEditRect.left,commentWriteInternalHeight,
                SWP_NOZORDER);
@@ -556,12 +617,46 @@ LRESULT CCommentWriteWindow::OnEraseBkGnd(HDC wParam){
 }
 
 
+LRESULT CCommentWriteWindow::OnCtlolorEdit(HDC hdc,HWND hWnd){
+
+       if(hWnd == this->commentSubEdit){
+
+               
+               SetBkMode(hdc, TRANSPARENT);    // \94w\8ci\82ð\93§\89ß
+               SetBkColor(hdc,this->editBkColor);      // \83e\83L\83X\83g\82ª\8f\91\82©\82ê\82Ä\82¢\82é\95\94\95ª\82Ì\83e\83L\83X\83g\82Ì\94w\8ci\82Ì\90F
+       
+               return (LRESULT)editBkBrush.m_hBrush;
+       }
+
+       return 0;
+}
+
 LRESULT CCommentWriteWindow::OnButton(UINT hiWparam,INT_PTR loWparam,HWND lParam){
 
        if(lParam == commentWriteButton){
                
                this->SendChat();
 
+       } else if(lParam == this->ownerModeButton){
+
+               if(this->ownerModeButton.GetCheck() == BST_CHECKED){
+
+                       this->editBkColor = OWNEREDITCOLOR;
+
+               } else {
+
+                       this->editBkColor = NORMALEDITCOLOR;
+               }
+
+               if(this->editBkBrush.IsNull() == FALSE){
+
+                       this->editBkBrush.DeleteObject();
+
+               }
+
+               this->editBkBrush.CreateSolidBrush(editBkColor);
+               commentSubEdit.Invalidate();
+               
        }
 
        return TRUE;
@@ -636,7 +731,7 @@ void CSubChatEdit::OnKeyDown(TCHAR wParam, UINT upLParam,UINT loLParam){
                cs.Lock();
                                        
                if(untilConnectingFlag == FALSE){
-                       untilConnectingFlag = TRUE;
+                       
                        
 
                        self.SendChat();