OSDN Git Service

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