OSDN Git Service

2012/01/19 23:44:44
[nlite/nlite.git] / nlite / nlite_mailframe.h
1 #pragma once
2
3 namespace nlite{
4         
5
6         
7         const static LPCTSTR NLITE_MAINWINDOW = TEXT("nlite");
8
9         const static SIZE lowestFrameSize = {300,300};
10
11         
12
13         
14
15
16
17
18
19
20         class CNliteMainFrame : public CFrameWindowImpl<CNliteMainFrame>,
21                 public CUpdateUI<CNliteMainFrame>,public CMessageFilter, public CIdleHandler
22         {
23
24                 ///
25                 ///\92è\90\94
26                 ///
27                 enum{
28                         IDC_COMBO_REBAR = 301,
29                         IDC_COMBO_TITLE = 302
30                 };
31
32         public:
33                 class CSubLiveNoComboBox:public CWindowImpl<CEdit>{
34
35                         
36
37                 private:
38                         CNliteMainFrame &self;
39                         CComAutoCriticalSection cs;
40                         BOOL untilConnectingFlag;
41
42                 public:
43                         CSubLiveNoComboBox(CNliteMainFrame &in_self):self(in_self),untilConnectingFlag(FALSE){}
44
45
46                         BEGIN_MSG_MAP_EX(CSubLiveNoComboBox)
47                                 MSG_WM_KEYDOWN(OnKeyDown)
48                         END_MSG_MAP()
49
50                         void OnKeyDown(TCHAR wParam, UINT upLParam,UINT loLParam){
51                                 if(wParam == VK_RETURN){
52                                         
53                                         cs.Lock();
54                                         
55                                         if(untilConnectingFlag == FALSE){
56                                                 untilConnectingFlag = TRUE;
57                                                 std::vector<TCHAR> buffer(this->GetWindowTextLengthW() + 1); 
58                                                 ::GetWindowTextW(this->m_hWnd,&buffer[0],buffer.size());
59                                                 self.ConnectNicoLive(&buffer[0]);
60                                         }
61                                         
62                                         cs.Unlock();
63                                         
64                                         
65                                 }
66                                 return;
67                         }
68
69                         VOID AgreeInputLvNo(){
70                                 cs.Lock();
71                                 untilConnectingFlag = FALSE;
72                                 cs.Unlock();
73                         }
74
75                 };
76
77
78                 class CLiveUserData {
79
80                 private:
81
82                         CCommentView &commentView;
83                         CSubLiveNoComboBox &lvnocombo;
84
85                 public:
86                         CLiveUserData(CCommentView& cv,CSubLiveNoComboBox &combo):commentView(cv),lvnocombo(combo){}
87
88                         VOID OnConnect(){
89
90                                 commentView.OnConnect();
91
92                         }
93
94                         VOID OnChatReceveStart(StreamStatus &streamStatus){
95                                 
96                                 commentView.SetStreamStatus(streamStatus);
97                         }
98                 
99                         VOID OnChatReceve(NicoLiveChat_P chat,UINT_PTR count){
100
101                                 commentView.OnChatReceve(chat,count);
102
103                         }
104
105                         VOID OnChatReceveSettle(UINT_PTR commentCount,UINT_PTR commentCountSum){
106
107                                 commentView.OnChatReceveSettle(commentCount,commentCountSum);
108                                 lvnocombo.AgreeInputLvNo();
109                                 return;
110                         }
111
112                 };
113
114                 
115         public:
116
117                 typedef CFrameWindowImpl<CNliteMainFrame> baseWindow;
118
119                 // \83E\83B\83\93\83h\83E\83N\83\89\83X\96¼\81A\8b¤\92Ê\83\8a\83\\81[\83XID\81A\83X\83^\83C\83\8b\81A\94w\8ci\90F\82ð\93o\98^
120                 DECLARE_FRAME_WND_CLASS(NLITE_MAINWINDOW, IDC_NLITE)
121
122         private:
123                 CCommentView commentView;
124                 
125                 
126                 CStatusBarCtrl statusBar;
127                 CLiveUserData userData;
128                 CSubLiveNoComboBox subLiveNoComboBox;
129                 CCommentWriteWindow commentWriteWindow;
130                 CTabCtrl tabctrl;
131                 
132                 HFONT hTabFont;
133                 CComboBoxEx lvNoCombo;
134                 INT_PTR statusBarHeight;
135                 INT_PTR toolBarHeight;
136                 CNicoVideoAuth nicoVideoAuth;
137                 Property nliteProperty;
138                 CNicoLiveStream nicoLiveStream;
139         private:
140
141                 // \83\81\83b\83Z\81[\83W\83t\83B\83\8b\83^\8f\88\97\9d
142                 virtual BOOL PreTranslateMessage(MSG* pMsg){
143                         // \8aî\92ê\83N\83\89\83X\82ÌPreTranslateMessage\82ð\8cÄ\82Ñ\8fo\82·
144                         return CFrameWindowImpl<CNliteMainFrame>::PreTranslateMessage(pMsg);
145                 }
146
147                 // \83A\83C\83h\83\8b\8f\88\97\9d
148                 virtual BOOL OnIdle(){
149                         return FALSE;
150                 }
151
152
153         public:
154
155                 CNliteMainFrame()
156                         :userData(commentView,subLiveNoComboBox),
157                         subLiveNoComboBox(*this),
158                         commentWriteWindow(nicoLiveStream)
159                 {
160                         LOGFONT lf = {0};
161
162                         lf.lfHeight = 12;
163                         lf.lfCharSet = SHIFTJIS_CHARSET;
164                         hTabFont = CreateFontIndirect(&lf);
165                 }
166
167                 ~CNliteMainFrame(){
168
169                         DeleteObject(hTabFont);
170                 }
171
172                 
173                 BEGIN_UPDATE_UI_MAP(CNliteMainFrame)
174                         // \83G\83\93\83g\83\8a\82È\82µ
175                 END_UPDATE_UI_MAP()
176                 
177                 // \83\81\83b\83Z\81[\83W\83}\83b\83v
178                 BEGIN_MSG_MAP_EX(CNliteMainFrame)
179                         MSG_WM_CREATE(OnCreate)
180                         MSG_WM_DESTROY(OnDestroy)
181                         MESSAGE_HANDLER(WM_SIZE,OnSize)
182                         MSG_WM_SIZING(OnSizing)
183                         MESSAGE_HANDLER_EX(WM_ERASEBKGND,OnErasekgnd)
184                         COMMAND_ID_HANDLER_EX(IDM_EXIT, OnMenuExit)
185                         COMMAND_ID_HANDLER_EX(IDM_ABOUT,OnMenuAbount)
186                         COMMAND_ID_HANDLER_EX(IDM_COOKIE,OnCookie)
187                         NOTIFY_HANDLER(ATL_IDW_TOOLBAR,RBN_HEIGHTCHANGE,OnRbnHeightChange)
188                         // CFrameWindowImpl\83N\83\89\83X\82Ö\83`\83F\81[\83\93
189                         CHAIN_MSG_MAP(CFrameWindowImpl<CNliteMainFrame>)
190                 END_MSG_MAP()
191
192                 
193
194                 //\83`\83\89\83c\83L\82ð\82È\82­\82·
195                 LRESULT OnErasekgnd(UINT uMsg,WPARAM wParam,LPARAM lParam){
196
197                         return TRUE;
198                 }
199
200
201                 //\83c\81[\83\8b\83o\81[\8d\82\82³\95Ï\8dX
202                 LRESULT OnRbnHeightChange(INT_PTR wParam,LPNMHDR lParam,BOOL &bHandled){
203
204                         RECT toolbarRect;
205                         ::GetClientRect(m_hWndToolBar,&toolbarRect);
206                         toolBarHeight = toolbarRect.bottom - toolbarRect.top;
207
208                         RECT client;
209                         GetClientRect(&client);
210
211                         ChangeSize( _WTYPES_NS::CSize(client.right - client.left,client.bottom - client.top));
212
213
214
215                         return 0;
216                 }
217                 
218
219                 ///
220                 ///\83T\83C\83Y\95Ï\8dX\92\86\8f\88\97\9d
221                 ///
222                 VOID OnSizing(UINT wParam,LPRECT lParam){
223                         
224                         if(lParam->right - lParam->left < lowestFrameSize.cx){
225                                 lParam->right = lParam->left + lowestFrameSize.cx;
226                         }
227
228                         if(lParam->bottom - lParam->top < lowestFrameSize.cy){
229
230                                 lParam->bottom = lParam->top + lowestFrameSize.cy;
231                         }
232                         
233                 }
234                 
235                 //\83T\83C\83Y\95Ï\8dX\8cã
236                 LRESULT OnSize(UINT uMsg,WPARAM wParam,LPARAM lParam,BOOL& bHandled){
237
238
239                         SIZE clientSize;
240                         clientSize.cx = LOWORD(lParam);
241                         clientSize.cy = HIWORD(lParam);
242                         ChangeSize(clientSize);
243
244                         bHandled = FALSE;
245                         
246                         
247
248                         return 0;
249                 }
250
251                 VOID ChangeSize(const SIZE& client);
252
253
254                 LRESULT OnCreate(LPCREATESTRUCT lpcs);
255
256                 VOID ConnectNicoLive(LPCTSTR liveNo){
257                         
258                         nicoLiveStream.DisConnect();
259                         commentView.OnConnect();
260                         nicoLiveStream.Connect(nicoVideoAuth,liveNo,LiveCallBack,&userData);
261
262                 }
263
264                 VOID Initialize(LPCTSTR localAppDataPath){
265
266                         nliteProperty.ReadIniFile();
267
268                         commentView.SetProperty(nliteProperty.cvp);
269
270                         if(nliteProperty.gp.browserType == BT_NOSETTING){
271                                 nliteProperty.CookieSetting();
272                                 while(nliteProperty.gp.browserType == BT_NOSETTING){
273                                         ::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);
274                                         nliteProperty.CookieSetting();
275                                 }
276                         }
277                         
278                         nicoVideoAuth.SetBrowserType(nliteProperty.gp.browserType);
279                         
280                 }
281
282                 VOID Finalaize(){
283
284                         nliteProperty.cvp = commentView.GetProperty();
285                         nliteProperty.WriteIniFile();
286                 }
287
288                 VOID OnDestroy(){
289                         nicoLiveStream.DisConnect();
290                         commentView.DestroyWindow();
291                         
292                         PostQuitMessage(0);
293                         return;
294                 }
295
296                 VOID OnException(){
297
298                         nicoLiveStream.DisConnect();
299
300                 }
301
302                 //\83\81\83j\83\85\81[\82©\82ç\83t\83@\83C\83\8b\82ð\8fI\97¹\82ð\91I\91ð
303                 void OnMenuExit(UINT uNotifyCode, int nID, HWND hWndCtl){
304                         PostMessage(WM_CLOSE);
305                 }
306
307                 //\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¦
308                 void OnMenuAbount(UINT uNotifyCode,int nID,HWND hWndCtl){
309                 
310
311                         appInfo->show();
312                 }
313
314                 //\83N\83b\83L\81[\82Ì\90Ý\92è
315                 void OnCookie(UINT uNotifyCode,int nID,HWND hWndCtl){
316                         nliteProperty.CookieSetting();
317                         
318                         while(nliteProperty.gp.browserType == BT_NOSETTING){
319                                 ::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);
320                                 nliteProperty.CookieSetting();
321                         }
322                         
323
324                         nicoVideoAuth.SetBrowserType(nliteProperty.gp.browserType);
325
326                 }
327                 static NLIB_RESULT LiveCallBack(NICOLIVE_EVENT eventType,NicoLiveStream_P pNicoLiveStream,LPVOID option,NICOLIVE_PARAM param1,NICOLIVE_PARAM param2);
328
329                 
330         };
331
332
333
334
335         
336
337 }