OSDN Git Service

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