source: dev/ProjectEditor/WebSearch.cpp@ 59

Last change on this file since 59 was 24, checked in by dai_9181, 18 years ago

保存されていないドキュメントのタブに(*)をつける機能に対応。
MDITEXTEDITINFOをCMdiTextEditに変更。今後、オブジェクト指向化を進める。

File size: 24.7 KB
Line 
1#include "common.h"
2#include "CIEsink.h"
3
4
5#define ID_TIMER_POPUP_ANIMATION 100
6#define ID_TIMER_IDLE 200
7
8extern FWINLAYER SetLayeredWindowAttributes;
9
10
11LRESULT CALLBACK ResultListProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam){
12 CResultList *pobj_ResultList;
13 POINT pos;
14 RECT rc;
15 int iItem;
16
17 switch(message){
18 case WM_TIMER:
19 if(wParam==ID_TIMER_POPUP_ANIMATION){
20 pobj_ResultList=(CResultList *)GetWindowLong(hwnd,GWL_USERDATA);
21
22 SetLayeredWindowAttributes(hwnd, 0,(int)((double)255/(double)100*(double)(pobj_ResultList->iAnimeCount*10)), LWA_ALPHA);
23
24 GetWindowRect(hwnd,&rc);
25 rc.top++;
26 SetWindowPos(hwnd,0,rc.left,rc.top,0,0,SWP_NOSIZE);
27
28 pobj_ResultList->iAnimeCount+=1;
29 if(pobj_ResultList->iAnimeCount>10){
30 KillTimer(hwnd,ID_TIMER_POPUP_ANIMATION);
31
32 SetTimer(hwnd,ID_TIMER_IDLE,100,NULL);
33 }
34 }
35 else if(wParam==ID_TIMER_IDLE){
36 InvalidateRect(hwnd,NULL,0);
37 }
38 return 0;
39 case WM_PAINT:
40 pobj_ResultList=(CResultList *)GetWindowLong(hwnd,GWL_USERDATA);
41
42 RECT ClientRect;
43 GetClientRect(hwnd,&ClientRect);
44
45 //描画を開始
46 HDC hdc;
47 PAINTSTRUCT ps;
48 hdc=BeginPaint(hwnd,&ps);
49
50 //メモリデバイスコンテキストを生成
51 HDC memdc;
52 HBITMAP hMemBmp;
53 memdc=CreateCompatibleDC(hdc);
54 hMemBmp=CreateCompatibleBitmap(hdc,ClientRect.right,ClientRect.bottom);
55 SelectObject(memdc,hMemBmp);
56
57 //フォントをセット
58 extern HFONT hStatusFont;
59 HFONT hOldFont;
60 hOldFont=(HFONT)SelectObject(memdc,hStatusFont);
61
62 //ウィンドウサイズを取得(アイテム座標を取得)
63 GetCursorPos(&pos);
64 GetWindowRect(hwnd,&rc);
65 rc.bottom=rc.top+LINK_ITEM_HEIGHT;
66
67 //クライアント アイテム 座標を取得
68 ClientRect.left+=10;
69 ClientRect.bottom=ClientRect.top+LINK_ITEM_HEIGHT;
70
71 //ブラシを生成
72 HBRUSH hFaceBrush,hShadowBrush,hOldBrush;
73 hFaceBrush=CreateSolidBrush(GetSysColor(COLOR_3DFACE));
74 hShadowBrush=CreateSolidBrush(GetSysColor(COLOR_3DSHADOW));
75
76 for(iItem=0;iItem<10;iItem++){
77 if(rc.left<pos.x && pos.x<rc.right && rc.top<pos.y && pos.y<rc.bottom){
78
79 SetBkColor(memdc,GetSysColor(COLOR_3DSHADOW));
80
81 hOldBrush=(HBRUSH)SelectObject(memdc,hShadowBrush);
82 }
83 else{
84 extern HFONT hStatusFont;
85 hOldFont=(HFONT)SelectObject(memdc,hStatusFont);
86
87 SetBkColor(memdc,GetSysColor(COLOR_3DFACE));
88
89 hOldBrush=(HBRUSH)SelectObject(memdc,hFaceBrush);
90 }
91 SetTextColor(memdc,RGB(0,0,255));
92
93 PatBlt(memdc,ClientRect.left-10,ClientRect.top,ClientRect.right,ClientRect.bottom,PATCOPY);
94 SelectObject(memdc,hOldBrush);
95
96 DrawText(memdc,pobj_ResultList->pobj_OneTab->lpszTitle[iItem],-1,&ClientRect,DT_LEFT|DT_VCENTER|DT_SINGLELINE);
97
98 rc.top+=LINK_ITEM_HEIGHT;
99 rc.bottom=rc.top+LINK_ITEM_HEIGHT;
100
101 ClientRect.top+=LINK_ITEM_HEIGHT;
102 ClientRect.bottom=ClientRect.top+LINK_ITEM_HEIGHT;
103 }
104
105 SelectObject(memdc,hOldFont);
106
107 GetClientRect(hwnd,&ClientRect);
108 BitBlt(hdc,0,0,ClientRect.right,ClientRect.bottom,memdc,0,0,SRCCOPY);
109
110 EndPaint(hwnd,&ps);
111
112 DeleteObject(hFaceBrush);
113 DeleteObject(hShadowBrush);
114
115 DeleteDC(memdc);
116 DeleteObject(hMemBmp);
117 break;
118
119 case WM_LBUTTONDOWN:
120 pobj_ResultList=(CResultList *)GetWindowLong(hwnd,GWL_USERDATA);
121
122 GetCursorPos(&pos);
123 GetWindowRect(hwnd,&rc);
124 rc.bottom=rc.top+LINK_ITEM_HEIGHT;
125
126 for(iItem=0;iItem<10;iItem++){
127 if(rc.left<pos.x && pos.x<rc.right && rc.top<pos.y && pos.y<rc.bottom){
128 ShellExecute(hwnd,"open",pobj_ResultList->pobj_OneTab->lpszUrl[iItem],NULL,NULL,SW_SHOWNORMAL);
129 break;
130 }
131
132 rc.top+=LINK_ITEM_HEIGHT;
133 rc.bottom=rc.top+LINK_ITEM_HEIGHT;
134 }
135 return 0;
136 }
137 return DefWindowProc(hwnd,message,wParam,lParam);
138}
139
140CResultList::CResultList(COneTab *pot){
141 pobj_OneTab=pot;
142 iAnimeCount=0;
143
144 hwnd=CreateWindowEx(0,"ResultList","ResultList",
145 WS_POPUP|WS_CLIPCHILDREN|WS_VISIBLE|WS_BORDER,
146 0,0,0,0,
147 hOwner,0,hInst,0);
148
149 //ウィンドウを半透明にする
150 int lStyle;
151 lStyle=GetWindowLong(hwnd,GWL_EXSTYLE) | WS_EX_LAYERED;
152 SetWindowLong(hwnd,GWL_EXSTYLE,lStyle);
153 SetLayeredWindowAttributes(hwnd, 0, 0, LWA_ALPHA);
154
155 SetWindowLong(hwnd,GWL_USERDATA,(long)this);
156 SetTimer(hwnd,ID_TIMER_POPUP_ANIMATION,10,NULL);
157 BringWindowToTop(hwnd);
158
159 RECT rc;
160 GetWindowRect(pobj_OneTab->hTabWnd,&rc);
161
162 HDC hdc;
163 hdc=GetDC(hwnd);
164
165 extern HFONT hStatusFont;
166 HFONT hOldFont;
167 hOldFont=(HFONT)SelectObject(hdc,hStatusFont);
168
169
170 //アイテム数を取得
171 int iItem,iMaxWidth=0;
172 for(iItem=0;iItem<10;iItem++){
173 if(pobj_OneTab->lpszTitle[iItem]==0){
174 break;
175 }
176
177 SIZE size;
178 GetTextExtentPoint32(hdc,pobj_OneTab->lpszTitle[iItem],lstrlen(pobj_OneTab->lpszTitle[iItem]),&size);
179
180 if(iMaxWidth<size.cx){
181 //最大幅を取得
182 iMaxWidth=size.cx;
183 }
184 }
185
186 SelectObject(hdc,hOldFont);
187 ReleaseDC(hwnd,hdc);
188
189 MoveWindow(hwnd,rc.left,rc.top-iItem*LINK_ITEM_HEIGHT-10,iMaxWidth+20,iItem*LINK_ITEM_HEIGHT,1);
190}
191CResultList::~CResultList(){
192 DestroyWindow(hwnd);
193}
194
195
196
197LRESULT CALLBACK OneTabProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam){
198 COneTab *pobj_OneTab;
199 RECT rc;
200 POINT pos;
201
202 switch(message){
203 case WM_CREATE:
204 SetTimer(hwnd,0,100,NULL);
205 return 0;
206 case WM_TIMER:
207 InvalidateRect(hwnd,NULL,0);
208 return 0;
209 case WM_PAINT:
210 pobj_OneTab=(COneTab *)GetWindowLong(hwnd,GWL_USERDATA);
211
212 HBRUSH hBrush,hOldBrush;
213
214 HDC hdc;
215 PAINTSTRUCT ps;
216 hdc=BeginPaint(hwnd,&ps);
217
218 GetCursorPos(&pos);
219 GetWindowRect(hwnd,&rc);
220 HFONT hOldFont;
221 if(rc.left<=pos.x && pos.x<=rc.right && rc.top<=pos.y && pos.y<=rc.bottom){
222 extern HFONT hStatusFont;
223 hOldFont=(HFONT)SelectObject(hdc,hStatusFont);
224
225 SetBkColor(hdc,GetSysColor(COLOR_3DSHADOW));
226
227 hBrush=CreateSolidBrush(GetSysColor(COLOR_3DSHADOW));
228
229 //リストを表示
230 if(pobj_OneTab->pobj_ResultList==0){
231 pobj_OneTab->pobj_ResultList=new CResultList(pobj_OneTab);
232 }
233 }
234 else{
235 extern HFONT hStatusFont;
236 hOldFont=(HFONT)SelectObject(hdc,hStatusFont);
237
238 SetBkColor(hdc,GetSysColor(COLOR_3DFACE));
239
240 hBrush=CreateSolidBrush(GetSysColor(COLOR_3DFACE));
241
242 //リストを破棄
243 if(pobj_OneTab->pobj_ResultList){
244 GetWindowRect(pobj_OneTab->pobj_ResultList->hwnd,&rc);
245 if(!(rc.left<=pos.x && pos.x<=rc.right && rc.top<=pos.y && pos.y<=rc.bottom)){
246 delete pobj_OneTab->pobj_ResultList;
247 pobj_OneTab->pobj_ResultList=0;
248 }
249 }
250 }
251 SetTextColor(hdc,RGB(0,0,255));
252
253 GetClientRect(hwnd,&rc);
254
255 hOldBrush=(HBRUSH)SelectObject(hdc,hBrush);
256 PatBlt(hdc,0,0,rc.right,rc.bottom,PATCOPY);
257 SelectObject(hdc,hOldBrush);
258
259 rc.left++;
260 DrawText(hdc,pobj_OneTab->lpszString,-1,&rc,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
261
262 SelectObject(hdc,hOldFont);
263
264 //左端の境界線
265 HPEN hPen,hOldPen;
266 hPen=CreatePen(PS_SOLID,0,GetSysColor(COLOR_3DSHADOW));
267 hOldPen=(HPEN)SelectObject(hdc,hPen);
268 MoveToEx(hdc,0,0,NULL);
269 LineTo(hdc,0,rc.bottom-rc.top);
270 SelectObject(hdc,hOldPen);
271 DeleteObject(hPen);
272
273 EndPaint(hwnd,&ps);
274
275 DeleteObject(hBrush);
276 return 0;
277 case WM_LBUTTONDOWN:
278 pobj_OneTab=(COneTab *)GetWindowLong(hwnd,GWL_USERDATA);
279
280 ShellExecute(hwnd,"open",pobj_OneTab->lpszUrl[0],NULL,NULL,SW_SHOWNORMAL);
281 return 0;
282
283 case WM_COMMAND:
284 break;
285 }
286 return DefWindowProc(hwnd,message,wParam,lParam);
287}
288
289COneTab::COneTab(int WndNum,char *str){
290 //0で初期化
291 memset(this,0,sizeof(COneTab));
292
293 m_WndNum=WndNum;
294
295 lpszString=(char *)malloc(lstrlen(str)+1);
296 lstrcpy(lpszString,str);
297
298
299 //Web検索をかける
300 WebSearch();
301
302
303
304 /////////////////////////////////
305 // テキストアイテムの幅を取得
306 /////////////////////////////////
307
308 HDC hdc;
309 SIZE size;
310 hdc=GetDC(hOwner);
311
312 extern HFONT hStatusFont;
313 HFONT hOldFont;
314 hOldFont=(HFONT)SelectObject(hdc,hStatusFont);
315
316 GetTextExtentPoint32(hdc,lpszString,lstrlen(lpszString),&size);
317
318 SelectObject(hdc,hOldFont);
319
320 ReleaseDC(hOwner,hdc);
321 iWindowWidth=size.cx+20;
322
323 if(MdiInfo[WndNum].pMdiTextEdit==0) return;
324 hTabWnd=(HWND)SendMessage(MdiInfo[WndNum].pMdiTextEdit->hEdit,WM_SEARCH_TAB_CREATE,(WPARAM)WndNum,(LPARAM)this);
325}
326COneTab::~COneTab(){
327 free(lpszString);
328
329 int i;
330 for(i=0;i<10;i++){
331 if(lpszTitle[i]) free(lpszTitle[i]);
332 if(lpszUrl[i]) free(lpszUrl[i]);
333 }
334
335 if(MdiInfo[m_WndNum].pMdiTextEdit)
336 SendMessage(MdiInfo[m_WndNum].pMdiTextEdit->hEdit,WM_SEARCH_TAB_CLOSE,0,(LPARAM)hTabWnd);
337}
338
339void COneTab::WebSearch(){
340 //URLエンコード
341 char *temporary;
342 temporary=(char *)malloc(lstrlen(lpszString)*3+1024);
343 wsprintf(temporary,"辞書 %s",lpszString);
344 URLEncode(temporary);
345
346 char *lpszTempUrl;
347 lpszTempUrl=(char *)malloc(lstrlen(temporary)+1024);
348 sprintf(lpszTempUrl,"http://www.activebasic.com/application_web_search/search.php?query=%s&type=web&utf_sw=1&start=1",temporary);
349
350 free(temporary);
351
352
353 HINTERNET hInternet;
354 HINTERNET hNetFile;
355 hInternet = InternetOpen("Agent", 0, NULL, NULL, 0);
356 if(hInternet==0){
357 return;
358 }
359 hNetFile = InternetOpenUrl(hInternet, lpszTempUrl, NULL, 0, 0, 0);
360 if(hNetFile==0){
361 InternetCloseHandle(hInternet);
362 return;
363 }
364
365 /* オープンしたURLからデータを(1000バイトずつ)読み込む */
366 DWORD dwReadSize;
367 BOOL bResult;
368 char *buffer;
369 buffer=(char *)malloc(8192);
370 buffer[0]=0;
371
372 while(1){
373 char temp3[1024];
374 bResult = InternetReadFile(
375 hNetFile,
376 temp3,
377 1000,
378 &dwReadSize);
379
380 /* 全て読み込んだらループを抜ける */
381 if(bResult && (dwReadSize == 0)) break;
382
383 temp3[dwReadSize]=0;
384 lstrcat(buffer,temp3);
385 }
386
387
388 //UTF-8からShift-JISに変換
389 char *temp2;
390 temp2=(char *)malloc(8192);
391 nkf.pSetNkfOption("-sx"); //Shift-JISに変換(xは半角カタカナを全角に変換しないオプション)
392 nkf.pNkfConvert(temp2,buffer);
393 free(buffer);
394
395
396 InternetCloseHandle(hNetFile);
397 InternetCloseHandle(hInternet);
398
399
400 //タイトル・URLを取得
401 int iItem;
402 int i=0,i2;
403 for(iItem=0;iItem<10;iItem++){
404 lpszTitle[iItem]=(char *)malloc(lstrlen(temp2)+1);
405 lpszUrl[iItem]=(char *)malloc(lstrlen(temp2)+1);
406 for(i2=0;;i++,i2++){
407 //タイトル
408 if(temp2[i]=='\n'||temp2[i]=='\0'){
409 lpszTitle[iItem][i2]=0;
410 break;
411 }
412 lpszTitle[iItem][i2]=temp2[i];
413 }
414 if(temp2[i]){
415 //URL
416 for(i++,i2=0;;i++,i2++){
417 if(temp2[i]=='\n'||temp2[i]=='\0'){
418 lpszUrl[iItem][i2]=0;
419 break;
420 }
421 lpszUrl[iItem][i2]=temp2[i];
422 }
423 }
424 if(temp2[i]){
425 //サマリー
426 for(i++,i2=0;;i++,i2++){
427 if(temp2[i]=='\n'||temp2[i]=='\0'){
428 break;
429 }
430 }
431 }
432
433 if(temp2[i]=='\0') break;
434 i++;
435 }
436
437
438 free(temp2);
439
440
441 free(lpszTempUrl);
442}
443
444
445
446
447
448
449LRESULT CALLBACK WebResultWndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam){
450 switch(message){
451 case WM_COMMAND:
452 break;
453 }
454 return DefWindowProc(hwnd,message,wParam,lParam);
455}
456
457CWebResult::CWebResult(HWND hParent){
458 ppobj_OneTab=(COneTab **)malloc(1);
459 iTabNum=0;
460
461 hwnd=CreateWindowEx(0,"WebResult","WebResult",
462 WS_CHILD|WS_CLIPCHILDREN|WS_VISIBLE,
463 0,0,0,0,
464 hParent,0,hInst,0);
465}
466CWebResult::~CWebResult(){
467 int i;
468 for(i=0;i<iTabNum;i++){
469 delete ppobj_OneTab[i];
470 }
471
472 free(ppobj_OneTab);
473 ppobj_OneTab=0;
474
475 DestroyWindow(hwnd);
476}
477
478void CWebResult::resize(int x,int y,int cx,int cy){
479 MoveWindow(hwnd,x,y,cx,cy,1);
480}
481
482void CWebResult::add(int WndNum,char *lpszSearchText){
483 COneTab *pobj_temp_OneTab;
484 pobj_temp_OneTab=new COneTab(WndNum,lpszSearchText);
485 if(MdiInfo[WndNum].pMdiTextEdit==0){
486 delete pobj_temp_OneTab;
487 return;
488 }
489
490 if(pobj_temp_OneTab->lpszTitle[0]){
491 if(pobj_temp_OneTab->lpszTitle[0][0]=='\0'){
492 delete pobj_temp_OneTab;
493 return;
494 }
495 }
496 else{
497 delete pobj_temp_OneTab;
498 return;
499 }
500
501
502 ppobj_OneTab=(COneTab **)realloc(ppobj_OneTab,(iTabNum+1)*sizeof(COneTab));
503
504 //ローテーション
505 int i;
506 for(i=iTabNum-1;i>=0;i--){
507 ppobj_OneTab[i+1]=ppobj_OneTab[i];
508 }
509
510 ppobj_OneTab[0]=pobj_temp_OneTab;
511 iTabNum++;
512
513 if(iTabNum==10){
514 //古いアイテムを破棄
515 delete ppobj_OneTab[iTabNum-1];
516 iTabNum--;
517 }
518
519 int offset=0;
520 for(i=0;i<iTabNum;i++){
521 offset+=ppobj_OneTab[i]->iWindowWidth;
522 }
523 for(i=iTabNum-1;i>=0;i--){
524 offset-=ppobj_OneTab[i]->iWindowWidth;
525 MoveWindow(ppobj_OneTab[i]->hTabWnd,
526 offset,
527 0,
528 ppobj_OneTab[i]->iWindowWidth,
529 20,
530 1);
531 }
532}
533BOOL CWebResult::DuplicateCheck(char *str){
534 int i;
535 for(i=0;i<iTabNum;i++){
536 if(lstrcmpi(ppobj_OneTab[i]->lpszString,str)==0){
537 return 1;
538 }
539 }
540 return 0;
541}
542
543
544
545BOOL bSearchingWeb;
546char *lpszRetrySearchStr;
547void WebSearchThread(void *temp_str){
548 char *str;
549 str=(char *)malloc(lstrlen((char *)temp_str)+1);
550 lstrcpy(str,(char *)temp_str);
551 HeapDefaultFree(temp_str);
552
553 int WndNum;
554 WndNum=GetWndNum(GetWindow(hClient,GW_CHILD));
555 if(bSearchingWeb){
556 if(lpszRetrySearchStr) free(lpszRetrySearchStr);
557 lpszRetrySearchStr=str;
558
559 _endthread();
560 return;
561 }
562 bSearchingWeb=1;
563
564
565wait_repeat:
566 Sleep(500);
567 if(lpszRetrySearchStr){
568 free(str);
569
570 str=lpszRetrySearchStr;
571 lpszRetrySearchStr=0;
572 goto wait_repeat;
573 }
574
575
576 if(WndNum==-1){
577 goto exit;
578 }
579 if(MdiInfo[WndNum].pMdiTextEdit==0){
580 goto exit;
581 }
582
583 //重複チェック
584 if(MdiInfo[WndNum].pMdiTextEdit->pobj_WebResult->DuplicateCheck(str)){
585 goto exit;
586 }
587
588
589
590 extern MDIINFO MdiInfo[MAX_WNDNUM];
591 MdiInfo[WndNum].pMdiTextEdit->pobj_WebResult->add(WndNum,str);
592
593exit:
594 bSearchingWeb=0;
595
596 free(str);
597
598
599 if(lpszRetrySearchStr){
600 str=lpszRetrySearchStr;
601 lpszRetrySearchStr=0;
602 goto wait_repeat;
603 }
604
605
606 _endthread();
607}
608
609
610
611
612////////////////////////////
613// 以下、SideWeb
614////////////////////////////
615
616CComModule _Module;
617
618BEGIN_OBJECT_MAP(ObjectMap)
619END_OBJECT_MAP()
620
621HWND hNowIEWnd;
622LRESULT CALLBACK SideWebProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
623{
624 CComQIPtr<IWebBrowser2> pWB2 ;
625
626 switch (iMsg)
627 {
628 case WM_CREATE :
629 {
630 AtlAxWinInit();
631 hNowIEWnd = CreateWindow("AtlAxWin", "Shell.Explorer.2", WS_CHILD|WS_VISIBLE, 0,0,0,0,
632 hwnd, (HMENU)0, hInst, NULL);
633 if(!hNowIEWnd){
634 MessageBox(hOwner,"IEコンポーネントの生成に失敗しました","lockey_browser",MB_OK|MB_ICONEXCLAMATION);
635 PostQuitMessage(0);
636 return 0;
637 }
638
639 // ActiveXコントロールのインターフェースを要求
640 CComPtr<IUnknown> punkIE;
641 if (AtlAxGetControl(hNowIEWnd, &punkIE) == S_OK)
642 {
643 // IUnknownポインタからIWebBrowser2ポインタへキャスト
644 pWB2 = punkIE;
645
646 if(pWB2)
647 {
648 // シンクオブジェクトの作成
649 CComObject<CIESink>* sink;
650 CComObject<CIESink>::CreateInstance(&sink);
651
652 // イベントをDispatchするよう、IEコントロールにお願い
653 HRESULT hr = sink->AdviseToIE(punkIE);
654 if(SUCCEEDED(hr))
655 {
656 //成功
657 return 0;
658 }
659 }
660
661 MessageBox(hOwner,"IEコンポーネントの生成に失敗しました","ProjectEditor",MB_OK|MB_ICONEXCLAMATION);
662 PostQuitMessage(0);
663 return 0;
664 }
665
666 return 0 ;
667 }
668
669 case WM_SIZE :
670 MoveWindow(GetWindow(hwnd,GW_CHILD), 0, 0, LOWORD(lParam), HIWORD(lParam), 1) ;
671 return 0 ;
672
673 case WM_KEYDOWN:
674 {
675 // ActiveXコントロールのインターフェースを要求
676 CComPtr<IUnknown> punkIE;
677 if (AtlAxGetControl(hNowIEWnd, &punkIE) == S_OK)
678 {
679 // IUnknownポインタからIWebBrowser2ポインタへキャスト
680 pWB2 = punkIE;
681
682 CComQIPtr<IOleInPlaceActiveObject, &IID_IOleInPlaceActiveObject> pIOIPAO(pWB2) ;
683
684 if(pIOIPAO)
685 {
686 MSG msg;
687 msg.message = iMsg;
688 msg.wParam = wParam;
689 msg.lParam = lParam;
690
691 pIOIPAO->TranslateAccelerator(&msg);
692 }
693
694 return 0 ;
695 }
696 }
697
698 case WM_BROWS_GO:
699
700 {
701 // ActiveXコントロールのインターフェースを要求
702 CComPtr<IUnknown> punkIE;
703 if (AtlAxGetControl(hNowIEWnd, &punkIE) == S_OK)
704 {
705 // IUnknownポインタからIWebBrowser2ポインタへキャスト
706 pWB2 = punkIE;
707
708 // URLへ移動
709 CComVariant vempty, vUrl((char *)lParam);
710 pWB2->Navigate2 (&vUrl, &vempty, &vempty, &vempty, &vempty );
711 }
712 }
713
714 return 0;
715
716 case WM_BROWS_DESTROY:
717 DestroyWindow(hwnd);
718 return 0;
719
720 case WM_DESTROY :
721 {
722 // ActiveXコントロールのインターフェースを要求
723 CComPtr<IUnknown> punkIE;
724 if (AtlAxGetControl(hNowIEWnd, &punkIE) == S_OK)
725 {
726 // IUnknownポインタからIWebBrowser2ポインタへキャスト
727 pWB2 = punkIE;
728
729 pWB2.Release();
730 }
731
732 }
733 return 0 ;
734 }
735
736 return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
737}
738
739CChildSideWeb::CChildSideWeb(HWND hParent,HWND hTab,char *title,char *site){
740 hwnd=CreateWindowEx(WS_EX_CLIENTEDGE,"SideWeb","SideWeb",
741 WS_CHILD|WS_CLIPCHILDREN,
742 0,0,0,0,
743 hParent,0,hInst,0);
744 hIEWnd=hNowIEWnd;
745
746 TC_ITEM tcItem;
747 tcItem.mask=TCIF_TEXT;
748
749 tcItem.pszText=title;
750 TabCtrl_InsertItem(hTab,SendMessage(hTab,TCM_GETITEMCOUNT,0,0),&tcItem);
751
752 //タイトル
753 lpszTitle=(char *)malloc(lstrlen(title)+1);
754 lstrcpy(lpszTitle,title);
755
756 //サイト
757 lpszSite=(char *)malloc(lstrlen(site)+1);
758 lstrcpy(lpszSite,site);
759}
760CChildSideWeb::~CChildSideWeb(){
761 free(lpszTitle);
762 free(lpszSite);
763 DestroyWindow(hwnd);
764}
765
766
767CSideWeb *pobj_SideWeb=0;
768
769CSideWeb::CSideWeb(HWND hParent){
770 lpszNowUrl=0;
771 bShow=0;
772
773 _Module.Init(ObjectMap, hInst);
774
775 //タブを生成
776 extern HFONT hStatusFont;
777 hTab=CreateWindowEx(0,WC_TABCONTROL,NULL,
778 WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS|WS_VISIBLE,
779 0,0,0,0,
780 hParent,0,hInst,0);
781 SendMessage(hTab,WM_SETFONT,(long)hStatusFont,0);
782
783 //→ボタンを生成
784 hRightButton=CreateWindow("BUTTON","→",WS_CHILD|WS_VISIBLE,
785 0,0,20,13,
786 hParent,(HMENU)IDC_CLIP,hInst,0);
787 SendMessage(hRightButton,WM_SETFONT,(long)hStatusFont,0);
788
789
790 iChildSideWebNum=pobj_nv->pobj_DBDomain->iDomainNum+1;
791 ppobj_ChildSideWeb=(CChildSideWeb **)malloc(iChildSideWebNum*sizeof(CChildSideWeb *));
792 ppobj_ChildSideWeb[0]=new CChildSideWeb(hParent,hTab,"全般","");
793 int i;
794 for(i=0;i<pobj_nv->pobj_DBDomain->iDomainNum;i++){
795 ppobj_ChildSideWeb[i+1]=new CChildSideWeb(hParent,hTab,
796 pobj_nv->pobj_DBDomain->ppobj_Domain[i]->lpszName,
797 pobj_nv->pobj_DBDomain->ppobj_Domain[i]->lpszDomain);
798 }
799
800
801 TabCtrl_SetCurSel(hTab,0);
802 ShowWindow(ppobj_ChildSideWeb[0]->hwnd,SW_SHOW);
803 hNowIEWnd=ppobj_ChildSideWeb[0]->hIEWnd;
804}
805CSideWeb::~CSideWeb(){
806 int i;
807 for(i=0;i<iChildSideWebNum;i++){
808 delete ppobj_ChildSideWeb[i];
809 }
810 free(ppobj_ChildSideWeb);
811 ppobj_ChildSideWeb=0;
812
813 if(lpszNowUrl) free(lpszNowUrl);
814
815 DestroyWindow(hTab);
816 DestroyWindow(hRightButton);
817}
818void CSideWeb::resize(int x,int y,int cx,int cy){
819 int iTabHeight=25;
820
821 MoveWindow(hTab,x,y,cx-30,iTabHeight,1);
822
823 SetWindowPos(hRightButton,NULL,x+cx-25,y+7,0,0,SWP_NOSIZE);
824
825 int i;
826 for(i=0;i<iChildSideWebNum;i++){
827 MoveWindow(ppobj_ChildSideWeb[i]->hwnd,x,y+iTabHeight,cx,cy-iTabHeight,1);
828 }
829
830 m_Rect.left=x;
831 m_Rect.top=y;
832 m_Rect.right=x+cx;
833 m_Rect.bottom=y+cy;
834}
835
836void CSideWeb::GoPage(char *lpszUrl){
837 char *pTemp;
838 pTemp=(char *)malloc(lstrlen(lpszUrl)+1);
839 lstrcpy(pTemp,lpszUrl);
840
841 if(lpszNowUrl) free(lpszNowUrl);
842 lpszNowUrl=pTemp;
843
844 int iTabPos;
845 iTabPos=SendMessage(hTab,TCM_GETCURSEL,0,0);
846
847
848 pTemp=(char *)malloc(lstrlen(lpszNowUrl)+1024);
849 if(ppobj_ChildSideWeb[iTabPos]->lpszSite[0])
850 sprintf(pTemp,"%s&site=%s",lpszNowUrl,ppobj_ChildSideWeb[iTabPos]->lpszSite);
851 else lstrcpy(pTemp,lpszNowUrl);
852
853 SendMessage(ppobj_ChildSideWeb[iTabPos]->hwnd,WM_BROWS_GO,0,(LPARAM)pTemp);
854
855 free(pTemp);
856
857 bShow=1;
858 ResizeOwnerWnd();
859}
860
861void CSideWeb::SelChangeEvent(){
862 extern MDIINFO MdiInfo[MAX_WNDNUM];
863 char temporary[MAX_PATH];
864
865 int i;
866 i=TabCtrl_GetCurSel(hTab);
867
868 TC_ITEM tcItem;
869 tcItem.mask=TCIF_TEXT;
870 tcItem.pszText=temporary;
871 tcItem.cchTextMax=MAX_PATH;
872 TabCtrl_GetItem(hTab,i,&tcItem);
873
874 for(i=0;i<iChildSideWebNum;i++){
875 ShowWindow(ppobj_ChildSideWeb[i]->hwnd,SW_HIDE);
876 }
877
878 for(i=0;i<iChildSideWebNum;i++){
879 if(lstrcmpi(temporary,ppobj_ChildSideWeb[i]->lpszTitle)==0){
880 ShowWindow(ppobj_ChildSideWeb[i]->hwnd,SW_SHOW);
881 hNowIEWnd=ppobj_ChildSideWeb[i]->hIEWnd;
882 GoPage(lpszNowUrl);
883 break;
884 }
885 }
886}
887
888void CSideWeb::GetRect(RECT *prc){
889 *prc=m_Rect;
890}
891
892
893
894
895
896CWebStrings obj_WebStrings;
897
898CWebStrings::CWebStrings(){
899 buffer=(char *)malloc(1);
900 buffer[0]=0;
901
902 ppStr=(char **)malloc(1);
903 iStrNum=0;
904}
905CWebStrings::~CWebStrings(){
906 free(buffer);
907
908 int i;
909 for(i=0;i<iStrNum;i++){
910 free(ppStr[i]);
911 }
912 free(ppStr);
913}
914
915void CWebStrings::add(char *query){
916 //重複チェック
917 int i;
918 for(i=0;i<iStrNum;i++){
919 if(lstrcmpi(ppStr[i],query)==0){
920 return;
921 }
922 }
923
924 ppStr=(char **)realloc(ppStr,(iStrNum+1)*sizeof(char *));
925 ppStr[iStrNum]=(char *)malloc(lstrlen(query)+1);
926 lstrcpy(ppStr[iStrNum],query);
927 iStrNum++;
928}
929
930void CWebStrings::clear(){
931 buffer[0]=0;
932
933 int i;
934 for(i=0;i<iStrNum;i++){
935 free(ppStr[i]);
936 }
937 iStrNum=0;
938}
939
940char *CWebStrings::GetBuffer(){
941 buffer[0]=0;
942 int i;
943 for(i=0;i<iStrNum;i++){
944 buffer=(char *)realloc(buffer,lstrlen(buffer)+lstrlen(ppStr[i])+2);
945 if(i) lstrcat(buffer," ");
946 lstrcat(buffer,ppStr[i]);
947 }
948 return buffer;
949}
950
951
952
953//////////////////////////
954// Web検索用ドメイン管理
955//////////////////////////
956
957CDomain::CDomain(char *name,char *domain){
958 //表示名
959 lpszName=(char *)HeapAlloc(hHeap,0,lstrlen(name)+1);
960 lstrcpy(lpszName,name);
961
962 //ドメイン
963 lpszDomain=(char *)HeapAlloc(hHeap,0,lstrlen(domain)+1);
964 lstrcpy(lpszDomain,domain);
965}
966CDomain::~CDomain(){
967 HeapDefaultFree(lpszName);
968 HeapDefaultFree(lpszDomain);
969}
970
971
972void CDBDomain::init(){
973 int i;
974 for(i=0;i<iDomainNum;i++){
975 delete ppobj_Domain[i];
976 }
977 iDomainNum=0;
978}
979CDBDomain::CDBDomain(){
980 ppobj_Domain=(CDomain **)HeapAlloc(hHeap,0,1);
981 iDomainNum=0;
982
983 m_hListView=0;
984}
985CDBDomain::~CDBDomain(){
986 init();
987 HeapDefaultFree(ppobj_Domain);
988}
989
990void CDBDomain::load(){
991 char temporary[MAX_PATH],temp2[MAX_PATH];
992 sprintf(temporary,"%sUserSetting\\domain.ini",pj_editor_Dir);
993
994 char *buffer;
995 buffer=ReadBuffer_NonErrMsg(temporary);
996 if(buffer){
997 int i;
998 i=0;
999 while(buffer[i]){
1000 //表示名
1001 i=GetOneParameter(buffer,i,temporary);
1002 if(temporary[0]=='\0') break;
1003
1004 //ドメイン
1005 i=GetOneParameter(buffer,i,temp2);
1006 if(temp2[0]=='\0') break;
1007
1008 if(buffer[i]=='\r'&&buffer[i+1]=='\n'){
1009 i+=2;
1010 }
1011
1012 add(temporary,temp2);
1013 }
1014 HeapDefaultFree(buffer);
1015 }
1016 else{
1017 add("辞書","ja.wikipedia.org");
1018 add("MSDN","msdn.microsoft.com");
1019 }
1020}
1021void CDBDomain::save(){
1022 char temporary[MAX_PATH];
1023 sprintf(temporary,"%sUserSetting\\domain.ini",pj_editor_Dir);
1024
1025 char *buffer;
1026 buffer=(char *)HeapAlloc(hHeap,0,iDomainNum*MAX_PATH*2+1);
1027 buffer[0]=0;
1028
1029 int i;
1030 for(i=0;i<iDomainNum;i++){
1031 sprintf(buffer+lstrlen(buffer),"%s,%s\r\n",ppobj_Domain[i]->lpszName,ppobj_Domain[i]->lpszDomain);
1032 }
1033
1034 WriteBuffer(temporary,buffer,lstrlen(buffer));
1035
1036 HeapDefaultFree(buffer);
1037}
1038
1039void CDBDomain::copy_get(CDBDomain *pobj_DBDomain){
1040 init();
1041
1042 int i;
1043 for(i=0;i<pobj_DBDomain->iDomainNum;i++){
1044 add(pobj_DBDomain->ppobj_Domain[i]->lpszName,pobj_DBDomain->ppobj_Domain[i]->lpszDomain);
1045 }
1046}
1047
1048void CDBDomain::SetListView(HWND hListView){
1049 m_hListView=hListView;
1050
1051 int i;
1052 for(i=0;i<iDomainNum;i++){
1053 LV_ITEM item;
1054
1055 item.mask=LVIF_TEXT;
1056 item.pszText=ppobj_Domain[i]->lpszName;
1057 item.iItem=i;
1058 item.iSubItem=0;
1059 ListView_InsertItem(m_hListView,&item);
1060
1061 item.pszText=ppobj_Domain[i]->lpszDomain;
1062 item.iItem=i;
1063 item.iSubItem++;
1064 ListView_SetItem(m_hListView,&item);
1065 }
1066}
1067
1068void CDBDomain::add(char *name,char *domain){
1069 ppobj_Domain=(CDomain **)HeapReAlloc(hHeap,0,ppobj_Domain,(iDomainNum+1)*sizeof(CDomain *));
1070 ppobj_Domain[iDomainNum]=new CDomain(name,domain);
1071 iDomainNum++;
1072
1073
1074 if(m_hListView){
1075 int i;
1076 i=ListView_GetItemCount(m_hListView);
1077
1078 //リストビューに追加
1079 LV_ITEM item;
1080 item.mask=LVIF_TEXT;
1081 item.pszText=name;
1082 item.iItem=i;
1083 item.iSubItem=0;
1084 ListView_InsertItem(m_hListView,&item);
1085
1086 item.pszText=domain;
1087 item.iItem=i;
1088 item.iSubItem++;
1089 ListView_SetItem(m_hListView,&item);
1090 }
1091}
1092void CDBDomain::del(char *name){
1093 int i;
1094 for(i=0;i<iDomainNum;i++){
1095 if(lstrcmp(ppobj_Domain[i]->lpszName,name)==0) break;
1096 }
1097 if(i==iDomainNum) return;
1098
1099 if(m_hListView){
1100 //リストビューから削除
1101 ListView_DeleteItem(m_hListView,i);
1102 }
1103
1104 delete ppobj_Domain[i];
1105 iDomainNum--;
1106 for(;i<iDomainNum;i++){
1107 ppobj_Domain[i]=ppobj_Domain[i+1];
1108 }
1109}
1110void CDBDomain::change(char *szBeforeName,char *name,char *domain){
1111 int i;
1112 for(i=0;i<iDomainNum;i++){
1113 if(lstrcmp(ppobj_Domain[i]->lpszName,szBeforeName)==0) break;
1114 }
1115 if(i==iDomainNum) return;
1116
1117 ppobj_Domain[i]->lpszName=(char *)HeapReAlloc(hHeap,0,ppobj_Domain[i]->lpszName,lstrlen(name)+1);
1118 lstrcpy(ppobj_Domain[i]->lpszName,name);
1119
1120 ppobj_Domain[i]->lpszDomain=(char *)HeapReAlloc(hHeap,0,ppobj_Domain[i]->lpszDomain,lstrlen(domain)+1);
1121 lstrcpy(ppobj_Domain[i]->lpszDomain,domain);
1122
1123
1124 if(m_hListView){
1125 //リストビューの設定
1126 ListView_SetItemText(m_hListView,i,0,name);
1127 ListView_SetItemText(m_hListView,i,1,domain);
1128 }
1129}
Note: See TracBrowser for help on using the repository browser.