OSDN Git Service

2752b0c3a6471d62ffca938aab87708fa1419cdc
[nlite/nlite.git] / nlite / nlite_commentWrite.cpp
1 #include "stdafx.h"
2 #include "nlite_include.h"
3
4 namespace nlite{
5
6
7 const static SIZE commentColorBoxSize = {35,0};
8
9 const static LPCTSTR ANONYMOUS_MAILCOMMAND = TEXT("184");
10 const static LPCTSTR ANONYMOUS_BOTTONSTRING = ANONYMOUS_MAILCOMMAND;
11 const static LPCTSTR OWNERMODE_BOTTONSTRING = TEXT("\8eå\83R\83\81");
12 const static LPCTSTR WRITE_BOTTONSTRING = TEXT("\8f\91\82«\8d\9e\82Ý");
13 const static LPCTSTR CHECKBUTTON_HIDDENSTRING = TEXT(" ");
14
15
16 const static COLORREF OWNEREDITCOLOR = RGB(255,192,192);
17 const static COLORREF NORMALEDITCOLOR = RGB(255,255,255);
18 const static RECT COMMENTWRITEWINDOW_SEPARATEFSIZE = {0,5,0,5};
19 const static UINT_PTR COMMENTWRITEWINDOW_SIDESEPARATESIZE = 5;
20 const static UINT_PTR INIT_COMMENTWRITE_MAXLENGTH = 60;
21 const static UINT_PTR CHECKBUTTON_SUBSCRIPT_HEIGHT = 10;
22 const static LPCTSTR DEFAULT_COMMENTCOLOR = TEXT("white");
23 const static LPCTSTR DEFAULT_COMMENTSIZE = TEXT("medium");
24 const static LPCTSTR DEFAULT_COMMENTPOS = TEXT("naka");
25 const static COLORREF MAX_COLOR = 0xFFFFFF;
26
27
28
29 namespace generalUser{
30         const CommentColorInfo COMMENT_COLORLIST[] = {
31                 {DEFAULT_COMMENTCOLOR,PALETTERGB(0xFF,0xFF,0xFF)},      //\94\92
32                 {TEXT("red"),PALETTERGB(0xFF,0x00,0x00)},                       //\90Ô
33                 {TEXT("pink"),PALETTERGB(0xFF,0x80,0x80)},                      //\83s\83\93\83N
34                 {TEXT("orange"),PALETTERGB(0xFF,0xC0,0x00)},            //\83I\83\8c\83\93\83W
35                 {TEXT("yellow"),PALETTERGB(0xFF,0xFF,0x00)},            //\89©\90F
36                 {TEXT("green"),PALETTERGB(0x00,0xFF,0x00)},                     //\97Î
37                 {TEXT("cyan"),PALETTERGB(0x00,0xFF,0xFF)},                      //\8a¦\90F
38                 {TEXT("blue"),PALETTERGB(0x00,0x00,0xFF)},                      //\90Â
39                 {TEXT("purple"),PALETTERGB(0xC0,0x00,0xFF)},            //\8e\87
40         
41         };
42
43         const CommentSizeInfo COMMENT_SIZELIST[] = {
44                 {TEXT("\95\81\92Ê\81@"),DEFAULT_COMMENTSIZE},                           //\95\81\92Ê\83T\83C\83Y
45                 {TEXT("\8f¬\81@"),TEXT("small")}                                            //\8f¬\83T\83C\83Y
46         };
47
48
49         const CommentPosInfo COMMENT_POSLIST[] = {
50                 {TEXT("\92Ê\8fí\81@"),DEFAULT_COMMENTPOS}                                     //\92Ê\8fí\95\\8e¦
51         };
52 }
53
54 namespace premiumUser{
55
56         const CommentColorInfo COMMENT_COLORLIST[] = {
57                 {TEXT("black"),PALETTERGB(0x00,0x00,0x00)},                     //\8d\95
58                 {TEXT("white2"),PALETTERGB(0xCC,0xCC,0x99)},            //\94\92\82»\82Ì\82Q
59                 {TEXT("red2"),PALETTERGB(0xCC,0x00,0x33)},                      //\90Ô\82»\82Ì\82Q
60                 {TEXT("pink2"),PALETTERGB(0xFF,0x33,0xCC)},                     //\83s\83\93\83N\82»\82Ì\82Q
61                 {TEXT("orange2"),PALETTERGB(0xFF,0x66,0x00)},           //\83I\83\8c\83\93\83W\82»\82Ì\82Q
62                 {TEXT("yellow2"),PALETTERGB(0x99,0x99,0x00)},           //\89©\90F\82»\82Ì\82Q
63                 {TEXT("green2"),PALETTERGB(0x00,0xCC,0x66)},            //\97Î\82»\82Ì\82Q
64                 {TEXT("cyan2"),PALETTERGB(0x00,0xCC,0xCC)},                     //\8a¦\90F\82»\82Ì\82Q
65                 {TEXT("blue2"),PALETTERGB(0x33,0x99,0xFF)},                     //\90Â\82»\82Ì\82Q
66                 {TEXT("purple2"),PALETTERGB(0x66,0x33,0xCC)}            //\8e\87\82»\82Ì\82Q
67         //      {TEXT("black2"),PALETTERGB(0x66,0x66,0x66)}                     //\8d\95\82»\82Ì\82Q\82Í\82È\82¢\81H
68         };
69
70         const CommentSizeInfo COMMENT_SIZELIST[] = {
71                 {TEXT("\91å\81@"),TEXT("big")}                                                      //\91å\83T\83C\83Y
72         };
73
74
75
76         const CommentPosInfo COMMENT_POSLIST[] = {
77                 {TEXT("\89º\81@"),TEXT("shita")},                                           //\89º\82É\95\\8e¦
78                 {TEXT("\8fã\81@"),TEXT("ue")}                                                       //\8fã\82É\95\\8e¦
79         };
80 }
81
82
83
84
85
86 template<typename T>
87 static VOID addItemList(CComboBox &combo,T * colorList,UINT_PTR length){
88
89         UINT_PTR startItemcount = combo.GetCount();
90         length+= startItemcount;
91         for(UINT_PTR index = startItemcount; index < length;index++){
92
93                 combo.AddString(colorList[index - startItemcount].name);
94                 combo.SetItemDataPtr(index,(LPVOID)&colorList[index - startItemcount]);
95
96         }
97
98         return;
99 }
100
101
102
103 template<typename T>
104 static UINT_PTR CalcComboBoxWidth(CComboBox &combo){
105
106         CPaintDC pdc(combo);
107         SIZE size;
108         UINT_PTR rslt = 0;
109         UINT_PTR itemCount = combo.GetCount();
110         LPCTSTR name;
111         for(UINT_PTR index = 0;index < itemCount;index++){
112                 name = ((T*)combo.GetItemDataPtr(index))->name;
113                 ::GetTextExtentPoint32(pdc,name,_tcslen(name),&size);
114                 rslt = rslt < (UINT_PTR)size.cx ? size.cx : rslt;
115         }
116
117         return rslt;
118 }
119
120 CCommentWriteWindow::CCommentWriteWindow(CNicoLiveStream &in_nicoLiveStream):
121 commentWriteHeight(0),
122 commentWriteInternalHeight(0),
123 commentWriteMaxLength(INIT_COMMENTWRITE_MAXLENGTH),
124 nicoLiveStream(in_nicoLiveStream),
125 commentSubEdit(*this),
126 streamTime(0)
127 {}
128
129
130 UINT_PTR CCommentWriteWindow::GetHeight(){
131
132         return commentWriteHeight + infoDispHeight - COMMENTWRITEWINDOW_SEPARATEFSIZE.top;
133 }
134
135
136 LRESULT CCommentWriteWindow::OnCreate(LPCREATESTRUCT lpReateStruct){
137
138         //\83E\83B\83\93\83h\83E\8dì\90¬\8f\88\97\9d
139
140         commentPosBox.Create(m_hWnd,0,WC_COMBOBOX,WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST ,0,COMMENTPOS_BOX);
141         commentSizeBox.Create(m_hWnd,0,WC_COMBOBOX,WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST,0,COMMENTSIZE_BOX);
142         commentColorBox.Create(m_hWnd,0,WC_COMBOBOX,WS_CHILD | WS_VISIBLE  | CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED ,0,COMMENTCOLOR_BOX);
143         anonymousButton.Create(m_hWnd,0,WC_BUTTON,WS_CHILD | WS_VISIBLE |  BS_AUTOCHECKBOX | BS_PUSHLIKE,0,ANONYMOUS_BUTTON);
144         ownerModeButton.Create(m_hWnd,0,WC_BUTTON,WS_CHILD |BS_AUTOCHECKBOX | BS_PUSHLIKE,0,OWNERMODE_BUTTON);
145         commentSubEdit.Create(m_hWnd,0,WC_EDIT,WS_CHILD | WS_VISIBLE | WS_BORDER | ES_AUTOHSCROLL,0,COMMENT_EDIT);
146         commentWriteButton.Create(m_hWnd,0,WC_BUTTON,WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,0,COMMENTWRITE_BOTTON);
147         commentPosBox.SetFont(AtlGetDefaultGuiFont());
148         commentSizeBox.SetFont(AtlGetDefaultGuiFont());
149         commentColorBox.SetFont(AtlGetDefaultGuiFont());
150         
151         
152         anonymousButton.SetFont(AtlGetDefaultGuiFont());
153         commentSubEdit.SetFont(AtlGetDefaultGuiFont());
154         commentSubEdit.SetLimitText(commentWriteMaxLength);
155         commentWriteButton.SetWindowTextW(WRITE_BOTTONSTRING);
156         commentWriteButton.SetFont(AtlGetDefaultGuiFont());
157         commentSubEdit.SetWindowTextW(TEXT(""));
158         
159         addItemList(commentColorBox,generalUser::COMMENT_COLORLIST,ARRAY_LENGTH(generalUser::COMMENT_COLORLIST));
160         addItemList(commentSizeBox,generalUser::COMMENT_SIZELIST,ARRAY_LENGTH(generalUser::COMMENT_SIZELIST));
161         addItemList(commentPosBox,generalUser::COMMENT_POSLIST,ARRAY_LENGTH(generalUser::COMMENT_POSLIST));
162         commentColorBox.SetCurSel(0);
163         commentSizeBox.SetCurSel(0);
164         commentPosBox.SetCurSel(0);
165         CFontHandle font;
166         font = AtlGetDefaultGuiFont();
167         CPaintDC pdc(*this);
168         SIZE thisSize;
169         LPCTSTR sample = TEXT(" ");
170
171         GetTextExtentPoint32(pdc,sample,_tcslen(sample),&thisSize);
172         commentWriteHeight = thisSize.cy  + COMMENTWRITEWINDOW_SEPARATEFSIZE.top + COMMENTWRITEWINDOW_SEPARATEFSIZE.bottom;
173         infoDispHeight = commentWriteHeight;
174         commentWriteInternalHeight = commentWriteHeight - (COMMENTWRITEWINDOW_SEPARATEFSIZE.top + COMMENTWRITEWINDOW_SEPARATEFSIZE.bottom);
175
176         LOGFONT anonymousLogFont = {0};
177         anonymousLogFont.lfHeight = CHECKBUTTON_SUBSCRIPT_HEIGHT;
178         anonymousLogFont.lfCharSet = SHIFTJIS_CHARSET;
179
180         checkButtonFont.CreateFontIndirect(&anonymousLogFont);
181         anonymousButton.SetFont(checkButtonFont);
182         ownerModeButton.SetFont(checkButtonFont);
183         CFontHandle f = AtlGetDefaultGuiFont();
184         LOGFONT timeLogFont;
185         f.GetLogFont(timeLogFont);
186         
187         timeLogFont.lfWeight = FW_BOLD;
188         
189         timeFont.CreateFontIndirectW(&timeLogFont);
190         anonymousButton.SetWindowTextW(ANONYMOUS_MAILCOMMAND);
191         ownerModeButton.SetWindowText(OWNERMODE_BOTTONSTRING);
192         return 0;
193 }
194
195 VOID CCommentWriteWindow::OnDestroy(){
196         commentPosBox.DestroyWindow();
197         commentSizeBox.DestroyWindow();
198         commentColorBox.DestroyWindow();
199         anonymousButton.DestroyWindow();
200         commentSubEdit.DestroyWindow();
201         commentWriteButton.DestroyWindow();
202
203 }
204
205
206
207 LRESULT CCommentWriteWindow::OnSize(UINT wParam,SIZE lParam){
208         ChangeSize(lParam);
209         return 0;
210 }
211 VOID CCommentWriteWindow::OnPaint(HDC hdc){
212
213         CPaintDC pdc(*this);
214         RECT clientRect;
215         this->GetClientRect(&clientRect);
216
217         pdc.FillRect(&clientRect,COLOR_BTNFACE);
218
219         
220         
221
222         pdc.SetBkColor(GetSysColor(COLOR_BTNFACE));
223         if(streamTime != 0){
224
225                 RECT timeStringRect;
226                 
227                 TCHAR timeString[LENGTH_256];
228                 _tcscpy(timeString,TEXT("\8co\89ß\8e\9e\8aÔ:"));
229                 LPTSTR timePtr = timeString + _tcslen(timeString);
230                 time_t dispTime = static_cast<time_t>(difftime(streamTime,nicoLiveStream.GetStartTime()));
231                 LPTSTR timeFormat;
232                 BOOL yetStartFlag = FALSE;
233                 if(dispTime < 0){
234                         yetStartFlag = TRUE;
235                         dispTime = abs(dispTime);
236                 }
237
238                 tm dispTimeStruct = *gmtime(&dispTime);
239
240                 if(dispTimeStruct.tm_hour > 0 && yetStartFlag == TRUE){
241
242                         timeFormat = TEXT("-%H:%M:%S");
243
244                 } else if(dispTimeStruct.tm_hour <= 0 && yetStartFlag == TRUE){
245
246                         timeFormat = TEXT("   -%M:%S");
247
248                 } else if(dispTimeStruct.tm_hour > 0){
249
250                         timeFormat = TEXT(" %H:%M:%S");
251
252                 }else {
253                 
254                         timeFormat = TEXT("    %M:%S");
255
256                 }
257
258                 _tcsftime(timePtr,ARRAY_LENGTH(timeString) - _tcslen(timeString),timeFormat,&dispTimeStruct);
259
260                 INT_PTR len = _tcslen(timeString);
261                 pdc.SelectFont(timeFont);
262
263                 
264                 timeStringRect.top = COMMENTWRITEWINDOW_SEPARATEFSIZE.top;
265                 timeStringRect.left = COMMENTWRITEWINDOW_SIDESEPARATESIZE;
266                 timeStringRect.bottom =timeStringRect.top;
267                 timeStringRect.right = timeStringRect.bottom;
268                 pdc.DrawTextW(timeString,len,&timeStringRect,DT_CALCRECT);
269                 pdc.DrawTextW(timeString,len,&timeStringRect,0);
270         }
271
272
273         
274         
275         return;
276 }
277
278 VOID CSubChatEdit::EnterChatBox(LPVOID userData){
279
280         auto owner = ((CSubChatEdit*)userData)->self;
281         auto &self = *((CSubChatEdit*)userData);
282         CCommentMaker commentMaker;
283         std::vector<TCHAR> chat(owner.commentSubEdit.GetWindowTextLengthW() + 1);
284
285
286         owner.commentSubEdit.GetWindowTextW(&chat[0],chat.size());
287         commentMaker.SetChatString(&chat[0]);
288         if(owner.anonymousButton.GetCheck() == BST_CHECKED){
289
290                 commentMaker.AddMail(ANONYMOUS_MAILCOMMAND);
291         }
292         INT_PTR sizeIndex = owner.commentSizeBox.GetCurSel();
293         if(sizeIndex == CB_ERR)sizeIndex = 0;
294         auto &rCommentSizeInfo = *(CommentSizeInfo*)owner.commentSizeBox.GetItemDataPtr(sizeIndex);
295
296         if(_tcscmp(rCommentSizeInfo.userData,DEFAULT_COMMENTSIZE) != 0){
297
298                 commentMaker.AddMail(rCommentSizeInfo.userData);
299
300         }
301         INT_PTR posIndex = owner.commentPosBox.GetCurSel();
302         if(posIndex == CB_ERR)posIndex = 0;
303         auto &rCommentPosInfo = *(CommentPosInfo*)owner.commentPosBox.GetItemDataPtr(posIndex);
304
305         if(_tcscmp(rCommentPosInfo.userData,DEFAULT_COMMENTPOS) != 0){
306
307                 commentMaker.AddMail(rCommentPosInfo.userData);
308         }
309
310         INT_PTR colorIndex = owner.commentColorBox.GetCurSel();
311         if(colorIndex == CB_ERR)colorIndex = 0;
312         auto &rCommentColorInfo = *(CommentColorInfo*)owner.commentColorBox.GetItemDataPtr(colorIndex);
313
314         if(_tcscmp(rCommentColorInfo.name,DEFAULT_COMMENTCOLOR) != 0){
315
316                 commentMaker.AddMail(rCommentColorInfo.name);
317         }
318
319
320         NLIB_RESULT code = NLIB_ERR_CODE_NOTSET;
321
322         if(owner.nicoLiveStream.IsOwner() ==TRUE && owner.ownerModeButton.GetCheck() == BST_CHECKED){
323                 
324                 code = owner.nicoLiveStream.SendOwnerChat(commentMaker);
325
326         } else {
327
328                 code = owner.nicoLiveStream.SendChat(commentMaker);
329
330         }
331
332         switch(code){
333
334         case NLIB_ERR_OK:
335
336
337                 owner.commentSubEdit.SetWindowText(TEXT(""));
338                 goto end;
339
340         case NLIB_ERR_NOT_LIVECONNECT:
341         case NLIB_FAILED_CONNECT:       
342                 ::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);
343                 owner.commentSubEdit.AgreeEnter();
344                 break;
345
346         
347
348
349
350         default:
351                 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__));
352                 owner.commentSubEdit.AgreeEnter();
353                 break;
354
355         }
356
357
358 end:
359
360
361
362         if((owner.nicoLiveStream.IsOwner())){
363
364                 Sleep(1000);
365
366         }else {
367                 Sleep(3000);
368         }
369         ((CSubChatEdit*)userData)->AgreeEnter();
370
371         _endthread();
372         return;
373 }
374
375 BOOL CCommentWriteWindow::SendChat(){
376
377         this->commentSubEdit.SetReadOnly(TRUE);
378         _beginthread(CSubChatEdit::EnterChatBox,0,&this->commentSubEdit);
379         
380         
381
382         
383
384
385
386         return TRUE;
387 }
388
389
390 BOOL CCommentWriteWindow::SetText(LPCTSTR lpStr){
391         
392         BOOL rslt = this->commentSubEdit.SetWindowText(lpStr);
393         if(rslt == TRUE){
394                 commentSubEdit.SetFocus();
395                 int cursor = commentSubEdit.GetWindowTextLength();
396                 commentSubEdit.SetSel(cursor,cursor);
397                 //commentSubEdit.ShowCaret();
398         }
399         return rslt; 
400 }
401
402 VOID CCommentWriteWindow::OnChatReceveStart(CNicoLiveStream &nicoLiveStream,NicoLiveThreadComment_P threadComment){
403         
404         this->ShowWindow(SW_HIDE);
405         this->commentColorBox.ResetContent();
406         this->commentPosBox.ResetContent();
407         this->commentSizeBox.ResetContent();
408
409         addItemList(commentColorBox,generalUser::COMMENT_COLORLIST,ARRAY_LENGTH(generalUser::COMMENT_COLORLIST));
410         addItemList(commentSizeBox,generalUser::COMMENT_SIZELIST,ARRAY_LENGTH(generalUser::COMMENT_SIZELIST));
411         addItemList(commentPosBox,generalUser::COMMENT_POSLIST,ARRAY_LENGTH(generalUser::COMMENT_POSLIST));
412
413
414         if(nicoLiveStream.IsPremium() == TRUE){
415
416                 addItemList(commentColorBox,premiumUser::COMMENT_COLORLIST,ARRAY_LENGTH(premiumUser::COMMENT_COLORLIST));
417                 addItemList(commentSizeBox,premiumUser::COMMENT_SIZELIST,ARRAY_LENGTH(premiumUser::COMMENT_SIZELIST));
418                 addItemList(commentPosBox,premiumUser::COMMENT_POSLIST,ARRAY_LENGTH(premiumUser::COMMENT_POSLIST));
419
420         }
421         this->commentColorBox.SetCurSel(0);
422         this->commentPosBox.SetCurSel(0);
423         this->commentSizeBox.SetCurSel(0);
424
425         
426
427         this->ShowWindow(SW_SHOW);
428         this->streamTime = threadComment->server_time;
429         this->SetTimer(TIMER_ID,1000,NULL);
430         if(nicoLiveStream.IsOwner() == TRUE){
431
432                 this->ownerModeButton.ShowWindow(SW_SHOW);
433                 ownerModeButton.SetCheck(BST_CHECKED);
434                 editBkColor = OWNEREDITCOLOR;
435                  
436         } else {
437
438                 this->ownerModeButton.ShowWindow(SW_HIDE);
439                 editBkColor = NORMALEDITCOLOR;
440
441         }
442
443         if(this->editBkBrush.IsNull() ==FALSE){
444                 editBkBrush.DeleteObject();
445         }
446
447         editBkBrush.CreateSolidBrush(editBkColor);
448         SIZE size;
449         RECT windowRect;
450         this->GetClientRect(&windowRect);
451         size.cx = windowRect.right - windowRect.left;
452         size.cy = windowRect.bottom - windowRect.top;
453         ChangeSize(size);
454
455         return;
456 }
457
458 VOID CCommentWriteWindow::ChangeSize(SIZE &size){
459
460         SIZE commentAnonymousButtonSize;
461         SIZE commentWriteButtonSize;
462         commentWriteButton.GetIdealSize(&commentWriteButtonSize);
463         anonymousButton.GetIdealSize(&commentAnonymousButtonSize);
464         UINT_PTR defwindowCount = 0;
465         RECT commentPosBoxRect;
466         RECT commentSizeBoxRect;
467         RECT commentColorBoxRect;
468         RECT anonymousButtonRect;
469         RECT commentEditRect;
470         RECT commentWriteButtonRect;
471         RECT ownerModeButtonRect;
472         RECT thisWindowRect;
473
474         UINT_PTR writeSpaceHeight = COMMENTWRITEWINDOW_SEPARATEFSIZE.top * 2 + commentWriteInternalHeight;
475         this->GetWindowRect(&thisWindowRect);
476
477         commentPosBoxRect.left = COMMENTWRITEWINDOW_SIDESEPARATESIZE;
478         this->commentPosBoxCS.Lock();
479         commentPosBoxRect.right = commentPosBoxRect.left + CalcComboBoxWidth<CommentPosInfo>(commentPosBox);
480         this->commentPosBoxCS.Unlock();
481
482         commentSizeBoxRect.left = commentPosBoxRect.right + COMMENTWRITEWINDOW_SIDESEPARATESIZE;
483         this->commentSizeBoxCS.Lock();
484         commentSizeBoxRect.right = commentSizeBoxRect.left + CalcComboBoxWidth<CommentSizeInfo>(commentSizeBox);
485         this->commentSizeBoxCS.Unlock();
486
487         commentColorBoxRect.left = commentSizeBoxRect.right + COMMENTWRITEWINDOW_SIDESEPARATESIZE;
488         commentColorBoxRect.right = commentColorBoxRect.left + commentColorBoxSize.cx;
489
490
491         
492         anonymousButtonRect.left = commentColorBoxRect.right + COMMENTWRITEWINDOW_SIDESEPARATESIZE;
493         anonymousButtonRect.right = anonymousButtonRect.left + commentAnonymousButtonSize.cx;
494
495         if(ownerModeButton.IsWindowVisible() == TRUE){
496
497                 
498                 SIZE ownerModeButtonSize;
499                 ownerModeButton.GetIdealSize(&ownerModeButtonSize);
500                 ownerModeButtonRect.left = anonymousButtonRect.right + COMMENTWRITEWINDOW_SIDESEPARATESIZE;
501                 ownerModeButtonRect.right = ownerModeButtonRect.left + ownerModeButtonSize.cx;
502                 commentEditRect.left = ownerModeButtonRect.right + COMMENTWRITEWINDOW_SIDESEPARATESIZE;
503                 defwindowCount = 7;
504         } else {
505
506                 commentEditRect.left = anonymousButtonRect.right + COMMENTWRITEWINDOW_SIDESEPARATESIZE;
507                 defwindowCount = 6;
508         }
509         
510         commentWriteButtonRect.right = size.cx - COMMENTWRITEWINDOW_SIDESEPARATESIZE;
511         commentWriteButtonRect.left = commentWriteButtonRect.right - commentWriteButtonSize.cx;
512
513         commentEditRect.right = commentWriteButtonRect.left - COMMENTWRITEWINDOW_SIDESEPARATESIZE;
514
515         
516
517         //\88Ú\93®\8f\88\97\9d
518         HDWP hDwp = BeginDeferWindowPos(defwindowCount);
519         
520         commentPosBox.DeferWindowPos(hDwp,*this,
521                 commentPosBoxRect.left,writeSpaceHeight,commentPosBoxRect.right - commentPosBoxRect.left,commentWriteInternalHeight,
522                 SWP_NOZORDER);
523
524         commentSizeBox.DeferWindowPos(hDwp,*this,
525                 commentSizeBoxRect.left,writeSpaceHeight,commentSizeBoxRect.right - commentSizeBoxRect.left,commentWriteInternalHeight,
526                 SWP_NOZORDER);
527
528         commentColorBox.DeferWindowPos(hDwp,*this,
529                 commentColorBoxRect.left,writeSpaceHeight,commentColorBoxRect.right - commentColorBoxRect.left,commentWriteInternalHeight,
530                 SWP_NOZORDER);
531
532         anonymousButton.DeferWindowPos(hDwp,*this,
533                 anonymousButtonRect.left,writeSpaceHeight,anonymousButtonRect.right - anonymousButtonRect.left,commentWriteInternalHeight,
534                 SWP_NOZORDER);
535
536         if(ownerModeButton.IsWindowVisible() == TRUE){
537                 ownerModeButton.DeferWindowPos(hDwp,*this,
538                         ownerModeButtonRect.left,writeSpaceHeight,ownerModeButtonRect.right - ownerModeButtonRect.left,commentWriteInternalHeight,
539                 SWP_NOZORDER);
540
541         }
542         commentSubEdit.DeferWindowPos(hDwp,*this,
543                 commentEditRect.left,writeSpaceHeight,commentEditRect.right - commentEditRect.left,commentWriteInternalHeight,
544                 SWP_NOZORDER);
545
546         commentWriteButton.DeferWindowPos(hDwp,*this,
547                 commentWriteButtonRect.left,writeSpaceHeight,commentWriteButtonRect.right - commentWriteButtonRect.left,commentWriteInternalHeight,
548                 SWP_NOZORDER);
549
550         EndDeferWindowPos(hDwp);
551
552         return;
553 }
554
555 VOID CCommentWriteWindow::OnDrawItem(UINT wParam,LPDRAWITEMSTRUCT lParam){
556         
557         
558
559         if(lParam->hwndItem == commentColorBox.m_hWnd && commentColorBox.GetCount() > 0){
560                 
561                 
562
563                 RECT drawRect = lParam->rcItem;
564                 UINT_PTR itemNo = 0;
565                 INT_PTR curselNo = commentColorBox.GetCurSel();
566                 CDCHandle dcHandle = lParam->hDC;
567                 CBrush bkBrush;
568                 const UINT_PTR width = 1;
569                 drawRect.left += width;
570                 drawRect.top += width;
571                 drawRect.right -= width;
572                 drawRect.bottom -= width;
573
574                 if(lParam->itemID == ((UINT)-1)){
575                         itemNo = curselNo == CB_ERR ? 0 : curselNo;
576                 } else {
577                         itemNo = lParam->itemID;
578                 }
579                 
580                 CommentInfo<COLORREF> &commentColor = *(CommentInfo<COLORREF> *)commentColorBox.GetItemDataPtr(itemNo);
581                 
582                 
583                 if(lParam->itemState & (ODS_FOCUS | ODS_COMBOBOXEDIT)){
584                         
585                         
586                         
587                         bkBrush.CreateSolidBrush(PALETTERGB(160,160,160));
588                                 
589                 } else {
590
591                         bkBrush.CreateSolidBrush(PALETTERGB(255,255,255));
592
593                 }
594
595
596                 
597                 
598                 CBrush brush;
599                 CPen cpen;
600
601                 brush.CreateSolidBrush(commentColor.userData);
602                 dcHandle.SelectBrush(brush);
603                 dcHandle.FillRect(&lParam->rcItem,bkBrush);
604                 dcHandle.SelectBrush(brush);
605                 dcHandle.SelectPen((HPEN)::GetStockObject(BLACK_PEN));
606                 dcHandle.Rectangle(&drawRect);
607                 
608         }
609
610         return;
611 }
612
613 LRESULT CCommentWriteWindow::OnEraseBkGnd(HDC wParam){
614
615         return TRUE;
616 }
617
618
619 LRESULT CCommentWriteWindow::OnCtlolorEdit(HDC hdc,HWND hWnd){
620
621         if(hWnd == this->commentSubEdit){
622
623                 
624                 SetBkMode(hdc, TRANSPARENT);    // \94w\8ci\82ð\93§\89ß
625                 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
626         
627                 return (LRESULT)editBkBrush.m_hBrush;
628         }
629
630         return 0;
631 }
632
633 LRESULT CCommentWriteWindow::OnButton(UINT hiWparam,INT_PTR loWparam,HWND lParam){
634
635         if(lParam == commentWriteButton){
636                 
637                 this->SendChat();
638
639         } else if(lParam == this->ownerModeButton){
640
641                 if(this->ownerModeButton.GetCheck() == BST_CHECKED){
642
643                         this->editBkColor = OWNEREDITCOLOR;
644
645                 } else {
646
647                         this->editBkColor = NORMALEDITCOLOR;
648                 }
649
650                 if(this->editBkBrush.IsNull() == FALSE){
651
652                         this->editBkBrush.DeleteObject();
653
654                 }
655
656                 this->editBkBrush.CreateSolidBrush(editBkColor);
657                 commentSubEdit.Invalidate();
658                 
659         }
660
661         return TRUE;
662 }
663
664 VOID CCommentWriteWindow::OnTimer(UINT id){
665         streamTime++;
666         this->Invalidate();
667
668         return;
669 }
670
671 VOID CCommentWriteWindow::OnMeasureItem(UINT wParam,LPMEASUREITEMSTRUCT lParam){
672
673         switch(lParam->CtlID){
674
675         case COMMENTCOLOR_BOX:
676                 {
677                         SIZE itemSize;
678                         CPaintDC pdc(*this);
679                         pdc.SelectFont(AtlGetDefaultGuiFont());
680                         LPCTSTR sample = TEXT(" ");
681                         ::GetTextExtentPoint32(pdc,sample,_tcslen(sample),&itemSize);
682                         lParam->itemHeight = itemSize.cy;
683
684                 }
685                 break;
686
687         }
688
689         
690
691         return;
692 }
693
694
695
696
697 VOID CCommentWriteWindow::OnSendChatResult(){
698
699         commentSubEdit.AgreeEnter();
700         return;
701 }
702
703
704
705 VOID CCommentWriteWindow::OnHeartBeat(NicoLiveHeartBeat_P heartBeat){
706
707         if(heartBeat->status == NLIB_ERR_OK){
708                 streamTime = heartBeat->time;
709
710         }
711
712         return;
713 }
714
715 VOID CCommentWriteWindow::OnDisConnect(){
716
717         this->KillTimer(TIMER_ID);
718
719         return;
720 }
721
722
723 //
724 //CSubChatEdit\83N\83\89\83X
725 //////////////////////////////////////////////////////////////////////////////////////
726
727 void CSubChatEdit::OnKeyDown(TCHAR wParam, UINT upLParam,UINT loLParam){
728         if(wParam == VK_RETURN){
729                                         
730                 cs.Lock();
731                                         
732                 if(untilConnectingFlag == FALSE){
733                         untilConnectingFlag = TRUE;
734                         
735
736                         self.SendChat();
737                 }
738                                         
739                 cs.Unlock();
740                                         
741                                         
742         }
743         return;
744 }
745
746
747 VOID CSubChatEdit::AgreeEnter(){
748         cs.Lock();
749         this->SetReadOnly(FALSE);
750         untilConnectingFlag = FALSE;
751         cs.Unlock();
752 }
753
754 }