OSDN Git Service

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