OSDN Git Service

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