OSDN Git Service

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