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

Last change on this file since 489 was 489, checked in by dai_9181, 15 years ago

abdevをATL化するための下準備

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
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    TODO: ここをしっかりしないと動きませーん
774    extern CComModule _Module;
775    _Module.Init(ObjectMap, hInst);
776*/
777
778    //タブを生成
779    extern HFONT hStatusFont;
780    hTab=CreateWindowEx(0,WC_TABCONTROL,NULL,
781        WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS|WS_VISIBLE,
782        0,0,0,0,
783        hParent,0,hInst,0);
784    SendMessage(hTab,WM_SETFONT,(long)hStatusFont,0);
785
786    //→ボタンを生成
787    hRightButton=CreateWindow("BUTTON","→",WS_CHILD|WS_VISIBLE,
788        0,0,20,13,
789        hParent,(HMENU)IDC_CLIP,hInst,0);
790    SendMessage(hRightButton,WM_SETFONT,(long)hStatusFont,0);
791
792
793    iChildSideWebNum=pobj_nv->pobj_DBDomain->iDomainNum+1;
794    ppobj_ChildSideWeb=(CChildSideWeb **)malloc(iChildSideWebNum*sizeof(CChildSideWeb *));
795    ppobj_ChildSideWeb[0]=new CChildSideWeb(hParent,hTab,"全般","");
796    int i;
797    for(i=0;i<pobj_nv->pobj_DBDomain->iDomainNum;i++){
798        ppobj_ChildSideWeb[i+1]=new CChildSideWeb(hParent,hTab,
799            pobj_nv->pobj_DBDomain->ppobj_Domain[i]->lpszName,
800            pobj_nv->pobj_DBDomain->ppobj_Domain[i]->lpszDomain);
801    }
802
803
804    TabCtrl_SetCurSel(hTab,0);
805    ShowWindow(ppobj_ChildSideWeb[0]->hwnd,SW_SHOW);
806    hNowIEWnd=ppobj_ChildSideWeb[0]->hIEWnd;
807}
808CSideWeb::~CSideWeb(){
809    int i;
810    for(i=0;i<iChildSideWebNum;i++){
811        delete ppobj_ChildSideWeb[i];
812    }
813    free(ppobj_ChildSideWeb);
814    ppobj_ChildSideWeb=0;
815
816    if(lpszNowUrl) free(lpszNowUrl);
817
818    DestroyWindow(hTab);
819    DestroyWindow(hRightButton);
820}
821void CSideWeb::resize(int x,int y,int cx,int cy){
822    int iTabHeight=25;
823
824    MoveWindow(hTab,x,y,cx-30,iTabHeight,1);
825
826    SetWindowPos(hRightButton,NULL,x+cx-25,y+7,0,0,SWP_NOSIZE);
827
828    int i;
829    for(i=0;i<iChildSideWebNum;i++){
830        MoveWindow(ppobj_ChildSideWeb[i]->hwnd,x,y+iTabHeight,cx,cy-iTabHeight,1);
831    }
832
833    m_Rect.left=x;
834    m_Rect.top=y;
835    m_Rect.right=x+cx;
836    m_Rect.bottom=y+cy;
837}
838
839void CSideWeb::GoPage(char *lpszUrl){
840    char *pTemp;
841    pTemp=(char *)malloc(lstrlen(lpszUrl)+1);
842    lstrcpy(pTemp,lpszUrl);
843
844    if(lpszNowUrl) free(lpszNowUrl);
845    lpszNowUrl=pTemp;
846
847    int iTabPos;
848    iTabPos=SendMessage(hTab,TCM_GETCURSEL,0,0);
849
850
851    pTemp=(char *)malloc(lstrlen(lpszNowUrl)+1024);
852    if(ppobj_ChildSideWeb[iTabPos]->lpszSite[0])
853        sprintf(pTemp,"%s&site=%s",lpszNowUrl,ppobj_ChildSideWeb[iTabPos]->lpszSite);
854    else lstrcpy(pTemp,lpszNowUrl);
855
856    SendMessage(ppobj_ChildSideWeb[iTabPos]->hwnd,WM_BROWS_GO,0,(LPARAM)pTemp);
857
858    free(pTemp);
859
860    bShow=1;
861    ResizeOwnerWnd();   
862}
863
864void CSideWeb::SelChangeEvent(){
865    extern MDIINFO MdiInfo[MAX_WNDNUM];
866    char temporary[MAX_PATH];
867
868    int i;
869    i=TabCtrl_GetCurSel(hTab);
870
871    TC_ITEM tcItem;
872    tcItem.mask=TCIF_TEXT;
873    tcItem.pszText=temporary;
874    tcItem.cchTextMax=MAX_PATH;
875    TabCtrl_GetItem(hTab,i,&tcItem);
876
877    for(i=0;i<iChildSideWebNum;i++){
878        ShowWindow(ppobj_ChildSideWeb[i]->hwnd,SW_HIDE);
879    }
880
881    for(i=0;i<iChildSideWebNum;i++){
882        if(lstrcmpi(temporary,ppobj_ChildSideWeb[i]->lpszTitle)==0){
883            ShowWindow(ppobj_ChildSideWeb[i]->hwnd,SW_SHOW);
884            hNowIEWnd=ppobj_ChildSideWeb[i]->hIEWnd;
885            GoPage(lpszNowUrl);
886            break;
887        }
888    }
889}
890
891void CSideWeb::GetRect(RECT *prc){
892    *prc=m_Rect;
893}
894
895
896
897
898
899CWebStrings obj_WebStrings;
900
901CWebStrings::CWebStrings(){
902    buffer=(char *)malloc(1);
903    buffer[0]=0;
904
905    ppStr=(char **)malloc(1);
906    iStrNum=0;
907}
908CWebStrings::~CWebStrings(){
909    free(buffer);
910
911    int i;
912    for(i=0;i<iStrNum;i++){
913        free(ppStr[i]);
914    }
915    free(ppStr);
916}
917
918void CWebStrings::add(char *query){
919    //重複チェック
920    int i;
921    for(i=0;i<iStrNum;i++){
922        if(lstrcmpi(ppStr[i],query)==0){
923            return;
924        }
925    }
926
927    ppStr=(char **)realloc(ppStr,(iStrNum+1)*sizeof(char *));
928    ppStr[iStrNum]=(char *)malloc(lstrlen(query)+1);
929    lstrcpy(ppStr[iStrNum],query);
930    iStrNum++;
931}
932
933void CWebStrings::clear(){
934    buffer[0]=0;
935
936    int i;
937    for(i=0;i<iStrNum;i++){
938        free(ppStr[i]);
939    }
940    iStrNum=0;
941}
942
943char *CWebStrings::GetBuffer(){
944    buffer[0]=0;
945    int i;
946    for(i=0;i<iStrNum;i++){
947        buffer=(char *)realloc(buffer,lstrlen(buffer)+lstrlen(ppStr[i])+2);
948        if(i) lstrcat(buffer," ");
949        lstrcat(buffer,ppStr[i]);
950    }
951    return buffer;
952}
953
954
955
956//////////////////////////
957// Web検索用ドメイン管理
958//////////////////////////
959
960CDomain::CDomain(char *name,char *domain){
961    //表示名
962    lpszName=(char *)HeapAlloc(hHeap,0,lstrlen(name)+1);
963    lstrcpy(lpszName,name);
964
965    //ドメイン
966    lpszDomain=(char *)HeapAlloc(hHeap,0,lstrlen(domain)+1);
967    lstrcpy(lpszDomain,domain);
968}
969CDomain::~CDomain(){
970    HeapDefaultFree(lpszName);
971    HeapDefaultFree(lpszDomain);
972}
973
974
975void CDBDomain::init(){
976    int i;
977    for(i=0;i<iDomainNum;i++){
978        delete ppobj_Domain[i];
979    }
980    iDomainNum=0;
981}
982CDBDomain::CDBDomain(){
983    ppobj_Domain=(CDomain **)HeapAlloc(hHeap,0,1);
984    iDomainNum=0;
985
986    m_hListView=0;
987}
988CDBDomain::~CDBDomain(){
989    init();
990    HeapDefaultFree(ppobj_Domain);
991}
992
993void CDBDomain::load(){
994    char temporary[MAX_PATH],temp2[MAX_PATH];
995    sprintf(temporary,"%sUserSetting\\domain.ini",pj_editor_Dir);
996
997    char *buffer;
998    buffer=ReadBuffer_NonErrMsg(temporary);
999    if(buffer){
1000        int i;
1001        i=0;
1002        while(buffer[i]){
1003            //表示名
1004            i=GetOneParameter(buffer,i,temporary);
1005            if(temporary[0]=='\0') break;
1006
1007            //ドメイン
1008            i=GetOneParameter(buffer,i,temp2);
1009            if(temp2[0]=='\0') break;
1010
1011            if(buffer[i]=='\r'&&buffer[i+1]=='\n'){
1012                i+=2;
1013            }
1014
1015            add(temporary,temp2);
1016        }
1017        HeapDefaultFree(buffer);
1018    }
1019    else{
1020        add("辞書","ja.wikipedia.org");
1021        add("MSDN","msdn.microsoft.com");
1022    }
1023}
1024void CDBDomain::save(){
1025    char temporary[MAX_PATH];
1026    sprintf(temporary,"%sUserSetting\\domain.ini",pj_editor_Dir);
1027
1028    char *buffer;
1029    buffer=(char *)HeapAlloc(hHeap,0,iDomainNum*MAX_PATH*2+1);
1030    buffer[0]=0;
1031
1032    int i;
1033    for(i=0;i<iDomainNum;i++){
1034        sprintf(buffer+lstrlen(buffer),"%s,%s\r\n",ppobj_Domain[i]->lpszName,ppobj_Domain[i]->lpszDomain);
1035    }
1036
1037    WriteBuffer(temporary,buffer,lstrlen(buffer));
1038
1039    HeapDefaultFree(buffer);
1040}
1041
1042void CDBDomain::copy_get(CDBDomain *pobj_DBDomain){
1043    init();
1044
1045    int i;
1046    for(i=0;i<pobj_DBDomain->iDomainNum;i++){
1047        add(pobj_DBDomain->ppobj_Domain[i]->lpszName,pobj_DBDomain->ppobj_Domain[i]->lpszDomain);
1048    }
1049}
1050
1051void CDBDomain::SetListView(HWND hListView){
1052    m_hListView=hListView;
1053
1054    int i;
1055    for(i=0;i<iDomainNum;i++){
1056        LV_ITEM item;
1057
1058        item.mask=LVIF_TEXT;
1059        item.pszText=ppobj_Domain[i]->lpszName;
1060        item.iItem=i;
1061        item.iSubItem=0;
1062        ListView_InsertItem(m_hListView,&item);
1063
1064        item.pszText=ppobj_Domain[i]->lpszDomain;
1065        item.iItem=i;
1066        item.iSubItem++;
1067        ListView_SetItem(m_hListView,&item);
1068    }
1069}
1070
1071void CDBDomain::add(char *name,char *domain){
1072    ppobj_Domain=(CDomain **)HeapReAlloc(hHeap,0,ppobj_Domain,(iDomainNum+1)*sizeof(CDomain *));
1073    ppobj_Domain[iDomainNum]=new CDomain(name,domain);
1074    iDomainNum++;
1075
1076
1077    if(m_hListView){
1078        int i;
1079        i=ListView_GetItemCount(m_hListView);
1080
1081        //リストビューに追加
1082        LV_ITEM item;
1083        item.mask=LVIF_TEXT;
1084        item.pszText=name;
1085        item.iItem=i;
1086        item.iSubItem=0;
1087        ListView_InsertItem(m_hListView,&item);
1088
1089        item.pszText=domain;
1090        item.iItem=i;
1091        item.iSubItem++;
1092        ListView_SetItem(m_hListView,&item);
1093    }
1094}
1095void CDBDomain::del(char *name){
1096    int i;
1097    for(i=0;i<iDomainNum;i++){
1098        if(lstrcmp(ppobj_Domain[i]->lpszName,name)==0) break;
1099    }
1100    if(i==iDomainNum) return;
1101
1102    if(m_hListView){
1103        //リストビューから削除
1104        ListView_DeleteItem(m_hListView,i);
1105    }
1106
1107    delete ppobj_Domain[i];
1108    iDomainNum--;
1109    for(;i<iDomainNum;i++){
1110        ppobj_Domain[i]=ppobj_Domain[i+1];
1111    }
1112}
1113void CDBDomain::change(char *szBeforeName,char *name,char *domain){
1114    int i;
1115    for(i=0;i<iDomainNum;i++){
1116        if(lstrcmp(ppobj_Domain[i]->lpszName,szBeforeName)==0) break;
1117    }
1118    if(i==iDomainNum) return;
1119
1120    ppobj_Domain[i]->lpszName=(char *)HeapReAlloc(hHeap,0,ppobj_Domain[i]->lpszName,lstrlen(name)+1);
1121    lstrcpy(ppobj_Domain[i]->lpszName,name);
1122
1123    ppobj_Domain[i]->lpszDomain=(char *)HeapReAlloc(hHeap,0,ppobj_Domain[i]->lpszDomain,lstrlen(domain)+1);
1124    lstrcpy(ppobj_Domain[i]->lpszDomain,domain);
1125
1126
1127    if(m_hListView){
1128        //リストビューの設定
1129        ListView_SetItemText(m_hListView,i,0,name);
1130        ListView_SetItemText(m_hListView,i,1,domain);
1131    }
1132}
Note: See TracBrowser for help on using the repository browser.