source: dev/trunk/ab5.0/abdev/ProjectEditor/WebSearch.cpp@ 475

Last change on this file since 475 was 475, checked in by dai_9181, 17 years ago

構成管理を変更中・・・(いったんコミット)

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