home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / abmldlg.cpp next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  25.7 KB  |  956 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. // abmldlg.cpp : implementation file
  19. //
  20.  
  21. #include "stdafx.h"
  22. #include "addrfrm.h"
  23. #include "template.h"
  24. #include "wfemsg.h"
  25. #include "msg_srch.h"
  26. #include "dirprefs.h"
  27. #include "abmldlg.h"
  28. #include "compfrm.h"
  29. #include "apiaddr.h"
  30. #include "nethelp.h"    // help
  31. #include "xp_help.h"
  32. #include "intl_csi.h"
  33.  
  34. #ifdef _DEBUG
  35. #undef THIS_FILE
  36. static char BASED_CODE THIS_FILE[] = __FILE__;
  37. #endif
  38.  
  39. extern "C" {
  40. #include "xpgetstr.h"
  41. extern int MK_ADDR_ADD_PERSON_TO_ABOOK;
  42. extern int MK_UNABLE_TO_OPEN_ADDR_FILE;
  43. };
  44.  
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CAddrDialogEntryList
  47.  
  48. class CABMLDialogEntryList: public IMsgList {
  49.  
  50.     CABMLDialog *m_pABMLDialog;
  51.     unsigned long m_ulRefCount;
  52.  
  53. public:
  54. // IUnknown Interface
  55.     STDMETHODIMP            QueryInterface(REFIID,LPVOID *);
  56.     STDMETHODIMP_(ULONG)    AddRef(void);
  57.     STDMETHODIMP_(ULONG)    Release(void);
  58.  
  59. // IMsgList Interface
  60.     virtual void ListChangeStarting( MSG_Pane* pane, XP_Bool asynchronous,
  61.                                      MSG_NOTIFY_CODE notify, MSG_ViewIndex where,
  62.                                      int32 num);
  63.     virtual void ListChangeFinished( MSG_Pane* pane, XP_Bool asynchronous,
  64.                                      MSG_NOTIFY_CODE notify, MSG_ViewIndex where,
  65.                                      int32 num);
  66.     virtual void GetSelection( MSG_Pane* pane, MSG_ViewIndex **indices, int *count, 
  67.                                 int *focus);
  68.     virtual void SelectItem( MSG_Pane* pane, int item );
  69.  
  70.     virtual void CopyMessagesInto( MSG_Pane *pane, MSG_ViewIndex *indices, int count,
  71.                                    MSG_FolderInfo *folderInfo) {}
  72.     virtual void MoveMessagesInto( MSG_Pane *pane, MSG_ViewIndex *indices, int count,
  73.                                    MSG_FolderInfo *folderInfo) {}
  74.  
  75.     CABMLDialogEntryList( CABMLDialog *pAddrDialog ) {
  76.         m_ulRefCount = 0;
  77.         m_pABMLDialog = pAddrDialog;
  78.     }
  79. };
  80.  
  81.  
  82. STDMETHODIMP CABMLDialogEntryList::QueryInterface(REFIID refiid, LPVOID * ppv)
  83. {
  84.     *ppv = NULL;
  85.     if (IsEqualIID(refiid,IID_IUnknown))
  86.            *ppv = (LPUNKNOWN) this;
  87.     else if (IsEqualIID(refiid,IID_IMsgList))
  88.            *ppv = (LPMSGLIST) this;
  89.  
  90.     if (*ppv != NULL) {
  91.            AddRef();
  92.         return NOERROR;
  93.     }
  94.             
  95.     return ResultFromScode(E_NOINTERFACE);
  96. }
  97.  
  98. STDMETHODIMP_(ULONG) CABMLDialogEntryList::AddRef(void)
  99. {
  100.     return ++m_ulRefCount;
  101. }
  102.  
  103. STDMETHODIMP_(ULONG) CABMLDialogEntryList::Release(void)
  104. {
  105.     ULONG ulRef;
  106.     ulRef = --m_ulRefCount;
  107.     if (m_ulRefCount == 0) 
  108.         delete this;       
  109.     return ulRef;       
  110. }
  111.  
  112. void CABMLDialogEntryList::ListChangeStarting( MSG_Pane* pane, XP_Bool asynchronous,
  113.                                        MSG_NOTIFY_CODE notify, MSG_ViewIndex where,
  114.                                        int32 num)
  115. {
  116.     if (m_pABMLDialog) {
  117.         m_pABMLDialog->ListChangeStarting( pane, asynchronous,
  118.                                                  notify, where, num );
  119.     }
  120. }
  121.  
  122. void CABMLDialogEntryList::ListChangeFinished( MSG_Pane* pane, XP_Bool asynchronous,
  123.                                        MSG_NOTIFY_CODE notify, MSG_ViewIndex where,
  124.                                        int32 num)
  125. {
  126.     if (m_pABMLDialog) {
  127.         m_pABMLDialog->ListChangeFinished( pane, asynchronous,
  128.                                                  notify, where, num );
  129.     }
  130. }
  131.  
  132. void CABMLDialogEntryList::GetSelection( MSG_Pane* pane, MSG_ViewIndex **indices, int *count, 
  133.                                 int *focus)
  134. {
  135. }
  136.  
  137. void CABMLDialogEntryList::SelectItem( MSG_Pane* pane, int item )
  138. {
  139. }
  140.  
  141.  
  142.  
  143. /////////////////////////////////////////////////////////////////////////////
  144. // CAddrDialog
  145.  
  146. CABMLDialog::CABMLDialog(DIR_Server* dir, CWnd* pParent, 
  147.     ABID listID, MWContext* context)
  148.     : CDialog(CABMLDialog::IDD, pParent)
  149. {
  150.     CString msg;
  151.  
  152.     //{{AFX_DATA_INIT(CAddrList)
  153.     m_description = _T("");
  154.     m_name = _T("");
  155.     m_nickname = _T("");
  156.     //}}AFX_DATA_INIT
  157.  
  158.     m_dir = dir;
  159.     m_entryID = listID;
  160.     m_addingEntries = FALSE;
  161.     m_saved = TRUE;
  162.     m_errorCode = 0;
  163.     m_changingEntry = FALSE;
  164.     m_pFont = NULL;
  165.     m_pDropTarget = NULL;
  166.  
  167.     CABMLDialogEntryList *pInstance = new CABMLDialogEntryList( this );
  168.     pInstance->QueryInterface( IID_IMsgList, (LPVOID *) &m_pIAddrList );
  169.  
  170.     HandleErrorReturn(AB_InitMailingListPane(&m_addrBookPane,
  171.         &m_entryID,
  172.         dir,
  173.         theApp.m_pABook,
  174.         context, WFE_MSGGetMaster(),
  175.         ABFullName, TRUE), this); 
  176.  
  177.     ApiApiPtr(api);
  178.     m_pUnkAddress = api->CreateClassInstance(
  179.         APICLASS_ADDRESSCONTROL,NULL);
  180.     m_pUnkAddress->QueryInterface(IID_IAddressControl,(LPVOID*)&m_pIAddressList);
  181.     m_pIAddressList->SetControlParent(this);
  182.  
  183.     //{{AFX_DATA_INIT(CAddrDialog)
  184.         // NOTE: the ClassWizard will add member initialization here
  185.     //}}AFX_DATA_INIT
  186. }
  187.  
  188. CABMLDialog::~CABMLDialog ( )
  189. {
  190.     if(m_pDropTarget) {
  191.         m_pDropTarget->Revoke();
  192.         delete m_pDropTarget;
  193.         m_pDropTarget = NULL;
  194.     }
  195. }
  196.  
  197. void CABMLDialog::DoDataExchange(CDataExchange* pDX)
  198. {
  199.     CDialog::DoDataExchange(pDX);
  200.     //{{AFX_DATA_MAP(CAddrList)
  201.     DDX_Text(pDX, IDC_Description, m_description);
  202.     DDX_Text(pDX, IDC_NAME, m_name);
  203.     DDX_Text(pDX, IDC_NICKNAME, m_nickname);
  204.     //}}AFX_DATA_MAP
  205. }
  206.  
  207.  
  208. void CABMLDialog::PostNcDestroy()
  209. {
  210.     delete this;
  211.  
  212. } // END OF    FUNCTION CABMLDialog::PostNcDestroy()
  213.  
  214.  
  215. void CABMLDialog::OnDestroy( )
  216. {
  217.     CleanupOnClose();
  218.     if (m_pFont)
  219.         theApp.ReleaseAppFont(m_pFont);
  220. }
  221.  
  222.  
  223. void CABMLDialog::CleanupOnClose()
  224. {
  225.     if (m_pIAddrList)
  226.         m_pIAddrList->Release();
  227.  
  228.     HandleErrorReturn(AB_CloseMailingListPane(&m_addrBookPane), this);
  229.     ((CAddrFrame*) GetParent())->CloseListProperties (this, m_entryID);
  230.     
  231.     m_pUnkAddress->Release();
  232. }
  233.  
  234. void CABMLDialog::OnHelp()
  235. {
  236.     if (m_entryID == MSG_MESSAGEIDNONE)
  237.         NetHelp(HELP_ADD_LIST_MAILING_LIST);
  238.     else
  239.         NetHelp(HELP_MAIL_LIST_PROPS);
  240. }
  241.  
  242. /////////////////////////////////////////////////////////////////////////////
  243. // CABMLDialog Overloaded methods
  244. /////////////////////////////////////////////////////////////////////////////
  245. BOOL CABMLDialog::OnInitDialog( )
  246. {
  247.     if (CDialog::OnInitDialog()) {
  248.         CWnd* widget;
  249.         CRect rect2, rect3;
  250.  
  251.         HDC hDC = ::GetDC(m_hWnd);
  252.         LOGFONT lf;  
  253.         memset(&lf,0,sizeof(LOGFONT));
  254.  
  255.         MWContext * context = FE_GetAddressBookContext ((MSG_Pane *) m_addrBookPane, FALSE);
  256.  
  257.         lf.lfPitchAndFamily = FF_SWISS;
  258.         lf.lfWeight = FW_NORMAL;
  259.         lf.lfCharSet = IntlGetLfCharset(CIntlWin::GetSystemLocaleCsid());
  260.         if (CIntlWin::GetSystemLocaleCsid() == CS_LATIN1)
  261.              _tcscpy(lf.lfFaceName, "MS Sans Serif");
  262.         else
  263.              _tcscpy(lf.lfFaceName, IntlGetUIPropFaceName(CIntlWin::GetSystemLocaleCsid()));
  264.         lf.lfHeight = -MulDiv(9, ::GetDeviceCaps(hDC, LOGPIXELSY), 72);
  265.         m_pFont = theApp.CreateAppFont( lf );
  266.         ::SendMessage(::GetDlgItem(m_hWnd, IDC_NAME), WM_SETFONT, (WPARAM)m_pFont, FALSE);
  267.         ::SendMessage(::GetDlgItem(m_hWnd, IDC_NICKNAME), WM_SETFONT, (WPARAM)m_pFont, FALSE);
  268.         ::SendMessage(::GetDlgItem(m_hWnd, IDC_Description), WM_SETFONT, (WPARAM)m_pFont, FALSE);
  269.         ::ReleaseDC(m_hWnd,hDC);
  270.  
  271.         MSG_SetFEData( (MSG_Pane*) m_addrBookPane, (void *) m_pIAddrList );
  272.  
  273.         widget = GetDlgItem(IDC_ENTRIES);
  274.         widget->GetWindowRect(&rect2);
  275.         widget->GetClientRect(&rect3);
  276.         ScreenToClient(rect2);
  277.  
  278.         widget->DestroyWindow ();
  279.  
  280.         CRect rect(0,0,0,0);
  281.         m_pIAddressList->Create(this,IDC_ADDRESSLIST);
  282.         m_pIAddressList->AddAddressType(NULL);
  283.         m_pIAddressList->SetDefaultBitmapId (IDB_PERSON);
  284.    
  285.         CListBox * pWnd = m_pIAddressList->GetListBox();
  286.         pWnd->Invalidate();
  287.         pWnd->MoveWindow(rect2.left, rect2.top, rect3.right, rect3.bottom, TRUE);
  288.         m_pIAddressList->SetCSID(CIntlWin::GetSystemLocaleCsid());
  289.  
  290.         CPaintDC dc ( pWnd );      
  291.          
  292.         pWnd->GetWindowRect(rect);    
  293.         ScreenToClient(rect);    
  294.         rect.InflateRect(4,4); 
  295.         WFE_DrawRaisedRect(dc.GetSafeHdc(),rect);       
  296.  
  297.         AddEntriesToList (-1, -1);
  298.         m_addingEntries = FALSE;
  299.             
  300.         HandleErrorReturn (AB_GetFullName(m_dir, theApp.m_pABook, m_entryID, m_name.GetBuffer(kMaxFullNameLength)), this);
  301.         m_name.ReleaseBuffer(-1);
  302.         HandleErrorReturn (AB_GetNickname(m_dir, theApp.m_pABook, m_entryID, m_nickname.GetBuffer(kMaxNameLength)), this);
  303.         m_nickname.ReleaseBuffer(-1);
  304.         HandleErrorReturn (AB_GetInfo(m_dir, theApp.m_pABook, m_entryID, m_description.GetBuffer(kMaxInfo)), this);
  305.         m_description.ReleaseBuffer(-1);
  306.         UpdateData(FALSE);
  307.  
  308.         if(!m_pDropTarget) {
  309.            m_pDropTarget = new CMailListDropTarget(this);
  310.            m_pDropTarget->Register(this);
  311.         }
  312.         DragAcceptFiles();
  313.  
  314.     } else {
  315.         return FALSE;
  316.     }
  317.  
  318.     return TRUE;
  319. }
  320.  
  321.  
  322. /////////////////////////////////////////////////////////////////////////////
  323. // CAddrDialog message handlers
  324.  
  325. BEGIN_MESSAGE_MAP(CABMLDialog, CDialog)
  326.     //{{AFX_MSG_MAP(CABMLDialog)
  327.     ON_BN_CLICKED( IDOK, OnOK)
  328.     ON_BN_CLICKED( IDCANCEL, OnCancel)
  329.     ON_BN_CLICKED( IDC_REMOVEITEM, OnRemoveEntry)
  330.     ON_BN_CLICKED( ID_HELP, OnHelp)
  331.     ON_WM_CREATE()
  332.     ON_WM_DESTROY()
  333.     //}}AFX_MSG_MAP
  334. END_MESSAGE_MAP()
  335.  
  336.  
  337. int CABMLDialog::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  338. {
  339.     m_MailNewsResourceSwitcher.Reset();
  340.     int res = CDialog::OnCreate(lpCreateStruct);
  341.  
  342.     MSG_SetFEData( (MSG_Pane*) m_addrBookPane, (void *) m_pIAddrList );
  343.     return res;
  344. }
  345.  
  346.  
  347. BOOL CABMLDialog::PreTranslateMessage( MSG* pMsg )
  348. {
  349.     if (pMsg->message == WM_KEYDOWN)
  350.     {
  351.         if (pMsg->wParam == VK_TAB)
  352.         {
  353.             BOOL bControl = GetKeyState(VK_CONTROL) & 0x8000;
  354.             BOOL bShift = GetKeyState(VK_SHIFT) & 0x8000;
  355.             CWnd* hwndNext = NULL;
  356.  
  357.             CWnd* hwndFocus = GetFocus();
  358.  
  359.             CWnd* hwndDescription = GetDlgItem( IDC_Description );
  360.             CWnd* hwndEntries = m_pIAddressList->GetListBox();
  361.             CEdit* hwndEntriesEdit = m_pIAddressList->GetAddressNameField();
  362.             CWnd* hwndOK = GetDlgItem( IDOK );
  363.  
  364.             if ( bShift ) {
  365.                 // Tab backward
  366.                 if ( hwndFocus == hwndEntries || hwndFocus == hwndEntriesEdit ) {
  367.                     // Tab backward into description
  368.                     hwndNext = hwndDescription;    
  369.                     if (IsWindow(hwndEntriesEdit->m_hWnd)) {
  370.                         hwndEntriesEdit->ShowWindow(SW_HIDE);
  371.                     }
  372.                 } else if (hwndFocus == hwndOK) {
  373.                     // Tab into list
  374.                     hwndNext = hwndEntries;
  375.                 }
  376.             } else {
  377.                 // Tab forward
  378.                 if (hwndFocus == hwndDescription) {
  379.                     // Handle tabbing into list
  380.                     hwndNext = hwndEntries;
  381.                 } else if ( hwndFocus == hwndEntries || hwndFocus == hwndEntriesEdit ) {
  382.                     if (IsWindow(hwndEntriesEdit->m_hWnd)) {
  383.                         hwndEntriesEdit->ShowWindow(SW_HIDE);
  384.                     }
  385.                     hwndNext = hwndOK;
  386.                 }
  387.             }
  388.             if ( hwndNext ) {
  389.                 hwndNext->SetFocus();
  390.                 return TRUE;
  391.             }
  392.         }
  393.     }
  394.     return CDialog::PreTranslateMessage(pMsg);
  395. }
  396.  
  397. void CABMLDialog::OnOK() 
  398. {
  399.     // TODO: Add your specialized code here and/or call the base class
  400.     MailingListEntry        list;
  401.     ABID                    tempID = MSG_MESSAGEIDNONE;
  402.     int                        errorID = 0;
  403.     MSG_ViewIndex            index = 0;
  404.     uint32                    count = 0;
  405.     DIR_Server*                pab = NULL;
  406.     uint                    i = 0;
  407.  
  408.     MWContext * context = FE_GetAddressBookContext ((MSG_Pane *) m_addrBookPane, FALSE);
  409.     INTL_CharSetInfo csi = LO_GetDocumentCharacterSetInfo(context);
  410.  
  411.     UpdateData();
  412.     list.Initialize();
  413.     list.pNickName = m_nickname.GetBuffer(0);
  414.     list.pFullName = m_name.GetBuffer(0);
  415.     list.pInfo = m_description.GetBuffer(0);
  416.     list.WinCSID = INTL_GetCSIWinCSID(csi);
  417.  
  418.     DIR_GetPersonalAddressBook (theApp.m_directories, &pab);
  419.     XP_ASSERT (pab);
  420.     if (!pab)
  421.         HandleErrorReturn(MK_UNABLE_TO_OPEN_ADDR_FILE, this);
  422.  
  423.     AB_GetEntryCountInMailingList(m_addrBookPane, &count);
  424.  
  425.     do
  426.     {
  427.         if ((errorID = AB_ModifyMailingListAndEntriesWithChecks(m_addrBookPane, &list,
  428.             &index, i)) != 0) {
  429.             if (MK_ADDR_ADD_PERSON_TO_ABOOK == errorID)
  430.             {
  431.                 CString s;
  432.                 if (s.LoadString( IDS_BOOKMARK_ADDRESSPROPERTIES ))
  433.                 {
  434.                     char * fullname = NULL;
  435.                     m_pIAddressList->SetSel (index, TRUE);
  436.                     tempID = AB_GetEntryIDAt((AddressPane*) m_addrBookPane, index);
  437.                     AB_GetExpandedName (pab, 
  438.                         theApp.m_pABook, tempID, &fullname);
  439.                     char* tmp = PR_smprintf(XP_GetString (MK_ADDR_ADD_PERSON_TO_ABOOK),
  440.                                         fullname);
  441.                     if (tmp && fullname)
  442.                     {
  443.                         if (::MessageBox(this->m_hWnd, tmp, s, MB_OKCANCEL | MB_APPLMODAL) != IDOK)
  444.                         {
  445.                             XP_FREEIF (tmp);
  446.                             XP_FREEIF (fullname);
  447.                             return;
  448.                         }
  449.                         else
  450.                             errorID = 0;
  451.                         i = index;
  452.                         if (i == count - 1)
  453.                         {
  454.                             errorID = AB_ModifyMailingListAndEntriesWithChecks(m_addrBookPane, &list,
  455.                                 &index, MSG_VIEWINDEXNONE);
  456.                             HandleErrorReturn(errorID, this);
  457.                         }
  458.                     }
  459.                     XP_FREEIF (tmp);
  460.                     XP_FREEIF (fullname);
  461.                 }
  462.             }
  463.             else
  464.             {
  465.                 m_pIAddressList->SetSel (index, TRUE);
  466.                 HandleErrorReturn(errorID, this);
  467.                 break;
  468.             }
  469.         }
  470.         i++;
  471.     } while (i < count && errorID == 0); 
  472.  
  473.     if (!errorID)
  474.         DestroyWindow();
  475. }
  476.  
  477. void CABMLDialog::OnCancel() 
  478. {
  479.     CDialog::OnCancel();
  480.     DestroyWindow();
  481. }
  482.  
  483. void CABMLDialog::AddEntriesToList(int index, int num)
  484. {
  485.     uint32 count = 0;
  486.     ABID entryID;
  487.     ABID type;
  488.     DIR_Server* pab = NULL;
  489.     CListBox * pWnd = m_pIAddressList->GetListBox();
  490.  
  491.     if (m_changingEntry)
  492.         return;
  493.  
  494.     DIR_GetPersonalAddressBook (theApp.m_directories, &pab);
  495.  
  496.     XP_ASSERT (pab);
  497.  
  498.     if (pab)
  499.     {
  500.         HandleErrorReturn (AB_GetEntryCountInMailingList(m_addrBookPane, &count), this);
  501.  
  502.         if (count) {
  503.             m_addingEntries = TRUE;
  504.             if (index != -1)
  505.             {
  506.                 count = index + num;
  507.                 for (int i = index; i < count; i++) 
  508.                 {
  509.                     // add the entry to the list
  510.                     m_pIAddressList->InsertEntry(i, FALSE, "", "", IDB_PERSON, 0);
  511.                 }
  512.             }
  513.             else 
  514.             {
  515.                 pWnd->ResetContent();
  516.                 index = 0;
  517.                 for (int i = 0; i < count; i++) 
  518.                 {
  519.                     // add the entry to the list
  520.                     m_pIAddressList->AppendEntry(FALSE, "", "", IDB_PERSON, 0);
  521.                 }
  522.             }
  523.  
  524.             for (int j = index; j < count; j++) 
  525.             {
  526.                 if ((entryID = AB_GetEntryIDAt((AddressPane*) m_addrBookPane, j)) != MSG_MESSAGEIDNONE) 
  527.                 {
  528.                     char *fullname = NULL;
  529.                     // need to change the bitmap based on the type
  530.                     HandleErrorReturn (AB_GetType (pab, theApp.m_pABook, entryID, &type), this);
  531.                     // if the entry is null, use a null terminated string 
  532.                     HandleErrorReturn (AB_GetExpandedName (pab, 
  533.                         theApp.m_pABook, entryID, &fullname), this);
  534.                     // add the entry to the list
  535.                     m_pIAddressList->SetEntry(j,
  536.                         "",fullname,type==ABTypeList?IDB_MAILINGLIST:IDB_PERSON,entryID);
  537.                     XP_FREEIF (fullname);
  538.                 }
  539.             }
  540.         }
  541.         else {
  542.             m_pIAddressList->AppendEntry();
  543.         }
  544.     }
  545.     else {
  546.         // add the entry to the list
  547.         m_pIAddressList->AppendEntry();
  548.     }
  549.     
  550.     pWnd->Invalidate();
  551.     pWnd->UpdateWindow();
  552. }
  553.  
  554. #ifdef XP_WIN16
  555.     #define LPNMHDR NMHDR*
  556. #endif
  557.  
  558. void CABMLDialog::OnRemoveEntry(void)
  559. {
  560.     ASSERT(m_pIAddressList);
  561.     CListBox * pListBox = m_pIAddressList->GetListBox();
  562.     if (pListBox->GetCount())
  563.     {
  564.         CListBox * pWnd = m_pIAddressList->GetListBox();
  565.         m_pIAddressList->RemoveSelection();
  566.     }
  567. }
  568.  
  569. void CABMLDialog::ListChangeStarting( MSG_Pane* pane, XP_Bool asynchronous,
  570.                                         MSG_NOTIFY_CODE notify, MSG_ViewIndex where,
  571.                                         int32 num)
  572. {
  573.     if ( pane == (MSG_Pane*) m_addrBookPane ) {
  574.         ++m_iMysticPlane;
  575.     }
  576. }
  577.  
  578.  
  579. void CABMLDialog::ListChangeFinished( MSG_Pane* pane, XP_Bool asynchronous,
  580.                                         MSG_NOTIFY_CODE notify, MSG_ViewIndex where,
  581.                                         int32 num)
  582. {
  583.     ABID entryID = MSG_MESSAGEIDNONE;
  584.     if ( pane == (MSG_Pane*) m_addrBookPane ) {
  585.         switch ( notify ) {
  586.         case MSG_NotifyNone:
  587.             break;
  588.  
  589.         case MSG_NotifyInsertOrDelete:
  590.             // this could happen from someone deleting one of the members from the
  591.             // address book or an undo action adding a member back in
  592.             {
  593.                 if (num > 0)
  594.                     AddEntriesToList(CASTINT(where), CASTINT(num));
  595.                 else
  596.                     AddEntriesToList(-1, -1);
  597.             }
  598.             break;
  599.  
  600.         case MSG_NotifyChanged:
  601.             if ((entryID = AB_GetEntryIDAt((AddressPane*) m_addrBookPane, where)) != MSG_MESSAGEIDNONE) 
  602.             {
  603.                 char *fullname = NULL;
  604.                 DIR_Server* pab  = NULL;
  605.                 ABID type;
  606.                 DIR_GetPersonalAddressBook (theApp.m_directories, &pab);
  607.                 XP_ASSERT (pab);
  608.                 if (pab)
  609.                 {
  610.                     HandleErrorReturn (AB_GetExpandedName (pab, 
  611.                         theApp.m_pABook, entryID, &fullname), this);
  612.                     HandleErrorReturn (AB_GetType (pab, theApp.m_pABook, entryID, &type), this);
  613.                     m_pIAddressList->SetItemBitmap(CASTINT(where), type==ABTypeList?IDB_MAILINGLIST:IDB_PERSON);
  614.                     m_pIAddressList->SetItemEntryID(CASTINT(where), entryID);
  615.                     m_pIAddressList->SetItemName(CASTINT(where), fullname);
  616.                     XP_FREEIF (fullname);
  617.                 }
  618.             }
  619.             break;
  620.  
  621.         case MSG_NotifyAll:
  622.         case MSG_NotifyScramble:
  623.             AddEntriesToList(-1, -1);
  624.             break;
  625.         }
  626.  
  627.         if (( !--m_iMysticPlane && m_addrBookPane)) {
  628.             CListBox * pWnd = m_pIAddressList->GetListBox();
  629.             pWnd->Invalidate();
  630.             pWnd->UpdateWindow();
  631.         }
  632.     }
  633. }
  634.  
  635.  
  636. void CABMLDialog::HandleErrorReturn(int errorid, CWnd* parent)
  637. {    
  638.     if (errorid) {
  639.         CString s;
  640.         HWND parentWnd = NULL;
  641.         if (parent)
  642.             parentWnd = parent->m_hWnd;
  643.         if (s.LoadString( IDS_BOOKMARK_ADDRESSPROPERTIES ))
  644.             ::MessageBox(parentWnd, XP_GetString(errorid), s, MB_OK | MB_APPLMODAL);
  645.     }
  646. }
  647.  
  648.  
  649. // IAddressParent stuff
  650. // these functions are in compbar.cpp, they should be prototyped
  651. // in some header file and placed somewhere more appropriate
  652.  
  653. extern "C" char * wfe_ExpandForNameCompletion(char * pString);
  654. extern "C" char * wfe_ExpandName(char * pString, unsigned long* entryID, UINT* bitmapID);
  655.  
  656. int CABMLDialog::ChangedItem (char * pString, int index, HWND hwnd, char ** ppFullName, unsigned long* entryID, UINT* bitmapID)
  657. {
  658.     if (!m_addingEntries) {
  659.         ABID type, field, tempID = MSG_MESSAGEIDNONE;
  660.         char* fullname = NULL;
  661.         m_saved = FALSE;
  662.         int errorID = 0;
  663.  
  664.         DIR_Server* pab  = NULL;
  665.  
  666.         DIR_GetPersonalAddressBook (theApp.m_directories, &pab);
  667.  
  668.         XP_ASSERT (pab);
  669.         tempID = (*entryID);
  670.  
  671.         if (pab)
  672.         {
  673.             // check if this is one that has already been
  674.             // expanded and hasn't changed
  675.             if (tempID != MSG_MESSAGEIDNONE) {
  676.                 AB_GetExpandedName (pab, 
  677.                     theApp.m_pABook, tempID, &fullname);
  678.                 if (fullname)
  679.                 {
  680.                     if (XP_STRCMP (fullname, pString) == 0)
  681.                     {
  682.                         (*ppFullName) = fullname;
  683.                         return 0;
  684.                     }
  685.                 }
  686.             }
  687.  
  688.             m_changingEntry = TRUE;
  689.  
  690.             AB_GetIDForNameCompletion(
  691.                 theApp.m_pABook,
  692.                 pab, 
  693.                 &tempID, &field, (LPCTSTR)pString);
  694.         
  695.             if (tempID != MSG_MESSAGEIDNONE)
  696.             {            
  697.                 if ((*entryID) == MSG_MESSAGEIDNONE)
  698.                     m_errorCode = AB_AddIDToMailingListAt (m_addrBookPane, tempID, index);
  699.                 else
  700.                     m_errorCode = AB_ReplaceIDInMailingListAt(m_addrBookPane, tempID, index);
  701.  
  702.                 AB_GetExpandedName (pab, 
  703.                     theApp.m_pABook, tempID, &fullname);
  704.                 // need to change the bitmap based on the type
  705.                 AB_GetType (pab, 
  706.                     theApp.m_pABook, tempID, &type);
  707.                 if (type == ABTypeList)
  708.                     (*bitmapID) = IDB_MAILINGLIST;          
  709.                 else
  710.                     (*bitmapID) = IDB_PERSON; 
  711.             }
  712.             else {
  713.                 PersonEntry person;
  714.                 person.Initialize();
  715.                 person.pGivenName = pString;
  716.                 person.pEmailAddress = pString;
  717.                 MWContext * context = FE_GetAddressBookContext ((MSG_Pane *) m_addrBookPane, FALSE);
  718.                 INTL_CharSetInfo csi = LO_GetDocumentCharacterSetInfo(context);
  719.                 person.WinCSID = INTL_GetCSIWinCSID(csi);
  720.  
  721.                 m_errorCode = AB_AddPersonToMailingListAt(m_addrBookPane, &person, index, &tempID);
  722.                 fullname = (char *) XP_ALLOC (kMaxFullNameLength);
  723.                 if (fullname)
  724.                 {
  725.                     XP_STRCPY (fullname, "");
  726.                     XP_STRCPY (fullname, pString);
  727.                 }
  728.                 (*bitmapID) = IDB_PERSON; 
  729.             }  
  730.             m_changingEntry = FALSE;
  731.             (*ppFullName) = fullname;
  732.             (*entryID) = tempID;
  733.             return 0;
  734.         }
  735.         else
  736.             return 0;
  737.     }
  738.     return 0;
  739. }
  740.  
  741. void CABMLDialog::DeletedItem (HWND hwnd, LONG id, int index)
  742. {
  743.     HandleErrorReturn (AB_RemoveIDFromMailingListAt (m_addrBookPane, index), this);
  744. }
  745.  
  746. void CABMLDialog::AddedItem (HWND hwnd, LONG id, int index)
  747. {
  748. }
  749.  
  750. char * CABMLDialog::NameCompletion(char * pString)
  751. {
  752.     ABID entryID = -1;
  753.     ABID field = -1;
  754.     DIR_Server* pab  = NULL;
  755.  
  756.     DIR_GetPersonalAddressBook (theApp.m_directories, &pab);
  757.     if (pab != NULL && theApp.m_pABook)
  758.     {
  759.     AB_GetIDForNameCompletion(
  760.         theApp.m_pABook,
  761.         pab, 
  762.         &entryID,&field,(LPCTSTR)pString);
  763.     if (entryID != -1)
  764.     {
  765.             if (field == ABNickname) {
  766.                 char szNickname[kMaxNameLength];
  767.                 AB_GetNickname(
  768.                     pab, 
  769.                     theApp.m_pABook, entryID, szNickname);
  770.                 if (strlen(szNickname))
  771.                     return strdup(szNickname);
  772.             }
  773.         else {
  774.                 char szFullname[kMaxFullNameLength];
  775.                 AB_GetFullName(pab, theApp.m_pABook, 
  776.                     entryID, szFullname);
  777.                 if (strlen(szFullname))
  778.                     return strdup(szFullname);
  779.             }
  780.         }
  781.     }
  782.  
  783.     return NULL;
  784. }
  785.  
  786. BOOL CABMLDialog::IsDragInListBox(CPoint *pPoint)
  787. {
  788.     CRect listRect;
  789.  
  790.     CListBox * pListBox = m_pIAddressList->GetListBox();
  791.     pListBox->GetWindowRect(LPRECT(listRect));
  792.     ScreenToClient(LPRECT(listRect));
  793.     if (listRect.PtInRect(*pPoint))
  794.         return TRUE;
  795.     else
  796.         return FALSE;
  797. }
  798.  
  799. BOOL CABMLDialog::ProcessVCardData(COleDataObject * pDataObject, CPoint &point)
  800. {
  801.     UINT clipFormat, fromABFormat;
  802.     BOOL retVal;
  803.     CWnd * pWnd = GetFocus();
  804.     ABID tempID = MSG_MESSAGEIDNONE;
  805.     HGLOBAL hEntryIDs = NULL;
  806.     LPSTR pEntryIDs = NULL;
  807.  
  808.     if (pDataObject->IsDataAvailable(
  809.         clipFormat = ::RegisterClipboardFormat(vCardClipboardFormat))) 
  810.     {
  811.         if (pDataObject->IsDataAvailable(
  812.             fromABFormat = ::RegisterClipboardFormat(ADDRESSBOOK_SOURCETARGET_FORMAT)))
  813.         {
  814.             hEntryIDs = pDataObject->GetGlobalData(fromABFormat);
  815.             pEntryIDs = (LPSTR)GlobalLock(hEntryIDs);
  816.             ASSERT(pEntryIDs);
  817.         }
  818.         HGLOBAL hAddresses = pDataObject->GetGlobalData(clipFormat);
  819.         LPSTR pAddresses = (LPSTR)GlobalLock(hAddresses);
  820.         ASSERT(pAddresses);
  821.         XP_List * pEntries;
  822.         int32 iEntries;
  823.  
  824.         if (m_pIAddressList)
  825.         {
  826.             int itemNum = 0;
  827.             char * szType = NULL;
  828.             char * szName = NULL;
  829.             char * pszType = NULL;
  830.             CListBox * pListBox = m_pIAddressList->GetListBox();
  831.             if (!AB_ConvertVCardsToExpandedName(theApp.m_pABook,pAddresses,&pEntries,&iEntries))
  832.             {
  833.                 XP_List * node = pEntries;
  834.                 char *pTemp = NULL;
  835.  
  836.                 if (pEntryIDs)    //from Address Book
  837.                     pTemp = pEntryIDs;
  838.  
  839.                 for (int32 i = 0; i < iEntries+1; i++)
  840.                 {
  841.                     char * pString = (char *)node->object; 
  842.                     if (pString != NULL)
  843.                     {
  844.                         m_changingEntry = TRUE;
  845.                         int nIndex = pListBox->GetCount() - 1;
  846.                         if (pEntryIDs)    //from Address Book
  847.                         {
  848.                             char  szEntryID[20];
  849.                             ABID  entryID;
  850.                             ABID type;
  851.                             char *fullname = NULL;
  852.                             DIR_Server* pab = NULL;
  853.  
  854.                             szEntryID[0] = '\0';
  855.                             int nPos = 0;
  856.                             while (pTemp[nPos] != '\0')
  857.                             {
  858.                                 if (pTemp[nPos] == '-')
  859.                                 {
  860.                                     strncpy(szEntryID, pTemp, nPos);
  861.                                     szEntryID[nPos] = '\0';
  862.                                     pTemp = pTemp + nPos + 1;
  863.                                     break;
  864.                                 }
  865.                                 else 
  866.                                     nPos++;
  867.                             }
  868.                             entryID    = atol(szEntryID);
  869.  
  870.                             DIR_GetPersonalAddressBook (theApp.m_directories, &pab);
  871.                             m_errorCode = AB_AddIDToMailingListAt(m_addrBookPane, entryID, nIndex);
  872.                             // need to change the bitmap based on the type
  873.                             HandleErrorReturn (AB_GetType (pab, theApp.m_pABook, entryID, &type));
  874.                             // if the entry is null, use a null terminated string 
  875.                             HandleErrorReturn (AB_GetExpandedName (pab, 
  876.                                 theApp.m_pABook, entryID, &fullname));
  877.                             m_pIAddressList->SetEntry(nIndex, "", fullname, type==ABTypeList?IDB_MAILINGLIST:IDB_PERSON, 0);
  878.                             m_pIAddressList->AppendEntry(FALSE);
  879.                             XP_FREEIF (fullname);
  880.                         }
  881.                         else
  882.                         {
  883.                             char* names = NULL;
  884.                             char* addresses = NULL;
  885.                             int num = 0;
  886.  
  887.                             num = MSG_ParseRFC822Addresses(pString, &names, &addresses);
  888.  
  889.                             if (num > 0)
  890.                             {
  891.                                 XP_ASSERT(names);
  892.                                 XP_ASSERT(addresses);
  893.  
  894.                                 PersonEntry person;
  895.                                 person.Initialize();
  896.                                 person.pGivenName = names;
  897.                                 person.pEmailAddress = addresses;
  898.                                 MWContext * context = FE_GetAddressBookContext ((MSG_Pane *) m_addrBookPane, FALSE);
  899.                                 INTL_CharSetInfo csi = LO_GetDocumentCharacterSetInfo(context);
  900.                                 person.WinCSID = INTL_GetCSIWinCSID(csi);
  901.                                 m_errorCode = AB_AddPersonToMailingListAt(m_addrBookPane, &person, nIndex, &tempID);
  902.                                 m_pIAddressList->InsertEntry(nIndex, FALSE, "", pString, IDB_PERSON, 0);
  903.                                 m_pIAddressList->AppendEntry(FALSE, "", "", IDB_PERSON);
  904.  
  905.                                 XP_FREEIF(names);
  906.                                 XP_FREEIF(addresses);
  907.                             }
  908.                         }
  909.                     }
  910.                     node = node->next;
  911.                     if (!node)
  912.                         break;
  913.                 }
  914.                 XP_ListDestroy(pEntries);
  915.             }
  916.             if (hEntryIDs)
  917.                 GlobalUnlock(hEntryIDs);
  918.             GlobalUnlock(hAddresses);
  919.             retVal = TRUE;
  920.             m_changingEntry = FALSE;
  921.         }
  922.     }
  923.     if (pWnd && ::IsWindow(pWnd->m_hWnd))
  924.         pWnd->SetFocus();
  925.     return retVal;
  926. }
  927.  
  928. //////////////////////////////////////////////////////////////////////////////
  929. // CMailListDropTarget
  930.  
  931. DROPEFFECT CMailListDropTarget::OnDragOver(CWnd * pWnd,
  932.     COleDataObject * pDataObject, DWORD dwKeyState, CPoint point)
  933. {
  934.     DROPEFFECT deReturn = DROPEFFECT_NONE;
  935.     // Only interested in vcard
  936.     if(pDataObject->IsDataAvailable(
  937.       ::RegisterClipboardFormat(vCardClipboardFormat)) )
  938.     {
  939.         if (m_pOwner->IsDragInListBox(&point))
  940.             deReturn = DROPEFFECT_COPY;
  941.     }
  942.     return(deReturn);
  943.  
  944. BOOL CMailListDropTarget::OnDrop
  945. (CWnd * pWnd, COleDataObject * pDataObject, DROPEFFECT, CPoint point)
  946. {
  947.     if (pDataObject->IsDataAvailable(::RegisterClipboardFormat(vCardClipboardFormat)) )
  948.     {
  949.         return m_pOwner->ProcessVCardData(pDataObject,point);
  950.     }
  951.     return FALSE;
  952. }
  953.  
  954.  
  955.