OSDN Git Service

バグレポート機能実装途中
[nlite/nlite.git] / nlite / nlite_mainframe.cpp
1 #include "stdafx.h"
2
3 #include "nlite_include.h"
4
5
6 namespace nlite{
7
8 static const RECT commentViewSize = {5,0,5,0};
9
10 ///
11 ///\92è\90\94
12 ///
13 enum{
14         IDC_COMBO_REBAR = 301,
15         IDC_COMBO_TITLE = 302
16 };
17
18
19
20 ///
21 ///\83E\83B\83\93\83h\83E\8dÅ\92á\83T\83C\83Y
22 ///
23 const static SIZE lowestFrameSize = {300,300};
24
25
26
27 CNliteMainFrame::~CNliteMainFrame(){
28
29         DeleteObject(hTabFont);
30 }
31
32 CNliteMainFrame::CNliteMainFrame()
33         :userData(*this),
34         subLiveNoComboBox(*this),
35         commentWriteWindow(nicoLiveStream),
36         commentView(nicoLiveStream,nicoVideoAuth)
37 {
38         LOGFONT lf = {0};
39
40         lf.lfHeight = 10;
41         lf.lfCharSet = SHIFTJIS_CHARSET;
42         hTabFont = CreateFontIndirect(&lf);
43 }
44
45
46 // \83\81\83b\83Z\81[\83W\83t\83B\83\8b\83^\8f\88\97\9d
47 BOOL CNliteMainFrame::PreTranslateMessage(MSG* pMsg){
48         // \8aî\92ê\83N\83\89\83X\82ÌPreTranslateMessage\82ð\8cÄ\82Ñ\8fo\82·
49         return CFrameWindowImpl<CNliteMainFrame>::PreTranslateMessage(pMsg);
50 }
51
52 // \83A\83C\83h\83\8b\8f\88\97\9d
53 BOOL CNliteMainFrame::OnIdle(){
54         return FALSE;
55 }
56
57 //\83T\83C\83Y\95Ï\8dX\8f\88\97\9d
58 VOID CNliteMainFrame::ChangeSize(const SIZE& client){
59
60         
61         UINT_PTR tabheight = client.cy - (toolBarHeight + statusBarHeight + commentWriteWindow.GetHeight());
62
63         
64         RECT tabWindowRect = {0};
65         RECT commentViewRect = {0};
66         RECT commentWriteWindowRect = {0};
67
68
69         tabWindowRect.left = 0;
70         tabWindowRect.top = toolBarHeight;
71         tabWindowRect.right =  client.cx - tabWindowRect.left;
72         tabWindowRect.bottom = tabWindowRect.top + tabheight;
73         
74         
75         commentWriteWindowRect.left = 0;
76         commentWriteWindowRect.top = tabWindowRect.bottom;
77         commentWriteWindowRect.right = commentWriteWindowRect.left + client.cx;
78         commentWriteWindowRect.bottom = commentWriteWindowRect.top + commentWriteWindow.GetHeight();
79
80
81         
82
83         tabctrl.MoveWindow(tabWindowRect.left,tabWindowRect.top,tabWindowRect.right - tabWindowRect.left ,tabWindowRect.bottom - tabWindowRect.top);
84         
85         
86         tabctrl.GetClientRect(&commentViewRect);
87         tabctrl.AdjustRect(FALSE,&commentViewRect);
88
89         commentView.MoveWindow(commentViewRect.left, commentViewRect.top,commentViewRect.right - commentViewRect.left, commentViewRect.bottom - commentViewRect.top);
90
91         commentWriteWindow.MoveWindow(commentWriteWindowRect.left,commentWriteWindowRect.top,commentWriteWindowRect.right - commentWriteWindowRect.left ,commentWriteWindowRect.bottom - commentWriteWindowRect.top);
92         commentWriteWindow.Invalidate();
93         ::InvalidateRect(m_hWndStatusBar,NULL,TRUE);
94
95 //      tabctrl.SetWindowPos(*this,0,0,0,0,SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW);
96 //      commentWriteWindow.SetWindowPos(*this,0,0,0,0,SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW);
97         return;
98 }
99
100 LRESULT CNliteMainFrame::OnCbSelChange(UINT hiWparam,int loWparam,HWND lParam){
101
102         if(lParam == this->lvNoCombo){
103                 INT_PTR cursel = this->lvNoCombo.GetCurSel();
104                 if(cursel == CB_ERR)goto end;
105                 auto it = this->subLiveNoComboBox.liveInfoList.begin();
106                 std::advance(it,cursel);
107                 this->ConnectNicoLive(it->second);
108
109         }
110
111 end:
112
113         return 0;
114 }
115
116 LRESULT CNliteMainFrame::OnCreate(LPCREATESTRUCT lpcs){
117
118         
119         // \83X\83e\81[\83^\83X\83o\81[\82ð\8dì\90¬
120         m_hWndStatusBar = m_hStatusBar.Create(*this);
121         UIAddStatusBar(m_hWndStatusBar);
122         // \83X\83e\81[\83^\83X\83o\81[\82É\83y\83C\83\93\82ð\90Ý\92è
123         //INT_PTR nPanes[] = {ID_DEFAULT_PANE, IDS_PANE_TIME};
124         //m_hStatusBar.SetPanes(nPanes, sizeof(nPanes)/sizeof(nPanes[0]));
125         //progresBar.Create(m_hWnd,0,NULL,);
126         //m_hStatusBar.SetClipboardViewer
127         tabctrl.Create(m_hWnd,0,NULL,WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_DLGFRAME );
128         commentView.Create(tabctrl.m_hWnd);
129         
130         commentWriteWindow.Create(m_hWnd,0,NULL,WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN  );
131         CreateSimpleReBar();
132         HWND hWndToolBar = CreateSimpleToolBarCtrl(m_hWnd,IDC_NLITE, FALSE, ATL_SIMPLE_TOOLBAR_PANE_STYLE);
133         lvNoCombo.Create(m_hWnd, CRect(0, 0, 100, 100), NULL,WS_CHILD | WS_VISIBLE | WS_VSCROLL  | CBS_DROPDOWN | CBS_AUTOHSCROLL, 0, IDC_COMBO_REBAR);
134         lvNoCombo.LimitText(LENGTH_512);
135
136         subLiveNoComboBox.SubclassWindow(lvNoCombo.GetEditCtrl());
137         lvNoCombo.SetFont(AtlGetDefaultGuiFont());
138         
139         
140
141         //AddSimpleReBarBand(hWndToolBar);
142         AddSimpleReBarBand(lvNoCombo,TEXT("\95ú\91\97URL"));
143         SizeSimpleReBarBands();
144         
145         //tabctrl.SetWindowPos(*this,0,0,0,0,SWP_SHOWWINDOW);
146         
147         tabctrl.SetFont(hTabFont);
148         tabctrl.AddItem(TCIF_TEXT | TCIF_PARAM, _T("\83R\83\81\83\93\83g\88ê\97\97"), 0, (DWORD)commentView.m_hWnd);
149
150         
151                 
152         // \83\81\83b\83Z\81[\83W\83\8b\81[\83v\82É\83\81\83b\83Z\81[\83W\83t\83B\83\8b\83^\82Æ\83A\83C\83h\83\8b\83n\83\93\83h\83\89\82ð\92Ç\89Á
153         CMessageLoop* pLoop = _Module.GetMessageLoop();
154         pLoop->AddMessageFilter(this);
155         pLoop->AddIdleHandler(this);
156
157         RECT wndRect;
158         this->GetWindowRect(&wndRect);
159         
160         LONG cyMaxImized = GetSystemMetrics (SM_CYMAXIMIZED);
161         wndRect.bottom = nliteProperty.GetMainFrameProperty().GetWindowSize().cy != 0 ? nliteProperty.GetMainFrameProperty().GetWindowSize().cy : (LONG)cyMaxImized / 2;
162         wndRect.right = nliteProperty.GetMainFrameProperty().GetWindowSize().cx != 0 ? nliteProperty.GetMainFrameProperty().GetWindowSize().cx : commentViewSize.left + commentViewSize.right + 20 + commentView.GetColumnHolSizeSum();
163
164         
165
166         RECT statusbarRect;
167         ::GetClientRect(m_hWndStatusBar,&statusbarRect);
168
169         statusBarHeight = statusbarRect.bottom - statusbarRect.top;
170         
171         
172
173         this->MoveWindow(wndRect.left,wndRect.top,wndRect.right,wndRect.bottom);
174         
175         listenerSettingWindow.Create(*this);
176         
177         this->SetMenuItemCheck(IDM_FRONT_WINDOW_CHECK,nliteProperty.GetMainFrameProperty().IsWindowFront());
178         this->SetMenuItemCheck(IDM_SPEAK_COMMENT_CHECK,nliteProperty.GetCommentReadProperty().IsCommentRead());
179         
180         this->SetWindowPos(nliteProperty.GetMainFrameProperty().IsWindowFront() == TRUE ? HWND_TOPMOST : HWND_NOTOPMOST,0,0,0,0,SWP_NOSIZE | SWP_NOMOVE);
181
182         return 0;
183 }
184
185
186
187 VOID CNliteMainFrame::Initialize(LPCTSTR localAppDataPath){
188
189         try{
190                 
191
192         
193                 
194
195                 commentView.SetProperty(nliteProperty.GetCommentViewProperty(),nliteProperty.GetGeneralProperty());
196                 if(nliteProperty.GetGeneralProperty().GetBrowserType() == BT_NOSETTING){
197                         nliteProperty.CookieSetting();
198                         while(nliteProperty.GetGeneralProperty().GetBrowserType() == BT_NOSETTING){
199                                 ::MessageBox(NULL,TEXT("\83u\83\89\83E\83U\83^\83C\83v\82ð\8ew\92è\82µ\82Ä\82­\82¾\82³\82¢\81B\82±\82ê\88È\8aO\82Ì\83u\83\89\83E\83U\82Í\8c»\8dÝ\8eg\97p\82·\82é\82±\82Æ\82Í\82Å\82«\82Ü\82¹\82ñ"),TEXT("\83u\83\89\83E\83U\83^\83C\83v\8ew\92è\83G\83\89\81["),MB_OK);
200                                 nliteProperty.CookieSetting();
201                         }
202                 }
203                         
204                 nicoVideoAuth.SetBrowserType(nliteProperty.GetGeneralProperty().GetBrowserType());
205                 nicoLiveStream.SetResFrom(200);
206         }catch(Exception &e){
207
208                 ::MessageBox(NULL,e.what(),TEXT("\90Ý\92è\83t\83@\83C\83\8b\93Ç\82Ý\8d\9e\82Ý\83G\83\89\81["),MB_OK | MB_ICONERROR);
209
210         }
211         return;
212                         
213 }
214
215 VOID CNliteMainFrame::OnClose(){
216         this->ShowWindow(SW_HIDE);
217         nicoLiveStream.DisConnect();
218         this->DestroyWindow();
219         
220         return;
221 }
222
223 VOID CNliteMainFrame::OnDestroy(){
224         
225         commentView.DestroyWindow();
226                         
227         PostQuitMessage(0);
228         return;
229 }
230
231
232 VOID CNliteMainFrame::OnException(){
233
234         nicoLiveStream.DisConnect();
235
236 }
237
238
239 BOOL CNliteMainFrame::IsMenuItemChecked(UINT item){
240         MENUITEMINFO menuInfo;
241         menuInfo.fMask = MIIM_STATE;
242         menuInfo.cbSize = sizeof(menuInfo);
243         ::GetMenuItemInfo(this->GetMenu(),item,FALSE,&menuInfo);
244         return menuInfo.fState == MFS_CHECKED;
245 }
246
247
248 VOID CNliteMainFrame::SetMenuItemCheck(UINT item,BOOL state){
249         MENUITEMINFO menuInfo;
250         menuInfo.cbSize = sizeof(menuInfo);
251         menuInfo.fMask = MIIM_STATE;
252         menuInfo.fState = state == TRUE ? MFS_CHECKED :MFS_UNCHECKED;
253         ::SetMenuItemInfo(this->GetMenu(),item,FALSE,&menuInfo);
254
255 }
256
257 //\83\81\83j\83\85\81[\82©\82ç\83t\83@\83C\83\8b\82ð\8fI\97¹\82ð\91I\91ð
258 VOID CNliteMainFrame::OnMenuExit(UINT uNotifyCode, int nID, HWND hWndCtl){
259         PostMessage(WM_CLOSE);
260 }
261
262 //\83\81\83j\83\85\81[\82Ì\83A\83v\83\8a\83P\81[\83V\83\87\83\93\83o\81[\83W\83\87\83\93\8fî\95ñ\95\\8e¦
263 VOID CNliteMainFrame::OnMenuAbount(UINT uNotifyCode,int nID,HWND hWndCtl){
264         appInfo->show();
265 }
266
267 VOID CNliteMainFrame::Finalaize(){
268
269         nliteProperty.SetCommentViewProperty(commentView.GetProperty());
270         nliteProperty.WriteProperty();
271         listenerList.WriteProperty(nliteProperty.GetListenerDataPath());
272 }
273
274 VOID CNliteMainFrame::OnViewPreference(UINT uNotifyCode,int nID,HWND hWndCtl){
275
276         //ViewerPropertyWindow propetyWindow(TEXT("\83r\83\85\81[\83A\90Ý\92è"));
277         
278         //propetyWindow.DoModal();
279
280         return;
281 }
282
283 LRESULT CNliteMainFrame::OnUnlockLvNoBuffer(UINT uMsg,WPARAM wParam,LPARAM lParam){
284         this->lvNoBufCS.Unlock();
285         return 0;
286 }
287
288 //\83N\83b\83L\81[\82Ì\90Ý\92è
289 VOID CNliteMainFrame::OnCookie(UINT uNotifyCode,int nID,HWND hWndCtl){
290         nliteProperty.CookieSetting();
291                         
292         while(nliteProperty.GetGeneralProperty().GetBrowserType() == BT_NOSETTING){
293                 ::MessageBox(NULL,TEXT("\83u\83\89\83E\83U\83^\83C\83v\82ð\8ew\92è\82µ\82Ä\82­\82¾\82³\82¢\81B\82±\82ê\88È\8aO\82Ì\83u\83\89\83E\83U\82Í\8c»\8dÝ\8eg\97p\82·\82é\82±\82Æ\82Í\82Å\82«\82Ü\82¹\82ñ"),TEXT("\83u\83\89\83E\83U\83^\83C\83v\8ew\92è\83G\83\89\81["),MB_OK);
294                 nliteProperty.CookieSetting();
295         }
296                         
297         try {
298                 nicoVideoAuth.SetBrowserType(nliteProperty.GetGeneralProperty().GetBrowserType());
299         } catch(NLIBException &e){
300
301                 MessageBox(e.what(),TEXT("\83N\83b\83L\81[\8eæ\93¾\8e¸\94s"),MB_OK | MB_ICONERROR);
302
303         }
304         
305
306 }
307
308 VOID CNliteMainFrame::OnSpeakCommentCheck(UINT uNotifyCode,int nID,HWND hWndCtl){
309
310
311         nliteProperty.GetCommentReadProperty().SetCommentRead(!IsMenuItemChecked(IDM_SPEAK_COMMENT_CHECK));
312         SetMenuItemCheck(IDM_SPEAK_COMMENT_CHECK,nliteProperty.GetCommentReadProperty().IsCommentRead() );
313         
314         return;
315 }
316
317 VOID CNliteMainFrame::OnFrontWindowCheck(UINT uNotifyCode,int nID,HWND hWndCtl){
318
319
320         nliteProperty.GetMainFrameProperty().SetWindowFront(!IsMenuItemChecked(IDM_FRONT_WINDOW_CHECK));
321         SetMenuItemCheck(IDM_FRONT_WINDOW_CHECK,nliteProperty.GetMainFrameProperty().IsWindowFront() );
322         this->SetWindowPos(nliteProperty.GetMainFrameProperty().IsWindowFront() == TRUE ? HWND_TOPMOST : HWND_NOTOPMOST,0,0,0,0,SWP_NOSIZE | SWP_NOMOVE);
323         return;
324 }
325
326 VOID CNliteMainFrame::ConnectingThread(LPVOID userData){
327
328         auto &self = *(CNliteMainFrame*)userData;
329         CString lvNoString = self.lvNoBuffer;
330         self.SendMessage(UM_UNLOCK_LVNOBUFFER,(WPARAM)0,(LPARAM)0);
331         try {
332                 self.nicoLiveStream.DisConnect();
333                 self.commentView.OnConnect();
334                 
335         
336                 NLIB_RESULT code = self.nicoLiveStream.Connect(self.nicoVideoAuth,lvNoString,LiveCallBack,&self.userData);
337
338                 //\83G\83\89\81[\83R\81[\83h\8f\88\97\9d
339                 switch(code){
340         
341                         //\90³\8fí\8fI\97¹
342                 case NLIB_ERR_OK:
343
344                         
345                         goto end;
346
347                         //\91z\92è\82³\82ê\82½\83G\83\89\81[\83R\81[\83h
348                 case NLIB_ERR_COOKIE_FAILED:
349                 case NLIB_LIVENO_FAILED_UNDEFEINE:
350                 case NLIB_FAILED_CONNECT:
351                 case NLIB_ERR_GETPLAYERSTATUS_INVALID_LV:
352                 case NLIB_ERR_GETPLAYERSTATUS_INVALID_THREAD:
353                 case NLIB_ERR_GETPLAYERSTATUS_CLOSED:
354                 case NLIB_ERR_GETPLAYERSTATUS_UNKNOWN_ERROR:
355                 case NLIB_ERR_GETPLAYERSTATUS_SERVER_ERROR:
356                 case NLIB_ERR_GETPLAYERSTATUS_DELETED:
357                 case NLIB_ERR_GETPLAYERSTATUS_FULL:
358                 case NLIB_ERR_GETPLAYERSTATUS_PERMISSION_DENIED:
359                 case NLIB_ERR_GETPLAYERSTATUS_ACCESS_LOCKED:
360                 case NLIB_ERR_GETPLAYERSTATUS_REQUIRE_COMMUNITY_MEMBER:
361                 case NLIB_ERR_GETPLAYERSTATUS_COMINGSOON:
362                 case NLIB_ERR_GETPLAYERSTATUS_NOTFOUND:
363                 case NLIB_ERR_GETPLAYERSTATUS_NOTLOGIN:
364                 case NLIB_ERR_GETPLAYERSTATUS_UNKNOWN:
365                 case NLIB_ERR_GETPLAYERSTATUS_MAINTENANCE:
366                 case NLIB_ERR_GETPLAYERSTATUS_NOT_PERMITTED:
367                 case NLIB_ERR_GETPLAYERSTATUS_REQUIRE_ACCEPT_PRINT_TIMESHIFT_TICKET:
368                 case NLIB_ERR_GETPLAYERSTATUS_TSARCHIVE:
369                 case NLIB_ERR_GETPLAYERSTATUS_USERTIMESHIFT:
370                 case NLIB_ERR_GETPLAYERSTATUS_UNDEFINED:
371                 case NLIB_ERR_GETPLAYERSTATUS_NOAUTH:
372                 case NLIB_ERR_GETPLAYERSTATUS_CHANT_PARSE:
373                 case NLIB_ERR_GETPLAYERSTATUS_BLOCK_NOW_COUNT_OVERFLOW:
374
375
376                         
377                         ::MessageBox(self,NLIB_GetErrorMessage(code),TEXT("\95ú\91\97\90Ú\91±\83G\83\89\81["),MB_ICONERROR | MB_OK);
378
379                         break;
380
381
382                         //\91z\92è\82³\82ê\82Ä\82¢\82È\82¢\83G\83\89\81[\83R\81[\83h
383                 default:
384                 
385                         UnexpectedErrorMessageShow( TEXT("\95ú\91\97\90Ú\91±\92\86\82É"),NLIB_GetErrorMessage(code),__LINE__,TEXT(__FILE__),TEXT(__FUNCTION__));
386
387                 
388                         break;
389
390                 }
391                 self.subLiveNoComboBox.AgreeInputLvNo();
392                 
393
394         } catch(nlib::Exception &e){
395
396                 UnexpectedErrorMessageShow( TEXT("\95ú\91\97\90Ú\91±\92\86\82É"),e.what(),e.getLineNo(),e.getFileName(),e.getFunctionName());
397
398         }
399 end:
400         
401         self.subLiveNoComboBox.AgreeInputLvNo();
402         _endthread();
403         return;
404 }
405
406
407 BOOL CNliteMainFrame::ConnectNicoLive(LPCTSTR liveNo){
408         
409         lvNoCombo.GetEditCtrl().SetReadOnly(TRUE);
410         subLiveNoComboBox.untilConnectingFlag = TRUE;
411         EnableWindow(FALSE);
412         lvNoBufCS.Lock();
413         this->lvNoBuffer = liveNo;
414         _beginthread(CNliteMainFrame::ConnectingThread,0,this);
415
416         
417
418
419         return TRUE;
420
421 }
422
423
424 //\83T\83C\83Y\95Ï\8dX\8cã
425 LRESULT CNliteMainFrame::OnSize(UINT uMsg,WPARAM wParam,LPARAM lParam,BOOL& bHandled){
426
427
428         SIZE clientSize;
429         clientSize.cx = LOWORD(lParam);
430         clientSize.cy = HIWORD(lParam);
431         ChangeSize(clientSize);
432
433         bHandled = FALSE;
434                         
435                         
436
437         return 0;
438 }
439
440
441 ///
442 ///\83T\83C\83Y\95Ï\8dX\92\86\8f\88\97\9d
443 ///
444 VOID CNliteMainFrame::OnSizing(UINT wParam,LPRECT lParam){
445                         
446         if(lParam->right - lParam->left < lowestFrameSize.cx){
447                 lParam->right = lParam->left + lowestFrameSize.cx;
448         }
449
450         if(lParam->bottom - lParam->top < lowestFrameSize.cy){
451
452                 lParam->bottom = lParam->top + lowestFrameSize.cy;
453         }
454                         
455 }
456
457
458 //\83c\81[\83\8b\83o\81[\8d\82\82³\95Ï\8dX
459 LRESULT CNliteMainFrame::OnRbnHeightChange(INT_PTR wParam,LPNMHDR lParam,BOOL &bHandled){
460
461         RECT toolbarRect;
462         ::GetClientRect(m_hWndToolBar,&toolbarRect);
463         toolBarHeight = toolbarRect.bottom - toolbarRect.top;
464
465         RECT client;
466         GetClientRect(&client);
467
468         ChangeSize( _WTYPES_NS::CSize(client.right - client.left,client.bottom - client.top));
469
470
471
472         return 0;
473 }
474
475 LRESULT CNliteMainFrame::OnUpDateUI(UINT uMsg,WPARAM wParam,LPARAM lParam){
476
477
478         commentView.UpDateUI();
479
480         return 0;
481 }
482
483 LRESULT CNliteMainFrame::OnClickChatNo(UINT uMsg,WPARAM wParam,LPARAM lParam){
484
485         auto &chatData = *(CChatData*)wParam;
486         CString setString;
487         if(chatData.GetListnerData().GetName().Length() == 0){
488                 setString.Format(TEXT(">>%d "),chatData.GetNo());
489         }else{
490                 setString.Format(TEXT(">>%s "),chatData.GetListnerData().GetName());
491         }
492
493         this->commentWriteWindow.SetText(setString);
494
495         return 0;
496
497 }
498
499 LRESULT CNliteMainFrame::OnClickUserName(UINT uMsg,WPARAM wParam,LPARAM lParam){
500
501         auto &chatData = *(CChatData*)wParam;
502         listenerSettingWindow.ShowSettingWindow(chatData.GetListnerData());
503
504
505         return 0;
506 }
507
508
509 NLIB_RESULT CNliteMainFrame::LiveCallBack(NICOLIVE_EVENT eventType,NicoLiveStream_P pNicoLiveStream,LPVOID option,NICOLIVE_PARAM param1,NICOLIVE_PARAM param2){
510
511         CLiveUserData &userData = (*(CLiveUserData*)option);
512
513         try{
514                 
515
516                 switch(eventType){
517
518                 case NICOLIVE_EVENT_RECEVE_CONNECTRESULT:
519
520                         userData.OnChatReceveStart(userData.self.nicoLiveStream,(NicoLiveThreadComment_P)param1);
521
522                         break;
523
524                 case NICOLIVE_EVENT_RECEVE_CHAT:
525
526                         userData.OnChatReceve((NicoLiveChat_P) param1,param2);
527
528                         break;
529
530                 case NICOLIVE_EVENT_RECEVE_CHATSETTLE:
531
532                         userData.OnChatReceveSettle(param1,param2);
533
534                         break;
535
536                 case NICOLIVE_EVENT_RECEVE_CHATSENDRESULT:
537
538                         userData.OnChatSendResult(reinterpret_cast<NicoLiveSendResultComment_P>(param1));
539
540                         break;
541
542                 case NICOLIVE_EVENT_SEND_HEARTBEAT:
543
544                         userData.OnHeartBeat(reinterpret_cast<NicoLiveHeartBeat_P>(param1));
545
546                         break;
547
548
549                 case NICOLIVE_EVENT_DISCONNECT:
550
551                         userData.OnDisconnect();
552
553                         break;
554
555                 case NICOLIVE_EVENT_ERR_CONNECT:
556
557                         throw NLiveException(TEXT("\90Ú\91±\83G\83\89\81[\82Å\82·"),__LINE__,TEXT(__FILE__),TEXT(__FUNCTION__));
558
559                         break;
560
561                 default:
562
563                         throw NLiveException(TEXT("\97\\8aú\82µ\82È\82¢\83\81\83b\83Z\81[\83W\82ª\91\97\90M\82³\82ê\82Ü\82µ\82½"),__LINE__,TEXT(__FILE__),TEXT(__FUNCTION__));
564
565                         break;
566                 }
567
568         } catch(Exception e){
569                 UnexpectedErrorMessageShow(TEXT("\83n\83\93\83h\83\8b\82³\82ê\82Ä\82¢\82È\82¢\83G\83\89\81["),e.what(),e.getLineNo(),e.getFileName(),e.getFunctionName());
570         
571         } catch(std::exception e){
572                 UnexpectedErrorMessageShow(TEXT("\83n\83\93\83h\83\8b\82³\82ê\82Ä\82¢\82È\82¢\95s\96¾\82Ì\83G\83\89\81["),CComBSTR(e.what()),-1,TEXT("\94­\90\83t\83@\83C\83\8b\82ª\93Á\92è\8fo\97\88\82Ü\82¹\82ñ"),TEXT("\94­\90\8aÖ\90\94\82ª\93Á\92è\82Å\82«\82Ü\82¹\82ñ"));
573         }
574         
575
576         
577
578         return NLIB_ERR_OK;
579 }
580
581
582 LRESULT CNliteMainFrame::OnSetCursor(LRESULT msg,WPARAM wParam,LPARAM lParam,BOOL &bHandled){
583
584         
585         BOOL rslt = FALSE;
586         
587         if(this->subLiveNoComboBox.untilConnectingFlag == TRUE || this->commentWriteWindow.IsWrighthing() == TRUE){
588                 
589                 if(this->subLiveNoComboBox.untilConnectingFlag == TRUE){
590                         ::SetCursor(::LoadCursorW(NULL,IDC_WAIT));
591                 } else if(this->commentWriteWindow.IsWrighthing() == TRUE){
592                         ::SetCursor(::LoadCursorW(NULL,IDC_APPSTARTING));
593                 }
594                 bHandled = TRUE;
595                 rslt = TRUE;
596         
597
598
599
600         } else {
601                 bHandled = FALSE;
602         }
603         
604
605         return TRUE;
606
607 }
608
609
610 //
611 //CSubLiveNoComboBox
612 ////////////////////////////////////
613
614 CNliteMainFrame::CSubLiveNoComboBox::CSubLiveNoComboBox(CNliteMainFrame &in_self):self(in_self),untilConnectingFlag(FALSE){}
615
616 static VOID AgreeEnterKeyThread(LPVOID userData){
617
618         Sleep(1000);
619         auto noCombo = (CNliteMainFrame::CSubLiveNoComboBox*) userData;
620         noCombo->AgreeInputLvNo();
621
622         return;
623 }
624
625 VOID CNliteMainFrame::CSubLiveNoComboBox::OnKeyDown(TCHAR wParam, UINT upLParam,UINT loLParam){
626         if(wParam == VK_RETURN){
627                                         
628                 cs.Lock();
629                                         
630                 //INT_PTR no = self.lvNoCombo.GetCurSel();
631                 if(untilConnectingFlag == FALSE){
632                         
633                         std::vector<TCHAR> buffer(this->GetWindowTextLengthW() + 1); 
634                         ::GetWindowTextW(this->m_hWnd,&buffer[0],buffer.size());
635                         
636                         
637                         self.ConnectNicoLive(&buffer[0]);
638                 }               
639                 cs.Unlock();
640                                         
641                                         
642         } else {
643
644                 this->DefWindowProc();
645
646         }
647         return;
648 }
649
650 LRESULT CNliteMainFrame::CSubLiveNoComboBox::OnMouseWheel(UINT loWparam,SHORT hiWparam,CPoint &point){
651
652
653         return FALSE;
654 }
655
656
657
658 VOID CNliteMainFrame::CSubLiveNoComboBox::AddLiveInfo(CNicoLiveStream &stream,LvnoSearchFunctional &functional){
659         
660         CNLiteString dispComboString;
661         dispComboString += stream.GetId();
662         dispComboString += TEXT("\81@-");
663         dispComboString += stream.GetDefaultCommunity();
664         dispComboString += TEXT("\81@title\81F");
665         dispComboString += stream.GetTitle();
666
667         if(std::find_if(liveInfoList.begin(),liveInfoList.end(),functional) == liveInfoList.end()){
668                 liveInfoList.push_back(LiveInfo(dispComboString,stream.GetId()));
669                 
670                 self.lvNoCombo.InsertItem(self.lvNoCombo.GetCount(),dispComboString,0,0,0,0);
671         
672         } 
673         functional.dispData = dispComboString;
674
675         
676
677
678         return;
679 }
680
681
682 VOID CNliteMainFrame::CSubLiveNoComboBox::AgreeInputLvNo(){
683         cs.Lock();
684         self.lvNoCombo.GetEditCtrl().SetReadOnly(FALSE);
685         self.EnableWindow(TRUE);
686         untilConnectingFlag = FALSE;
687         POINT mousePoint;
688         ::GetCursorPos(&mousePoint);
689         ::SetCursorPos(mousePoint.x,mousePoint.y);
690         cs.Unlock();
691 }
692
693
694 //
695 //CLiveUserData
696 /////////////////////////////////////////////////////////////////////////
697
698 CNliteMainFrame::CLiveUserData::CLiveUserData(CNliteMainFrame &self):self(self)
699 {}
700
701
702
703 VOID CNliteMainFrame::CLiveUserData::OnConnect(){
704
705         self.commentView.OnConnect();
706
707 }
708
709
710 VOID CNliteMainFrame::CLiveUserData::OnChatReceveStart(CNicoLiveStream &stream,NicoLiveThreadComment_P threadComment){
711         
712         LvnoSearchFunctional functional(stream.GetId());
713         self.commentWriteWindow.OnChatReceveStart(stream,threadComment);
714         self.subLiveNoComboBox.AddLiveInfo(stream,functional);
715         self.subLiveNoComboBox.SetWindowText(functional.dispData);
716         self.subLiveNoComboBox.AgreeInputLvNo();
717         
718         return;
719 }
720
721 VOID CNliteMainFrame::CLiveUserData::OnChatReceve(NicoLiveChat_P chat,UINT_PTR count){
722
723         self.commentView.OnChatReceve(chat,count);
724         
725 }
726
727 VOID CNliteMainFrame::CLiveUserData::OnChatReceveSettle(UINT_PTR commentCount,UINT_PTR commentCountSum){
728
729         self.commentView.OnChatReceveSettle(commentCount,commentCountSum);
730         
731         return;
732 }
733
734 VOID CNliteMainFrame::CLiveUserData::OnChatSendResult(NicoLiveSendResultComment_P sendResult){
735         self.commentWriteWindow.OnSendChatResult();
736         return;
737 }
738
739
740 VOID CNliteMainFrame::CLiveUserData::OnHeartBeat(NicoLiveHeartBeat_P heartBeat){
741
742         self.commentWriteWindow.OnHeartBeat(heartBeat);
743
744         return;
745 }
746
747
748
749 VOID CNliteMainFrame::CLiveUserData::OnDisconnect(){
750         self.commentWriteWindow.OnDisConnect();
751         return;
752 }
753
754 }