home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / urlbar.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  28.0 KB  |  1,167 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #include "stdafx.h"
  20. #include "mainfrm.h"
  21. #include "urlbar.h"
  22. #include "cxdc.h"
  23. #include "custom.h"
  24. #include "dropmenu.h"
  25. #include "hk_funcs.h"
  26. #include "prefapi.h"
  27. #include "glhist.h"
  28.  
  29. extern void wfe_Progress(MWContext *pContext, const char *pMessage);
  30.  
  31. #ifdef _DEBUG
  32. #undef THIS_FILE
  33. static char BASED_CODE THIS_FILE[] = __FILE__;
  34. #endif
  35.  
  36.  
  37. /****************************************************************************
  38. *
  39. *    CONSTANTS
  40. *
  41. ****************************************************************************/
  42.  
  43. // Positions/dimensions for certain widgets (page rep icon, quick file button)
  44.  
  45. static const int DRAG_ICON_WIDTH = 16;
  46. static const int DRAG_ICON_HEIGHT = 15;
  47.  
  48. static const int BOOKMARKS_TEXT_LEFT = 10;
  49.  
  50. BEGIN_MESSAGE_MAP(CURLBar, CURLBarBase) 
  51.     //{{AFX_MSG_MAP(CURLBar)
  52.     ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateEditCopy)
  53.     ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, OnUpdateEditCut)
  54.     ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdateEditPaste)
  55.     ON_UPDATE_COMMAND_UI(ID_EDIT_UNDO, OnUpdateEditUndo)
  56.     ON_WM_MOUSEMOVE()
  57.     ON_WM_LBUTTONDBLCLK()
  58.     ON_WM_CREATE()
  59.     ON_WM_DESTROY()
  60.     ON_WM_CLOSE()
  61.     ON_WM_LBUTTONDOWN()
  62.     ON_WM_SIZE()
  63.     ON_WM_PAINT()
  64.     ON_WM_SHOWWINDOW()
  65.     ON_WM_ERASEBKGND()
  66.     ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
  67.     ON_COMMAND(ID_EDIT_CUT, OnEditCut)
  68.     ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
  69.     ON_COMMAND(ID_EDIT_UNDO, OnEditUndo)
  70.     ON_WM_LBUTTONUP()
  71.     ON_WM_CTLCOLOR()
  72.     ON_WM_PALETTECHANGED()
  73.     //}}AFX_MSG_MAP
  74. END_MESSAGE_MAP()
  75.  
  76. #ifndef _AFXDLL
  77. #undef new
  78. #endif
  79. IMPLEMENT_DYNCREATE(CURLBar, CURLBarBase)
  80. #ifndef _AFXDLL
  81. #define new DEBUG_NEW  // MSVC Debugging new...goes to regular new in release mode
  82. #endif
  83.  
  84. // Buffers to hold all of the bitmaps.  Freed when the last URL bar
  85. //   gets destructed
  86. //
  87. static int numberOfUrlBars = 0;
  88. static CBitmap * pDragURLBitmap = NULL;
  89.  
  90. /////////////////////////////////////////////////////////////////////////////
  91. // CURLBar dialog
  92.  
  93. CURLBar::CURLBar(): CURLBarBase(),
  94.     m_cpLBDown(0,0),
  95.     m_DragIconY(0)
  96. {
  97.     m_pBox = NULL;
  98.     m_pIMWContext = NULL;
  99.     m_nTextStatus = TRUE; // == "location" is displayed
  100.     m_bAddToDropList = FALSE;
  101.  
  102.     m_pFont = NULL;
  103.     m_DragIconX = 0;
  104.     m_pPageProxy = NULL;
  105.     m_hBackgroundBrush = CreateSolidBrush(RGB(192, 192, 192));
  106.     numberOfUrlBars++;
  107.     m_nBoxHeight = 0;
  108. }
  109.  
  110. void CURLBar::SetContext( LPUNKNOWN pUnk )
  111. {
  112.     if (m_pIMWContext) {
  113.         m_pIMWContext->Release();
  114.         m_pIMWContext = NULL;
  115.     }
  116.     if (pUnk)
  117.     {
  118.         pUnk->QueryInterface( IID_IMWContext, (LPVOID *) &m_pIMWContext );
  119.         m_pPageProxy->SetContext(pUnk);
  120.     }
  121. }
  122.  
  123. LRESULT CURLBar::WindowProc( UINT message, WPARAM wParam, LPARAM lParam )
  124. {
  125.     if ( ( message == WM_COMMAND ) &&
  126. #ifdef WIN32
  127.         ( LOWORD( wParam ) == IDC_URL_EDIT ) )
  128.             switch ( HIWORD ( wParam ) )
  129. #else
  130.         ( wParam == IDC_URL_EDIT ) )
  131.             switch ( HIWORD ( lParam ) )      
  132. #endif
  133.     {
  134.         case CBN_EDITCHANGE:
  135.             OnEditChange ( );
  136.             break;
  137.  
  138.         case CBN_SELCHANGE:
  139.             OnSelChange ( );
  140.             Invalidate(FALSE);
  141.             break;
  142.  
  143.         case CBN_CLOSEUP:
  144.             Invalidate(FALSE);
  145.             break;
  146.  
  147.     }
  148.     return CURLBarBase::WindowProc ( message, wParam, lParam );
  149. }
  150.  
  151.  
  152. void CURLBar::OnLButtonDown(UINT nFlags, CPoint point)
  153. {
  154.     CDialogBar::OnLButtonDown(nFlags, point);
  155.  
  156.     int load = FALSE;
  157.  
  158.     if (!m_pIMWContext) 
  159.         return;
  160.  
  161.     MapWindowPoints(GetParent(), &point, 1);
  162.     GetParent()->SendMessage(WM_LBUTTONDOWN, nFlags, MAKELPARAM(point.x, point.y));
  163.  
  164.  
  165. }
  166.  
  167. HBRUSH CURLBar::OnCtlColor( CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  168. {
  169.   return CURLBarBase::OnCtlColor(pDC, pWnd, nCtlColor);
  170. }
  171.  
  172. void CURLBar::OnPaint() 
  173.  
  174. {
  175.     CURLBarBase::OnPaint ( );
  176.  
  177.     CClientDC dc(this);
  178.  
  179.     CRect rcClient;
  180.  
  181.     GetClientRect(&rcClient);
  182.     
  183.     HPALETTE hPalette = WFE_GetUIPalette(GetParentFrame());
  184.     HPALETTE hOldPalette = ::SelectPalette(dc.m_hDC, hPalette, FALSE);
  185.  
  186.     // Use our background color
  187.     ::FillRect(dc.m_hDC, &rcClient, sysInfo.m_hbrBtnFace);
  188.  
  189. #ifdef _WIN32
  190.     if ( sysInfo.m_bWin4 )
  191.         m_pBox->SetFont( CFont::FromHandle ( (HFONT) GetStockObject (DEFAULT_GUI_FONT) ) );
  192.     else 
  193. #endif
  194.     if ( !sysInfo.m_bDBCS )
  195.         m_pBox->SetFont ( CFont::FromHandle ( (HFONT) GetStockObject ( ANSI_VAR_FONT ) ) );
  196.     else
  197.     {
  198.         ASSERT(m_pFont != NULL);
  199.         ::SendMessage(m_pBox->GetSafeHwnd(), WM_SETFONT, (WPARAM)m_pFont, FALSE);
  200.     }
  201.     m_pBox->UpdateWindow ( );
  202.  
  203.      if ( !sysInfo.m_bWin4 )
  204.      {
  205.          // Draw 3D frame around URL box
  206.  
  207.         RECT rect;
  208.         m_pBox->GetWindowRect ( &rect );
  209.         rect.right++;
  210.         rect.bottom++;
  211.         rect.left--;
  212.         rect.top--;
  213.  
  214.         ScreenToClient ( &rect );
  215.         rect.right--;
  216.         rect.bottom--;
  217.  
  218.         RECT rcTmp = rect;
  219.         ::InflateRect( &rcTmp, -1, -1 );
  220.     
  221.         WFE_DrawHighlight( dc.m_hDC, &rcTmp, 
  222.                    RGB(128, 128, 128), 
  223.                    RGB(0, 0, 0));
  224.         WFE_DrawHighlight( dc.m_hDC, &rect, 
  225.                    RGB(192, 192, 192), 
  226.                    RGB(231, 231, 231) );
  227.     }
  228.  
  229.     ::SelectPalette(dc.m_hDC, hOldPalette, TRUE);
  230.  
  231. }
  232.  
  233. void CURLBar::OnShowWindow( BOOL bShow, UINT nStatus )
  234. {
  235.     m_bEraseBackground = bShow;
  236. }
  237.  
  238. BOOL CURLBar::OnEraseBkgnd( CDC* pDC )
  239. {
  240.     if ( m_bEraseBackground ) {
  241.         m_bEraseBackground = FALSE;
  242.         return (BOOL) Default();
  243.     } else {
  244.         return TRUE;
  245.     }
  246. }
  247.  
  248.  
  249. #define TOTAL_SAVED_URLS        15
  250. #define TOTAL_DISPLAYED_URLS    10
  251.  
  252. int CURLBar::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  253. {
  254.     int nRtn = CURLBarBase::OnCreate(lpCreateStruct);
  255.  
  256.     if (nRtn != -1)
  257.     {
  258.         CRect rect(0,0,0,0);
  259.  
  260.         // Create the proxy container
  261.         m_pProxySurround = new CProxySurroundWnd();
  262.         m_pProxySurround->Create(this);
  263.  
  264.         // Create the page proxy
  265.         m_pPageProxy = new CPageProxyWindow;
  266.         m_pPageProxy->Create(m_pProxySurround);
  267.  
  268.         // Create the edit box
  269.         m_pBox = new CEditWnd(this);
  270.         m_pBox->Create(
  271.             WS_CHILD|WS_VISIBLE|WS_TABSTOP,
  272.             rect, (CWnd *) m_pProxySurround, IDC_URL_EDIT);
  273.         
  274.     }
  275.  
  276.     return(nRtn);
  277. }
  278.  
  279. void CURLBar::OnDestroy( )
  280. {
  281.     CWnd::OnDestroy();
  282. }
  283.   
  284.  
  285. void CURLBar::OnClose()
  286. {
  287. }
  288.  
  289. void CURLBar::OnPaletteChanged( CWnd* pFocusWnd )
  290. {
  291.     if (pFocusWnd != this) {
  292.         HPALETTE hPalette = WFE_GetUIPalette(GetParentFrame());
  293.         if (WFE_IsGlobalPalette(hPalette)) {
  294.             HDC hDC = ::GetDC(m_hWnd);
  295.             HPALETTE hOldPalette = ::SelectPalette(hDC, hPalette, FALSE);
  296.             ::SelectPalette(hDC, hOldPalette, TRUE);
  297.             ::ReleaseDC(m_hWnd, hDC);
  298.         }
  299.         Invalidate();
  300.     }
  301. }
  302.  
  303.  
  304.  
  305. CURLBar::~CURLBar()
  306. {
  307.     delete m_pBox;
  308.     if (m_pFont) {
  309.         theApp.ReleaseAppFont(m_pFont);
  310.     }
  311.     delete m_pPageProxy;
  312.  
  313.     ::DeleteObject(m_hBackgroundBrush);
  314.     // decrease reference count
  315.     // if we are the last one delete all of the bitmaps
  316.     if(0 == --numberOfUrlBars) {
  317.         delete pDragURLBitmap;
  318.         pDragURLBitmap = NULL;
  319.     }
  320.  
  321. }
  322.  
  323. void CURLBar::DoDataExchange(CDataExchange* pDX)
  324. {
  325.     CURLBarBase::DoDataExchange(pDX);
  326.     //{{AFX_DATA_MAP(CURLBar)
  327.     //}}AFX_DATA_MAP
  328. }
  329.  
  330. /////////////////////////////////////////////////////////////////////////////
  331. // CURLBar message handlers
  332.  
  333. void CURLBar::OnSize(UINT nType, int cx, int cy)
  334. {
  335.  
  336.     int txtSpacing;
  337.     int boxSpacing;
  338.     CRect rcURLtext, rcIcon, bookmarkRect;
  339.     int x = BOOKMARKS_TEXT_LEFT;
  340.     
  341.     CWnd *pText = GetDlgItem( IDC_URLTEXT );
  342.  
  343.     if (pText) {
  344.         pText->GetWindowRect(&rcURLtext);
  345.         // figure out how big we need to make the box
  346.         CDC * pDC = m_pBox->GetDC();
  347.         
  348.         TEXTMETRIC tm;
  349.  
  350.         // creates font for multibyte system running on WinNT and Win16 
  351.         // on Win95, m_pFont should point to DEFAULT_GUI_FONT
  352.         // on single byte NT or win16, it should point to ANSI_VAR_FONT
  353. #ifdef XP_WIN32
  354.         if (sysInfo.m_bWin4 == TRUE)
  355.             m_pBox->SetFont( CFont::FromHandle ( (HFONT) GetStockObject (DEFAULT_GUI_FONT) ) );
  356.         else 
  357. #endif
  358.         if (sysInfo.m_bDBCS == FALSE)
  359.             m_pBox->SetFont ( CFont::FromHandle ( (HFONT) GetStockObject ( ANSI_VAR_FONT ) ) );
  360.         else {
  361.             if (m_pFont == 0) {
  362.                 LOGFONT lf;
  363.                 XP_MEMSET(&lf,0,sizeof(LOGFONT));
  364.                 lf.lfPitchAndFamily = FF_SWISS;
  365.                 lf.lfCharSet = IntlGetLfCharset(0);
  366.                    lf.lfHeight = -MulDiv(9,pDC->GetDeviceCaps(LOGPIXELSY), 72);
  367.                 strcpy(lf.lfFaceName, IntlGetUIPropFaceName(0));
  368.                 lf.lfWeight = 400;
  369.                 m_pFont = theApp.CreateAppFont( lf );
  370.             }
  371.             ::SendMessage(m_pBox->GetSafeHwnd(), WM_SETFONT, (WPARAM)m_pFont, FALSE);
  372.         }
  373.  
  374.         pDC->GetTextMetrics(&tm);
  375.         // stay inside of the space we've been given                                   
  376.         m_nBoxHeight = tm.tmHeight; // + tm.tmDescent;
  377.         if(m_nBoxHeight > (cy - 2))
  378.             m_nBoxHeight = cy - 2;
  379.         m_pBox->ReleaseDC(pDC);       
  380.     }
  381.  
  382.     CURLBarBase::OnSize(nType, cx, cy);
  383.  
  384.     if( pText && m_pBox ) 
  385.     {
  386.         // position the "Location" text 
  387.         txtSpacing = (cy - rcURLtext.Height()) / 2 ; 
  388.  
  389.         pText->MoveWindow(x, 
  390.                           txtSpacing, rcURLtext.Width(), rcURLtext.Height());
  391.  
  392.         x += rcURLtext.Width() + 3;
  393.  
  394.         m_DragIconX = x;
  395.  
  396.         // Position the proxy surround wnd
  397.         
  398.         m_pProxySurround->MoveWindow(x-1, 1, ( cx - x - 
  399.                         ( GetSystemMetrics(SM_CXBORDER) * 2)),cy-2);
  400.  
  401.         boxSpacing = (cy - m_nBoxHeight) / 2 ;
  402.         m_DragIconY = boxSpacing + (m_nBoxHeight - DRAG_ICON_HEIGHT)/2;
  403.  
  404.         m_pPageProxy->MoveWindow(1, m_DragIconY-1, DRAG_ICON_WIDTH, DRAG_ICON_HEIGHT);
  405.         
  406.         x += DRAG_ICON_WIDTH + 2;
  407.  
  408.         // position the location edit box
  409.         m_pBox->MoveWindow( DRAG_ICON_WIDTH+3,
  410.                    (cy - m_nBoxHeight) / 2 -1, 
  411.                    ( cx - x - 
  412.                         ( GetSystemMetrics(SM_CXBORDER) * 2)) ,
  413.                         m_nBoxHeight); 
  414.     }
  415.       
  416.     m_DragIconY = boxSpacing + (m_nBoxHeight - DRAG_ICON_HEIGHT)/2 + 1;
  417.     
  418.     
  419. }
  420.  
  421. //////////////////////////////////////////////////////////////////////////////
  422. // The user has hit return in the URL box.  download the current selection and
  423. // give the focus back to the frame
  424. void CURLBar::ProcessEnterKey() 
  425. {
  426.     char *new_text = NULL;
  427.     char    text[1000];
  428.     URL_Struct * URL_s;
  429.  
  430.     if (!m_pIMWContext) return;
  431.  
  432.     m_pBox->GetWindowText(text, 1000);
  433.  
  434.     if (text[0])
  435.     {
  436.         MWContext *context = m_pIMWContext->GetContext();
  437.         int32 id;
  438.  
  439.         if (context)
  440.         {
  441.             id = XP_CONTEXTID(context);
  442.         }
  443.         else
  444.         {
  445.             id = 0;
  446.         }
  447.  
  448.         if (HK_CallHook(HK_LOCATION, NULL, id, text, &new_text))
  449.         {
  450.             // Nothing, new_text is already set.
  451.         }
  452.         else
  453.         {
  454.             new_text = NULL;
  455.         }
  456.     }
  457.  
  458.     if (new_text)
  459.     {
  460.         URL_s = NET_CreateURLStruct(new_text, NET_DONT_RELOAD);
  461.         XP_FREE(new_text);
  462.     }
  463.     else
  464.     {
  465.         URL_s = NET_CreateURLStruct(text, NET_DONT_RELOAD);
  466.     }
  467.  
  468.     //    Load up.
  469.     m_pIMWContext->GetUrl(URL_s, FO_CACHE_AND_PRESENT);
  470. }
  471.  
  472.  
  473. //////////////////////////////////////////////////////////////////////////////////////
  474. // Set the current url bar to the given string and make sure that the text label
  475. //   says "Location:".  We are probably setting it more frequently than we
  476. //   need to because of the location / netsite history
  477. void CURLBar::UpdateFields( const char * msg )
  478. {       
  479.     CWnd *pText = GetDlgItem( IDC_URLTEXT );
  480.  
  481.     // strip random backend crap out of the url
  482.     msg = LM_StripWysiwygURLPrefix(msg);
  483.  
  484.     CString cs(msg);
  485.     m_pBox->SetWindowText(cs); 
  486.     UpdateWindow();
  487.     //m_pBox->SetEditSel(cs.GetLength()-1,cs.GetLength());
  488.     m_pBox->Clear();
  489.     
  490.     // If this was a netsite server change the string
  491.     History_entry*    pEntry = SHIST_GetCurrent(&m_pIMWContext->GetContext()->hist);
  492.  
  493.     if (pEntry && pEntry->is_netsite)
  494.         pText->SetWindowText(szLoadString(IDS_NETSITE));
  495.     else
  496.         pText->SetWindowText(szLoadString(IDS_LOCATION));
  497.  
  498.     m_nTextStatus = TRUE;
  499. }
  500.  
  501. void CURLBar::OnEditCopy()
  502. {
  503.     m_pBox->Copy();
  504.     OnEditChange();
  505. }
  506.  
  507. void CURLBar::OnUpdateEditCopy(CCmdUI* pCmdUI)    {
  508.     int iStartSel, iEndSel;
  509.     m_pBox->GetSel(iStartSel, iEndSel);
  510.  
  511.     if(iStartSel != iEndSel)    {
  512.         pCmdUI->Enable(TRUE);
  513.     }
  514.     else    {
  515.         pCmdUI->Enable(FALSE);
  516.     }
  517. }
  518.  
  519. void CURLBar::OnEditCut()
  520. {
  521.     m_pBox->Cut();
  522.     OnEditChange();
  523. }
  524.  
  525. void CURLBar::OnUpdateEditCut(CCmdUI* pCmdUI)    {
  526.     int iStartSel, iEndSel;
  527.     m_pBox->GetSel(iStartSel, iEndSel);
  528.  
  529.     if(iStartSel != iEndSel)    {
  530.         pCmdUI->Enable(TRUE);
  531.     }
  532.     else    {
  533.         pCmdUI->Enable(FALSE);
  534.     }
  535. }
  536.  
  537. void CURLBar::OnEditPaste()
  538. {
  539.  
  540.     m_pBox->Paste();
  541.     OnEditChange();
  542. }
  543.  
  544. void CURLBar::OnUpdateEditPaste(CCmdUI* pCmdUI)    {
  545.     pCmdUI->Enable(::IsClipboardFormatAvailable(CF_TEXT));
  546. }
  547.  
  548. void CURLBar::OnEditUndo()
  549. {
  550.     m_pBox->Undo();
  551.     OnEditChange();
  552. }
  553.  
  554. void CURLBar::OnUpdateEditUndo(CCmdUI* pCmdUI)    {
  555.     pCmdUI->Enable(m_pBox->CanUndo());
  556. }
  557.  
  558. void CURLBar::OnSelChange()
  559. {
  560. }
  561.  
  562. ///////////////////////////////////////////////////////////////////////////////////////
  563. // The user has modified the text in the edit field.  make sure it is now labeled as
  564. //   "Go to:" rather than "Location:"
  565. void CURLBar::OnEditChange()
  566. {
  567.     CWnd *pText = GetDlgItem( IDC_URLTEXT );
  568.  
  569.     if( pText && m_nTextStatus )
  570.     {
  571.         pText->SetWindowText(szLoadString(IDS_GOTO));
  572.         m_nTextStatus = FALSE;
  573.     }
  574. }
  575.  
  576. void CURLBar::OnMouseMove(UINT nFlags, CPoint point) 
  577. {
  578.     CURLBarBase::OnMouseMove(nFlags, point);
  579.     // Display previous status
  580.     wfe_Progress( m_pIMWContext->GetContext(), "" );
  581.  
  582.       MapWindowPoints(GetParent(), &point, 1);
  583.     GetParent()->SendMessage(WM_MOUSEMOVE, nFlags, MAKELPARAM(point.x, point.y));
  584.  
  585. }
  586.  
  587. void CURLBar::OnLButtonDblClk(UINT nFlags, CPoint point) 
  588. {
  589.     CURLBarBase::OnLButtonDblClk(nFlags, point);
  590.  
  591. }
  592.  
  593.  
  594. void CURLBar::OnLButtonUp(UINT nFlags, CPoint point) 
  595. {
  596.     MapWindowPoints(GetParent(), &point, 1);
  597.     GetParent()->SendMessage(WM_LBUTTONUP, nFlags, MAKELPARAM(point.x, point.y));
  598.  
  599. }
  600.  
  601. CEditWnd::~CEditWnd()
  602. {
  603.     if (m_idTimer)
  604.         KillTimer(m_idTimer);
  605.     if (m_pComplete)
  606.         free(m_pComplete);
  607. }
  608.  
  609.  
  610. BEGIN_MESSAGE_MAP(CEditWnd,CGenericEdit)
  611.     ON_WM_TIMER()
  612. END_MESSAGE_MAP()
  613.  
  614.  
  615. LRESULT CEditWnd::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  616. {
  617.     LRESULT result = CEdit::DefWindowProc(message,wParam,lParam);
  618.     if (message == WM_CHAR)
  619.     {
  620.         switch (wParam)
  621.         {
  622.             case VK_BACK:
  623.                 break;
  624.             default:
  625.                 UrlCompletion();
  626.                 break;
  627.         }
  628.     }
  629.     return result;
  630. }
  631.  
  632. #define URL_AUTO_CHECK_DELAY    25
  633. #define URL_TIMER 10
  634.  
  635. BOOL CEditWnd::PreTranslateMessage ( MSG * msg )
  636. {
  637.    if ( msg->message == WM_KEYDOWN)
  638.    {
  639.       CURLBar* pBar = (CURLBar*)m_pBar;
  640.       LPMWCONTEXT pCX = pBar->GetContext();
  641.       
  642.       switch(msg->wParam)
  643.       {
  644.          case VK_RETURN:
  645.              // Kill any urlcompletion still on the timer
  646.              m_bRestart = TRUE;
  647.              if (m_idTimer)
  648.              {
  649.                 KillTimer(m_idTimer);
  650.                 m_idTimer = 0;
  651.              }
  652.                   
  653.              if (pCX) 
  654.              {
  655.                 CString url;
  656.                 char *new_url = NULL;
  657.                 char *url_str;
  658.                 GetWindowText ( url );
  659.  
  660.                 // Call the location_hook to process and possibly change the
  661.                 // text just entered.
  662.         
  663.                 if ((url)&&(*url))
  664.                 {
  665.                     MWContext *context = (MWContext *)pCX;
  666.                     int32 id;
  667.  
  668.                     if (context)
  669.                     {
  670.                         id = XP_CONTEXTID(context);
  671.                     }
  672.                     else
  673.                     {
  674.                         id = 0;
  675.                     }
  676.  
  677.                     const char *c_url = (const char *)url;
  678.                     url_str = (char *)c_url;
  679.                     if (HK_CallHook(HK_LOCATION, NULL, id, url_str, &new_url))
  680.                     {
  681.                         // Nothing, new_url is already set.
  682.                     }
  683.                     else
  684.                     {
  685.                         new_url = NULL;
  686.                     }
  687.                 }
  688.             
  689.                 if (new_url)
  690.                 {
  691.                     if ( strlen ( new_url ) )
  692.                     {
  693.                         pCX->NormalGetUrl(new_url);
  694.                     }
  695.                     XP_FREE(new_url);
  696.                 }
  697.                 else
  698.                 {
  699.                     if ( strlen ( url ) )
  700.                     {
  701.                         pCX->NormalGetUrl(url);
  702.                     }
  703.                 }
  704.              }
  705.              break;
  706.          case VK_DOWN:
  707.             {
  708.                int nStart, nEnd;
  709.                CString csOriginal, csPartial;
  710.                GetWindowText(csOriginal);
  711.                GetSel(nStart,nEnd);
  712.                if (nEnd>=nStart)
  713.                {
  714.                   csPartial = csOriginal.Left(nStart);
  715.                   char * pszResult = NULL;
  716.                   switch (urlMatch(csPartial,&pszResult,FALSE, m_Scroll = TRUE))
  717.                   {
  718.                      case stillSearching:
  719.                         if (!m_idTimer)
  720.                         {
  721.                            m_idTimer = SetTimer(URL_TIMER, URL_AUTO_CHECK_DELAY, NULL);
  722.                            m_bRestart = FALSE;
  723.                         }
  724.                         break;
  725.                   }
  726.                   DrawCompletion(csPartial,pszResult);
  727.                }
  728.             }
  729.             return TRUE;
  730.         default:
  731.             m_Scroll = FALSE;
  732.             break;
  733.       }
  734.     }
  735.    return CEdit::PreTranslateMessage ( msg );
  736. }
  737.  
  738. void CEditWnd::UrlCompletion()
  739. {
  740.     CString cs;
  741.     Bool cursorAtEnd, textSelected;
  742.     int nStart, nEnd;
  743.     GetWindowText(cs);
  744.     GetSel(nStart,nEnd);
  745.     char * pszResult = NULL;
  746.  
  747.  
  748.     textSelected = (nEnd - nStart) ? TRUE : FALSE;
  749.     cursorAtEnd = (!textSelected && ( nEnd == cs.GetLength() ));
  750.  
  751.     if(textSelected || cursorAtEnd)
  752.     {
  753.         switch (urlMatch(cs,&pszResult,m_bRestart, m_Scroll = FALSE))
  754.         {
  755.             case dontCallOnIdle:
  756.             case notFoundDone:
  757.             case foundDone:
  758.                 m_bRestart = TRUE;
  759.                 if (m_idTimer)
  760.                 {
  761.                     KillTimer(m_idTimer);
  762.                     m_idTimer = 0;
  763.                 }
  764.                 break;
  765.             case stillSearching:
  766.                 m_bRestart = FALSE;
  767.                 if (!m_idTimer)
  768.                 {
  769.                     m_idTimer = SetTimer(URL_TIMER, URL_AUTO_CHECK_DELAY, NULL);
  770.                     break;
  771.                 }
  772.                 break;
  773.         }
  774.     
  775.         DrawCompletion(cs, pszResult);
  776.     }
  777. }
  778.  
  779. void CEditWnd::DrawCompletion(CString & cs, char * pszResult)
  780. {
  781.     if (pszResult)
  782.     {
  783.         if (m_pComplete)
  784.         {
  785.             free(m_pComplete);
  786.             m_pComplete = NULL;
  787.         }
  788.         m_pComplete = strdup(pszResult);
  789.         UINT iPre = cs.GetLength();
  790.         CString csNew;
  791.         csNew = cs;
  792.         if (iPre >= 0 && iPre <= strlen(pszResult))
  793.             csNew += CString(&pszResult[iPre]);
  794.         SetWindowText(csNew);
  795.         SetSel((int)iPre,-1);
  796.         free(pszResult);
  797.         pszResult = NULL;
  798.     }
  799. }
  800.  
  801. void CEditWnd::OnTimer( UINT  nIDEvent )
  802. {
  803.    if (nIDEvent == m_idTimer)
  804.    {
  805.       int nStart, nEnd;
  806.       CString csOriginal, csPartial;
  807.       GetWindowText(csOriginal);
  808.       GetSel(nStart,nEnd);
  809.       if ( (nEnd>=nStart) && m_Scroll )
  810.          csPartial = csOriginal.Left(nStart);
  811.       else
  812.          csPartial = csOriginal;
  813.       char * pszResult = NULL;
  814.       switch (urlMatch(csPartial,&pszResult,m_bRestart, m_Scroll))
  815.       {
  816.          case dontCallOnIdle:
  817.              m_bRestart = FALSE;
  818.              if (m_idTimer)
  819.              {
  820.                  KillTimer(m_idTimer);
  821.                  m_idTimer = 0;
  822.              }
  823.              break;
  824.          case notFoundDone:
  825.          case foundDone:
  826.              m_bRestart = TRUE;
  827.              if (m_idTimer)
  828.              {
  829.                  KillTimer(m_idTimer);
  830.                  m_idTimer = 0;
  831.              }
  832.              break;
  833.       }
  834.       DrawCompletion(csPartial, pszResult);
  835.     }
  836. }
  837.  
  838.  
  839. // CProxySurroundWnd
  840.  
  841. BEGIN_MESSAGE_MAP(CProxySurroundWnd, CWnd) 
  842.     //{{AFX_MSG_MAP(CProxySurroundWnd)
  843.     ON_WM_PAINT()
  844.     //}}AFX_MSG_MAP
  845. END_MESSAGE_MAP()
  846.  
  847. BOOL CProxySurroundWnd::Create(CWnd *pParent)
  848. {
  849.     CRect rect(0, 0, 10, 10); // will size/position it later
  850.  
  851.     BOOL bRtn = CWnd::CreateEx( NULL, 
  852.                                 NULL, 
  853.                                 NULL, 
  854.                                 WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE | WS_BORDER, 
  855.                                 0, 0, 10, 10,
  856.                                 pParent ? pParent->m_hWnd : NULL, 0 );
  857.     return bRtn;
  858. }
  859.  
  860. void CProxySurroundWnd::OnPaint() 
  861. {
  862.     CWnd::OnPaint ( );
  863.  
  864.     CClientDC dc(this);
  865.  
  866.     CRect rcClient;
  867.  
  868.     GetClientRect(&rcClient);
  869.     
  870.     // Use window background color
  871.     HBRUSH br = ::CreateSolidBrush(::GetSysColor(COLOR_WINDOW));
  872.     ::FillRect(dc.m_hDC,&rcClient,br);
  873.     ::DeleteObject(br);
  874.  
  875. }
  876.  
  877. ///////////////////////////////////////////////////////////////////////////////////////////
  878. //                                Class CPageProxyWindow
  879. ///////////////////////////////////////////////////////////////////////////////////////////
  880.  
  881. #define IDT_PROXYFOCUS 16420
  882. #define PROXYFOCUS_DELAY_MS 10
  883.  
  884. CPageProxyWindow::CPageProxyWindow(void)
  885. {
  886.     m_bDraggingURL = FALSE;
  887.     m_bDragIconHit = FALSE;
  888.     m_bDragStatusHint = FALSE;
  889.     m_pIMWContext = NULL;
  890. }
  891.  
  892. CPageProxyWindow::~CPageProxyWindow(void)
  893. {
  894.  
  895.  
  896. }
  897. void CPageProxyWindow::SetContext( LPUNKNOWN pUnk )
  898. {
  899.     if (m_pIMWContext) {
  900.         m_pIMWContext->Release();
  901.         m_pIMWContext = NULL;
  902.     }
  903.     if (pUnk)
  904.         pUnk->QueryInterface( IID_IMWContext, (LPVOID *) &m_pIMWContext );
  905. }
  906.  
  907. BOOL CPageProxyWindow::Create(CWnd *pParent)
  908. {
  909.     CRect rect(0, 0, 10, 10); // will size/position it later
  910.  
  911.     BOOL bRtn = CWnd::CreateEx( NULL, 
  912.                                 AfxRegisterWndClass( CS_SAVEBITS, theApp.LoadCursor( IDC_HANDOPEN ), 
  913.                                                      (HBRUSH)(COLOR_BTNFACE+1) ), 
  914.                                 NULL, 
  915.                                 WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_VISIBLE, 
  916.                                 0, 0, 10, 10,
  917.                                 pParent ? pParent->m_hWnd : NULL, 0 );
  918.     if(bRtn)
  919.     {
  920.         CString tipStr;
  921.  
  922.         tipStr.LoadString(IDS_DRAGURLTIP);
  923.  
  924.         
  925.         m_ToolTip.Create(this, TTS_ALWAYSTIP);
  926.  
  927.  
  928.         m_ToolTip.AddTool(this, (const char*) tipStr );
  929.  
  930.         m_ToolTip.Activate(TRUE);
  931.         m_ToolTip.SetDelayTime(200);
  932.     
  933.     }
  934.  
  935.     return bRtn;
  936. }
  937.  
  938. ///////////////////////////////////////////////////////////////////////////////////////////
  939. //                                CPageProxyWindow Messages
  940. ///////////////////////////////////////////////////////////////////////////////////////////
  941.  
  942. int CPageProxyWindow::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  943. {
  944.  
  945.     return(0);
  946. }
  947.  
  948. BEGIN_MESSAGE_MAP(CPageProxyWindow, CWnd) 
  949.     //{{AFX_MSG_MAP(CPageProxyWindow)
  950.     ON_WM_MOUSEMOVE()
  951.     ON_WM_LBUTTONDBLCLK()
  952.     ON_WM_LBUTTONDOWN()
  953.     ON_WM_PAINT()
  954.     ON_WM_SHOWWINDOW()
  955.     ON_WM_ERASEBKGND()
  956.     ON_WM_LBUTTONUP()
  957.     ON_WM_TIMER()
  958.     ON_WM_MOUSEACTIVATE()
  959.  
  960.     //}}AFX_MSG_MAP
  961. END_MESSAGE_MAP()
  962.  
  963. void CPageProxyWindow::OnLButtonDblClk(UINT nFlags, CPoint point) 
  964. {
  965.     CWnd::OnLButtonDblClk(nFlags, point);
  966.  
  967.     if ( m_pIMWContext && !m_pIMWContext->GetContext()->waitingMode && 
  968.          !m_bDraggingURL && !m_bDragIconHit)  {
  969.         WINCX(m_pIMWContext->GetContext())->CopyCurrentURL();
  970.     }
  971. }
  972.  
  973.  
  974. void CPageProxyWindow::OnLButtonUp(UINT nFlags, CPoint point) 
  975. {
  976.     ReleaseCapture();
  977.     m_bDragIconHit = FALSE;
  978.     MSG msg = *(GetCurrentMessage());
  979.     m_ToolTip.RelayEvent(&msg);
  980.  
  981.     SetCursor(theApp.LoadCursor(IDC_HANDOPEN));
  982.  
  983. }
  984.  
  985. int CPageProxyWindow::OnMouseActivate( CWnd *, UINT, UINT )
  986. {
  987.     //
  988.     // Prevent the frame window from activating.  Allows for easier drag/drop from proxy
  989.     // to a different top-level window in that the browser frame retains it's z-position.
  990.     //
  991.     return MA_NOACTIVATE;
  992. }
  993.  
  994. void CPageProxyWindow::OnMouseMove(UINT nFlags, CPoint point) 
  995. {
  996.     CWnd::OnMouseMove(nFlags, point);
  997.  
  998.     SetCursor(theApp.LoadCursor(IDC_HANDOPEN));
  999.  
  1000.     if ( m_pIMWContext && !m_pIMWContext->GetContext()->waitingMode && !m_bDraggingURL ) {
  1001.         if ( m_bDragIconHit &&
  1002.              ((abs(point.x - m_cpLBDown.x) > 3)
  1003.              || (abs(point.y - m_cpLBDown.y) > 3)) ) {
  1004.             // We moved enough to start dragging
  1005.             m_bDraggingURL = TRUE;
  1006.             // DragNDrop baby!
  1007.             m_bDragStatusHint = FALSE;
  1008.             RedrawWindow();
  1009.             ReleaseCapture();
  1010.             WINCX(m_pIMWContext->GetContext())->DragCurrentURL();
  1011.             // Done -- clear flags
  1012.             m_bDraggingURL = FALSE;
  1013.             m_bDragIconHit = FALSE;
  1014.  
  1015.             // Return focus to frame??
  1016.             // Not such a good idea; Drag/drop ops should maintain z-order.
  1017.             // GetTopLevelFrame()->SetFocus();
  1018.        } else if( (point.x >= 0) && 
  1019.                    (point.x <=  DRAG_ICON_WIDTH) &&
  1020.                    (point.y >= 0) && 
  1021.                    (point.y <=  DRAG_ICON_HEIGHT) ) {
  1022.             // Mouse is over the icon and button is up
  1023.             // TODO: Simulate ToolTip here (IDS_DRAG_THIS_URL_TIP)
  1024.             // For now -- display on StatusBar
  1025.             if ( !m_bDragStatusHint ) {
  1026.                 m_pIMWContext->Progress(m_pIMWContext->GetContext(), szLoadString(ID_DRAG_THIS_URL));
  1027.                 m_bDragStatusHint = TRUE;
  1028.                 m_hFocusTimer = SetTimer(IDT_PROXYFOCUS, PROXYFOCUS_DELAY_MS, NULL);
  1029.                 RedrawWindow();
  1030.                 }
  1031.        } else if (m_bDragStatusHint) {
  1032.             // Restore message to previous contents
  1033.           #if 0
  1034.             m_pIMWContext->Progress(m_pIMWContext->GetContext(), "");
  1035.           #else
  1036.             // Display previous status
  1037.             wfe_Progress( m_pIMWContext->GetContext(), "" );
  1038.           #endif
  1039.             m_bDragStatusHint = FALSE;
  1040.             RedrawWindow();
  1041.  
  1042.         }
  1043.     }
  1044.  
  1045.     m_ToolTip.Activate(TRUE);
  1046.     MSG msg = *(GetCurrentMessage());
  1047.     m_ToolTip.RelayEvent(&msg);
  1048. }
  1049.  
  1050. void CPageProxyWindow::OnLButtonDown(UINT nFlags, CPoint point)
  1051. {
  1052.     CWnd::OnLButtonDown(nFlags, point);
  1053.  
  1054.     int load = FALSE;
  1055.  
  1056.     if (!m_pIMWContext) 
  1057.         return;
  1058.  
  1059.     m_cpLBDown = point;
  1060.     
  1061.     //CLM: Check if clicking in the Drag icon:
  1062.     if (!m_pIMWContext->GetContext()->waitingMode && (point.x >= 0) && 
  1063.         (point.x <=  DRAG_ICON_WIDTH) &&
  1064.         (point.y >= 0) && 
  1065.         (point.y <=  DRAG_ICON_HEIGHT)) {
  1066.         m_bDragIconHit = TRUE;
  1067.         SetCursor(theApp.LoadCursor(IDC_LINK_COPY));
  1068.  
  1069.         SetCapture();
  1070.     }
  1071.  
  1072.     MSG msg = *(GetCurrentMessage());
  1073.     m_ToolTip.RelayEvent(&msg);
  1074.  
  1075.  
  1076. }
  1077.  
  1078. void CPageProxyWindow::OnPaint() 
  1079. {
  1080.     CWnd::OnPaint ( );
  1081.  
  1082.     CClientDC dc(this);
  1083.  
  1084.     CRect rcClient;
  1085.  
  1086.     GetClientRect(&rcClient);
  1087.     
  1088.     // Use window background color
  1089.     HBRUSH br = ::CreateSolidBrush(::GetSysColor(COLOR_WINDOW));
  1090.     ::FillRect(dc.m_hDC,&rcClient,br);
  1091.     ::DeleteObject(br);
  1092.  
  1093.     CDC SrcDC;
  1094.     SrcDC.CreateCompatibleDC(&dc);
  1095.  
  1096.  
  1097.     // Draw the bitmap for dragging this URL
  1098.  
  1099.     // Create the bitmaps if we haven't already
  1100.     if(pDragURLBitmap == NULL) {
  1101.         pDragURLBitmap = new CBitmap;
  1102.  
  1103.         if(pDragURLBitmap) {
  1104.             pDragURLBitmap->LoadBitmap( IDB_DRAG_URL );
  1105.         }
  1106.     }
  1107.  
  1108.     if(pDragURLBitmap) {
  1109.         CPoint bitmapStart(m_bDragStatusHint ? DRAG_ICON_WIDTH : 0 , 0);
  1110.  
  1111.         CBitmap *pOldBitmap = SrcDC.SelectObject(pDragURLBitmap);
  1112.         ::FEU_TransBlt( &SrcDC, &dc,
  1113.                         bitmapStart, 
  1114.                         CPoint(0, 0),
  1115.                         DRAG_ICON_WIDTH, DRAG_ICON_HEIGHT,WFE_GetUIPalette(GetParentFrame()));
  1116.  
  1117.         SrcDC.SelectObject( pOldBitmap );
  1118.     }
  1119.  
  1120.  
  1121.     SrcDC.DeleteDC();
  1122.  
  1123.  
  1124. }
  1125.  
  1126. void CPageProxyWindow::OnShowWindow( BOOL bShow, UINT nStatus )
  1127. {
  1128.     m_bEraseBackground = bShow;
  1129. }
  1130.  
  1131. BOOL CPageProxyWindow::OnEraseBkgnd( CDC* pDC )
  1132. {
  1133.     if ( m_bEraseBackground ) {
  1134.         m_bEraseBackground = FALSE;
  1135.         return (BOOL) Default();
  1136.     } else {
  1137.         return TRUE;
  1138.     }
  1139. }
  1140.  
  1141. void CPageProxyWindow::OnTimer( UINT  nIDEvent )
  1142. {
  1143.     if(nIDEvent == IDT_PROXYFOCUS)
  1144.     {
  1145.         POINT point;
  1146.  
  1147.         KillTimer(IDT_PROXYFOCUS);
  1148.         m_hFocusTimer = 0;
  1149.         GetCursorPos(&point);
  1150.  
  1151.         CRect rcClient;
  1152.         GetWindowRect(&rcClient);
  1153.  
  1154.         if (!rcClient.PtInRect(point))
  1155.         {
  1156.             m_bDragStatusHint = FALSE;
  1157.             RedrawWindow();
  1158.         
  1159.         }
  1160.         else
  1161.             m_hFocusTimer = SetTimer(IDT_PROXYFOCUS, PROXYFOCUS_DELAY_MS, NULL);
  1162.  
  1163.     }
  1164.  
  1165.  
  1166. }
  1167.