home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / addrdlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  65.2 KB  |  2,495 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. // addrdlg.cpp : implementation file
  19. //
  20.  
  21. #include "stdafx.h"
  22. #include "wfemsg.h"
  23. #include "msg_srch.h"
  24. #include "dirprefs.h"
  25. #include "addrdlg.h"
  26. #include "apiaddr.h"
  27. #include "nethelp.h" 
  28. #include "prefapi.h"
  29. #include "intl_csi.h"
  30. #include "srchdlg.h"
  31.  
  32. #ifdef _DEBUG
  33. #undef THIS_FILE
  34. static char BASED_CODE THIS_FILE[] = __FILE__;
  35. #endif
  36.  
  37. extern "C" {
  38. #include "xpgetstr.h"
  39. extern int MK_ADDR_CCNAME;
  40. extern int MK_ADDR_BCCNAME;
  41. extern int MK_ADDR_TONAME;
  42. };
  43.  
  44. #define ADDRESS_DIALOG_TIMER                7
  45. #define TYPEDOWN_SPEED                        300
  46. #define LDAP_SEARCH_SPEED                    1250
  47. #define ADDRDLG_OUTLINER_TYPEDOWN_TIMER     251
  48. #define OUTLINER_TYPEDOWN_SPEED                1250
  49.  
  50.  
  51. class CAddrDialog;
  52.  
  53.  
  54. CAddrDialogCX::CAddrDialogCX(CAddrDialog *pDialog)  
  55. : CStubsCX(AddressCX, MWContextAddressBook)
  56. {
  57.     m_pDialog = pDialog;
  58.     m_lPercent = 0;
  59.     m_bAnimated = FALSE;
  60. }
  61.  
  62.  
  63. void CAddrDialogCX::SetProgressBarPercent(MWContext *pContext, int32 lPercent ) {
  64.     //    Ensure the safety of the value.
  65.  
  66.     lPercent = lPercent < 0 ? 0 : ( lPercent > 100 ? 100 : lPercent );
  67.  
  68.     if ( m_lPercent == lPercent ) {
  69.         return;
  70.     }
  71.  
  72.     m_lPercent = lPercent;
  73.     if (m_pDialog) {
  74.         m_pDialog->SetProgressBarPercent(lPercent);
  75.     }
  76. }
  77.  
  78. void CAddrDialogCX::Progress(MWContext *pContext, const char *pMessage) {
  79.     m_csProgress = pMessage;
  80.     if ( m_pDialog ) {
  81.         m_pDialog->SetStatusText(pMessage);
  82.     }
  83. }
  84.  
  85. int32 CAddrDialogCX::QueryProgressPercent()    {
  86.     return m_lPercent;
  87. }
  88.  
  89.  
  90. void CAddrDialogCX::AllConnectionsComplete(MWContext *pContext)    
  91. {
  92.     //  Call the base.
  93.     CStubsCX::AllConnectionsComplete(pContext);
  94.  
  95.     //    Also, we can clear the progress bar now.
  96.     m_lPercent = 0;
  97.     if ( m_pDialog ) {
  98.         m_pDialog->SetProgressBarPercent(m_lPercent);
  99.         m_pDialog->AllConnectionsComplete(pContext);
  100.     }
  101.     if (m_pDialog) {
  102.         m_pDialog->SendMessageToDescendants(WM_IDLEUPDATECMDUI, (WPARAM)TRUE, (LPARAM)0);
  103.     }
  104. }
  105.  
  106. void CAddrDialogCX::UpdateStopState( MWContext *pContext )
  107. {
  108.     if (m_pDialog) {
  109.         m_pDialog->SendMessageToDescendants(WM_IDLEUPDATECMDUI, (WPARAM)TRUE, (LPARAM)0);
  110.     }
  111. }
  112.  
  113. CWnd *CAddrDialogCX::GetDialogOwner() const {
  114.     return m_pDialog;
  115. }
  116.  
  117.  
  118. /////////////////////////////////////////////////////////////////////////////
  119. // CAddrDialogEntryList
  120.  
  121. class CAddrDialogEntryList: public IMsgList {
  122.  
  123.     CAddrDialog *m_pAddrDialog;
  124.     unsigned long m_ulRefCount;
  125.  
  126. public:
  127. // IUnknown Interface
  128.     STDMETHODIMP            QueryInterface(REFIID,LPVOID *);
  129.     STDMETHODIMP_(ULONG)    AddRef(void);
  130.     STDMETHODIMP_(ULONG)    Release(void);
  131.  
  132. // IMsgList Interface
  133.     virtual void ListChangeStarting( MSG_Pane* pane, XP_Bool asynchronous,
  134.                                      MSG_NOTIFY_CODE notify, MSG_ViewIndex where,
  135.                                      int32 num);
  136.     virtual void ListChangeFinished( MSG_Pane* pane, XP_Bool asynchronous,
  137.                                      MSG_NOTIFY_CODE notify, MSG_ViewIndex where,
  138.                                      int32 num);
  139.     virtual void GetSelection( MSG_Pane* pane, MSG_ViewIndex **indices, int *count, 
  140.                                 int *focus);
  141.     virtual void SelectItem( MSG_Pane* pane, int item );
  142.  
  143.     virtual void CopyMessagesInto( MSG_Pane *pane, MSG_ViewIndex *indices, int count,
  144.                                    MSG_FolderInfo *folderInfo) {}
  145.     virtual void MoveMessagesInto( MSG_Pane *pane, MSG_ViewIndex *indices, int count,
  146.                                    MSG_FolderInfo *folderInfo) {}
  147.  
  148.     CAddrDialogEntryList( CAddrDialog *pAddrDialog ) {
  149.         m_ulRefCount = 0;
  150.         m_pAddrDialog = pAddrDialog;
  151.     }
  152. };
  153.  
  154.  
  155. STDMETHODIMP CAddrDialogEntryList::QueryInterface(REFIID refiid, LPVOID * ppv)
  156. {
  157.     *ppv = NULL;
  158.     if (IsEqualIID(refiid,IID_IUnknown))
  159.            *ppv = (LPUNKNOWN) this;
  160.     else if (IsEqualIID(refiid,IID_IMsgList))
  161.            *ppv = (LPMSGLIST) this;
  162.     else if (IsEqualIID(refiid,IID_IMailFrame))
  163.         *ppv = (LPMAILFRAME) m_pAddrDialog;
  164.  
  165.     if (*ppv != NULL) {
  166.            AddRef();
  167.         return NOERROR;
  168.     }
  169.             
  170.     return ResultFromScode(E_NOINTERFACE);
  171. }
  172.  
  173. STDMETHODIMP_(ULONG) CAddrDialogEntryList::AddRef(void)
  174. {
  175.     return ++m_ulRefCount;
  176. }
  177.  
  178. STDMETHODIMP_(ULONG) CAddrDialogEntryList::Release(void)
  179. {
  180.     ULONG ulRef;
  181.     ulRef = --m_ulRefCount;
  182.     if (m_ulRefCount == 0) 
  183.         delete this;       
  184.     return ulRef;       
  185. }
  186.  
  187. void CAddrDialogEntryList::ListChangeStarting( MSG_Pane* pane, XP_Bool asynchronous,
  188.                                        MSG_NOTIFY_CODE notify, MSG_ViewIndex where,
  189.                                        int32 num)
  190. {
  191.     if (m_pAddrDialog) {
  192.         m_pAddrDialog->ListChangeStarting( pane, asynchronous,
  193.                                                  notify, where, num );
  194.     }
  195. }
  196.  
  197. void CAddrDialogEntryList::ListChangeFinished( MSG_Pane* pane, XP_Bool asynchronous,
  198.                                        MSG_NOTIFY_CODE notify, MSG_ViewIndex where,
  199.                                        int32 num)
  200. {
  201.     if (m_pAddrDialog) {
  202.         m_pAddrDialog->ListChangeFinished( pane, asynchronous,
  203.                                                  notify, where, num );
  204.     }
  205. }
  206.  
  207. void CAddrDialogEntryList::GetSelection( MSG_Pane* pane, MSG_ViewIndex **indices, int *count, 
  208.                                 int *focus)
  209. {
  210. }
  211.  
  212. void CAddrDialogEntryList::SelectItem( MSG_Pane* pane, int item )
  213. {
  214. }
  215.  
  216.  
  217.  
  218. /////////////////////////////////////////////////////////////////////////////
  219. // CAddrDialog
  220.  
  221. CAddrDialog::CAddrDialog(
  222.     CWnd* pParent, /*=NULL*/
  223.     BOOL isMapi, LPSTR winText, MAPIAddressCallbackProc mapiCB, MAPIAddressGetAddrProc mapiGetProc  // rhp - MAPI
  224.     )
  225.     : CDialog(CAddrDialog::IDD, pParent)
  226. {
  227.  
  228.     CString msg;
  229.     int result = 0;
  230.     INTL_CharSetInfo csi;
  231.  
  232.     m_pCX = new CAddrDialogCX( this );
  233.     csi = LO_GetDocumentCharacterSetInfo(m_pCX->GetContext());
  234.  
  235.     m_pCX->GetContext()->type = MWContextAddressBook;
  236.     m_pCX->GetContext()->fancyFTP = TRUE;
  237.     m_pCX->GetContext()->fancyNews = TRUE;
  238.     m_pCX->GetContext()->intrupt = FALSE;
  239.     m_pCX->GetContext()->reSize = FALSE;
  240.     INTL_SetCSIWinCSID(csi, CIntlWin::GetSystemLocaleCsid());
  241.  
  242.     m_pOutliner = NULL;
  243.     m_addrBookPane = NULL;
  244.     m_bSearching = FALSE;
  245.     m_directory = 0;
  246.     m_pDropTarget = NULL;
  247.     m_idefButtonID = IDC_TO;
  248.  
  249.     CAddrDialogEntryList *pInstance = new CAddrDialogEntryList( this );
  250.     pInstance->QueryInterface( IID_IMsgList, (LPVOID *) &m_pIAddrList );
  251.  
  252.     HandleErrorReturn((result = AB_CreateAddressBookPane(&m_addrBookPane,
  253.             m_pCX->GetContext(),
  254.             WFE_MSGGetMaster())));
  255.  
  256.   // rhp - MAPI stuff...
  257.   m_isMAPI = isMapi;
  258.   m_mapiHeader = NULL;
  259.   m_mapiCBProc = NULL;
  260.   m_mapiGetAddrProc = NULL;
  261.     
  262.   if (m_isMAPI)
  263.   {
  264.     if ( (winText) && (*winText) )
  265.     {
  266.       m_mapiHeader = strdup(winText);
  267.     }
  268.  
  269.     m_mapiCBProc = mapiCB; 
  270.     m_mapiGetAddrProc = mapiGetProc;
  271.   }
  272.  
  273.     //{{AFX_DATA_INIT(CAddrDialog)
  274.         // NOTE: the ClassWizard will add member initialization here
  275.     //}}AFX_DATA_INIT
  276. }
  277.  
  278. void CAddrDialog::OnKeyDown ( UINT nChar, UINT nRepCnt, UINT nFlags )
  279. {
  280.     CDialog::OnKeyDown ( nChar, nRepCnt, nFlags );
  281. }
  282.  
  283. void CAddrDialog::CleanupOnClose()
  284. {
  285.     // DestroyContext will call Interrupt, but if we wait until after DestroyContext
  286.     // to call MSG_SearchFree, the MWContext will be gone, and we'll be reading freed memory
  287.  
  288.     PREF_SetIntPref("mail.addr_picker.sliderwidth", m_pSplitter->GetPaneSize());
  289.  
  290.     if (XP_IsContextBusy (m_pCX->GetContext()))
  291.         XP_InterruptContext (m_pCX->GetContext());
  292.     MSG_SearchFree ((MSG_Pane*) m_addrBookPane);
  293.  
  294.     if (m_pIAddrList)
  295.         m_pIAddrList->Release();
  296.  
  297.     if (m_addrBookPane)
  298.         HandleErrorReturn(AB_CloseAddressBookPane(&m_addrBookPane));
  299.  
  300.     if(!m_pCX->IsDestroyed()) {
  301.         m_pCX->DestroyContext();
  302.     }
  303.     if (m_pFont){
  304.         theApp.ReleaseAppFont(m_pFont);
  305.     }
  306.  
  307.     if (m_pOutlinerParent){
  308.         delete m_pOutlinerParent;
  309.     }
  310.  
  311.     if (m_pDirOutlinerParent){
  312.         delete m_pDirOutlinerParent;
  313.     }
  314.  
  315.     if (m_pSplitter){
  316.         delete m_pSplitter;
  317.     }
  318.  
  319.     if (m_pDropTarget) {
  320.         m_pDropTarget->Revoke();
  321.         delete m_pDropTarget;
  322.         m_pDropTarget = NULL;
  323.     }
  324.  
  325.   // rhp - for MAPI
  326.   if (m_isMAPI)
  327.   {
  328.     if (m_mapiHeader)
  329.       free(m_mapiHeader);
  330.   }
  331. }
  332.  
  333. /////////////////////////////////////////////////////////////////////////////
  334. // CAddrDialog Overloaded methods
  335. /////////////////////////////////////////////////////////////////////////////
  336.  
  337. // rhp - this is needed for the population of the to address type...
  338. void
  339. CAddrDialog::ProcessMAPIAddressPopulation(void)
  340. {
  341.   int     index = 0;
  342.   LPSTR   name;
  343.   LPSTR   address;
  344.   int     addrType;
  345.  
  346.   if (!m_mapiGetAddrProc)
  347.     return;
  348.  
  349.   CListBox *pBucket = GetBucket();
  350.  
  351.   while ( m_mapiGetAddrProc(&name, &address, &addrType) )
  352.   {
  353.     char          *formatted;
  354.     char          tempString[512] = "";
  355.     int           nIndex = -1;
  356.     NSADDRESSLIST *pAddress = new NSADDRESSLIST;
  357.  
  358.     ASSERT(pAddress);
  359.     if (!pAddress)
  360.       continue;
  361.  
  362.     if ((name) && (*name))
  363.     {
  364.       strcat(tempString, name);
  365.       strcat(tempString, " ");
  366.     }
  367.  
  368.     if ( (!address) || (!(*address)) )
  369.       continue;
  370.  
  371.     strcat(tempString, "<");
  372.     strcat(tempString, address);
  373.     strcat(tempString, ">");
  374.  
  375.     pAddress->ulHeaderType = addrType;
  376.     pAddress->idBitmap = 0; 
  377.     pAddress->idEntry = 0;
  378.     pAddress->szAddress = strdup (tempString);
  379.  
  380.     GetFormattedString(tempString, addrType, &formatted);
  381.     if (formatted) 
  382.     {
  383.       nIndex = pBucket->InsertString( index, formatted );
  384.       free (formatted);
  385.     }
  386.  
  387.     if ( nIndex < 0 )
  388.       return;
  389.  
  390.     pBucket->SetItemDataPtr( nIndex, pAddress );
  391.     ++index;
  392.   }
  393.  
  394.   OnSelchange();
  395. }
  396.  
  397. BOOL CAddrDialog::OnInitDialog( )
  398. {
  399.     if (CDialog::OnInitDialog()) {
  400.         CWnd* widget;
  401.         CRect rect2, rect3, rect4;
  402.         UINT aIDArray[] = { IDS_SECURITY_STATUS, IDS_TRANSFER_STATUS, ID_SEPARATOR};
  403.         int result = 0;
  404.  
  405.         CListBox *pBucket = GetBucket();
  406.  
  407.         DIR_Server* dir = (DIR_Server*)XP_ListGetObjectNum(theApp.m_directories, 1);
  408.  
  409.         XP_ASSERT (dir);
  410.  
  411.         if (!dir)
  412.             return FALSE;
  413.  
  414.         HandleErrorReturn((result = AB_InitializeAddressBookPane(m_addrBookPane,
  415.             dir,
  416.             theApp.m_pABook,
  417.             ABFullName,
  418.             TRUE)));
  419.  
  420.         if (result) {
  421.             EndDialog(IDCANCEL);
  422.             return TRUE;
  423.         }
  424.  
  425.         widget = GetDlgItem(IDC_ADDRESSLIST);
  426.         widget->GetWindowRect(&rect2);
  427.         widget->GetClientRect(&rect3);
  428.         GetClientRect(&rect4);
  429.         ClientToScreen(&rect4);
  430.         rect2.OffsetRect(-rect4.left, -rect4.top);
  431.  
  432.         widget->DestroyWindow ();
  433.  
  434.         // create slider control
  435.         m_pSplitter = (CMailNewsSplitter *) RUNTIME_CLASS(CMailNewsSplitter)->CreateObject();
  436.  
  437.         ASSERT(m_pSplitter);
  438.  
  439. #ifdef _WIN32
  440.         m_pSplitter->CreateEx(0, NULL, NULL,
  441.                                   WS_CHILD|WS_VISIBLE|WS_TABSTOP,
  442.                                   0, 0, 0, 0,
  443.                                   this->m_hWnd, (HMENU) IDC_ADDRESSLIST );
  444. #else
  445.         CCreateContext Context;
  446.         Context.m_pCurrentFrame = NULL; //  nothing to base on
  447.         Context.m_pCurrentDoc = NULL;  //  nothing to base on
  448.         Context.m_pNewViewClass = NULL; // nothing to base on
  449.         Context.m_pNewDocTemplate = NULL;   //  nothing to base on
  450.         m_pSplitter->Create( NULL, NULL,
  451.                                  WS_CHILD|WS_VISIBLE |WS_TABSTOP,
  452.                                  rect2, this, IDC_ADDRESSLIST, &Context ); 
  453. #endif 
  454.  
  455.         // create the outliner control
  456.         m_pOutlinerParent = new CAddrDialogOutlinerParent;
  457. #ifdef _WIN32
  458.         m_pOutlinerParent->CreateEx ( WS_EX_CLIENTEDGE, NULL, _T("NSOutlinerParent"), 
  459.                                 WS_TABSTOP|WS_VISIBLE|WS_CHILD|WS_CLIPCHILDREN,
  460.                                 0, 0, 0, 0,
  461.                                 m_pSplitter->m_hWnd, (HMENU) 99);
  462. #else
  463.         rect2.SetRectEmpty();
  464.         m_pOutlinerParent->Create( NULL, _T("NSOutlinerParent"), 
  465.                                   WS_BORDER|WS_TABSTOP|WS_VISIBLE|WS_CHILD,
  466.                                   rect2, m_pSplitter, 99);
  467. #endif
  468.  
  469.         m_pOutlinerParent->CreateColumns ( );
  470.         m_pOutlinerParent->EnableFocusFrame(TRUE);
  471.         m_pOutliner = (CAddrDialogOutliner *) m_pOutlinerParent->m_pOutliner;
  472.         m_pOutliner->SetPane(m_addrBookPane);
  473.         m_pOutliner->SetContext( m_pCX->GetContext() );
  474.  
  475.         // create the directory outliner control
  476.         m_pDirOutlinerParent = new CAddrDialogDirOutlinerParent;
  477.  
  478. #ifdef _WIN32
  479.         m_pDirOutlinerParent->CreateEx(WS_EX_CLIENTEDGE, NULL, _T("NSOutlinerParent"),
  480.                                   WS_TABSTOP|WS_VISIBLE|WS_CHILD|WS_CLIPCHILDREN,
  481.                                   0,0,0,0, m_pSplitter->m_hWnd, (HMENU) 100 );
  482. #else
  483.         m_pDirOutlinerParent->Create( NULL, _T("NSOutlinerParent"),
  484.                                  WS_BORDER|WS_TABSTOP|WS_VISIBLE|WS_CHILD,
  485.                                  CRect(0,0,0,0), m_pSplitter, 100);
  486. #endif
  487.  
  488.         m_pDirOutliner = (CAddrDialogDirOutliner *) m_pDirOutlinerParent->m_pOutliner;
  489.         m_pDirOutlinerParent->CreateColumns ( );
  490.         m_pDirOutlinerParent->EnableFocusFrame(TRUE);
  491.         m_pDirOutliner->SetContext( m_pCX->GetContext() );
  492.         m_pDirOutliner->SetPane(m_addrBookPane);
  493.         m_pDirOutliner->SetDirectoryIndex(0);
  494.  
  495.         // 4 seems to work with all the beveled border
  496.         int32 prefInt = 4;
  497.         PREF_GetIntPref("mail.addr_picker.sliderwidth", &prefInt);
  498.         RECT rect;
  499.         GetClientRect(&rect);
  500.         m_pSplitter->AddPanes(m_pDirOutlinerParent, m_pOutlinerParent, prefInt, TRUE);
  501.         m_pSplitter->SetWindowPos(GetDlgItem(ID_NAVIGATE_INTERRUPT), rect2.left, rect2.top, rect3.right, rect3.bottom, SWP_SHOWWINDOW);
  502.  
  503.         m_pDirOutlinerParent->SetWindowPos(GetDlgItem(ID_NAVIGATE_INTERRUPT), 0, 0, 
  504.             rect3.right, rect3.bottom, SWP_NOMOVE|SWP_NOSIZE);
  505.         m_pOutlinerParent->SetWindowPos(m_pDirOutlinerParent, 0, 0, 
  506.             rect3.right, rect3.bottom, SWP_NOMOVE|SWP_NOSIZE);
  507.         // reset the tab order
  508.         widget = GetDlgItem (IDC_TO);
  509.         widget->SetWindowPos(m_pOutlinerParent, 0, 0, 
  510.             rect3.right, rect3.bottom, SWP_NOMOVE|SWP_NOSIZE);
  511.         UpdateDirectories();
  512.  
  513.         // create the status bar
  514.         widget = GetDlgItem(IDC_StatusRect);
  515.         widget->GetWindowRect(&rect2);
  516.         widget->GetClientRect(&rect3);
  517.         ScreenToClient(&rect2);
  518.  
  519.         widget->DestroyWindow ();
  520.  
  521.         m_barStatus.Create(this, TRUE, FALSE);
  522.  
  523.         m_barStatus.MoveWindow(&rect2, TRUE);
  524.     
  525.         m_barStatus.SetIndicators( aIDArray, sizeof(aIDArray) / sizeof(UINT) );
  526.  
  527.         DoUpdateWidget(IDC_DIRSEARCH, AB_LDAPSearchCmd, TRUE);
  528.         DoUpdateWidget(IDC_TO, AB_NewMessageCmd, TRUE);
  529.         UpdateMsgButtons();
  530.  
  531.         CGenericFrame *pCompose = (CGenericFrame *)GetParent();
  532.  
  533.         ApiApiPtr(api);
  534.         LPUNKNOWN pUnk = api->CreateClassInstance(
  535.              APICLASS_ADDRESSCONTROL, NULL, (APISIGNATURE)pCompose);
  536.         if (pUnk)
  537.         {
  538.             LPADDRESSCONTROL pIAddressControl;
  539.             HRESULT hRes = pUnk->QueryInterface(IID_IAddressControl,(LPVOID*)&pIAddressControl);
  540.             ASSERT(hRes==NOERROR);
  541.             LPNSADDRESSLIST pList = NULL;
  542.             int count = pIAddressControl->GetAddressList(&pList);
  543.             pUnk->Release();
  544.             for (int index = 0; index < count; index++)
  545.             {
  546.                 if (pList[index].szAddress)
  547.                 {
  548.                     if (strlen (pList[index].szAddress)) 
  549.                     {
  550.                         NSADDRESSLIST *pAddress = new NSADDRESSLIST;
  551.                         char * formatted;
  552.                         int nIndex = -1;
  553.                         ASSERT(pAddress);
  554.                         pAddress->ulHeaderType = pList[index].ulHeaderType;
  555.                         pAddress->idBitmap = pList[index].idBitmap; 
  556.                         pAddress->idEntry = pList[index].idEntry;
  557.                         pAddress->szAddress = strdup (pList[index].szAddress);
  558.                         GetFormattedString(pList[index].szAddress, pList[index].ulHeaderType, &formatted);
  559.                         if (formatted) 
  560.                         {
  561.                             nIndex = pBucket->InsertString( index, formatted );
  562.                             free (formatted);
  563.                         }
  564.                         free (pList[index].szAddress);
  565.                         if ( nIndex < 0 )
  566.                             return 0;
  567.                         pBucket->SetItemDataPtr( nIndex, pAddress );
  568.                     }
  569.                 }
  570.             }
  571.             free(pList);
  572.             OnSelchange();
  573.         } else 
  574.         {
  575.             return FALSE;
  576.         }
  577.     } else 
  578.     {
  579.         return FALSE;
  580.     }
  581.  
  582.     HDC hDC = ::GetDC(m_hWnd);
  583.     LOGFONT lf;  
  584.     memset(&lf,0,sizeof(LOGFONT));
  585.     lf.lfPitchAndFamily = FF_SWISS;
  586.     lf.lfWeight = FW_NORMAL;
  587.     lf.lfCharSet = IntlGetLfCharset(CIntlWin::GetSystemLocaleCsid());
  588.     if (CIntlWin::GetSystemLocaleCsid() == CS_LATIN1)
  589.         _tcscpy(lf.lfFaceName, "MS Sans Serif");
  590.     else
  591.         _tcscpy(lf.lfFaceName, IntlGetUIPropFaceName(CIntlWin::GetSystemLocaleCsid()));
  592.     lf.lfHeight = -MulDiv(9, ::GetDeviceCaps(hDC, LOGPIXELSY), 72);
  593.     m_pFont = theApp.CreateAppFont( lf );
  594.     ::ReleaseDC(m_hWnd,hDC);
  595.  
  596.     ::SendMessage(::GetDlgItem(m_hWnd, IDC_ADDRNAME), WM_SETFONT, (WPARAM)m_pFont, FALSE);
  597.     ::SendMessage(::GetDlgItem(m_hWnd, IDC_ADDRESSBKT), WM_SETFONT, (WPARAM)m_pFont, FALSE);
  598.  
  599.     if(!m_pDropTarget) {
  600.        m_pDropTarget = new CAddressPickerDropTarget(this);
  601.        m_pDropTarget->Register(this);
  602.     }
  603.     DragAcceptFiles();
  604.  
  605.     CComboBox *directory = (CComboBox*) GetDlgItem(IDC_DIRECTORIES);
  606.     directory->SetCurSel (0);
  607.     m_pOutliner->SetDirectoryIndex(    directory->GetCurSel());
  608.     m_pDirOutliner->SetFocusLine(0);
  609.     if (m_pOutliner->GetTotalLines())
  610.         m_pOutliner->SelectItem (0);
  611.     GetDlgItem(IDC_ADDRNAME)->SetFocus();
  612.     SendMessage(DM_SETDEFID, m_idefButtonID, TRUE);
  613.     GetDlgItem(m_idefButtonID)->SendMessage(BM_SETSTYLE, BS_DEFPUSHBUTTON, MAKELPARAM(TRUE, 0));
  614.     GetDlgItem(IDC_DONE_EDITING)->SendMessage(BM_SETSTYLE, BS_PUSHBUTTON, MAKELPARAM(TRUE, 0));
  615.  
  616.   // rhp - for MAPI
  617.   if (m_isMAPI) 
  618.   {
  619.     ProcessMAPIAddressPopulation();
  620.  
  621.     if (m_mapiHeader)
  622.     {
  623.       SetWindowText(m_mapiHeader);
  624.     }
  625.   }
  626.  
  627.     return FALSE;
  628. }
  629.  
  630.  
  631. void CAddrDialog::GetFormattedString(char* fullname, MSG_HEADER_SET header, char** formatted)
  632. {
  633.  
  634.     CString formattedString;
  635.     if (fullname) {
  636.         switch (header) {
  637.             case MSG_TO_HEADER_MASK:
  638.                 formattedString.Format(XP_GetString (MK_ADDR_TONAME), fullname);
  639.                 break;
  640.             case MSG_CC_HEADER_MASK:
  641.                 formattedString.Format(XP_GetString (MK_ADDR_CCNAME), fullname);
  642.                 break;
  643.             case MSG_BCC_HEADER_MASK:
  644.                 formattedString.Format(XP_GetString (MK_ADDR_BCCNAME), fullname);
  645.                 break;
  646.             default:
  647.                 formattedString.Format(XP_GetString (MK_ADDR_TONAME), fullname);
  648.         }
  649.     }
  650.     (*formatted) = strdup (formattedString);
  651. }
  652.  
  653. void CAddrDialog::Progress(const char *pMessage)
  654. {
  655.     m_barStatus.SetWindowText( pMessage );
  656. }
  657.  
  658.  
  659. void CAddrDialog::SetProgressBarPercent(int32 lPercent)
  660. {
  661.     m_barStatus.SetPercentDone (lPercent);
  662. } // END OF    FUNCTION CAddrDialog::DrawProgressBar()
  663.  
  664.  
  665. /////////////////////////////////////////////////////////////////////////////
  666. // CAddrDialog message handlers
  667.  
  668. BEGIN_MESSAGE_MAP(CAddrDialog, CDialog)
  669.     //{{AFX_MSG_MAP(CAddrDialog)
  670.     ON_WM_TIMER ()
  671.     ON_EN_SETFOCUS(IDC_ADDRNAME, OnSetFocusName)
  672.     ON_EN_CHANGE(IDC_ADDRNAME, OnChangeName)
  673.     ON_CBN_SELCHANGE(IDC_DIRECTORIES, OnChangeDirectory)
  674.     ON_BN_CLICKED(IDC_DIRSEARCH, OnDirectorySearch)
  675.     ON_BN_CLICKED(ID_NAVIGATE_INTERRUPT, OnStopSearch)
  676.     ON_BN_CLICKED( IDC_DONE_EDITING, OnDone)
  677.     ON_BN_CLICKED( IDCANCEL, OnCancel)
  678.     ON_WM_CREATE()
  679.     ON_WM_DESTROY()
  680.     ON_WM_KEYDOWN()
  681.     ON_COMMAND(IDC_TO, OnComposeMsg)
  682.     ON_COMMAND(IDC_CC, OnComposeCCMsg)
  683.     ON_COMMAND(IDC_BCC, OnComposeBCCMsg)
  684.     ON_COMMAND(ID_ITEM_PROPERTIES, OnGetProperties)
  685.     ON_LBN_SELCHANGE(IDC_ADDRESSBKT, OnSelchange)
  686.     ON_COMMAND(ID_HELP, OnHelp)
  687.     ON_LBN_SETFOCUS(IDC_ADDRESSBKT, OnSetFocusBucket)
  688.     //}}AFX_MSG_MAP
  689. END_MESSAGE_MAP()
  690.  
  691. BOOL CAddrDialog::PreTranslateMessage( MSG* pMsg )
  692. {
  693.     if (pMsg->message == WM_KEYDOWN && pMsg->hwnd == m_pOutliner->GetSafeHwnd())
  694.     {
  695.         if (pMsg->wParam != VK_TAB && pMsg->wParam != VK_ESCAPE && pMsg->wParam != VK_RETURN) {
  696.             ::SendMessage(pMsg->hwnd, WM_KEYDOWN, pMsg->wParam, pMsg->lParam);
  697.             return TRUE;
  698.         }
  699.     }
  700.  
  701.     if (pMsg->message == WM_KEYDOWN && pMsg->hwnd == GetBucket()->GetSafeHwnd())
  702.     {
  703.         if (pMsg->wParam == VK_DELETE || pMsg->wParam == VK_BACK) {
  704.             OnRemove();
  705.             return TRUE;
  706.         }
  707.     }
  708.  
  709.     if (pMsg->message == WM_KEYDOWN && pMsg->hwnd == GetDlgItem(IDC_ADDRNAME)->GetSafeHwnd())
  710.     {
  711.         if (pMsg->wParam == VK_UP || pMsg->wParam == VK_DOWN) {
  712.             ::SendMessage(m_pOutliner->GetSafeHwnd(), WM_KEYDOWN, pMsg->wParam, pMsg->lParam);
  713.             CWnd* widget = NULL;
  714.             widget = GetDlgItem (GetDefaultButtonID());
  715.             if (widget) {
  716.                 SendMessage(DM_SETDEFID, GetDefaultButtonID(), TRUE);
  717.                 widget->SendMessage(BM_SETSTYLE, BS_DEFPUSHBUTTON, MAKELPARAM(TRUE, 0));
  718.                 widget = GetDlgItem (IDC_DONE_EDITING);
  719.                 widget->SendMessage(BM_SETSTYLE, BS_PUSHBUTTON, MAKELPARAM(TRUE, 0));
  720.             }
  721.             return TRUE;
  722.         }
  723.     }
  724.  
  725.     if (pMsg->message == WM_KEYDOWN) {    
  726.         if (pMsg->wParam == VK_TAB) {
  727.             HWND hwndNext = NULL;
  728.             HWND hwndFocus = ::GetFocus();
  729.  
  730.             HWND hwndPossibleNext = ::GetNextDlgTabItem( m_hWnd, pMsg->hwnd, FALSE );
  731.  
  732.             HWND hwndPossiblePrev = ::GetNextDlgTabItem( m_hWnd, pMsg->hwnd, TRUE );
  733.  
  734.             HWND hwndDirOutliner = m_pDirOutliner ? m_pDirOutliner->m_hWnd : NULL;
  735.             HWND hwndOutliner = m_pOutliner ? m_pOutliner->m_hWnd : NULL;
  736.             HWND hwndSlider = m_pSplitter ? m_pSplitter->m_hWnd : NULL;
  737.             HWND hwndDefSendButton = GetDlgItem(m_idefButtonID) ? GetDlgItem(m_idefButtonID)->m_hWnd : NULL;
  738.             HWND hwndPropButton = GetDlgItem(ID_ITEM_PROPERTIES) ? GetDlgItem(ID_ITEM_PROPERTIES)->m_hWnd : NULL;
  739.                 
  740.  
  741.             if ( GetKeyState(VK_SHIFT) & 0x8000 ) {
  742.  
  743.                 // Tab backward
  744.                 if ( hwndFocus == hwndPropButton ) {
  745.                     // Handle tabbing back to the to/cc/bcc buttons
  746.                     if (::IsWindowEnabled (hwndDefSendButton)) {
  747.                         hwndNext = hwndDefSendButton;
  748.                         DWORD defID = SendMessage(DM_GETDEFID, 0, 0);
  749.                         int defaultID = LOWORD (defID);
  750.                         SendMessage(DM_SETDEFID, m_idefButtonID, TRUE);
  751.                         GetDlgItem(m_idefButtonID)->SendMessage(BM_SETSTYLE, BS_DEFPUSHBUTTON, MAKELPARAM(TRUE, 0));
  752.                         if (defaultID != m_idefButtonID)
  753.                             GetDlgItem(defaultID)->SendMessage(BM_SETSTYLE, BS_PUSHBUTTON, MAKELPARAM(TRUE, 0));
  754.                     }
  755.                 } else if (hwndFocus == hwndOutliner) {
  756.                     // Handle tabbing out of outliner into the directory list
  757.                     if (m_pSplitter->IsOnePaneClosed())
  758.                         hwndNext = hwndPossiblePrev;
  759.                     else
  760.                         hwndNext = hwndDirOutliner;
  761.                 } else if ( hwndFocus == hwndDirOutliner ) {
  762.                     // Handle tabbing out of the slider
  763.                     hwndNext = hwndPossiblePrev;
  764.                 } else if ( hwndPossiblePrev == hwndSlider ) {
  765.                     // Handle tabbing back to the outliner from the 
  766.                     // to/cc/bcc buttons the bucket
  767.                     hwndNext = hwndOutliner;
  768.                 }
  769.  
  770.             } else {
  771.  
  772.                 // Tab forward
  773.                 if (hwndFocus == hwndOutliner) {
  774.                     // Handle tabbing out of outliner
  775.                     if (::IsWindowEnabled (hwndDefSendButton)) {
  776.                         hwndNext = hwndDefSendButton;
  777.                         DWORD defID = SendMessage(DM_GETDEFID, 0, 0);
  778.                         int defaultID = LOWORD (defID);
  779.                         SendMessage(DM_SETDEFID, m_idefButtonID, TRUE);
  780.                         GetDlgItem(m_idefButtonID)->SendMessage(BM_SETSTYLE, BS_DEFPUSHBUTTON, MAKELPARAM(TRUE, 0));
  781.                         if (defaultID != m_idefButtonID)
  782.                             GetDlgItem(defaultID)->SendMessage(BM_SETSTYLE, BS_PUSHBUTTON, MAKELPARAM(TRUE, 0));
  783.                     }
  784.                 } else if ( hwndPossibleNext == hwndSlider ) {
  785.                     // handle tabbing into the directory list
  786.                     if (m_pSplitter->IsOnePaneClosed())
  787.                         hwndNext = hwndOutliner;
  788.                     else
  789.                         hwndNext = hwndDirOutliner;
  790.                 } else if (hwndFocus == hwndDirOutliner) {
  791.                     // Handle tabbing out of the directory list
  792.                     // and into the results list
  793.                     hwndNext = hwndOutliner;
  794.                 }
  795.  
  796.             }
  797.             if ( hwndNext ) {
  798.                 ::SetFocus( hwndNext );
  799.                 return TRUE;
  800.             }
  801.         }
  802.     } // if tab && keydown 
  803.  
  804.     return CDialog::PreTranslateMessage(pMsg);
  805. }
  806.  
  807. void CAddrDialog::UpdateDirectories()
  808. {
  809.     DIR_Server* dir;
  810.     CComboBox *widget = (CComboBox*) GetDlgItem(IDC_DIRECTORIES);
  811.  
  812.     widget->ResetContent();
  813.  
  814.     XP_List *pTraverse = theApp.m_directories;
  815.     while(dir = (DIR_Server *)XP_ListNextObject(pTraverse)) {
  816.         if (dir->dirType == PABDirectory || dir->dirType == LDAPDirectory)
  817.             widget->AddString(dir->description);
  818.     }
  819.     if (m_directory == -1)
  820.         widget->SetCurSel(0);
  821.     else
  822.         widget->SetCurSel(m_directory);
  823.  
  824.     m_pDirOutliner->UpdateCount();
  825. }
  826.  
  827.  
  828. DIR_Server * CAddrDialog::GetCurrentDirectoryServer()
  829. {
  830.     return (DIR_Server*) XP_ListGetObjectNum (theApp.m_directories, m_pOutliner->GetDirectoryIndex() + 1);
  831. }
  832.  
  833.  
  834. void CAddrDialog::OnTimer(UINT nID)
  835. {
  836.     CWnd::OnTimer(nID);
  837.     if (nID == ADDRESS_DIALOG_TIMER) {
  838.         KillTimer(m_uTypedownClock);
  839.         if (!m_name.IsEmpty()) {
  840.             DIR_Server* dir;
  841.             dir = GetCurrentDirectoryServer();
  842.             if (dir->dirType == LDAPDirectory)
  843.                 PerformListDirectory (m_name.GetBuffer(0));
  844.             else
  845.                 PerformTypedown(m_name.GetBuffer(0));
  846.             m_name.ReleaseBuffer();
  847.         }
  848.     }
  849. }
  850.  
  851.  
  852. void CAddrDialog::DoDataExchange(CDataExchange* pDX)
  853. {
  854.     CDialog::DoDataExchange(pDX);
  855.     //{{AFX_DATA_MAP(CAddrDialog)
  856.     DDX_Text(pDX, IDC_ADDRNAME, m_name);
  857.     DDX_CBIndex(pDX, IDC_DIRECTORIES, m_directory);
  858.     //}}AFX_DATA_MAP
  859. }
  860.  
  861.  
  862. void CAddrDialog::OnChangeName() 
  863. {
  864.     // TODO: Add your control notification handler code here
  865.     if (IsSearching()) {
  866.         OnDirectorySearch();
  867.         SendMessage(DM_SETDEFID, m_idefButtonID, TRUE);
  868.         GetDlgItem(m_idefButtonID)->SendMessage(BM_SETSTYLE, BS_DEFPUSHBUTTON, MAKELPARAM(TRUE, 0));
  869.         GetDlgItem(IDC_DONE_EDITING)->SendMessage(BM_SETSTYLE, BS_PUSHBUTTON, MAKELPARAM(TRUE, 0));
  870.         return;
  871.     }
  872.  
  873.     UpdateData(TRUE);
  874.  
  875.     if (m_name != m_save) {
  876.         m_save = m_name;
  877.         KillTimer(m_uTypedownClock);
  878.         if (m_name.GetLength())
  879.         {
  880.             DIR_Server* dir = NULL;
  881.             SendMessage(DM_SETDEFID, m_idefButtonID, TRUE);
  882.             GetDlgItem(m_idefButtonID)->SendMessage(BM_SETSTYLE, BS_DEFPUSHBUTTON, MAKELPARAM(TRUE, 0));
  883.             GetDlgItem(IDC_DONE_EDITING)->SendMessage(BM_SETSTYLE, BS_PUSHBUTTON, MAKELPARAM(TRUE, 0));
  884.             dir = GetCurrentDirectoryServer();
  885.             if (dir->dirType == PABDirectory)
  886.                 m_uTypedownClock = SetTimer(ADDRESS_DIALOG_TIMER, TYPEDOWN_SPEED, NULL);
  887.             else {
  888.                 int32 prefInt = LDAP_SEARCH_SPEED;
  889.                 PREF_GetIntPref("ldap_1.autoComplete.interval", &prefInt);
  890.                 m_uTypedownClock = SetTimer(ADDRESS_DIALOG_TIMER, prefInt, NULL);
  891.             }
  892.         }
  893.     }
  894. }
  895.  
  896.  
  897. void CAddrDialog::OnSetFocusName() 
  898. {
  899.     CEdit *widget = (CEdit*) GetDlgItem(IDC_ADDRNAME);
  900.     if (widget)
  901.         widget->SetSel(0, -1, TRUE);
  902.     SendMessage(DM_SETDEFID, m_idefButtonID, TRUE);
  903.     GetDlgItem(m_idefButtonID)->SendMessage(BM_SETSTYLE, BS_DEFPUSHBUTTON, MAKELPARAM(TRUE, 0));
  904.     GetDlgItem(IDC_DONE_EDITING)->SendMessage(BM_SETSTYLE, BS_PUSHBUTTON, MAKELPARAM(TRUE, 0));
  905. }
  906.  
  907. void CAddrDialog::OnSetFocusBucket() 
  908. {
  909.     CListBox *pBucket = (CListBox*)GetDlgItem(IDC_ADDRESSBKT);
  910.  
  911.     if (pBucket->GetCount()) {
  912.         SendMessage(DM_SETDEFID, IDC_DONE_EDITING, TRUE);
  913.         GetDlgItem(IDC_DONE_EDITING)->SendMessage(BM_SETSTYLE, BS_DEFPUSHBUTTON, MAKELPARAM(TRUE, 0));
  914.         GetDlgItem(m_idefButtonID)->SendMessage(BM_SETSTYLE, BS_PUSHBUTTON, MAKELPARAM(TRUE, 0));
  915.     }
  916. }
  917.  
  918. void CAddrDialog::OnChangeDirectory() 
  919. {
  920.     // TODO: Add your control notification handler code here
  921.     if (IsSearching())
  922.         return;
  923.  
  924.     UpdateData(TRUE);
  925.  
  926.     if (m_directory != m_savedir) {
  927.         m_savedir = m_directory;
  928.         if (m_directory != -1) {
  929.             if (m_pDirOutliner)
  930.                 m_pDirOutliner->SetDirectoryIndex(m_directory);
  931.             PerformChangeDirectory(m_directory);
  932.         }
  933.     }
  934. }
  935.  
  936. void CAddrDialog::OnSelchange() 
  937. {
  938.     CListBox *pBucket = (CListBox*)GetDlgItem(IDC_ADDRESSBKT);
  939.  
  940.     BOOL bEnabled = (pBucket->GetCount() > 0)? TRUE : FALSE;
  941.     pBucket->EnableWindow (bEnabled);
  942.     GetDlgItem(IDC_DONE_EDITING)->EnableWindow(bEnabled);
  943.     if (bEnabled) {
  944.         SendMessage(DM_SETDEFID, IDC_DONE_EDITING, TRUE);
  945.         GetDlgItem(IDC_DONE_EDITING)->SendMessage(BM_SETSTYLE, BS_DEFPUSHBUTTON, MAKELPARAM(TRUE, 0));
  946.         GetDlgItem(m_idefButtonID)->SendMessage(BM_SETSTYLE, BS_PUSHBUTTON, MAKELPARAM(TRUE, 0));
  947.     }
  948.     else {
  949.         GetDlgItem(IDC_ADDRNAME)->SetFocus();
  950.         SendMessage(DM_SETDEFID, m_idefButtonID, TRUE);
  951.         GetDlgItem(m_idefButtonID)->SendMessage(BM_SETSTYLE, BS_DEFPUSHBUTTON, MAKELPARAM(TRUE, 0));
  952.         GetDlgItem(IDC_DONE_EDITING)->SendMessage(BM_SETSTYLE, BS_PUSHBUTTON, MAKELPARAM(TRUE, 0));
  953.     }
  954.  
  955.   
  956.     // TODO: Add your control notification handler code here
  957. }
  958.  
  959. void CAddrDialog::DoUpdateWidget( int command, AB_CommandType cmd, BOOL bUseCheck )
  960. {
  961.  
  962.     CWnd* widget;
  963.  
  964.     XP_Bool bSelectable = FALSE, bPlural = FALSE;
  965.     MSG_COMMAND_CHECK_STATE sState;
  966.  
  967.     if (m_addrBookPane) {
  968.         if (m_pOutliner) {
  969.             MSG_ViewIndex *indices = NULL;
  970.             int count = 0;
  971.             m_pOutliner->GetSelection(indices, count);
  972.             AB_CommandStatus(m_addrBookPane,
  973.                               cmd,
  974.                               indices, count,
  975.                               &bSelectable,
  976.                               &sState,
  977.                               NULL,
  978.                               &bPlural);
  979.         } else {
  980.             AB_CommandStatus(m_addrBookPane,
  981.                               cmd,
  982.                               NULL, 0,
  983.                               &bSelectable,
  984.                               &sState,
  985.                               NULL,
  986.                               &bPlural);
  987.         }
  988.     }
  989.  
  990.     widget = GetDlgItem ( command );
  991.     widget->EnableWindow(bSelectable);
  992. }
  993.  
  994.  
  995. void CAddrDialog::OnDirectorySearch() 
  996. {
  997.     // TODO: Add your control notification handler code here
  998.     if (m_directory != -1) 
  999.         PerformDirectorySearch();
  1000. }
  1001.  
  1002.  
  1003. int CAddrDialog::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  1004. {
  1005.     m_MailNewsResourceSwitcher.Reset();
  1006.     int res = CDialog::OnCreate(lpCreateStruct);
  1007.  
  1008.     MSG_SetFEData( (MSG_Pane*) m_addrBookPane, (void *) m_pIAddrList );
  1009.     return res;
  1010. }
  1011.  
  1012. // rhp - This is for MAPI processing...
  1013. void
  1014. CAddrDialog::ProcessMAPIOnDone(void)
  1015. {
  1016.   CListBox *pBucket = GetBucket();
  1017.   
  1018.   int count = pBucket->GetCount();
  1019.   if (count != LB_ERR && count > 0)
  1020.   {
  1021.       for (int index = 0; index < count; index++)
  1022.       {
  1023.         NSADDRESSLIST * pAddress = (NSADDRESSLIST *)(pBucket->GetItemDataPtr(index));
  1024.         ASSERT(pAddress);
  1025.         if (m_mapiCBProc)
  1026.         {
  1027.           m_mapiCBProc(count, index, pAddress->ulHeaderType, 
  1028.                           pAddress->szAddress); // rhp - for MAPI
  1029.         }
  1030.         delete (pAddress);
  1031.       }
  1032.   }
  1033.   
  1034.   CDialog::OnOK();
  1035.   CleanupOnClose();
  1036. }
  1037.  
  1038. void CAddrDialog::OnDone() 
  1039. {
  1040.     NSADDRESSLIST* pAddressList;
  1041.     CListBox *pBucket = GetBucket();
  1042.  
  1043.   // rhp - for MAPI...
  1044.   if (m_isMAPI)
  1045.   {
  1046.     ProcessMAPIOnDone();
  1047.     return;
  1048.   }
  1049.  
  1050.     int count = pBucket->GetCount();
  1051.     if (count != LB_ERR && count > 0)
  1052.     {
  1053.         pAddressList = (NSADDRESSLIST *)calloc(count, sizeof(NSADDRESSLIST));
  1054.         if (pAddressList)
  1055.         {
  1056.             for (int index = 0; index < count; index++)
  1057.             {
  1058.                 NSADDRESSLIST * pAddress = (NSADDRESSLIST *)(pBucket->GetItemDataPtr(index));
  1059.                 ASSERT(pAddress);
  1060.                 pAddressList[index].ulHeaderType = pAddress->ulHeaderType;
  1061.                 pAddressList[index].idBitmap = pAddress->idBitmap;
  1062.                 pAddressList[index].idEntry = pAddress->idEntry;
  1063.                 pAddressList[index].szAddress = pAddress->szAddress;
  1064.                 delete (pAddress);
  1065.             }
  1066.         }
  1067.     
  1068.         CGenericFrame *pCompose = (CGenericFrame *)GetParent();
  1069.  
  1070.         ApiApiPtr(api);
  1071.         LPUNKNOWN pUnk = api->CreateClassInstance(
  1072.              APICLASS_ADDRESSCONTROL, NULL, (APISIGNATURE)pCompose);
  1073.         if (pUnk)
  1074.         {
  1075.             LPADDRESSCONTROL pIAddressControl;
  1076.             HRESULT hRes = pUnk->QueryInterface(IID_IAddressControl,(LPVOID*)&pIAddressControl);
  1077.             ASSERT(hRes==NOERROR);
  1078.             int ct = pIAddressControl->SetAddressList(pAddressList, count);
  1079.             pUnk->Release();
  1080.         }
  1081.     }
  1082.  
  1083.     CDialog::OnOK();
  1084.     CleanupOnClose();
  1085. }
  1086.  
  1087.  
  1088. void CAddrDialog::OnCancel() 
  1089. {
  1090.     CDialog::OnCancel();
  1091.     CleanupOnClose();
  1092. }
  1093.  
  1094. void CAddrDialog::ListChangeStarting( MSG_Pane* pane, XP_Bool asynchronous,
  1095.                                         MSG_NOTIFY_CODE notify, MSG_ViewIndex where,
  1096.                                         int32 num)
  1097. {
  1098.     if ( pane == (MSG_Pane*) m_addrBookPane ) {
  1099.         if ( m_pOutliner ) {
  1100.             m_pOutliner->MysticStuffStarting( asynchronous, notify,
  1101.                                                    where, num );
  1102.         }
  1103.     }
  1104. }
  1105.  
  1106. void CAddrDialog::ListChangeFinished( MSG_Pane* pane, XP_Bool asynchronous,
  1107.                                         MSG_NOTIFY_CODE notify, MSG_ViewIndex where,
  1108.                                         int32 num)
  1109. {
  1110.     if ( pane == (MSG_Pane*) m_addrBookPane ) {
  1111.         if ( m_pOutliner ) {
  1112.             m_pOutliner->MysticStuffFinishing( asynchronous, notify,
  1113.                                                     where, num );
  1114.             UpdateMsgButtons();
  1115.         }
  1116.     }
  1117. }
  1118.  
  1119.  
  1120. void CAddrDialog::SetStatusText(const char* pMessage)
  1121. {
  1122.     m_barStatus.SetWindowText( pMessage );
  1123. }
  1124.  
  1125.  
  1126. void CAddrDialog::SetSearchResults(MSG_ViewIndex index, int32 num)
  1127. {
  1128.  
  1129.     CString csStatus;
  1130.  
  1131.     ASSERT(m_pOutliner);
  1132.     AB_LDAPSearchResults(m_addrBookPane, index, num);
  1133.     if (num > 1 ) {
  1134.         csStatus.Format( szLoadString(IDS_SEARCHHITS), num );
  1135.     } else if ( num > 0 ) {
  1136.         csStatus.LoadString( IDS_SEARCHONEHIT );
  1137.     } else {
  1138.         csStatus.LoadString( IDS_SEARCHNOHITS );
  1139.     }
  1140.  
  1141.     m_barStatus.SetWindowText( csStatus );
  1142.  
  1143. }
  1144.  
  1145. STDMETHODIMP CAddrDialog::QueryInterface(REFIID refiid, LPVOID * ppv)
  1146. {
  1147.     *ppv = NULL;
  1148.     if (IsEqualIID(refiid,IID_IUnknown))
  1149.            *ppv = (LPUNKNOWN) (LPMAILFRAME) this;
  1150.     else if (IsEqualIID(refiid,IID_IMailFrame))
  1151.         *ppv = (LPMAILFRAME) this;
  1152.  
  1153.     if (*ppv != NULL) {
  1154.            AddRef();
  1155.         return NOERROR;
  1156.     }
  1157.             
  1158.     return ResultFromScode(E_NOINTERFACE);
  1159. }
  1160.  
  1161. STDMETHODIMP_(ULONG) CAddrDialog::AddRef(void)
  1162. {
  1163.     return 0; // Not a real component
  1164. }
  1165.  
  1166. STDMETHODIMP_(ULONG) CAddrDialog::Release(void)
  1167. {
  1168.     return 0; // Not a real component
  1169. }
  1170.  
  1171. // IMailFrame interface
  1172. CMailNewsFrame *CAddrDialog::GetMailNewsFrame()
  1173. {
  1174.     return (CMailNewsFrame *) NULL; 
  1175. }
  1176.  
  1177. MSG_Pane *CAddrDialog::GetPane()
  1178. {
  1179.     return (MSG_Pane*) m_addrBookPane;
  1180. }
  1181.  
  1182. void CAddrDialog::PaneChanged(MSG_Pane *pane, XP_Bool asynchronous, 
  1183.                                  MSG_PANE_CHANGED_NOTIFY_CODE notify, int32 value)
  1184. {
  1185.     if (notify == MSG_PaneDirectoriesChanged) {
  1186.         if (IsSearching())
  1187.             OnStopSearch ();
  1188.         CComboBox *widget = (CComboBox*) GetDlgItem(IDC_DIRECTORIES);
  1189.         m_savedir = -1;
  1190.         widget->SetCurSel (0);
  1191.         OnChangeDirectory();
  1192.         UpdateDirectories();
  1193.     }
  1194. }
  1195.  
  1196.  
  1197. void CAddrDialog::AllConnectionsComplete( MWContext *pContext )
  1198. {
  1199.     OnStopSearch();
  1200.  
  1201.     int total = m_pOutliner->GetTotalLines();
  1202.     CString csStatus;
  1203.     if ( total > 1 ) {
  1204.         csStatus.Format( szLoadString( IDS_SEARCHHITS ), total );
  1205.     } else if ( total > 0 ) {
  1206.         csStatus.LoadString( IDS_SEARCHONEHIT );
  1207.     } else {
  1208.         csStatus.LoadString( IDS_SEARCHNOHITS );
  1209.     }
  1210.     m_barStatus.SetWindowText( csStatus );
  1211.  
  1212.     SendMessageToDescendants(WM_IDLEUPDATECMDUI, (WPARAM)TRUE, (LPARAM)0);
  1213. }
  1214.  
  1215.  
  1216. void CAddrDialog::PerformTypedown (char* name)
  1217. {
  1218.     if (!m_bSearching)
  1219.         m_pOutliner->OnTypedown (name);
  1220. }
  1221.  
  1222. void CAddrDialog::PerformListDirectory (char* name)
  1223. {
  1224.     // Build Search
  1225.     m_barStatus.SetWindowText( szLoadString( IDS_SEARCHING ) );
  1226.     m_bSearching = TRUE;
  1227.     GetDlgItem(IDC_DIRECTORIES)->EnableWindow(FALSE);
  1228.     GetDlgItem( IDC_DIRSEARCH)->EnableWindow(FALSE);
  1229.     GetDlgItem( ID_NAVIGATE_INTERRUPT)->EnableWindow(TRUE);
  1230.     m_pOutliner->UpdateCount();
  1231.     m_barStatus.StartAnimation();
  1232.  
  1233.     HandleErrorReturn(AB_SearchDirectory(m_addrBookPane, name));
  1234. }
  1235.  
  1236.  
  1237. void CAddrDialog::MoveSelections(MSG_HEADER_SET header)
  1238. {
  1239.     CString csAddress;
  1240.     MSG_ViewIndex *indices;
  1241.     int count;
  1242.     CGenericFrame * pCompose = (CGenericFrame *)GetParent();
  1243.     CListBox *pBucket = GetBucket();
  1244.     pBucket->EnableWindow (TRUE);
  1245.  
  1246.     m_pOutliner->GetSelection(indices, count);
  1247.  
  1248.     // delete the entries 
  1249.     for (int32 i = 0; i < count; i++) {
  1250.         // should we stop on error?
  1251.         char* fullname = NULL;
  1252.         CString formattedString;
  1253.         ABID entryID = AB_GetEntryIDAt((AddressPane*) m_addrBookPane, indices[i]);
  1254.         AB_GetExpandedName(GetCurrentDirectoryServer(), 
  1255.             theApp.m_pABook, entryID, &fullname);
  1256.  
  1257.         if (fullname){ 
  1258.             ABID type;
  1259.  
  1260.             // need to change the bitmap based on the type
  1261.             AB_GetType (GetCurrentDirectoryServer(), 
  1262.                 theApp.m_pABook, entryID, &type);
  1263.             AddStringToBucket(pBucket, header, fullname, type, entryID);
  1264.         }
  1265.     }
  1266.     CEdit *widget = (CEdit*) GetDlgItem(IDC_ADDRNAME);
  1267.     if (widget)
  1268.         widget->SetSel(0, -1, TRUE);
  1269.     pBucket->EnableWindow (TRUE);
  1270.     SendMessage(DM_SETDEFID, IDC_DONE_EDITING, TRUE);
  1271.     GetDlgItem(IDC_DONE_EDITING)->SendMessage(BM_SETSTYLE, BS_DEFPUSHBUTTON, MAKELPARAM(TRUE, 0));
  1272.     GetDlgItem(m_idefButtonID)->SendMessage(BM_SETSTYLE, BS_PUSHBUTTON, MAKELPARAM(TRUE, 0));
  1273. }
  1274.  
  1275. void CAddrDialog::AddStringToBucket
  1276. (CListBox *pBucket, MSG_HEADER_SET header, char* fullname, ABID type, ABID entryID)
  1277. {
  1278.     CString formattedString;
  1279.     switch (header) {
  1280.         case MSG_TO_HEADER_MASK:
  1281.             formattedString.Format(XP_GetString(MK_ADDR_TONAME), fullname);
  1282.             break;
  1283.         case MSG_CC_HEADER_MASK:
  1284.             formattedString.Format(XP_GetString(MK_ADDR_CCNAME), fullname);
  1285.             break;
  1286.         case MSG_BCC_HEADER_MASK:
  1287.             formattedString.Format(XP_GetString(MK_ADDR_BCCNAME), fullname);
  1288.             break;
  1289.         default:
  1290.             formattedString.Format(XP_GetString(MK_ADDR_TONAME), fullname);
  1291.     }
  1292.  
  1293.     if (pBucket->FindStringExact(0, (LPCTSTR) formattedString ) == LB_ERR) {
  1294.         int idx = pBucket->AddString(formattedString);
  1295.         if ((idx != LB_ERR) || (idx != LB_ERRSPACE))
  1296.         {
  1297.             NSADDRESSLIST *pAddress = new NSADDRESSLIST;
  1298.             ASSERT(pAddress);
  1299.             pAddress->ulHeaderType = header;
  1300.  
  1301.             if (type == ABTypeList)
  1302.                 pAddress->idBitmap = IDB_MAILINGLIST;          
  1303.             else
  1304.                 pAddress->idBitmap = IDB_PERSON; 
  1305.  
  1306.             pAddress->idEntry = entryID;
  1307.             pAddress->szAddress = fullname;
  1308.             pBucket->SetItemDataPtr( idx, pAddress );
  1309.         }
  1310.     }
  1311.     int total = pBucket->GetCount();
  1312.     if (total)
  1313.     {
  1314.         GetDlgItem(IDC_DONE_EDITING)->EnableWindow(TRUE);
  1315.         pBucket->SetCurSel(total - 1);
  1316.     }
  1317.     else
  1318.         GetDlgItem(IDC_DONE_EDITING)->EnableWindow(FALSE);
  1319. }
  1320.  
  1321.  
  1322. void CAddrDialog::OnRemove()
  1323. {
  1324.     CListBox *pBucket = GetBucket();
  1325.     int prevSel = pBucket->GetCurSel();
  1326.     if (prevSel != -1)
  1327.     {
  1328.         NSADDRESSLIST * pAddress = (NSADDRESSLIST *)(pBucket->GetItemDataPtr(prevSel));
  1329.         if (pAddress->szAddress)
  1330.             free (pAddress->szAddress);
  1331.         delete pAddress;
  1332.  
  1333.         int count = pBucket->DeleteString (prevSel);
  1334.         if (count) {
  1335.             if (prevSel)
  1336.                 pBucket->SetCurSel (prevSel - 1);
  1337.             else
  1338.                 pBucket->SetCurSel (prevSel);
  1339.         }
  1340.         OnSelchange();
  1341.     }
  1342. }
  1343.  
  1344.  
  1345. void CAddrDialog::OnComposeMsg()
  1346. {
  1347.     MoveSelections(MSG_TO_HEADER_MASK);
  1348.     m_idefButtonID = IDC_TO;
  1349. }
  1350.  
  1351.  
  1352. void CAddrDialog::OnComposeCCMsg()
  1353. {
  1354.     MoveSelections(MSG_CC_HEADER_MASK);
  1355.     m_idefButtonID = IDC_CC;
  1356. }
  1357.  
  1358.  
  1359. void CAddrDialog::OnComposeBCCMsg()
  1360. {
  1361.     MoveSelections(MSG_BCC_HEADER_MASK);
  1362.     m_idefButtonID = IDC_BCC;
  1363. }
  1364.  
  1365.  
  1366. void CAddrDialog::OnGetProperties()
  1367. {
  1368.     MSG_ViewIndex *indices = NULL;
  1369.     int count;
  1370.     CAddrDialogOutliner *pOutliner = (CAddrDialogOutliner *) m_pOutliner;
  1371.  
  1372.     if (pOutliner)
  1373.     {
  1374.         pOutliner->GetSelection(indices, count);
  1375.         // AB_Command(pOutliner->GetPane(), AB_ImportLdapEntriesCmd, indices, count);
  1376.     }
  1377. }
  1378.  
  1379. void CAddrDialog::HandleErrorReturn(int errorid)
  1380. {    
  1381.     if (errorid) {
  1382.         CString s;
  1383.         if (s.LoadString( IDS_BOOKMARK_ADDRESSPROPERTIES ))
  1384.             ::MessageBox(NULL, XP_GetString(errorid), s, MB_OK);
  1385.     }
  1386. }
  1387.  
  1388.  
  1389. void CAddrDialog::PerformChangeDirectory (int dirIndex)
  1390. {
  1391.     m_pOutliner->SetDirectoryIndex(dirIndex);
  1392.     DIR_Server* dir = GetCurrentDirectoryServer();
  1393.     HandleErrorReturn(AB_ChangeDirectory(m_addrBookPane, dir));
  1394.     DoUpdateWidget(IDC_DIRSEARCH, AB_LDAPSearchCmd, TRUE);
  1395.     DoUpdateWidget(IDC_TO, AB_NewMessageCmd, TRUE);
  1396.     m_pOutliner->UpdateCount( );
  1397.  
  1398.     int idx = m_barStatus.CommandToIndex(IDS_SECURITY_STATUS);
  1399.     if (idx > -1) {
  1400.         UINT nID = IDS_SECURITY_STATUS;
  1401.         UINT nStyle; 
  1402.         int nWidth;
  1403.         m_barStatus.GetPaneInfo( idx, nID, nStyle, nWidth );
  1404.         if (dir->isSecure)
  1405.             m_barStatus.SetPaneInfo(idx, IDS_SECURITY_STATUS, SBPS_NORMAL, nWidth);
  1406.         else
  1407.             m_barStatus.SetPaneInfo(idx, IDS_SECURITY_STATUS, SBPS_DISABLED, nWidth);
  1408.     }
  1409.     UpdateMsgButtons();
  1410. }
  1411.  
  1412.  
  1413. void CAddrDialog::OnUpdateDirectorySelection (int dirIndex)
  1414. {
  1415.     CComboBox *widget = (CComboBox*) GetDlgItem(IDC_DIRECTORIES);
  1416.     widget->SetCurSel(dirIndex);
  1417.     PerformChangeDirectory(dirIndex);
  1418. }
  1419.  
  1420.  
  1421. void CAddrDialog::OnStopSearch ()
  1422. {
  1423.     if ( m_bSearching) {
  1424.         // We've ended the search
  1425.         XP_InterruptContext( m_pCX->GetContext() );
  1426.         HandleErrorReturn(AB_FinishSearch(m_addrBookPane, m_pCX->GetContext()));
  1427.         m_bSearching = FALSE;
  1428.         GetDlgItem(IDC_DIRECTORIES)->EnableWindow(TRUE);
  1429.         GetDlgItem( IDC_DIRSEARCH)->EnableWindow(TRUE);
  1430.         GetDlgItem(ID_NAVIGATE_INTERRUPT)->EnableWindow (FALSE);
  1431.         m_pDirOutliner->EnableWindow(TRUE);
  1432.         m_barStatus.StopAnimation();
  1433.         if (m_pOutliner->GetTotalLines() && (m_pOutliner->GetFocusLine() != -1))
  1434.             m_pOutliner->SelectItem (0);
  1435.         return;
  1436.     }
  1437. }
  1438.  
  1439.  
  1440.  
  1441. void CAddrDialog::PerformDirectorySearch ()
  1442. {
  1443.     if ( m_bSearching) {
  1444.         OnStopSearch ();
  1445.         return;
  1446.     }
  1447.  
  1448.     CUIntArray buttonLabels;
  1449.     buttonLabels.SetSize (4, 1);
  1450.     buttonLabels [0] = IDS_SEARCH_PROMPT;
  1451.     buttonLabels [1] = IDS_CANCEL_BUTTON;
  1452.     buttonLabels [2] = IDS_HELP_BUTTON;
  1453.     buttonLabels [3] = IDS_ADVSEARCH;
  1454.  
  1455.     CSearchDialog searchDlg ((UINT) IDS_ADRSEARCH, 
  1456.         (MSG_Pane*) m_addrBookPane, 
  1457.         GetCurrentDirectoryServer(),
  1458.         this, 4, BUTTON_RIGHT, &buttonLabels);
  1459.     int result = searchDlg.DoModal(); 
  1460.  
  1461.     // Build Search
  1462.     if (result == IDOK)
  1463.     {
  1464.         GetDlgItem(IDC_DIRSEARCH)->EnableWindow (FALSE);
  1465.         GetDlgItem(ID_NAVIGATE_INTERRUPT)->EnableWindow (TRUE);
  1466.         GetDlgItem(IDC_DIRECTORIES)->EnableWindow(FALSE);
  1467.         GetDlgItem(IDC_ADDRNAME)->SetWindowText("");
  1468.  
  1469.         // Build Search
  1470.         m_barStatus.SetWindowText( szLoadString( IDS_SEARCHING ) );
  1471.         m_bSearching = TRUE;
  1472.         m_pOutliner->UpdateCount();
  1473.         m_pOutliner->SetFocus();
  1474.         m_pDirOutliner->EnableWindow(FALSE);
  1475.  
  1476.         HandleErrorReturn(AB_SearchDirectory(m_addrBookPane, NULL));
  1477.     }
  1478.  
  1479. }
  1480.  
  1481.  
  1482. //////////////////////////////////////////////////////////////////////////////
  1483. // CAddrDialogOutliner
  1484. BEGIN_MESSAGE_MAP(CAddrDialogOutliner, CMSelectOutliner)
  1485.     //{{AFX_MSG_MAP(CAddrDialogOutliner)
  1486.     ON_WM_KEYDOWN()
  1487.     ON_WM_TIMER()
  1488.     ON_WM_KILLFOCUS()
  1489.     //}}AFX_MSG_MAP
  1490. END_MESSAGE_MAP()
  1491.  
  1492. CAddrDialogOutliner::CAddrDialogOutliner ( )
  1493. {
  1494.     m_attribSortBy = ID_COLADDR_NAME;
  1495.     ApiApiPtr(api);
  1496.     m_pUnkUserImage = api->CreateClassInstance(APICLASS_IMAGEMAP);
  1497.     if (m_pUnkUserImage) {
  1498.         m_pUnkUserImage->QueryInterface(IID_IImageMap,(LPVOID*)&m_pIUserImage);
  1499.         ASSERT(m_pIUserImage);
  1500.         m_pIUserImage->Initialize(IDB_ADDRESSBOOK,16,16);
  1501.     }
  1502.     m_bSortAscending = TRUE;
  1503.     m_iMysticPlane = 0;
  1504.     m_dirIndex = 0;
  1505.     m_hFont = NULL;
  1506.     m_uTypedownClock = 0;
  1507. }
  1508.  
  1509. CAddrDialogOutliner::~CAddrDialogOutliner ( )
  1510. {
  1511.     if (m_pUnkUserImage) {
  1512.         if (m_pIUserImage)
  1513.             m_pUnkUserImage->Release();
  1514.     }
  1515.  
  1516.     if (m_hFont) {
  1517.         theApp.ReleaseAppFont(m_hFont);
  1518.     }
  1519. }
  1520.  
  1521. DIR_Server* CAddrDialogOutliner::GetCurrentDirectoryServer ()
  1522. {
  1523.     return (DIR_Server*)XP_ListGetObjectNum(theApp.m_directories, m_dirIndex + 1);
  1524. }
  1525.  
  1526. void CAddrDialogOutliner::SetDirectoryIndex(int dirIndex )
  1527. {
  1528.     m_dirIndex = dirIndex;
  1529.     DIR_Server* pServer = GetCurrentDirectoryServer ();
  1530.     int iCount = GetNumColumns();
  1531.     for (int i = 0; i < iCount; i++) {
  1532.         CString cs;
  1533.         int iColumn = GetColumnAtPos(i);
  1534.         if (pServer->dirType == LDAPDirectory)
  1535.         {
  1536.             DIR_AttributeId id;
  1537.             const char *text = NULL;
  1538.             switch (iColumn) {
  1539.             case ID_COLADDR_TYPE:
  1540.                 text = NULL;
  1541.                 break;
  1542.             case ID_COLADDR_NAME:
  1543.                 MSG_SearchAttribToDirAttrib(attribCommonName, &id);        
  1544.                 text = DIR_GetAttributeName(pServer, id);
  1545.                 break;
  1546.             case ID_COLADDR_EMAIL:
  1547.                 MSG_SearchAttribToDirAttrib(attrib822Address, &id);    
  1548.                 text = DIR_GetAttributeName(pServer, id);
  1549.                 break;
  1550.             case ID_COLADDR_COMPANY:
  1551.                 MSG_SearchAttribToDirAttrib(attribOrganization, &id);    
  1552.                 text = DIR_GetAttributeName(pServer, id);
  1553.                 break;
  1554.             case ID_COLADDR_PHONE:
  1555.                 MSG_SearchAttribToDirAttrib(attribPhoneNumber, &id);    
  1556.                 text = DIR_GetAttributeName(pServer, id);
  1557.                 break;
  1558.             case ID_COLADDR_LOCALITY:
  1559.                 MSG_SearchAttribToDirAttrib(attribLocality, &id);    
  1560.                 text = DIR_GetAttributeName(pServer, id);
  1561.                 break;
  1562.             case ID_COLADDR_NICKNAME:
  1563.                 text = NULL;    
  1564.                 break;
  1565.             default:
  1566.                 break;
  1567.             }
  1568.             if (text)
  1569.                 SetColumnName(iColumn, text);
  1570.         }
  1571.         else
  1572.         {
  1573.             switch (iColumn) {
  1574.             case ID_COLADDR_TYPE:
  1575.                 cs = "";
  1576.                 break;
  1577.             case ID_COLADDR_NAME:
  1578.                 cs.LoadString(IDS_USERNAME);        
  1579.                 break;
  1580.             case ID_COLADDR_EMAIL:
  1581.                 cs.LoadString(IDS_EMAILADDRESS);
  1582.                 break;
  1583.             case ID_COLADDR_COMPANY:
  1584.                 cs.LoadString(IDS_COMPANYNAME);
  1585.                 break;
  1586.             case ID_COLADDR_PHONE:
  1587.                 cs.LoadString(IDS_PHONE);
  1588.                 break;
  1589.             case ID_COLADDR_LOCALITY:
  1590.                 cs.LoadString(IDS_LOCALITY);
  1591.                 break;
  1592.             case ID_COLADDR_NICKNAME:
  1593.                 cs.LoadString(IDS_NICKNAME);
  1594.                 break;
  1595.             default:
  1596.                 break;
  1597.             }
  1598.         if (cs.GetLength())
  1599.             SetColumnName(iColumn, cs);
  1600.         }
  1601.     }
  1602.     GetParent()->Invalidate();
  1603.     GetParent()->UpdateWindow();
  1604.     ClearSelection();
  1605.     if (m_iTotalLines)
  1606.         SelectItem (0);
  1607. }
  1608.  
  1609.  
  1610. void CAddrDialogOutliner::OnTimer(UINT nID)
  1611. {
  1612.     CMSelectOutliner::OnTimer(nID);
  1613.     if (nID == ADDRDLG_OUTLINER_TYPEDOWN_TIMER) {
  1614.         KillTimer(m_uTypedownClock);
  1615.         m_psTypedown = "";
  1616.     }
  1617. }
  1618.  
  1619. void CAddrDialogOutliner::OnKeyDown ( UINT nChar, UINT nRepCnt, UINT nFlags )
  1620. {
  1621.     CMSelectOutliner::OnKeyDown ( nChar, nRepCnt, nFlags );
  1622.     KillTimer(m_uTypedownClock);
  1623.     if (nChar > VK_HELP) {
  1624.         KillTimer(m_uTypedownClock);
  1625.         m_psTypedown += nChar;
  1626.         OnTypedown (m_psTypedown.GetBuffer (0));
  1627.         m_psTypedown.ReleaseBuffer(-1);
  1628.         int32 prefInt = OUTLINER_TYPEDOWN_SPEED;
  1629.         PREF_GetIntPref("ldap_1.autoComplete.interval", &prefInt);
  1630.         m_uTypedownClock = SetTimer(ADDRDLG_OUTLINER_TYPEDOWN_TIMER, prefInt, NULL);
  1631.     }
  1632. }
  1633.  
  1634. void CAddrDialogOutliner::OnKillFocus( CWnd* pNewWnd )
  1635. {
  1636.     CMSelectOutliner::OnKillFocus (pNewWnd );
  1637.     m_psTypedown = "";    
  1638.     KillTimer(m_uTypedownClock);
  1639. }
  1640.  
  1641.  
  1642. void CAddrDialogOutliner::OnTypedown (char* name)
  1643. {
  1644.     MSG_ViewIndex index;
  1645.     uint    startIndex;
  1646.  
  1647.     if (GetFocusLine() != -1)
  1648.         startIndex = GetFocusLine();
  1649.     else
  1650.         startIndex = 0;
  1651.  
  1652.     AB_GetIndexMatchingTypedown(m_pane, &index, 
  1653.             (LPCTSTR) name, startIndex);
  1654.     ScrollIntoView(CASTINT(index));
  1655.     SelectItem (CASTINT(index));
  1656. }
  1657.  
  1658. void CAddrDialogOutliner::UpdateCount( )
  1659. {
  1660.     uint32 count;
  1661.  
  1662.     AB_GetEntryCount(GetCurrentDirectoryServer (), theApp.m_pABook, &count, ABTypeAll, NULL);
  1663.     SetTotalLines(CASTINT(count));
  1664. }
  1665.  
  1666.  
  1667. void CAddrDialogOutliner::SetPane(ABPane *pane)
  1668. {
  1669.     m_pane = pane;
  1670.     uint32 count;
  1671.  
  1672.     if (m_pane) {
  1673.         AB_GetEntryCount(GetCurrentDirectoryServer (), theApp.m_pABook, &count, ABTypeAll, NULL);
  1674.         SetTotalLines(CASTINT(count));
  1675.         Invalidate();
  1676.         UpdateWindow();
  1677.     }
  1678. }
  1679.  
  1680. void CAddrDialogOutliner::MysticStuffStarting( XP_Bool asynchronous,
  1681.                                             MSG_NOTIFY_CODE notify, 
  1682.                                             MSG_ViewIndex where,
  1683.                                             int32 num )
  1684. {
  1685.     ++m_iMysticPlane;
  1686. }
  1687.  
  1688. void CAddrDialogOutliner::MysticStuffFinishing( XP_Bool asynchronous,
  1689.                                              MSG_NOTIFY_CODE notify, 
  1690.                                              MSG_ViewIndex where,
  1691.                                              int32 num )
  1692. {
  1693.  
  1694. #ifdef _WIN32
  1695.             CWnd *pParent = GetParentOwner();
  1696. #else
  1697.             CWnd *pParent = GetOwner();      
  1698.             pParent = pParent->GetParent();
  1699.             ASSERT(pParent);
  1700. #endif
  1701.  
  1702.     switch ( notify ) 
  1703.     {
  1704.  
  1705.     case MSG_NotifyNone:
  1706.         break;
  1707.  
  1708.     case MSG_NotifyInsertOrDelete:
  1709.         // if its insert or delete then tell my frame to add the next chunk of values
  1710.         // from the search
  1711.         if (notify == MSG_NotifyInsertOrDelete 
  1712.             && ((CAddrDialog*)pParent)->IsSearching() && num > 0) 
  1713.         {
  1714.             ((CAddrDialog*)pParent)->SetSearchResults(where, num);
  1715.             HandleInsert(where, num);
  1716.         }
  1717.         else
  1718.         {
  1719.             if (num > 0)
  1720.                 HandleInsert(where, num);
  1721.             else
  1722.                 HandleDelete(where, -num);
  1723.         }
  1724.         break;
  1725.  
  1726.     case MSG_NotifyChanged:
  1727.         InvalidateLines( (int) where, (int) num );
  1728.         break;
  1729.  
  1730.     case MSG_NotifyAll:
  1731.     case MSG_NotifyScramble:
  1732.         Invalidate();
  1733.         break;
  1734.     }
  1735.  
  1736.     if (( !--m_iMysticPlane && m_pane)) 
  1737.     {
  1738.         uint32 count;
  1739.         AB_GetEntryCount(GetCurrentDirectoryServer (), theApp.m_pABook, &count, ABTypeAll, NULL);
  1740.         SetTotalLines(CASTINT(count));
  1741.         Invalidate();
  1742.         UpdateWindow();
  1743.     }
  1744. }
  1745.  
  1746.  
  1747. void CAddrDialogOutliner::SetTotalLines( int count)
  1748. {
  1749.     CMSelectOutliner::SetTotalLines(count);
  1750.     if (count = 0)
  1751.         ClearSelection();
  1752. }
  1753.  
  1754.  
  1755.  
  1756.  
  1757. BOOL CAddrDialogOutliner::RenderData  ( UINT iColumn, CRect &rect, CDC &dc, const char * text )
  1758. {
  1759.     if ( iColumn != ID_COLADDR_TYPE )
  1760.         return CMSelectOutliner::RenderData ( iColumn, rect, dc, text );
  1761.  
  1762.     int idxImage = 0;
  1763.  
  1764.     if (m_EntryLine.entryType == ABTypeList)
  1765.         idxImage = IDX_ADDRESSBOOKLIST;
  1766.     else
  1767.         idxImage = IDX_ADDRESSBOOKPERSON;
  1768.  
  1769.     m_pIUserImage->DrawImage ( idxImage,
  1770.         rect.left + ( ( rect.Width ( ) - 16 ) / 2 ), rect.top, &dc, FALSE );
  1771.     return TRUE;
  1772. }
  1773.  
  1774.  
  1775. int CAddrDialogOutliner::TranslateIcon ( void * pLineData )
  1776. {
  1777.     AB_EntryLine* line = (AB_EntryLine*) pLineData;
  1778.     int idxImage = 0;
  1779.  
  1780.     if (line->entryType == ABTypeList)
  1781.         idxImage = IDX_ADDRESSBOOKLIST;
  1782.     else
  1783.         idxImage = IDX_ADDRESSBOOKPERSON;
  1784.     return idxImage;
  1785. }
  1786.  
  1787. int CAddrDialogOutliner::TranslateIconFolder (void * pData)
  1788. {
  1789.     // We're a flat list, so we're never a folder
  1790.     return ( OUTLINER_ITEM );
  1791. }
  1792.  
  1793.  
  1794. BOOL CAddrDialogOutliner::ColumnCommand ( int iColumn, int iLine )
  1795. {
  1796.     // We have no column commands
  1797.     return FALSE;
  1798. }
  1799.  
  1800. HFONT CAddrDialogOutliner::GetLineFont(void *pLineData)
  1801. {
  1802.     if (!m_hFont)
  1803.     {
  1804.         HDC hDC = ::GetDC(m_hWnd);
  1805.         LOGFONT lf;  
  1806.         memset(&lf,0,sizeof(LOGFONT));
  1807.  
  1808.         lf.lfPitchAndFamily = FF_SWISS;
  1809.         lf.lfWeight = FW_NORMAL;
  1810.         lf.lfCharSet = IntlGetLfCharset(CIntlWin::GetSystemLocaleCsid());
  1811.         if (CIntlWin::GetSystemLocaleCsid() == CS_LATIN1)
  1812.              _tcscpy(lf.lfFaceName, "MS Sans Serif");
  1813.         else
  1814.              _tcscpy(lf.lfFaceName, IntlGetUIPropFaceName(CIntlWin::GetSystemLocaleCsid()));
  1815.         lf.lfHeight = -MulDiv(9, ::GetDeviceCaps(hDC, LOGPIXELSY), 72);
  1816.         m_hFont = theApp.CreateAppFont( lf );
  1817.         ::ReleaseDC(m_hWnd,hDC);
  1818.     }
  1819.     return m_hFont;
  1820. }
  1821.  
  1822.  
  1823. void * CAddrDialogOutliner::AcquireLineData ( int line )
  1824. {
  1825.     m_lineindex = line + 1;
  1826.     if ( line >= m_iTotalLines)
  1827.         return NULL;
  1828.     if (!AB_GetEntryLine(m_pane, line, &m_EntryLine ))
  1829.         return NULL;
  1830.  
  1831.     return &m_EntryLine;
  1832. }
  1833.  
  1834.  
  1835. void CAddrDialogOutliner::GetTreeInfo ( int iLine, uint32 * pFlags, int * pDepth, OutlinerAncestorInfo ** pAncestor )
  1836. {
  1837.     if ( pFlags ) *pFlags = 0; // Flags? 
  1838.     if ( pDepth ) *pDepth = 0; // We're flat, remember?
  1839. }
  1840.  
  1841.  
  1842. void CAddrDialogOutliner::ReleaseLineData ( void * )
  1843. {
  1844. }
  1845.  
  1846.  
  1847. LPCTSTR CAddrDialogOutliner::GetColumnText ( UINT iColumn, void * pLineData )
  1848. {
  1849.     AB_EntryLine* line = (AB_EntryLine*) pLineData;
  1850.  
  1851.     switch (iColumn) {
  1852.         case ID_COLADDR_NAME:
  1853.             return line->fullname;
  1854.             break;
  1855.         case ID_COLADDR_EMAIL:
  1856.             return line->emailAddress;
  1857.             break;
  1858.         case ID_COLADDR_COMPANY:
  1859.             return line->companyName;
  1860.             break;
  1861.         case ID_COLADDR_PHONE:
  1862.             if (line->entryType == ABTypePerson)
  1863.                 return line->workPhone;
  1864.             break;
  1865.         case ID_COLADDR_LOCALITY:
  1866.             return line->locality;
  1867.             break;
  1868.         case ID_COLADDR_NICKNAME:
  1869.             return line->nickname;
  1870.             break;
  1871.         default:
  1872.             break;
  1873.     }
  1874.     return ("");
  1875. }
  1876.  
  1877. void CAddrDialogOutliner::OnSelChanged()
  1878. {
  1879. #ifdef _WIN32
  1880.     CWnd *pParent = GetParentOwner();
  1881. #else
  1882.     CWnd *pParent = GetOwner();      
  1883.     pParent = pParent->GetParent();
  1884.     ASSERT(pParent);
  1885. #endif
  1886.     ((CAddrDialog*) pParent)->DoUpdateWidget(IDC_TO, AB_NewMessageCmd, TRUE);
  1887.     ((CAddrDialog*) pParent)->UpdateMsgButtons();
  1888.     CWnd* widget = NULL;
  1889.     widget = ((CAddrDialog*) pParent)->GetDlgItem (((CAddrDialog*) pParent)->GetDefaultButtonID());
  1890.     if (widget) {
  1891.         SendMessage(DM_SETDEFID, ((CAddrDialog*) pParent)->GetDefaultButtonID(), TRUE);
  1892.         widget->SendMessage(BM_SETSTYLE, BS_DEFPUSHBUTTON, MAKELPARAM(TRUE, 0));
  1893.         widget = ((CAddrDialog*) pParent)->GetDlgItem (IDC_DONE_EDITING);
  1894.         widget->SendMessage(BM_SETSTYLE, BS_PUSHBUTTON, MAKELPARAM(TRUE, 0));
  1895.     }
  1896. }
  1897.  
  1898. void CAddrDialogOutliner::OnSelDblClk()
  1899. {
  1900. #ifdef _WIN32
  1901.     CWnd *pParent = GetParentOwner();
  1902. #else
  1903.     CWnd *pParent = GetOwner();      
  1904.     pParent = pParent->GetParent();
  1905.     ASSERT(pParent);
  1906. #endif
  1907.  
  1908.     ((CAddrDialog*) pParent)->SetDefaultButtonID (IDC_TO);
  1909.     ((CAddrDialog*) pParent)->MoveSelections (MSG_TO_HEADER_MASK);
  1910. }
  1911.  
  1912. /////////////////////////////////////////////////////////////////////////////
  1913. // CAddrOutlinerParent
  1914.  
  1915. BEGIN_MESSAGE_MAP(CAddrDialogOutlinerParent, COutlinerParent)
  1916.     //{{AFX_MSG_MAP(CAddrDialogOutlinerParent)
  1917.     ON_WM_LBUTTONUP()
  1918.     //}}AFX_MSG_MAP
  1919. END_MESSAGE_MAP()
  1920.  
  1921. CAddrDialogOutlinerParent::CAddrDialogOutlinerParent()
  1922. {
  1923.  
  1924. }
  1925.  
  1926.  
  1927. CAddrDialogOutlinerParent::~CAddrDialogOutlinerParent()
  1928. {
  1929. }
  1930.  
  1931.  
  1932. BOOL CAddrDialogOutlinerParent::RenderData ( int idColumn, CRect & rect, CDC &dc, const char * text )
  1933. {
  1934.     int cx = 3, cy = 0;
  1935.     CAddrDialogOutliner *pOutliner = (CAddrDialogOutliner *) m_pOutliner;
  1936.     
  1937.     // Calculate text offset from top using font height.
  1938.     TEXTMETRIC tm;
  1939.     dc.GetTextMetrics ( &tm );
  1940.     cy = ( rect.bottom - rect.top - tm.tmHeight ) / 2;
  1941.         
  1942.     // Draw Text String
  1943.     dc.TextOut (rect.left + cx, rect.top + cy, text, _tcslen(text) );
  1944.  
  1945.     // Draw Sort Indicator
  1946.     MSG_COMMAND_CHECK_STATE sortType = pOutliner->m_attribSortBy == idColumn ? MSG_Checked : MSG_Unchecked;
  1947.  
  1948.     int idxImage = pOutliner->m_bSortAscending ? IDX_SORTINDICATORDOWN : IDX_SORTINDICATORUP;
  1949.     CSize cs = dc.GetTextExtent(text, _tcslen(text));
  1950.  
  1951.     if (idColumn == pOutliner->m_attribSortBy && cs.cx + 22 <= rect.Width()) {
  1952.         m_pIImage->DrawTransImage( idxImage,
  1953.                                    rect.left + 8 + cs.cx,
  1954.                                    (rect.top + rect.bottom) / 2 - 4,
  1955.                                    &dc );
  1956.     }
  1957.  
  1958.     return TRUE;
  1959. }
  1960.  
  1961.  
  1962. COutliner * CAddrDialogOutlinerParent::GetOutliner ( void )
  1963. {
  1964.     return new CAddrDialogOutliner;
  1965. }
  1966.  
  1967.  
  1968. void CAddrDialogOutlinerParent::CreateColumns ( void )
  1969.     CString cs; 
  1970.  
  1971.     m_pOutliner->AddColumn ("",        ID_COLADDR_TYPE,            24, 0, ColumnFixed, 0, TRUE );
  1972.     cs.LoadString(IDS_USERNAME);
  1973.     m_pOutliner->AddColumn (cs,            ID_COLADDR_NAME,        175, 0, ColumnVariable, 1500);
  1974.     cs.LoadString(IDS_EMAILADDRESS);
  1975.     m_pOutliner->AddColumn (cs,            ID_COLADDR_EMAIL,        175, 0, ColumnVariable, 1500); 
  1976.     cs.LoadString(IDS_COMPANYNAME);
  1977.     m_pOutliner->AddColumn (cs,            ID_COLADDR_COMPANY,        175, 0, ColumnVariable, 1500 ); 
  1978.     cs.LoadString(IDS_PHONE);
  1979.     m_pOutliner->AddColumn (cs,            ID_COLADDR_PHONE,        175, 0, ColumnVariable, 1500, FALSE);
  1980.     cs.LoadString(IDS_LOCALITY);
  1981.     m_pOutliner->AddColumn (cs,            ID_COLADDR_LOCALITY,    175, 0, ColumnVariable, 1500 );
  1982.     cs.LoadString(IDS_NICKNAME);
  1983.     m_pOutliner->AddColumn (cs,            ID_COLADDR_NICKNAME,    175, 0, ColumnVariable, 1500 );
  1984.     m_pOutliner->SetHasPipes( FALSE );
  1985.  
  1986.     m_pOutliner->SetVisibleColumns(DEF_VISIBLE_COLUMNS);
  1987.     m_pOutliner->LoadXPPrefs("mailnews.abook_columns_win");
  1988.  
  1989. }
  1990.  
  1991.  
  1992. BOOL CAddrDialogOutlinerParent::ColumnCommand ( int idColumn )
  1993. {    
  1994.     ABID lastSelection;
  1995.  
  1996.     CAddrDialogOutliner *pOutliner = (CAddrDialogOutliner *) m_pOutliner;
  1997.     
  1998.     if (pOutliner->GetFocusLine() != -1)
  1999.         lastSelection = AB_GetEntryIDAt((AddressPane*) pOutliner->GetPane(), pOutliner->GetFocusLine());
  2000.  
  2001.     SetCursor ( theApp.LoadStandardCursor ( IDC_WAIT ) );
  2002.  
  2003.     if (idColumn == pOutliner->m_attribSortBy) {
  2004.         pOutliner->m_bSortAscending = !pOutliner->m_bSortAscending; 
  2005.     }
  2006.     else
  2007.         pOutliner->m_bSortAscending = TRUE;
  2008.  
  2009.     pOutliner->m_attribSortBy = idColumn;
  2010.  
  2011.     switch (idColumn) {
  2012.         case ID_COLADDR_TYPE:
  2013.             AB_Command(pOutliner->GetPane(), AB_SortByTypeCmd, 0, 0);
  2014.             break;
  2015.         case ID_COLADDR_NAME:
  2016.             AB_Command(pOutliner->GetPane(), AB_SortByFullNameCmd, 0, 0);
  2017.             break;
  2018.         case ID_COLADDR_NICKNAME:
  2019.             AB_Command(pOutliner->GetPane(), AB_SortByNickname, 0, 0);
  2020.             break;
  2021.         case ID_COLADDR_LOCALITY:
  2022.             AB_Command(pOutliner->GetPane(), AB_SortByLocality, 0, 0);
  2023.             break;
  2024.         case ID_COLADDR_COMPANY:
  2025.             AB_Command(pOutliner->GetPane(), AB_SortByCompanyName, 0, 0);
  2026.             break;
  2027.         case ID_COLADDR_EMAIL:
  2028.             AB_Command(pOutliner->GetPane(), AB_SortByEmailAddress, 0, 0);
  2029.             break;
  2030.         default:
  2031.             AB_Command(pOutliner->GetPane(), AB_SortByFullNameCmd, 0, 0);
  2032.             break;
  2033.     }
  2034.     
  2035.  
  2036.     if (pOutliner->GetFocusLine() != -1) {
  2037.         uint index = CASTUINT(AB_GetIndexOfEntryID ((AddressPane*) pOutliner->GetPane(), lastSelection));
  2038.         pOutliner->SelectItem (index);
  2039.         pOutliner->ScrollIntoView(index);
  2040.     }
  2041.  
  2042.     Invalidate();
  2043.     pOutliner->Invalidate();
  2044.     SetCursor ( theApp.LoadStandardCursor ( IDC_ARROW ) );
  2045.     return TRUE;
  2046. }
  2047.  
  2048. void CAddrDialogOutlinerParent::OnLButtonUp( UINT nFlags, CPoint point )
  2049. {
  2050.     BOOL bSaveColumns = (m_pOutliner && 
  2051.         (m_bResizeColumn || m_bDraggingHeader || m_iPusherHit))? TRUE : FALSE;
  2052.     COutlinerParent::OnLButtonUp(nFlags, point);
  2053.     if (bSaveColumns)
  2054.         m_pOutliner->SaveXPPrefs("mailnews.abook_columns_win");
  2055. }
  2056.  
  2057.  
  2058.  
  2059. //////////////////////////////////////////////////////////////////////////////
  2060. // CAddrDialogDirOutliner
  2061. BEGIN_MESSAGE_MAP(CAddrDialogDirOutliner, CMSelectOutliner)
  2062.     //{{AFX_MSG_MAP(CAddrDialogDirOutliner)
  2063.     //}}AFX_MSG_MAP
  2064. END_MESSAGE_MAP()
  2065.  
  2066. CAddrDialogDirOutliner::CAddrDialogDirOutliner ( )
  2067. {
  2068.     ApiApiPtr(api);
  2069.     m_pUnkUserImage = api->CreateClassInstance(APICLASS_IMAGEMAP);
  2070.     if (m_pUnkUserImage) {
  2071.         m_pUnkUserImage->QueryInterface(IID_IImageMap,(LPVOID*)&m_pIUserImage);
  2072.         ASSERT(m_pIUserImage);
  2073.         m_pIUserImage->Initialize(IDB_DIRLIST,16,16);
  2074.     }
  2075.     m_iMysticPlane = 0;
  2076.     m_dirIndex = 0;
  2077.     m_hFont = NULL;
  2078. }
  2079.  
  2080. CAddrDialogDirOutliner::~CAddrDialogDirOutliner ( )
  2081. {
  2082.     if (m_pUnkUserImage) {
  2083.         if (m_pIUserImage)
  2084.             m_pUnkUserImage->Release();
  2085.     }
  2086.  
  2087.     if (m_hFont) {
  2088.         theApp.ReleaseAppFont(m_hFont);
  2089.     }
  2090. }
  2091.  
  2092.  
  2093. void CAddrDialogDirOutliner::SetDirectoryIndex(int dirIndex )
  2094. {
  2095.     m_dirIndex = dirIndex;
  2096.     SelectItem (CASTINT(m_dirIndex));
  2097. }
  2098.  
  2099.  
  2100. void CAddrDialogDirOutliner::UpdateCount( )
  2101. {
  2102.     m_iTotalLines = XP_ListCount (theApp.m_directories);
  2103.     if (!m_iTotalLines)
  2104.         ClearSelection();
  2105.     Invalidate();
  2106.     UpdateWindow();
  2107. }
  2108.  
  2109.  
  2110. void CAddrDialogDirOutliner::SetPane(ABPane *pane)
  2111. {
  2112.     m_pane = pane;
  2113.     uint32 count;
  2114.  
  2115.     if (m_pane) {
  2116.         SetTotalLines(XP_ListCount (theApp.m_directories));
  2117.         Invalidate();
  2118.         UpdateWindow();
  2119.     }
  2120. }
  2121.  
  2122. void CAddrDialogDirOutliner::MysticStuffStarting( XP_Bool asynchronous,
  2123.                                             MSG_NOTIFY_CODE notify, 
  2124.                                             MSG_ViewIndex where,
  2125.                                             int32 num )
  2126. {
  2127.     ++m_iMysticPlane;
  2128. }
  2129.  
  2130. void CAddrDialogDirOutliner::MysticStuffFinishing( XP_Bool asynchronous,
  2131.                                              MSG_NOTIFY_CODE notify, 
  2132.                                              MSG_ViewIndex where,
  2133.                                              int32 num )
  2134. {
  2135.  
  2136. #ifdef _WIN32
  2137.             CWnd *pParent = GetParentOwner();
  2138. #else
  2139.             CWnd *pParent = GetOwner();      
  2140.             pParent = pParent->GetParent();
  2141.             ASSERT(pParent);
  2142. #endif
  2143.  
  2144.     switch ( notify ) 
  2145.     {
  2146.  
  2147.     case MSG_NotifyNone:
  2148.         break;
  2149.  
  2150.     case MSG_NotifyInsertOrDelete:
  2151.         // if its insert or delete then tell my frame to add the next chunk of values
  2152.         // from the search
  2153.         if (num > 0)
  2154.             HandleInsert(where, num);
  2155.         else
  2156.             HandleDelete(where, -num);
  2157.  
  2158.         break;
  2159.  
  2160.     case MSG_NotifyChanged:
  2161.         InvalidateLines( (int) where, (int) num );
  2162.         break;
  2163.  
  2164.     case MSG_NotifyAll:
  2165.     case MSG_NotifyScramble:
  2166.         Invalidate();
  2167.         break;
  2168.     }
  2169.  
  2170.     if (( !--m_iMysticPlane && m_pane)) {
  2171.         SetTotalLines(XP_ListCount (theApp.m_directories));
  2172.         Invalidate();
  2173.         UpdateWindow();
  2174.     }
  2175. }
  2176.  
  2177.  
  2178. void CAddrDialogDirOutliner::SetTotalLines( int count)
  2179. {
  2180.     CMSelectOutliner::SetTotalLines(count);
  2181.     if (count = 0)
  2182.         ClearSelection();
  2183. }
  2184.  
  2185.  
  2186.  
  2187.  
  2188. BOOL CAddrDialogDirOutliner::RenderData  ( UINT iColumn, CRect &rect, CDC &dc, const char * text )
  2189. {
  2190.     if ( iColumn != ID_COLDIR_TYPE )
  2191.         return CMSelectOutliner::RenderData ( iColumn, rect, dc, text );
  2192.     int idxImage;
  2193.  
  2194.     if (m_pDirLine->dirType == LDAPDirectory)
  2195.         idxImage = IDX_DIRLDAPAB;
  2196.     else
  2197.         idxImage = IDX_DIRPERSONALAB;
  2198.  
  2199.     m_pIUserImage->DrawImage ( idxImage,
  2200.         rect.left + ( ( rect.Width ( ) - 16 ) / 2 ), rect.top, &dc, FALSE );
  2201.     return TRUE;
  2202. }
  2203.  
  2204.  
  2205. int CAddrDialogDirOutliner::TranslateIcon ( void * pLineData )
  2206. {
  2207.     DIR_Server* line = (DIR_Server*) pLineData;
  2208.     int idxImage = 0;
  2209.  
  2210.     if (m_pDirLine->dirType == ABTypeList)
  2211.         idxImage = IDX_DIRLDAPAB;
  2212.     else
  2213.         idxImage = IDX_DIRPERSONALAB;
  2214.     return idxImage;
  2215. }
  2216.  
  2217. int CAddrDialogDirOutliner::TranslateIconFolder (void * pData)
  2218. {
  2219.     // We're a flat list, so we're never a folder
  2220.     return ( OUTLINER_ITEM );
  2221. }
  2222.  
  2223.  
  2224. BOOL CAddrDialogDirOutliner::ColumnCommand ( int iColumn, int iLine )
  2225. {
  2226.     // We have no column commands
  2227.     return FALSE;
  2228. }
  2229.  
  2230. HFONT CAddrDialogDirOutliner::GetLineFont(void *pLineData)
  2231. {
  2232.     if (!m_hFont)
  2233.     {
  2234.         HDC hDC = ::GetDC(m_hWnd);
  2235.         LOGFONT lf;  
  2236.         memset(&lf,0,sizeof(LOGFONT));
  2237.  
  2238.         lf.lfPitchAndFamily = FF_SWISS;
  2239.         lf.lfWeight = FW_NORMAL;
  2240.         lf.lfCharSet = IntlGetLfCharset(CIntlWin::GetSystemLocaleCsid());
  2241.         if (CIntlWin::GetSystemLocaleCsid() == CS_LATIN1)
  2242.              _tcscpy(lf.lfFaceName, "MS Sans Serif");
  2243.         else
  2244.              _tcscpy(lf.lfFaceName, IntlGetUIPropFaceName(CIntlWin::GetSystemLocaleCsid()));
  2245.         lf.lfHeight = -MulDiv(9, ::GetDeviceCaps(hDC, LOGPIXELSY), 72);
  2246.         m_hFont = theApp.CreateAppFont( lf );
  2247.         ::ReleaseDC(m_hWnd,hDC);
  2248.     }
  2249.     return m_hFont;
  2250. }
  2251.  
  2252.  
  2253. void * CAddrDialogDirOutliner::AcquireLineData ( int line )
  2254. {
  2255.     m_lineindex = line + 1;
  2256.     if ( line >= m_iTotalLines)
  2257.         return NULL;
  2258.     m_pDirLine = (DIR_Server*) XP_ListGetObjectNum(theApp.m_directories, line + 1);
  2259.  
  2260.     return m_pDirLine;
  2261. }
  2262.  
  2263.  
  2264. void CAddrDialogDirOutliner::GetTreeInfo ( int iLine, uint32 * pFlags, int * pDepth, OutlinerAncestorInfo ** pAncestor )
  2265. {
  2266.     if ( pFlags ) *pFlags = 0; // Flags? 
  2267.     if ( pDepth ) *pDepth = 0; // We're flat, remember?
  2268. }
  2269.  
  2270.  
  2271. void CAddrDialogDirOutliner::ReleaseLineData ( void * )
  2272. {
  2273. }
  2274.  
  2275.  
  2276. LPCTSTR CAddrDialogDirOutliner::GetColumnText ( UINT iColumn, void * pLineData )
  2277. {
  2278.     DIR_Server* line = (DIR_Server*) pLineData;
  2279.  
  2280.     switch (iColumn) {
  2281.         case ID_COLDIR_NAME:
  2282.             return line->description;
  2283.             break;
  2284.         default:
  2285.             break;
  2286.     }
  2287.     return ("");
  2288. }
  2289.  
  2290. void CAddrDialogDirOutliner::OnSelChanged()
  2291. {
  2292. #ifdef _WIN32
  2293.     CWnd *pParent = GetParentOwner();
  2294. #else
  2295.     CWnd *pParent = GetOwner();      
  2296.     pParent = pParent->GetParent();
  2297.     ASSERT(pParent);
  2298. #endif
  2299.     MSG_ViewIndex *indices;
  2300.     int count;
  2301.  
  2302.     if (((CAddrDialog*) pParent)->IsSearching())
  2303.         return;
  2304.  
  2305.     GetSelection(indices, count);
  2306.  
  2307.     if (count == 1) 
  2308.         ((CAddrDialog*) pParent)->OnUpdateDirectorySelection(indices[0]);
  2309. }
  2310.  
  2311. void CAddrDialogDirOutliner::OnSelDblClk()
  2312. {
  2313.  
  2314. }
  2315.  
  2316. /////////////////////////////////////////////////////////////////////////////
  2317. // CAddrOutlinerParent
  2318.  
  2319. BEGIN_MESSAGE_MAP(CAddrDialogDirOutlinerParent, COutlinerParent)
  2320.     //{{AFX_MSG_MAP(CAddrDialogDirOutlinerParent)
  2321.     ON_WM_LBUTTONUP()
  2322.     //}}AFX_MSG_MAP
  2323. END_MESSAGE_MAP()
  2324.  
  2325. CAddrDialogDirOutlinerParent::CAddrDialogDirOutlinerParent()
  2326. {
  2327.  
  2328. }
  2329.  
  2330.  
  2331. CAddrDialogDirOutlinerParent::~CAddrDialogDirOutlinerParent()
  2332. {
  2333. }
  2334.  
  2335.  
  2336. BOOL CAddrDialogDirOutlinerParent::RenderData ( int idColumn, CRect & rect, CDC &dc, const char * text )
  2337. {
  2338.     int cx = 3, cy = 0;
  2339.     CAddrDialogDirOutliner *pOutliner = (CAddrDialogDirOutliner *) m_pOutliner;
  2340.     
  2341.     // Calculate text offset from top using font height.
  2342.     TEXTMETRIC tm;
  2343.     dc.GetTextMetrics ( &tm );
  2344.     cy = ( rect.bottom - rect.top - tm.tmHeight ) / 2;
  2345.         
  2346.     // Draw Text String
  2347.     dc.TextOut (rect.left + cx, rect.top + cy, text, _tcslen(text) );
  2348.  
  2349.     return TRUE;
  2350. }
  2351.  
  2352.  
  2353. COutliner * CAddrDialogDirOutlinerParent::GetOutliner ( void )
  2354. {
  2355.     return new CAddrDialogDirOutliner;
  2356. }
  2357.  
  2358.  
  2359. void CAddrDialogDirOutlinerParent::CreateColumns ( void )
  2360.  
  2361.     int iCol0 = 0,
  2362.         iCol1 = 0;
  2363.     CString cs; 
  2364.  
  2365.     m_pOutliner->AddColumn ("",            ID_COLDIR_TYPE,        24, 0, ColumnFixed, 0, TRUE );
  2366.     cs.LoadString(IDS_USERNAME);
  2367.     m_pOutliner->AddColumn (cs,            ID_COLDIR_NAME,        1500, 0, ColumnVariable, iCol0 ? iCol0 : 1500 );
  2368.     m_pOutliner->SetHasPipes( FALSE );
  2369.  
  2370.     m_pOutliner->SetVisibleColumns(DEF_DIRVISIBLE_COLUMNS);
  2371.     m_pOutliner->LoadXPPrefs("mailnews.abook_dir_columns_win");
  2372.  
  2373. }
  2374.  
  2375.  
  2376. void CAddrDialogDirOutlinerParent::OnLButtonUp( UINT nFlags, CPoint point )
  2377. {
  2378.     BOOL bSaveColumns = (m_pOutliner && 
  2379.         (m_bResizeColumn || m_bDraggingHeader || m_iPusherHit))? TRUE : FALSE;
  2380.     COutlinerParent::OnLButtonUp(nFlags, point);
  2381.     if (bSaveColumns)
  2382.         m_pOutliner->SaveXPPrefs("mailnews.abook_dir_columns_win");
  2383. }
  2384.  
  2385.  
  2386.  
  2387. void CAddrDialog::OnHelp() 
  2388. {
  2389.     NetHelp(HELP_SELECT_ADDRESSES);
  2390. }
  2391.  
  2392.  
  2393. BOOL CAddrDialog::IsDragInListBox(CPoint *pPoint)
  2394. {
  2395.     CRect listRect;
  2396.  
  2397.     CListBox *pBucket = GetBucket();
  2398.     pBucket->GetWindowRect(LPRECT(listRect));
  2399.     ScreenToClient(LPRECT(listRect));
  2400.     if (listRect.PtInRect(*pPoint))
  2401.         return TRUE;
  2402.     else
  2403.         return FALSE;
  2404. }
  2405.  
  2406. BOOL CAddrDialog::ProcessVCardData(COleDataObject * pDataObject, CPoint &point)
  2407. {
  2408.     UINT clipFormat;
  2409.     BOOL retVal = TRUE;;
  2410.     CWnd * pWnd = GetFocus();
  2411.     XP_List * pEntries;
  2412.     int32 iEntries;
  2413.  
  2414.     if (pDataObject->IsDataAvailable(
  2415.         clipFormat = ::RegisterClipboardFormat(vCardClipboardFormat))) 
  2416.     {
  2417.         HGLOBAL hAddresses = pDataObject->GetGlobalData(clipFormat);
  2418.         LPSTR pAddresses = (LPSTR)GlobalLock(hAddresses);
  2419.         ASSERT(pAddresses);
  2420.         if (!AB_ConvertVCardsToExpandedName(theApp.m_pABook,pAddresses,&pEntries,&iEntries))
  2421.         {
  2422.             CListBox *pBucket = GetBucket();
  2423.  
  2424.             XP_List * node = pEntries;
  2425.             for (int32 i = 0; i < iEntries+1; i++)
  2426.             {
  2427.                 char * pString = (char *)node->object;
  2428.                 if (pString != NULL)
  2429.                     AddStringToBucket(pBucket, MSG_TO_HEADER_MASK, pString, ABTypePerson, -1);
  2430.                 node = node->next;
  2431.                 if (!node)
  2432.                     break;
  2433.             }
  2434.             XP_ListDestroy(pEntries);
  2435.         }
  2436.     }
  2437.  
  2438.     if (pWnd && ::IsWindow(pWnd->m_hWnd))
  2439.         pWnd->SetFocus();
  2440.     return retVal;
  2441. }
  2442.  
  2443. void CAddrDialog::UpdateMsgButtons()
  2444. {
  2445.     if (m_pOutliner)
  2446.     {
  2447.         MSG_ViewIndex *indices;
  2448.         int count;
  2449.         BOOL bEnable;
  2450.  
  2451.         m_pOutliner->GetSelection(indices, count);
  2452.         bEnable = (count > 0) ? TRUE : FALSE;
  2453.         GetDlgItem(IDC_TO)->EnableWindow(bEnable);
  2454.         GetDlgItem(IDC_CC)->EnableWindow(bEnable);
  2455.         GetDlgItem(IDC_BCC)->EnableWindow(bEnable);
  2456.         GetDlgItem(ID_ITEM_PROPERTIES)->EnableWindow(bEnable);
  2457.     }
  2458.     DoUpdateWidget(IDC_DIRSEARCH, AB_LDAPSearchCmd, TRUE);
  2459.     if (m_bSearching)
  2460.         GetDlgItem(ID_NAVIGATE_INTERRUPT)->EnableWindow(TRUE);
  2461.     else
  2462.         GetDlgItem(ID_NAVIGATE_INTERRUPT)->EnableWindow(FALSE);
  2463. }
  2464.  
  2465. //////////////////////////////////////////////////////////////////////////////
  2466. // CAddressPickerDropTarget
  2467.  
  2468. DROPEFFECT CAddressPickerDropTarget::OnDragOver(CWnd * pWnd,
  2469.     COleDataObject * pDataObject, DWORD dwKeyState, CPoint point)
  2470. {
  2471.     DROPEFFECT deReturn = DROPEFFECT_NONE;
  2472.     // Only interested in vcard
  2473.     if(pDataObject->IsDataAvailable(
  2474.       ::RegisterClipboardFormat(vCardClipboardFormat)) )
  2475.     {
  2476.         if (m_pOwner->IsDragInListBox(&point))
  2477.             deReturn = DROPEFFECT_COPY;
  2478.     }
  2479.     return(deReturn);
  2480.  
  2481. BOOL CAddressPickerDropTarget::OnDrop
  2482. (CWnd * pWnd, COleDataObject * pDataObject, DROPEFFECT, CPoint point)
  2483. {
  2484.     if (pDataObject->IsDataAvailable(::RegisterClipboardFormat(vCardClipboardFormat)) )
  2485.     {
  2486.         return m_pOwner->ProcessVCardData(pDataObject,point);
  2487.     }
  2488.     return FALSE;
  2489. }
  2490.  
  2491.  
  2492.