2 #include "nlite_include.h"
7 const static SIZE commentColorBoxSize = {35,0};
9 const static LPCTSTR ANONYMOUS_MAILCOMMAND = TEXT("184");
10 const static LPCTSTR ANONYMOUS_BOTTONSTRING = ANONYMOUS_MAILCOMMAND;
12 const static LPCTSTR WRITE_BOTTONSTRING = TEXT("
\8f\91\82«
\8d\9e\82Ý");
13 const static LPCTSTR CHECKBUTTON_HIDDENSTRING = TEXT(" ");
15 const static RECT COMMENTWRITEWINDOW_SEPARATEFSIZE = {0,5,0,5};
16 const static UINT_PTR COMMENTWRITEWINDOW_SIDESEPARATESIZE = 5;
17 const static UINT_PTR INIT_COMMENTWRITE_MAXLENGTH = 60;
18 const static UINT_PTR CHECKBUTTON_SUBSCRIPT_HEIGHT = 10;
19 const static LPCTSTR DEFAULT_COMMENTCOLOR = TEXT("white");
20 const static LPCTSTR DEFAULT_COMMENTSIZE = TEXT("medium");
21 const static LPCTSTR DEFAULT_COMMENTPOS = TEXT("naka");
22 const static COLORREF MAX_COLOR = 0xFFFFFF;
26 namespace generalUser{
27 const CommentColorInfo COMMENT_COLORLIST[] = {
28 {DEFAULT_COMMENTCOLOR,RGB(0xFF,0xFF,0xFF)}, //
\94\92
29 {TEXT("red"),RGB(0xFF,0x00,0x00)}, //
\90Ô
30 {TEXT("pink"),RGB(0xFF,0x80,0x80)}, //
\83s
\83\93\83N
31 {TEXT("orange"),RGB(0xFF,0xC0,0x00)}, //
\83I
\83\8c\83\93\83W
32 {TEXT("yellow"),RGB(0xFF,0xFF,0x00)}, //
\89©
\90F
33 {TEXT("green"),RGB(0x00,0xFF,0x00)}, //
\97Î
34 {TEXT("cyan"),RGB(0x00,0xFF,0xFF)}, //
\8a¦
\90F
35 {TEXT("blue"),RGB(0x00,0x00,0xFF)}, //
\90Â
36 {TEXT("purple"),RGB(0xC0,0x00,0xFF)}, //
\8e\87
40 const CommentSizeInfo COMMENT_SIZELIST[] = {
41 {TEXT("
\95\81\92Ê
\81@"),DEFAULT_COMMENTSIZE}, //
\95\81\92Ê
\83T
\83C
\83Y
42 {TEXT("
\8f¬
\81@"),TEXT("small")} //
\8f¬
\83T
\83C
\83Y
46 const CommentPosInfo COMMENT_POSLIST[] = {
47 {TEXT("
\92Ê
\8fí
\81@"),DEFAULT_COMMENTPOS} //
\92Ê
\8fí
\95\
\8e¦
51 namespace premiumUser{
53 const CommentColorInfo COMMENT_COLORLIST[] = {
54 {TEXT("black"),RGB(0x00,0x00,0x00)}, //
\8d\95
55 {TEXT("white2"),RGB(0xCC,0xCC,0x99)}, //
\94\92\82»
\82Ì
\82Q
56 {TEXT("red2"),RGB(0xCC,0x00,0x33)}, //
\90Ô
\82»
\82Ì
\82Q
57 {TEXT("pink2"),RGB(0xFF,0x33,0xCC)}, //
\83s
\83\93\83N
\82»
\82Ì
\82Q
58 {TEXT("orange2"),RGB(0xFF,0x66,0x00)}, //
\83I
\83\8c\83\93\83W
\82»
\82Ì
\82Q
59 {TEXT("yellow2"),RGB(0x99,0x99,0x00)}, //
\89©
\90F
\82»
\82Ì
\82Q
60 {TEXT("green2"),RGB(0x00,0xCC,0x66)}, //
\97Î
\82»
\82Ì
\82Q
61 {TEXT("cyan2"),RGB(0x00,0xCC,0xCC)}, //
\8a¦
\90F
\82»
\82Ì
\82Q
62 {TEXT("blue2"),RGB(0x33,0x99,0xFF)}, //
\90Â
\82»
\82Ì
\82Q
63 {TEXT("purple2"),RGB(0x66,0x33,0xCC)} //
\8e\87\82»
\82Ì
\82Q
64 // {TEXT("black2"),RGB(0x66,0x66,0x66)} //
\8d\95\82»
\82Ì
\82Q
\82Í
\82È
\82¢
\81H
67 const CommentSizeInfo COMMENT_SIZELIST[] = {
68 {TEXT("
\91å
\81@"),TEXT("big")} //
\91å
\83T
\83C
\83Y
73 const CommentPosInfo COMMENT_POSLIST[] = {
74 {TEXT("
\89º
\81@"),TEXT("shita")}, //
\89º
\82É
\95\
\8e¦
75 {TEXT("
\8fã
\81@"),TEXT("ue")} //
\8fã
\82É
\95\
\8e¦
84 static VOID addItemList(CComboBox &combo,T * colorList,UINT_PTR length){
86 UINT_PTR startItemcount = combo.GetCount();
87 for(UINT_PTR index = startItemcount; index < length;index++){
89 combo.AddString(colorList[index - startItemcount].name);
90 combo.SetItemDataPtr(index,(LPVOID)&colorList[index - startItemcount]);
100 static UINT_PTR CalcComboBoxWidth(CComboBox &combo){
105 UINT_PTR itemCount = combo.GetCount();
107 for(UINT_PTR index = 0;index < itemCount;index++){
108 name = ((T*)combo.GetItemDataPtr(index))->name;
109 ::GetTextExtentPoint32(pdc,name,_tcslen(name),&size);
110 rslt = rslt < (UINT_PTR)size.cx ? size.cx : rslt;
116 CCommentWriteWindow::CCommentWriteWindow(CNicoLiveStream &in_nicoLiveStream):
117 commentWriteHeight(0),
118 commentWriteInternalHeight(0),
119 commentWriteMaxLength(INIT_COMMENTWRITE_MAXLENGTH),
120 nicoLiveStream(in_nicoLiveStream),
121 commentSubEdit(*this)
126 LRESULT CCommentWriteWindow::OnCreate(LPCREATESTRUCT lpReateStruct){
128 commentPosBox.Create(m_hWnd,0,WC_COMBOBOX,WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST ,0,COMMENTPOS_BOX);
129 commentSizeBox.Create(m_hWnd,0,WC_COMBOBOX,WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST,0,COMMENTSIZE_BOX);
130 commentColorBox.Create(m_hWnd,0,WC_COMBOBOX,WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED ,0,COMMENTCOLOR_BOX);
131 anonymousButton.Create(m_hWnd,0,WC_BUTTON,WS_CHILD | WS_VISIBLE | BS_CHECKBOX | BS_AUTOCHECKBOX ,0,ANONYMOUS_BUTTON);
132 commentEdit.Create(m_hWnd,0,WC_EDIT,WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL,0,COMMENT_EDIT);
133 commentWriteButton.Create(m_hWnd,0,WC_BUTTON,WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,0,COMMENTWRITE_BOTTON);
134 commentPosBox.SetFont(AtlGetDefaultGuiFont());
135 commentSizeBox.SetFont(AtlGetDefaultGuiFont());
136 commentColorBox.SetFont(AtlGetDefaultGuiFont());
139 anonymousButton.SetWindowTextW(CHECKBUTTON_HIDDENSTRING);
140 anonymousButton.SetFont(AtlGetDefaultGuiFont());
141 commentEdit.SetFont(AtlGetDefaultGuiFont());
142 commentEdit.SetLimitText(commentWriteMaxLength);
143 commentWriteButton.SetWindowTextW(WRITE_BOTTONSTRING);
144 commentWriteButton.SetFont(AtlGetDefaultGuiFont());
145 commentEdit.SetWindowTextW(TEXT(""));
147 addItemList(commentColorBox,generalUser::COMMENT_COLORLIST,ARRAY_LENGTH(generalUser::COMMENT_COLORLIST));
148 addItemList(commentSizeBox,generalUser::COMMENT_SIZELIST,ARRAY_LENGTH(generalUser::COMMENT_SIZELIST));
149 addItemList(commentPosBox,generalUser::COMMENT_POSLIST,ARRAY_LENGTH(generalUser::COMMENT_POSLIST));
150 commentColorBox.SetCurSel(0);
151 commentSizeBox.SetCurSel(0);
152 commentPosBox.SetCurSel(0);
154 font = AtlGetDefaultGuiFont();
157 LPCTSTR sample = TEXT(" ");
158 commentSubEdit.SubclassWindow(commentEdit);
159 GetTextExtentPoint32(pdc,sample,_tcslen(sample),&thisSize);
160 commentWriteHeight = thisSize.cy + (CHECKBUTTON_SUBSCRIPT_HEIGHT / 2) + COMMENTWRITEWINDOW_SEPARATEFSIZE.top + COMMENTWRITEWINDOW_SEPARATEFSIZE.bottom;
161 commentWriteInternalHeight = commentWriteHeight - (COMMENTWRITEWINDOW_SEPARATEFSIZE.top + COMMENTWRITEWINDOW_SEPARATEFSIZE.bottom);
165 VOID CCommentWriteWindow::OnDestroy(){
166 commentPosBox.DestroyWindow();
167 commentSizeBox.DestroyWindow();
168 commentColorBox.DestroyWindow();
169 anonymousButton.DestroyWindow();
170 commentEdit.DestroyWindow();
171 commentWriteButton.DestroyWindow();
175 VOID CCommentWriteWindow::OnSizing(UINT wParam,LPRECT lParam){
178 GetClientRect(&client);
180 ChangeSize( _WTYPES_NS::CSize(client.right - client.left,client.bottom - client.top));
184 LRESULT CCommentWriteWindow::OnSize(UINT wParam,SIZE lParam){
188 VOID CCommentWriteWindow::OnPaint(HDC hdc){
192 this->GetClientRect(&clientRect);
194 pdc.FillRect(&clientRect,COLOR_BTNFACE);
198 SIZE anonymousStringSize;
200 anonymousButton.GetWindowRect(&anonymousRect);
201 CPoint anonymousPoint(anonymousRect.left,anonymousRect.top);
202 ::ScreenToClient(*this,&anonymousPoint);
203 anonymousRect.right -= anonymousRect.left;
204 anonymousRect.bottom -= anonymousRect.top;
205 anonymousRect.left = anonymousPoint.x;
206 anonymousRect.top = anonymousPoint.y + anonymousRect.bottom;
209 ::GetTextExtentPoint32(pdc,ANONYMOUS_BOTTONSTRING,_tcslen(ANONYMOUS_BOTTONSTRING),&anonymousStringSize);
210 anonymousRect.right = anonymousRect.left + anonymousStringSize.cx;
211 anonymousRect.bottom = anonymousRect.top + anonymousStringSize.cy;
213 LOGFONT anonymousLogFont = {0};
214 anonymousLogFont.lfHeight = CHECKBUTTON_SUBSCRIPT_HEIGHT;
215 anonymousLogFont.lfCharSet = SHIFTJIS_CHARSET;
217 CFont anonymousFont = CreateFontIndirect(&anonymousLogFont);
218 pdc.SelectFont(anonymousFont);
219 pdc.SetBkColor(GetSysColor(COLOR_BTNFACE));
220 pdc.DrawText(ANONYMOUS_BOTTONSTRING,_tcslen(ANONYMOUS_BOTTONSTRING),&anonymousRect,0);
225 static VOID agreeEnterKeyThread(LPVOID userData){
228 ((CSubChatEdit*)userData)->AgreeEnter();
233 BOOL CCommentWriteWindow::SendChat(){
234 this->commentEdit.SetReadOnly(TRUE);
235 CCommentMaker commentMaker;
236 std::vector<TCHAR> chat(commentEdit.GetWindowTextLengthW() + 1);
237 commentEdit.GetWindowTextW(&chat[0],chat.size());
238 commentMaker.SetChatString(&chat[0]);
239 if(this->anonymousButton.GetCheck() == BST_CHECKED){
241 commentMaker.AddMail(ANONYMOUS_MAILCOMMAND);
243 INT_PTR sizeIndex = commentSizeBox.GetCurSel();
244 if(sizeIndex == CB_ERR)sizeIndex = 0;
245 auto &rCommentSizeInfo = *(CommentSizeInfo*)commentSizeBox.GetItemDataPtr(sizeIndex);
247 if(_tcscmp(rCommentSizeInfo.userData,DEFAULT_COMMENTSIZE) != 0){
249 commentMaker.AddMail(rCommentSizeInfo.userData);
252 INT_PTR posIndex = commentPosBox.GetCurSel();
253 if(posIndex == CB_ERR)posIndex = 0;
254 auto &rCommentPosInfo = *(CommentPosInfo*)commentPosBox.GetItemDataPtr(posIndex);
256 if(_tcscmp(rCommentPosInfo.userData,DEFAULT_COMMENTPOS) != 0){
258 commentMaker.AddMail(rCommentPosInfo.userData);
261 INT_PTR colorIndex = commentColorBox.GetCurSel();
262 if(colorIndex == CB_ERR)colorIndex = 0;
263 auto &rCommentColorInfo = *(CommentColorInfo*)commentColorBox.GetItemDataPtr(colorIndex);
265 if(_tcscmp(rCommentColorInfo.name,DEFAULT_COMMENTCOLOR) != 0){
267 commentMaker.AddMail(rCommentColorInfo.name);
272 NLIB_RESULT code = nicoLiveStream.SendChat(commentMaker);
279 this->commentEdit.SetWindowText(TEXT(""));
282 case NLIB_ERR_NOT_LIVECONNECT:
283 commentSubEdit.AgreeEnter();
284 ::MessageBox(NULL,NLIB_GetErrorMessage(code),TEXT("
\83R
\83\81\83\93\83g
\8f\91\82«
\8d\9e\82Ý
\83G
\83\89\81["),MB_ICONERROR | MB_OK);
290 commentSubEdit.AgreeEnter();
291 errprint(TEXT("
\83R
\83\81\83\93\83g
\8f\91\82«
\8d\9e\82Ý
\92\86\82É
\83G
\83\89\81[:%s"),NLIB_GetErrorMessage(code));
292 UnexpectedErrorMessageShow(TEXT("
\83R
\83\81\83\93\83g
\8f\91\82«
\8d\9e\82Ý
\92\86\82É"),NLIB_GetErrorMessage(code));
306 VOID CCommentWriteWindow::ChangeSize(SIZE &size){
308 SIZE commentAnonymousButtonSize;
309 SIZE commentWriteButtonSize;
310 commentWriteButton.GetIdealSize(&commentWriteButtonSize);
311 anonymousButton.GetIdealSize(&commentAnonymousButtonSize);
313 RECT commentPosBoxRect;
314 RECT commentSizeBoxRect;
315 RECT commentColorBoxRect;
316 RECT anonymousButtonRect;
317 RECT commentEditRect;
318 RECT commentWriteButtonRect;
321 this->GetWindowRect(&thisWindowRect);
323 commentPosBoxRect.left = COMMENTWRITEWINDOW_SIDESEPARATESIZE;
324 this->commentPosBoxCS.Lock();
325 commentPosBoxRect.right = commentPosBoxRect.left + CalcComboBoxWidth<CommentPosInfo>(commentPosBox);
326 this->commentPosBoxCS.Unlock();
328 commentSizeBoxRect.left = commentPosBoxRect.right + COMMENTWRITEWINDOW_SIDESEPARATESIZE;
329 this->commentSizeBoxCS.Lock();
330 commentSizeBoxRect.right = commentSizeBoxRect.left + CalcComboBoxWidth<CommentSizeInfo>(commentSizeBox);
331 this->commentSizeBoxCS.Unlock();
333 commentColorBoxRect.left = commentSizeBoxRect.right + COMMENTWRITEWINDOW_SIDESEPARATESIZE;
334 commentColorBoxRect.right = commentColorBoxRect.left + commentColorBoxSize.cx;
336 CDC cdc(anonymousButton.GetDC());
337 SIZE anonymousStringSize;
338 ::GetTextExtentPoint32(cdc,CHECKBUTTON_HIDDENSTRING,_tcslen(CHECKBUTTON_HIDDENSTRING),&anonymousStringSize);
340 anonymousButtonRect.left = commentColorBoxRect.right + COMMENTWRITEWINDOW_SIDESEPARATESIZE;
341 anonymousButtonRect.right = anonymousButtonRect.left + commentAnonymousButtonSize.cx - anonymousStringSize.cx;
343 commentEditRect.left = anonymousButtonRect.right + COMMENTWRITEWINDOW_SIDESEPARATESIZE;
345 commentWriteButtonRect.right = size.cx - COMMENTWRITEWINDOW_SIDESEPARATESIZE;
346 commentWriteButtonRect.left = commentWriteButtonRect.right - commentWriteButtonSize.cx;
348 commentEditRect.right = commentWriteButtonRect.left - COMMENTWRITEWINDOW_SIDESEPARATESIZE;
352 //
\88Ú
\93®
\8f\88\97\9d
353 HDWP hDwp = BeginDeferWindowPos(6);
355 commentPosBox.DeferWindowPos(hDwp,*this,
356 commentPosBoxRect.left,COMMENTWRITEWINDOW_SEPARATEFSIZE.top,commentPosBoxRect.right - commentPosBoxRect.left,commentWriteInternalHeight,
359 commentSizeBox.DeferWindowPos(hDwp,*this,
360 commentSizeBoxRect.left,COMMENTWRITEWINDOW_SEPARATEFSIZE.top,commentSizeBoxRect.right - commentSizeBoxRect.left,commentWriteInternalHeight,
363 commentColorBox.DeferWindowPos(hDwp,*this,
364 commentColorBoxRect.left,COMMENTWRITEWINDOW_SEPARATEFSIZE.top,commentColorBoxRect.right - commentColorBoxRect.left,commentWriteInternalHeight,
367 anonymousButton.DeferWindowPos(hDwp,*this,
368 anonymousButtonRect.left,COMMENTWRITEWINDOW_SEPARATEFSIZE.top,anonymousButtonRect.right - anonymousButtonRect.left,commentWriteInternalHeight - CHECKBUTTON_SUBSCRIPT_HEIGHT,
371 commentEdit.DeferWindowPos(hDwp,*this,
372 commentEditRect.left,COMMENTWRITEWINDOW_SEPARATEFSIZE.top,commentEditRect.right - commentEditRect.left,commentWriteInternalHeight,
375 commentWriteButton.DeferWindowPos(hDwp,*this,
376 commentWriteButtonRect.left,COMMENTWRITEWINDOW_SEPARATEFSIZE.top,commentWriteButtonRect.right - commentWriteButtonRect.left,commentWriteInternalHeight,
379 EndDeferWindowPos(hDwp);
384 VOID CCommentWriteWindow::OnDrawItem(UINT wParam,LPDRAWITEMSTRUCT lParam){
388 if(lParam->hwndItem == commentColorBox.m_hWnd && commentColorBox.GetCount() > 0){
392 RECT drawRect = lParam->rcItem;
394 INT_PTR curselNo = commentColorBox.GetCurSel();
395 CDCHandle dcHandle = lParam->hDC;
397 const UINT_PTR width = 1;
398 drawRect.left += width;
399 drawRect.top += width;
400 drawRect.right -= width;
401 drawRect.bottom -= width;
403 if(lParam->itemID == ((UINT)-1)){
404 itemNo = curselNo == CB_ERR ? 0 : curselNo;
406 itemNo = lParam->itemID;
409 CommentInfo<COLORREF> &commentColor = *(CommentInfo<COLORREF> *)commentColorBox.GetItemDataPtr(itemNo);
412 if(lParam->itemState & (ODS_FOCUS | ODS_COMBOBOXEDIT)){
416 bkBrush.CreateSolidBrush(RGB(160,160,160));
420 bkBrush.CreateSolidBrush(RGB(255,255,255));
430 brush.CreateSolidBrush(commentColor.userData);
431 dcHandle.SelectBrush(brush);
432 dcHandle.FillRect(&lParam->rcItem,bkBrush);
433 dcHandle.SelectBrush(brush);
434 dcHandle.SelectPen((HPEN)::GetStockObject(BLACK_PEN));
435 dcHandle.Rectangle(&drawRect);
442 LRESULT CCommentWriteWindow::OnEraseBkGnd(HDC wParam){
448 LRESULT CCommentWriteWindow::OnButton(UINT hiWparam,INT_PTR loWparam,HWND lParam){
450 if(lParam == commentWriteButton){
459 VOID CCommentWriteWindow::OnMeasureItem(UINT wParam,LPMEASUREITEMSTRUCT lParam){
461 switch(lParam->CtlID){
463 case COMMENTCOLOR_BOX:
467 pdc.SelectFont(AtlGetDefaultGuiFont());
468 LPCTSTR sample = TEXT(" ");
469 ::GetTextExtentPoint32(pdc,sample,_tcslen(sample),&itemSize);
470 lParam->itemHeight = itemSize.cy;
485 VOID CCommentWriteWindow::OnSendChatResult(){
487 commentSubEdit.AgreeEnter();
498 ////////////////////////////////////////
500 void CSubChatEdit::OnKeyDown(TCHAR wParam, UINT upLParam,UINT loLParam){
501 if(wParam == VK_RETURN){
505 if(untilConnectingFlag == FALSE){
506 untilConnectingFlag = TRUE;
520 VOID CSubChatEdit::AgreeEnter(){
522 self.commentEdit.SetReadOnly(FALSE);
523 untilConnectingFlag = FALSE;