home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / compfile.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  20.8 KB  |  735 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 "xp.h"
  21. #include "forward.h"
  22. #include "compfile.h"
  23. #include "compfrm.h"
  24. #include "compbar.h"
  25. #include "ole2.h"
  26. #include "abdefn.h"
  27. #include "wfemsg.h"
  28. #include "mailmisc.h"
  29. #include "nsadrlst.h"
  30.  
  31. extern char* wfe_ConstructFilterString(int type);
  32. extern char* XP_NetToDosFileName(const char * NetName);
  33.  
  34. #define  BITMAP_WIDTH   16
  35. #define  BITMAP_HEIGHT  16
  36.  
  37. BEGIN_MESSAGE_MAP(CNSAttachmentList, CListBox)
  38.     ON_WM_CREATE()
  39.     ON_WM_KEYDOWN()
  40.     ON_WM_LBUTTONDOWN()
  41.     ON_WM_DROPFILES()
  42.     ON_WM_DESTROY()
  43.     ON_COMMAND(ID_EDIT_DELETE,OnDelete)
  44. END_MESSAGE_MAP()
  45.  
  46. CNSAttachmentList::CNSAttachmentList(MSG_Pane * pPane) 
  47. {
  48.     m_pPane = pPane;    
  49.     m_pDropTarget = NULL;
  50. }
  51.  
  52. CNSAttachmentList::~CNSAttachmentList()
  53. {
  54.    if (m_pDropTarget)
  55.    {
  56.       m_pDropTarget->Revoke();
  57.       delete m_pDropTarget;
  58.    }
  59. }
  60.  
  61. BOOL CNSAttachmentList::Create(CWnd * pWnd, UINT id)
  62. {
  63.    BOOL bRetVal = CListBox::Create (
  64.       WS_CLIPCHILDREN|WS_CHILD|WS_VISIBLE|WS_VSCROLL|LBS_OWNERDRAWFIXED|
  65.       LBS_HASSTRINGS|LBS_NOTIFY|LBS_WANTKEYBOARDINPUT|LBS_NOINTEGRALHEIGHT,
  66.       CRect(0,0,0,0), pWnd, id);
  67.    return bRetVal;
  68. }
  69.  
  70. void CNSAttachmentList::OnDelete()
  71. {
  72.     if (GetFocus() == this)
  73.     {
  74.         int idx = GetCurSel();
  75.         if (idx != LB_ERR)
  76.         {
  77.             DeleteString(idx);
  78.             CComposeBar * pComposeBar = (CComposeBar*)GetParent();
  79.             pComposeBar->UpdateAttachmentInfo(GetCount());
  80.             UpdateAttachments();
  81.         }
  82.     }
  83. }
  84.  
  85. void CNSAttachmentList::OnUpdateDelete(CCmdUI * pCmdUI)
  86. {
  87.     if (GetFocus() == this)
  88.         pCmdUI->Enable(GetCount()>0);
  89. }
  90.  
  91. int CNSAttachmentList::OnCreate( LPCREATESTRUCT lpCreateStruct )
  92. {
  93.    int iRet = CListBox::OnCreate(lpCreateStruct);
  94.  
  95.     CComposeFrame * pFrame = (CComposeFrame*)GetParentFrame();
  96.     CDC * pdc = GetDC();
  97.  
  98.     LOGFONT lf;            
  99.     memset(&lf,0,sizeof(LOGFONT));
  100.     lf.lfPitchAndFamily = FF_SWISS;
  101.     if (INTL_DefaultWinCharSetID(0) == CS_LATIN1)
  102.         strcpy(lf.lfFaceName, "MS Sans Serif");
  103.     else
  104.         strcpy(lf.lfFaceName, IntlGetUIPropFaceName(0));
  105.     lf.lfCharSet = IntlGetLfCharset(pFrame->m_iCSID);
  106.     lf.lfHeight = -MulDiv(8,pdc->GetDeviceCaps(LOGPIXELSY), 72);
  107.     lf.lfQuality = PROOF_QUALITY;    
  108.     m_cfTextFont = theApp.CreateAppFont( lf );
  109.     ::SendMessage(GetSafeHwnd(), WM_SETFONT, (WPARAM)m_cfTextFont, FALSE);
  110.  
  111.    ReleaseDC(pdc);
  112.  
  113.  
  114.    BOOL bDisableButtons = TRUE;
  115.    if(GetMsgPane()) 
  116.    {
  117.         const MSG_AttachmentData * pDataList = MSG_GetAttachmentList(GetMsgPane());
  118.         if(pDataList) 
  119.         {
  120.             bDisableButtons = FALSE;
  121.             for (int i = 0; pDataList[i].url!=NULL; i++) 
  122.             {
  123.                 int idx;
  124.                 MSG_AttachmentData * pEntry = 
  125.                     (MSG_AttachmentData*)XP_CALLOC(1,sizeof(MSG_AttachmentData));
  126.                 ASSERT(pEntry);
  127.                 pEntry->url = XP_STRDUP(pDataList[i].url);
  128.                 if (pDataList[i].real_type) 
  129.                     pEntry->real_type = XP_STRDUP(pDataList[i].real_type);
  130.                 if (pDataList[i].description) 
  131.                     pEntry->description = XP_STRDUP(pDataList[i].description);
  132.                 if (pDataList[i].real_name) 
  133.                     pEntry->real_name = XP_STRDUP(pDataList[i].real_name);
  134.                 if (pDataList[i].real_name)
  135.                     idx = AddString (pEntry->real_name);
  136.                 else
  137.                     idx = AddString(pEntry->url);
  138. #ifdef DEBUG_bienvenu
  139.                 MSG_MessageLine msgLine;
  140.                 int ret = MSG_GetMessageLineForURL(WFE_MSGGetMaster(), pEntry->url, &msgLine);
  141. #endif
  142.                 ASSERT(idx!=LB_ERR);
  143.                 SetItemData(idx,(DWORD)pEntry);
  144.                 ASSERT(pEntry->url);
  145.                 if (pDataList[i].desired_type) 
  146.                 {
  147.                     pEntry->desired_type = XP_STRDUP(pDataList[i].desired_type);
  148.                     ASSERT(pEntry->desired_type);
  149.                 }
  150.             }
  151.             SetCurSel(0);
  152.         }
  153.    }
  154.  
  155.    if(!m_pDropTarget) {
  156.        m_pDropTarget = new CNSAttachDropTarget;
  157.        m_pDropTarget->Register(this);
  158.    }
  159.  
  160.    DragAcceptFiles();
  161.  
  162.    return(iRet);
  163. }
  164.  
  165. void CNSAttachmentList::AttachUrl(char * pUrl)
  166. {
  167.     CWnd * pFocusWnd = GetFocus();
  168.     CLocationDlg LocationDlg(pUrl,this);
  169.     if (LocationDlg.DoModal()==IDOK)
  170.     {
  171.         MSG_AttachmentData * pAttach = 
  172.             (MSG_AttachmentData *)XP_CALLOC(1,sizeof(MSG_AttachmentData));
  173.         ASSERT(pAttach);
  174.         pAttach->url = XP_STRDUP(LocationDlg.m_Location);
  175.         ASSERT(pAttach->url);
  176.         int idx = AddString(pAttach->url);
  177.         ASSERT(idx!=LB_ERR);
  178.         SetItemData(idx,(DWORD)pAttach);
  179.         SetCurSel(idx);
  180.         CComposeBar * pComposeBar = (CComposeBar*)GetParent();
  181.         pComposeBar->UpdateAttachmentInfo(GetCount());
  182.         UpdateAttachments();
  183.     }
  184.     pFocusWnd->SetFocus();
  185. }
  186.  
  187. void CNSAttachmentList::AddAttachment(char * pName)
  188. {
  189.     if(pName) 
  190.     {
  191.         MSG_AttachmentData * pAttach = 
  192.             (MSG_AttachmentData *)XP_CALLOC(1,sizeof(MSG_AttachmentData));
  193.         CString cs;
  194.         WFE_ConvertFile2Url(cs,(const char *)pName);
  195.         pAttach->url = XP_STRDUP(cs);
  196.         ASSERT(pAttach->url);
  197.  
  198.         int idx = AddString(pAttach->url);
  199.         CComposeBar * pComposeBar = (CComposeBar*)GetParent();
  200.         pComposeBar->UpdateAttachmentInfo(GetCount());
  201.         ASSERT(idx!=LB_ERR);
  202.         SetItemData(idx,(DWORD)pAttach);
  203.         SetCurSel(idx);
  204.     }
  205. }
  206.  
  207. void CNSAttachmentList::AttachFile() 
  208. {
  209.     CWnd * pFocusWnd = GetFocus();
  210.     CString cs;
  211.     cs.LoadString(IDS_FILETOATTACH);
  212.     char * pName = GetAttachmentName( (char*)((const char *)cs), ALL, TRUE);
  213.     char * part = NULL;
  214.     char * filename = NULL;
  215.     char * full_path = NULL;
  216.     if (pName) {
  217.         // this assumes that there are space separators between filenames
  218.         // if the dialog getting the filenames changes to explorer style
  219.         // then this should change
  220.         if (part = strstr(pName, " ")) {
  221.             full_path = (char *) XP_ALLOC(_MAX_PATH * sizeof(char));
  222.             if(!full_path){
  223.                 XP_FREEIF(pName);
  224.                 return;
  225.             }
  226.             *part = NULL;
  227.             part++;
  228.             while (part) {
  229.                 XP_STRCPY (full_path, "");
  230.                 XP_STRCAT (full_path, pName);
  231.                 if (*(full_path + strlen (full_path) - 1) != '\\')
  232.                     XP_STRCAT (full_path, "\\");
  233.                 filename = strstr(part, " ");
  234.                 if (filename) {
  235.                     *filename = NULL;
  236.                     filename++;
  237.                 }
  238.                 XP_STRCAT (full_path, part);
  239.                 AddAttachment(full_path);
  240.                 part = filename;
  241.             }
  242.             XP_FREE(full_path);
  243.         }
  244.         else
  245.             AddAttachment(pName);
  246.  
  247.     }
  248.     if (pName)
  249.        XP_FREE(pName);
  250.     pFocusWnd->SetFocus();
  251.     UpdateAttachments();
  252. }
  253.  
  254. void CNSAttachmentList::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
  255. {
  256.     switch (nChar) 
  257.     {
  258.         case VK_INSERT:
  259.             AttachFile();
  260.             break;
  261.  
  262.         case VK_DELETE:
  263.             RemoveAttachment();
  264.             break;
  265.     }
  266.     CListBox::OnKeyDown(nChar, nRepCnt, nFlags);
  267. }
  268.  
  269. void CNSAttachmentList::RemoveAttachment() 
  270. {
  271.     int idx = GetCurSel();
  272.     if (idx != LB_ERR) 
  273.     {
  274.         MSG_AttachmentData * pAttach = 
  275.             (MSG_AttachmentData*)GetItemData(idx);
  276.         ASSERT(pAttach);
  277.         if (pAttach == NULL)
  278.             return;
  279.         XP_FREE(pAttach);
  280.         DeleteString(idx);
  281.         CComposeBar * pComposeBar = (CComposeBar*)GetParent();
  282.         pComposeBar->UpdateAttachmentInfo(GetCount());
  283.         if (idx >= GetCount())
  284.             SetCurSel(idx-1);
  285.         UpdateAttachments();
  286.     }
  287. }
  288.  
  289. void CNSAttachmentList::Cleanup()
  290. {
  291.     int iCount = GetCount();
  292.     for (int i = 0; i<iCount; i++) {
  293.         MSG_AttachmentData * pAttach = 
  294.             (MSG_AttachmentData*)GetItemData(i);
  295.         if (pAttach != NULL)
  296.         {
  297.             if (pAttach->url)
  298.                 XP_FREE((void*)pAttach->url);
  299.             if (pAttach->desired_type)
  300.                 XP_FREE((void*)pAttach->desired_type);
  301.             if (pAttach->real_type)
  302.                 XP_FREE((void*)pAttach->real_type);
  303.             if (pAttach->description)
  304.                 XP_FREE((void*)pAttach->description);
  305.             if (pAttach->real_name)
  306.                 XP_FREE((void*)pAttach->real_name);
  307.         }
  308.         SetItemData(i,NULL);
  309.     }
  310. }
  311.  
  312. void CNSAttachmentList::UpdateAttachments()
  313. {
  314.     int iCount = GetCount();
  315.     if (iCount != LB_ERR)
  316.     {
  317.         MSG_AttachmentData * pAttachList = 
  318.             (MSG_AttachmentData *)XP_CALLOC(iCount+1,sizeof(MSG_AttachmentData));
  319.         if (!pAttachList)
  320.             return;
  321.         for (int i = 0; i<iCount; i++) {
  322.             MSG_AttachmentData * pAttach = 
  323.                 (MSG_AttachmentData*)GetItemData(i);
  324.             if (pAttach != NULL)
  325.                 XP_MEMCPY(&pAttachList[i],pAttach,sizeof(MSG_AttachmentData));
  326.         }
  327.         ASSERT(GetMsgPane());
  328.         MSG_SetAttachmentList(GetMsgPane(),pAttachList);
  329.         XP_FREE(pAttachList);
  330.     }
  331. }
  332.  
  333. char * CNSAttachmentList::GetAttachmentName(
  334.     char * prompt, int type, XP_Bool bMustExist, BOOL * pOpenIntoEditor)
  335. {
  336.  
  337.     OPENFILENAME fname;
  338.     char * full_path = NULL;
  339.     char   name[_MAX_FNAME];
  340.  
  341.     char* filter = wfe_ConstructFilterString(type);
  342.  
  343.     /* initialize the OPENFILENAME struct */
  344.     
  345.     BOOL result;
  346.     UINT index = (type == HTM_ONLY) ? 1 : type;
  347.  
  348.     // space for the full path name    
  349.     full_path = (char *) XP_ALLOC(_MAX_PATH * sizeof(char));
  350.     if(!full_path){
  351.         XP_FREE(filter);
  352.         return(NULL);
  353.     }
  354.     name[0]      = '\0';
  355.     full_path[0] = '\0';
  356.  
  357.     // set up the entries
  358.     fname.lStructSize = sizeof(OPENFILENAME);
  359.     fname.hwndOwner = m_hWnd;
  360.     fname.lpstrFilter = filter;
  361.     fname.lpstrCustomFilter = NULL;
  362.     fname.nFilterIndex = index;
  363.     fname.lpstrFile = full_path;
  364.     fname.nMaxFile = _MAX_PATH;
  365.     fname.lpstrFileTitle = name;
  366.     fname.nMaxFileTitle = _MAX_FNAME;
  367.     fname.lpstrInitialDir = NULL;
  368.     fname.lpstrTitle = prompt;
  369.     fname.Flags = OFN_HIDEREADONLY;
  370.     fname.lpstrDefExt = NULL;
  371.  
  372.     if(bMustExist)
  373.         fname.Flags |= OFN_FILEMUSTEXIST;
  374.  
  375.     if (!pOpenIntoEditor)
  376.         fname.Flags |= OFN_ALLOWMULTISELECT;
  377.  
  378.     result = FEU_GetOpenFileName(&fname);
  379.  
  380.     XP_FREE(filter);
  381.  
  382.     // see if the user selects a file or hits cancel    
  383.     if(result) {
  384.         return(full_path);
  385.     } else {
  386.         // user hit cancel
  387.         if(full_path) XP_FREE(full_path);
  388.         return(NULL);
  389.     }
  390. }
  391.  
  392. UINT CNSAttachmentList::ItemFromPoint(CPoint pt, BOOL& bOutside) const
  393. {
  394.     RECT rect;
  395.     GetClientRect(&rect);
  396.  
  397.     int iHeight = GetItemHeight(0);
  398.     int iCount = GetCount();
  399.     int iTopIndex = GetTopIndex();
  400.  
  401.     int iListHeight = iHeight * ( iCount - iTopIndex );
  402.     rect.bottom = rect.bottom < iListHeight ? rect.bottom : iListHeight;
  403.  
  404.     bOutside = !::PtInRect(&rect, pt);
  405.  
  406.     if ( bOutside ) {
  407.         return 0;
  408.     } 
  409.  
  410.     return (pt.y / iHeight) + iTopIndex; 
  411. }
  412.  
  413. //=============================================================== OnLButtonDown
  414. void CNSAttachmentList::OnLButtonDown(UINT nFlags, CPoint point) 
  415. {
  416.     CListBox::OnLButtonDown(nFlags, point);
  417.     BOOL bOutside;
  418.     if (!GetCount())
  419.     {
  420.         AttachFile();
  421.         return;
  422.     }
  423.     int nNewSelect = ItemFromPoint( point, bOutside );
  424.     CRect rect;
  425.     GetItemRect(nNewSelect,rect);
  426.     if (((point.y+rect.Height())/rect.Height())+GetTopIndex()>GetCount())
  427.     {
  428.         AttachFile();
  429.     }
  430. }
  431.  
  432. /////////////////////////////////////////////////////////////////////////////
  433. // CLocationDlg dialog
  434.  
  435.  
  436. CLocationDlg::CLocationDlg(char * pUrl, CWnd* pParent /*=NULL*/)
  437.     : CDialog(CLocationDlg::IDD, pParent)
  438. {
  439.     //{{AFX_DATA_INIT(CLocationDlg)
  440.     m_Location = pUrl;
  441.     //}}AFX_DATA_INIT
  442. }
  443.  
  444.  
  445. void CLocationDlg::DoDataExchange(CDataExchange* pDX)
  446. {
  447.     CDialog::DoDataExchange(pDX);
  448.     //{{AFX_DATA_MAP(CLocationDlg)
  449.     DDX_Control(pDX, IDC_EDIT1, m_LocationBox);
  450.     DDX_Text(pDX, IDC_EDIT1, m_Location);
  451.     //}}AFX_DATA_MAP
  452. }
  453.  
  454.  
  455. BEGIN_MESSAGE_MAP(CLocationDlg, CDialog)
  456.     //{{AFX_MSG_MAP(CLocationDlg)
  457.     //}}AFX_MSG_MAP
  458. END_MESSAGE_MAP()
  459.  
  460.  
  461. /////////////////////////////////////////////////////////////////////////////
  462. // CLocationDlg message handlers
  463.  
  464.  
  465. BOOL CLocationDlg::OnInitDialog() 
  466. {
  467.     CDialog::OnInitDialog();
  468.  
  469.     // TODO: Add extra initialization here
  470.     
  471.    m_LocationBox.SetFocus();    
  472.    m_LocationBox.SetSel(0,-1);
  473.  
  474.     return FALSE;  // return TRUE unless you set the focus to a control
  475.                   // EXCEPTION: OCX Property Pages should return FALSE
  476. }
  477.  
  478. BOOL wfe_GetBookmarkData( COleDataObject* pDataObject, char ** ppURL, char ** ppTitle );
  479.  
  480.  
  481. BOOL CNSAttachmentList::ProcessDropTarget(COleDataObject * pDataObject)
  482. {
  483.    HGLOBAL hString = NULL;
  484.    char * pString = NULL;
  485.    UINT clipFormat;
  486.     // Get any string data
  487.     if (pDataObject->IsDataAvailable(
  488.         ::RegisterClipboardFormat(NETSCAPE_BOOKMARK_FORMAT)))
  489.     {
  490.       char * pURL = NULL, *pTitle = NULL;
  491.       wfe_GetBookmarkData(pDataObject, &pURL, &pTitle);
  492.       if (pURL)
  493.       {
  494.          if (!strnicmp(pURL,"addbook",7))
  495.              return FALSE;
  496.          if (!strnicmp(pURL,"mailto",6))
  497.              return FALSE;
  498.     
  499.          AddAttachment(pURL);
  500.          UpdateAttachments();
  501.       }
  502.       return TRUE;
  503.     }
  504.     else if (pDataObject->IsDataAvailable(
  505.       clipFormat=::RegisterClipboardFormat(NETSCAPE_MESSAGE_FORMAT)))
  506.     {
  507.         HGLOBAL hContent = pDataObject->GetGlobalData (clipFormat);
  508.         MailNewsDragData *pDragData = (MailNewsDragData *) GlobalLock(hContent);
  509.  
  510.       if (pDragData != NULL)
  511.       {
  512.          for (int i = 0; i< pDragData->m_count; i++)
  513.          {
  514.             ASSERT(pDragData->m_indices);
  515.             MessageKey key = MSG_GetMessageKey(pDragData->m_pane, pDragData->m_indices[i]);
  516.             URL_Struct* pUrl = MSG_ConstructUrlForMessage(pDragData->m_pane, key);
  517.             if (pUrl != NULL)
  518.             {
  519.                if (pUrl->address)
  520.                   AddAttachment(pUrl->address);
  521.                   NET_FreeURLStruct(pUrl);
  522.             }
  523.          }
  524.          UpdateAttachments();
  525.       }
  526.       return TRUE;
  527.     }
  528.  
  529.    return FALSE;
  530. }
  531.  
  532. void CNSAttachmentList::OnDropFiles( HDROP hDropInfo )
  533. {
  534.    UINT wNumFilesDropped = ::DragQueryFile(hDropInfo,(UINT)-1,NULL,0);
  535.    if (wNumFilesDropped > 0)
  536.    {
  537.       for (UINT x = 0; x < wNumFilesDropped; x++)
  538.       {
  539.          int wPathnameSize = ::DragQueryFile(hDropInfo, x, NULL, 0);
  540.          char * pStr = (char*)XP_CALLOC(1,wPathnameSize+2);
  541.          ASSERT(pStr);
  542.          // Copy the pathname into the buffer & add to listbox
  543.          ::DragQueryFile(hDropInfo, x, pStr, wPathnameSize+1);
  544.          AddAttachment(pStr);
  545.          XP_FREE(pStr);
  546.       }
  547.       UpdateAttachments();
  548.    }
  549. }
  550.  
  551. void CNSAttachmentList::OnDestroy(void)
  552. {
  553.     Cleanup();
  554.     CListBox::OnDestroy();
  555. }
  556.  
  557. void CNSAttachmentList::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct ) 
  558. {
  559.     if (lpDrawItemStruct->itemID != -1) 
  560.     {
  561.         CDC dc;
  562.         dc.Attach(lpDrawItemStruct->hDC);
  563.  
  564.       HBRUSH hRegBrush = ::CreateSolidBrush( GetSysColor( COLOR_WINDOW ) );
  565.       HPEN hRegPen = ::CreatePen( PS_SOLID, 1, GetSysColor ( COLOR_WINDOW ) );
  566.        HBRUSH hHighBrush = ::CreateSolidBrush( GetSysColor( COLOR_HIGHLIGHT ) );
  567.        HPEN hHighPen = ::CreatePen( PS_SOLID, 1, GetSysColor ( COLOR_HIGHLIGHT ) );
  568.  
  569.       HBRUSH hOldBrush = (HBRUSH) dc.SelectObject ( hRegBrush );
  570.       HPEN hOldPen = (HPEN) dc.SelectObject ( hRegPen );
  571.       COLORREF cOldText = dc.SetTextColor ( GetSysColor ( COLOR_WINDOWTEXT ) );
  572.       COLORREF cOldBk = dc.SetBkColor ( GetSysColor ( COLOR_WINDOW ) );
  573.  
  574.         CRect rect(lpDrawItemStruct->rcItem);
  575.       BOOL bSelected = lpDrawItemStruct->itemState & ODS_SELECTED;
  576.  
  577.       if (bSelected && (GetFocus()==this))
  578.       {
  579.          dc.SelectObject ( hHighBrush );
  580.          dc.SelectObject ( hHighPen );
  581.          dc.SetTextColor ( GetSysColor ( COLOR_HIGHLIGHTTEXT ) );
  582.          dc.SetBkColor ( GetSysColor ( COLOR_HIGHLIGHT ) );
  583.       }
  584.  
  585.         dc.Rectangle(rect);
  586.  
  587.       MSG_AttachmentData * pAttach = (MSG_AttachmentData *)lpDrawItemStruct->itemData;
  588.       if (pAttach)
  589.       {
  590.          char* pFilePath = NULL;
  591.          char * pszString = 
  592.             (pAttach->real_name && strlen(pAttach->real_name)) ? pAttach->real_name : pAttach->url;
  593.          int idBitmap = 0;
  594.          if (!strnicmp(pAttach->url, "file:", strlen("file:")))
  595.          {
  596.             idBitmap = IDB_FILEATTACHMENT;
  597.             if (XP_STRCHR(pAttach->url, '#'))
  598.             {
  599.                char* pTemp = XP_STRCHR(pAttach->url, ':');
  600.                pFilePath = XP_NetToDosFileName(pTemp + 4); // remove :/// 4 bytes
  601.             }
  602.             else if (pszString == pAttach->url)
  603.             {
  604.                XP_ConvertUrlToLocalFile(pAttach->url, &pFilePath);
  605.             }
  606.             if (pFilePath)
  607.             {
  608.                char fname[_MAX_FNAME];
  609.                char ext[_MAX_EXT];
  610.                _splitpath(pFilePath, NULL, NULL, fname, ext);
  611.                *pFilePath = '\0';
  612.                strcat(pFilePath, fname);
  613.                strcat(pFilePath, ext);
  614.  
  615.          pszString = pFilePath; // rhp - move this into the conditional - or crash in MAPI
  616.             }
  617. //            pszString = pFilePath;
  618.          }
  619.          else if (MSG_RequiresNewsWindow(pAttach->url))
  620.                idBitmap = IDB_NEWSARTICLE;
  621.          else if (MSG_RequiresMailWindow(pAttach->url))
  622.                idBitmap = IDB_MAILMESSAGE;
  623.          else if (MSG_RequiresBrowserWindow(pAttach->url))
  624.                idBitmap = IDB_WEBATTACHMENT;
  625.          else
  626.             idBitmap = IDB_WEBATTACHMENT;
  627.  
  628.          rect.left += BITMAP_WIDTH + 4;
  629.          dc.DrawText(pszString,strlen(pszString),rect,DT_LEFT|DT_VCENTER);
  630.          rect.left -= BITMAP_WIDTH + 4;
  631.  
  632.          if (pFilePath)
  633.             XP_FREE(pFilePath);
  634.  
  635.          BITMAP bitmap;
  636.          CBitmap cbitmap;
  637.          cbitmap.LoadBitmap(MAKEINTRESOURCE(idBitmap));
  638.          cbitmap.GetObject(sizeof(BITMAP),&bitmap);
  639.          int center_x = 2;
  640.          int center_y = rect.top + (rect.Height()-bitmap.bmHeight)/2;
  641.          DrawTransparentBitmap( 
  642.             dc.GetSafeHdc(), 
  643.             (HBITMAP)cbitmap.GetSafeHandle(), 
  644.             center_x, center_y, 
  645.             RGB(255,0,255));
  646.          cbitmap.DeleteObject();
  647.       }
  648.  
  649.       if (bSelected)
  650.          dc.DrawFocusRect(rect);
  651.  
  652.       dc.SetTextColor ( cOldText );
  653.       dc.SetBkColor ( cOldBk );        
  654.       dc.SelectObject ( hOldPen );
  655.       dc.SelectObject ( hOldBrush );
  656.  
  657.         dc.Detach();
  658.  
  659.        VERIFY(DeleteObject( hRegBrush ));
  660.        VERIFY(DeleteObject( hRegPen ));
  661.        VERIFY(DeleteObject( hHighBrush ));
  662.        VERIFY(DeleteObject( hHighPen ));
  663.     }
  664. }
  665.  
  666.  
  667. //=============================================================== MeasureItem
  668. void CNSAttachmentList::MeasureItem( LPMEASUREITEMSTRUCT lpMeasureItemStruct )
  669. {
  670.     lpMeasureItemStruct->itemHeight = BITMAP_HEIGHT + 2;
  671. }
  672.  
  673.  
  674. //================================================================ DeleteItem
  675. void CNSAttachmentList::DeleteItem( LPDELETEITEMSTRUCT lpDeleteItemStruct ) 
  676. {
  677. }
  678.  
  679. //////////////////////////////////////////////////////////////////////////////
  680. // CNSAttachDropTarget
  681.  
  682. DROPEFFECT CNSAttachDropTarget::OnDragEnter(CWnd *, COleDataObject *, DWORD, CPoint)
  683. {
  684.     DROPEFFECT DropEffect = DROPEFFECT_NONE;
  685.     return(DropEffect);
  686. }
  687.  
  688. DROPEFFECT CNSAttachDropTarget::OnDragOver(CWnd * pWnd,
  689.     COleDataObject * pDataObject, DWORD dwKeyState, CPoint point)
  690. {
  691.     DROPEFFECT deReturn = DROPEFFECT_NONE;
  692.     // Only interested in bookmarks
  693.     if (pDataObject->IsDataAvailable(
  694.         ::RegisterClipboardFormat(NETSCAPE_BOOKMARK_FORMAT)))
  695.     {
  696.         deReturn = DROPEFFECT_COPY;
  697.     }
  698.     else if (pDataObject->IsDataAvailable(
  699.       ::RegisterClipboardFormat(NETSCAPE_MESSAGE_FORMAT)))
  700.     {
  701.         deReturn = DROPEFFECT_COPY;
  702.     }
  703.    else if(pDataObject->IsDataAvailable(
  704.       ::RegisterClipboardFormat(vCardClipboardFormat)) )
  705.     {
  706.         deReturn = DROPEFFECT_COPY;
  707.     }
  708.  
  709.     return(deReturn);
  710.  
  711.  
  712. void CNSAttachDropTarget::OnDragLeave(CWnd *)
  713. {
  714. }
  715.  
  716. BOOL CNSAttachDropTarget::OnDrop(CWnd * pWnd, COleDataObject * pDataObject, DROPEFFECT, CPoint point)
  717. {
  718.    CComposeFrame * pFrame = (CComposeFrame*)pWnd->GetParentFrame();
  719.    CComposeBar * pComposeBar = pFrame->GetComposeBar();
  720.    if(pDataObject->IsDataAvailable(::RegisterClipboardFormat(vCardClipboardFormat)) )
  721.    {
  722.       pComposeBar->OnAddressTab();
  723.       pComposeBar->UpdateWindow();
  724.       return pComposeBar->ProcessVCardData(pDataObject,point);
  725.    }
  726.    else 
  727.    {
  728.       pComposeBar->OnAttachTab();
  729.       pComposeBar->UpdateWindow();
  730.       return pComposeBar->m_pAttachmentList->ProcessDropTarget(pDataObject);
  731.    }
  732. }
  733.  
  734.