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

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. // addrfrm.cpp : implementation file
  20. //
  21.  
  22. #include "stdafx.h"
  23. #include "addrfrm.h"
  24. #ifdef FEATURE_ADDRPROP
  25. #include "addrprop.h"
  26. #endif
  27. #include "template.h"
  28. #include "xpgetstr.h"
  29. #include "wfemsg.h"
  30. #include "msg_srch.h"
  31. #include "dirprefs.h"
  32. #include "nethelp.h"
  33. #include "xp_help.h"
  34. #include "prefapi.h"
  35. #include "intlwin.h"
  36. #include "srchdlg.h"
  37. #include "intl_csi.h"
  38. #include "mailpriv.h"
  39. #include "mnprefs.h"
  40.  
  41. //RHP - Need this include for the call in confhook.cpp
  42. #include "confhook.h"
  43.  
  44. #ifndef _AFXDLL
  45. #undef new
  46. #endif
  47. IMPLEMENT_DYNCREATE(CAddrFrame, CGenericFrame)
  48. #ifndef _AFXDLL
  49. #define new DEBUG_NEW
  50. #endif
  51.  
  52. extern "C" {
  53. #include "xpgetstr.h"
  54. extern int MK_MSG_CANT_CALL_MAILING_LIST;
  55. extern int MK_MSG_CALL_NEEDS_IPADDRESS;
  56. extern int MK_MSG_CALL_NEEDS_EMAILADDRESS;
  57. extern int MK_MSG_CANT_FIND_CALLPOINT;
  58. extern int MK_ADDR_BOOK_CARD;
  59. extern int MK_ADDR_NEW_CARD;
  60. extern int MK_OUT_OF_MEMORY;
  61. extern int    MK_ADDR_FIRST_LAST_SEP;
  62. extern int    MK_ADDR_LAST_FIRST_SEP;
  63. };
  64.  
  65.  
  66. #define ADDRESS_BOOK_TIMER          6
  67. #define OUTLINER_TYPEDOWN_TIMER     250
  68. #define TYPEDOWN_SPEED                300
  69. #define LDAP_SEARCH_SPEED            1250
  70. #define OUTLINER_TYPEDOWN_SPEED        1250
  71.  
  72. static UINT AddrCodes[] = {
  73.     ID_ITEM_ADDUSER,
  74.     ID_ITEM_ADDLIST,
  75.     ID_ITEM_PROPERTIES,
  76.     ID_FILE_NEWMESSAGE,
  77.     ID_LIVE_CALL,
  78.     ID_EDIT_DELETE,
  79.     ID_NAVIGATE_INTERRUPT
  80.     };
  81.  
  82. int FE_ShowPropertySheetFor (MWContext* context, ABID entryID, PersonEntry* pPerson)
  83. {
  84.     DIR_Server *pab = NULL;
  85.     BOOL result = FALSE;
  86.  
  87. #ifdef FEATURE_ADDRPROP
  88.     DIR_GetPersonalAddressBook (theApp.m_directories, &pab);
  89.     XP_ASSERT (pab);
  90.  
  91.     if (pab) 
  92.     {
  93.         if (entryID != MSG_MESSAGEIDNONE) 
  94.         {
  95.             CString formattedString;
  96.             char fullname [kMaxFullNameLength];
  97.             AB_GetFullName(pab, theApp.m_pABook, entryID, fullname);
  98.             formattedString.Format(XP_GetString (MK_ADDR_BOOK_CARD), fullname);
  99.             CAddrEditProperties prop(NULL, pab,
  100.                 (const char *) formattedString, ABSTRACTCX(context)->GetDialogOwner(), entryID, pPerson, context);
  101.             prop.SetCurrentPage(0);
  102.             result = prop.DoModal();
  103.         }
  104.         else 
  105.         {
  106.             CString formattedString;
  107.             char* name = NULL;
  108.             name = (char *) XP_ALLOC(kMaxFullNameLength);
  109.             if (!name)
  110.                 return MK_OUT_OF_MEMORY;
  111.             XP_STRCPY (name, pPerson->pGivenName);
  112.             if (pPerson->pFamilyName)
  113.             {
  114.                 XP_STRNCPY_SAFE (name, XP_GetString (MK_ADDR_FIRST_LAST_SEP), kMaxFullNameLength);
  115.                 XP_STRNCPY_SAFE (name, pPerson->pFamilyName, kMaxFullNameLength);
  116.             }
  117.  
  118.             formattedString.Format(XP_GetString (MK_ADDR_BOOK_CARD), name);
  119.             XP_FREEIF (name);
  120.             CAddrEditProperties prop(NULL, pab,
  121.                 (const char *) formattedString, ABSTRACTCX(context)->GetDialogOwner(), 0, pPerson, context);
  122.             prop.SetCurrentPage(0);
  123.             result = prop.DoModal();
  124.         }
  125.     }
  126.  
  127.     if (result == IDOK)
  128.         result = TRUE;
  129.     if (result == IDCANCEL)
  130.         result = FALSE;
  131.     // if it is -1 then there was a memory problem creating the dialog 
  132.     // and we should return that
  133. #endif
  134.  
  135.     return result;
  136. }
  137.   
  138. void CAddrCX::DestroyContext()
  139. {
  140.     CStubsCX::DestroyContext();
  141. }
  142.  
  143.  
  144. CAddrBar::CAddrBar()
  145. {
  146.     m_iWidth = 0;
  147.     m_uTypedownClock = 0;
  148.     m_save = "";
  149.     m_savedir = -1;
  150.     m_pFont = NULL;
  151.     m_bRemoveLDAPDir = FALSE;
  152.  
  153.     PREF_GetBoolPref("mail.addr_book.ldap.disabled", &m_bRemoveLDAPDir);
  154.  
  155.     //{{AFX_DATA_INIT(CAddrbkView)
  156.     m_name = _T("");
  157.     m_directory = 0;
  158.     //}}AFX_DATA_INIT
  159.     // TODO: add construction code here
  160. }
  161.  
  162. CAddrBar::~CAddrBar()
  163. {
  164.     if (m_pFont) {
  165.         theApp.ReleaseAppFont(m_pFont);
  166.     }
  167. }
  168.  
  169. /////////////////////////////////////////////////////////////////////////////
  170. // CAddrBar Message handlers
  171.  
  172. BEGIN_MESSAGE_MAP(CAddrBar, CDialogBar)
  173.     //{{AFX_MSG_MAP(CAddrFrame)
  174.     ON_WM_CREATE()
  175.     ON_WM_SIZE()
  176.     ON_WM_TIMER ()
  177.     ON_EN_CHANGE(IDC_ADDRNAME, OnChangeName)
  178.      ON_EN_SETFOCUS(IDC_ADDRNAME, OnSetFocusName)
  179.     ON_CBN_SELCHANGE(IDC_DIRECTORIES, OnChangeDirectory)
  180.     ON_BN_CLICKED(IDC_DIRSEARCH, OnExtDirectorySearch)
  181.     //}}AFX_MSG_MAP
  182. END_MESSAGE_MAP()
  183.  
  184.  
  185. BOOL CAddrBar::Create(CWnd* pParentWnd, UINT nIDTemplate, UINT nStyle, UINT nID)
  186. {
  187.     BOOL res = CDialogBar::Create(pParentWnd, nIDTemplate, nStyle, nID);
  188.  
  189.     m_iWidth = m_sizeDefault.cx;
  190.  
  191.     return res;
  192. }
  193.  
  194.  
  195. int CAddrBar::OnCreate( LPCREATESTRUCT lpCreateStruct )
  196. {
  197.     int retval =  CDialogBar::OnCreate( lpCreateStruct);
  198.  
  199.     HDC hDC = ::GetDC(m_hWnd);
  200.     LOGFONT lf;  
  201.     memset(&lf,0,sizeof(LOGFONT));
  202.     lf.lfPitchAndFamily = FF_SWISS;
  203.     lf.lfWeight = FW_NORMAL;
  204.     lf.lfCharSet = IntlGetLfCharset(CIntlWin::GetSystemLocaleCsid());
  205.     if (CIntlWin::GetSystemLocaleCsid() == CS_LATIN1)
  206.         _tcscpy(lf.lfFaceName, "MS Sans Serif");
  207.     else
  208.         _tcscpy(lf.lfFaceName, IntlGetUIPropFaceName(CIntlWin::GetSystemLocaleCsid()));
  209.     lf.lfHeight = -MulDiv(9, ::GetDeviceCaps(hDC, LOGPIXELSY), 72);
  210.     m_pFont = theApp.CreateAppFont( lf );
  211.     ::ReleaseDC(m_hWnd,hDC);
  212.  
  213.     CRect rect;
  214.     GetClientRect(&rect);
  215.     m_sizeDefault = rect.Size();
  216.  
  217.     return retval;
  218. }
  219.  
  220. void CAddrBar::SetDirectoryIndex( int dirIndex )
  221. {
  222.        CComboBox *widget = (CComboBox*) GetDlgItem(IDC_DIRECTORIES);
  223.     m_savedir = -1;
  224.     widget->SetCurSel (dirIndex);
  225.     UpdateData(TRUE);
  226.     if (m_directory != m_savedir) {
  227.         m_savedir = m_directory;
  228.         if (m_directory != -1) {
  229.             XP_Bool bSelectable = FALSE, bPlural = FALSE;
  230.             MSG_COMMAND_CHECK_STATE sState;
  231.             CAddrFrame* frame = (CAddrFrame*) GetParentFrame();
  232.             AB_CommandStatus((ABPane*) frame->GetPane(),
  233.                               AB_LDAPSearchCmd,
  234.                               NULL, NULL,
  235.                               &bSelectable,
  236.                               &sState,
  237.                               NULL,
  238.                               &bPlural);
  239.             CWnd* widget = GetDlgItem ( IDC_DIRSEARCH );
  240.             widget->EnableWindow(bSelectable);
  241.         }
  242.     }
  243. }
  244.  
  245.  
  246. void CAddrBar::UpdateDirectories()
  247. {
  248.     DIR_Server* dir;
  249.     CComboBox *widget = (CComboBox*) GetDlgItem(IDC_DIRECTORIES);
  250.  
  251.     widget->ResetContent();
  252.  
  253.     XP_List *pTraverse = theApp.m_directories;
  254.     while (dir = (DIR_Server*) XP_ListNextObject(pTraverse)) {
  255.         if (m_bRemoveLDAPDir){
  256.             if (dir->dirType == PABDirectory)
  257.                 widget->AddString(dir->description);
  258.         }
  259.         else if (dir->dirType == PABDirectory || dir->dirType == LDAPDirectory)
  260.             widget->AddString(dir->description);
  261.     }
  262.  
  263.     if (m_directory == -1)
  264.         widget->SetCurSel(0);
  265.     else
  266.         widget->SetCurSel(m_directory);
  267. }
  268.  
  269. void CAddrBar::OnTimer(UINT nID)
  270. {
  271.     CWnd::OnTimer(nID);
  272.     if (nID == ADDRESS_BOOK_TIMER) {
  273.         KillTimer(m_uTypedownClock);
  274.         CAddrFrame* frame = (CAddrFrame*) GetParentFrame();
  275.         if (!m_name.IsEmpty()) {
  276.             frame->OnTypedown(m_name.GetBuffer(0));
  277.             m_name.ReleaseBuffer();
  278.         }
  279.     }
  280. }
  281.  
  282. void CAddrBar::OnKillFocus( CWnd* pNewWnd )
  283. {
  284.     KillTimer(m_uTypedownClock);
  285. }
  286.  
  287. void CAddrBar::DoDataExchange(CDataExchange* pDX)
  288. {
  289.     CDialogBar::DoDataExchange(pDX);
  290.     //{{AFX_DATA_MAP(CAddrbkView)
  291.     DDX_Text(pDX, IDC_ADDRNAME, m_name);
  292.     DDX_CBIndex(pDX, IDC_DIRECTORIES, m_directory);
  293.     //}}AFX_DATA_MAP
  294. }
  295.  
  296.  
  297. void CAddrBar::OnChangeName() 
  298. {
  299.     // TODO: Add your control notification handler code here
  300.     CAddrFrame* frame = (CAddrFrame*) GetParentFrame();
  301.     if (frame->IsSearching()) {
  302.         frame->OnExtendedDirectorySearch();
  303.     }
  304.  
  305.     UpdateData(TRUE);
  306.     if (m_name != m_save) {
  307.         m_save = m_name;
  308.         KillTimer(m_uTypedownClock);
  309.         if (m_name.GetLength())
  310.         {
  311.             DIR_Server* dir;
  312.             CComboBox *widget = (CComboBox*) GetDlgItem(IDC_DIRECTORIES);
  313.             dir = (DIR_Server*) XP_ListGetObjectNum (theApp.m_directories, widget->GetCurSel() + 1);
  314.             if (dir->dirType == PABDirectory)
  315.                 m_uTypedownClock = SetTimer(ADDRESS_BOOK_TIMER, TYPEDOWN_SPEED, NULL);
  316.             else {
  317.                 int32 prefInt = LDAP_SEARCH_SPEED;
  318.                 PREF_GetIntPref("ldap_1.autoComplete.interval", &prefInt);
  319.                 m_uTypedownClock = SetTimer(ADDRESS_BOOK_TIMER, prefInt, NULL);
  320.             }
  321.         }
  322.     }
  323. }
  324.  
  325.  
  326. void CAddrBar::OnSetFocusName() 
  327. {
  328.     CEdit *widget = (CEdit*) GetDlgItem(IDC_ADDRNAME);
  329.     widget->SetSel(0, -1, TRUE);
  330. }
  331.  
  332.  
  333. void CAddrBar::OnChangeDirectory() 
  334. {
  335.     // TODO: Add your control notification handler code here
  336.     CAddrFrame* frame = (CAddrFrame*) GetParentFrame();
  337.     if (frame->IsSearching())
  338.         return;
  339.  
  340.     UpdateData(TRUE);
  341.     if (m_directory != m_savedir) {
  342.         m_savedir = m_directory;
  343.         if (m_directory != -1) {
  344.  
  345.             frame->OnChangeDirectory(m_directory);
  346.             XP_Bool bSelectable = FALSE, bPlural = FALSE;
  347.             MSG_COMMAND_CHECK_STATE sState;
  348.             AB_CommandStatus((ABPane*) frame->GetPane(),
  349.                               AB_LDAPSearchCmd,
  350.                               NULL, NULL,
  351.                               &bSelectable,
  352.                               &sState,
  353.                               NULL,
  354.                               &bPlural);
  355.             CWnd* widget = GetDlgItem ( IDC_DIRSEARCH );
  356.             widget->EnableWindow(bSelectable);
  357.         }
  358.     }
  359. }
  360.  
  361.  
  362. void CAddrBar::OnExtDirectorySearch() 
  363. {
  364.     // TODO: Add your control notification handler code here    
  365.     CAddrFrame* frame = (CAddrFrame*) GetParentFrame();
  366.     if (m_directory != -1) {
  367.         KillTimer(m_uTypedownClock);
  368.         frame->OnExtendedDirectorySearch();
  369.     }
  370.  
  371.  
  372. static void GrowWindow( CWnd *pWnd, int dx, int dy )
  373. {
  374.     CRect rect;
  375.     CWnd *parent;
  376.  
  377.     pWnd->GetWindowRect(&rect);
  378.     if (parent = pWnd->GetParent())
  379.         parent->ScreenToClient(&rect);
  380.  
  381.     rect.bottom += dy;
  382.     if (rect.right + dx > 0)
  383.         rect.right += dx;
  384.  
  385.     pWnd->MoveWindow(&rect);
  386. }
  387.  
  388.  
  389. static void SlideWindow( CWnd *pWnd, int dx, int dy )
  390. {
  391.     CRect rect;
  392.     CWnd *parent;
  393.  
  394.     pWnd->GetWindowRect(&rect);
  395.     if (parent = pWnd->GetParent())
  396.         parent->ScreenToClient(&rect);
  397.  
  398.     rect.top += dy;
  399.     rect.left += dx;
  400.     rect.bottom += dy;
  401.     rect.right += dx;
  402.  
  403.     pWnd->MoveWindow(&rect, TRUE);
  404. }
  405.  
  406.  
  407. void CAddrBar::OnSize( UINT nType, int cx, int cy )
  408. {
  409.     CDialogBar::OnSize( nType, cx, cy );
  410.     if ( cx && m_iWidth && ( cx != m_iWidth ) ) {
  411.         CWnd *widget;
  412.         CRect rect1 (0,0,0,0);
  413.         int dx = cx - m_iWidth;
  414.  
  415.         widget = GetDlgItem(IDC_DIRSEARCH);
  416.         if (widget) {
  417.             SlideWindow(widget, dx, 0);
  418.             widget->GetWindowRect(&rect1);
  419.         }
  420.  
  421.         widget = GetDlgItem(IDC_ADDRNAME);
  422.         if (widget) {
  423.             CWnd *parent;
  424.             CRect rect;
  425.  
  426.             widget->GetWindowRect(&rect);
  427.             if (parent = widget->GetParent()) {
  428.                 parent->ScreenToClient(&rect1);
  429.                 parent->ScreenToClient(&rect);
  430.                 rect.right = rect1.left - 8;
  431.             }
  432.             widget->MoveWindow(&rect);
  433.         }
  434.         m_iWidth = cx;
  435.     }
  436. }
  437.  
  438. class CAddrFrame;
  439.  
  440. /////////////////////////////////////////////////////////////////////////////
  441. // CAddrEntryList
  442.  
  443. class CAddrEntryList: public IMsgList {
  444.  
  445.     CAddrFrame *m_pAddrFrame;
  446.     unsigned long m_ulRefCount;
  447.  
  448. public:
  449. // IUnknown Interface
  450.     STDMETHODIMP            QueryInterface(REFIID,LPVOID *);
  451.     STDMETHODIMP_(ULONG)    AddRef(void);
  452.     STDMETHODIMP_(ULONG)    Release(void);
  453.  
  454. // IMsgList Interface
  455.     virtual void ListChangeStarting( MSG_Pane* pane, XP_Bool asynchronous,
  456.                                      MSG_NOTIFY_CODE notify, MSG_ViewIndex where,
  457.                                      int32 num);
  458.     virtual void ListChangeFinished( MSG_Pane* pane, XP_Bool asynchronous,
  459.                                      MSG_NOTIFY_CODE notify, MSG_ViewIndex where,
  460.                                      int32 num);
  461.     virtual void GetSelection( MSG_Pane* pane, MSG_ViewIndex **indices, int *count, 
  462.                                 int *focus);
  463.     virtual void SelectItem( MSG_Pane* pane, int item );
  464.  
  465.     virtual void CopyMessagesInto( MSG_Pane *pane, MSG_ViewIndex *indices, int count,
  466.                                    MSG_FolderInfo *folderInfo) {}
  467.     virtual void MoveMessagesInto( MSG_Pane *pane, MSG_ViewIndex *indices, int count,
  468.                                    MSG_FolderInfo *folderInfo) {}
  469.  
  470.     CAddrEntryList( CAddrFrame *pAddrFrame ) {
  471.         m_ulRefCount = 0;
  472.         m_pAddrFrame = pAddrFrame;
  473.     }
  474. };
  475.  
  476.  
  477. STDMETHODIMP CAddrEntryList::QueryInterface(REFIID refiid, LPVOID * ppv)
  478. {
  479.     *ppv = NULL;
  480.     if (IsEqualIID(refiid,IID_IUnknown))
  481.            *ppv = (LPUNKNOWN) this;
  482.     else if (IsEqualIID(refiid,IID_IMsgList))
  483.            *ppv = (LPMSGLIST) this;
  484.     else if (IsEqualIID(refiid,IID_IMailFrame))
  485.         *ppv = (LPMAILFRAME) m_pAddrFrame;
  486.  
  487.     if (*ppv != NULL) {
  488.            AddRef();
  489.         return NOERROR;
  490.     }
  491.             
  492.     return ResultFromScode(E_NOINTERFACE);
  493. }
  494.  
  495. STDMETHODIMP_(ULONG) CAddrEntryList::AddRef(void)
  496. {
  497.     return ++m_ulRefCount;
  498. }
  499.  
  500. STDMETHODIMP_(ULONG) CAddrEntryList::Release(void)
  501. {
  502.     ULONG ulRef;
  503.     ulRef = --m_ulRefCount;
  504.     if (m_ulRefCount == 0) 
  505.         delete this;       
  506.     return ulRef;       
  507. }
  508.  
  509. void CAddrEntryList::ListChangeStarting( MSG_Pane* pane, XP_Bool asynchronous,
  510.                                        MSG_NOTIFY_CODE notify, MSG_ViewIndex where,
  511.                                        int32 num)
  512. {
  513.     if (m_pAddrFrame) {
  514.         m_pAddrFrame->ListChangeStarting( pane, asynchronous,
  515.                                                  notify, where, num );
  516.     }
  517. }
  518.  
  519. void CAddrEntryList::ListChangeFinished( MSG_Pane* pane, XP_Bool asynchronous,
  520.                                        MSG_NOTIFY_CODE notify, MSG_ViewIndex where,
  521.                                        int32 num)
  522. {
  523.     if (m_pAddrFrame) {
  524.         m_pAddrFrame->ListChangeFinished( pane, asynchronous,
  525.                                                  notify, where, num );
  526.     }
  527. }
  528.  
  529. void CAddrEntryList::GetSelection( MSG_Pane* pane, MSG_ViewIndex **indices, int *count, 
  530.                                 int *focus)
  531. {
  532. }
  533.  
  534. void CAddrEntryList::SelectItem( MSG_Pane* pane, int item )
  535. {
  536. }
  537.  
  538. /////////////////////////////////////////////////////////////////////////////
  539. // CAddrFrame
  540.  
  541. CAddrFrame *CAddrFrame::Open()
  542. {
  543.     if (!WFE_MSGCheckWizard())
  544.         return NULL;
  545.  
  546.     if (!theApp.m_pAddressWindow)    //starts the address book window
  547.     {
  548.         CCreateContext context;
  549.         context.m_pCurrentFrame = NULL;
  550.         context.m_pCurrentDoc = NULL;
  551.         context.m_pNewViewClass = NULL;
  552.         context.m_pNewDocTemplate = NULL;
  553.  
  554.         theApp.m_pAddressWindow = new CAddrFrame();
  555.         if(!theApp.m_pAddressWindow) return NULL;
  556.         CCreateContext Context;
  557.         Context.m_pCurrentFrame = NULL; //  nothing to base on
  558.         Context.m_pCurrentDoc = NULL;  //  nothing to base on
  559.         Context.m_pNewViewClass = NULL; // nothing to base on
  560.         Context.m_pNewDocTemplate = NULL;   //  nothing to base on
  561.         theApp.m_pAddressWindow->LoadFrame(IDR_ADDRESS_MENU, 
  562.         WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE |WS_CLIPCHILDREN|WS_CLIPSIBLINGS, NULL, &Context);
  563.     } 
  564.     else
  565.     {
  566.         theApp.m_pAddressWindow->ActivateFrame();
  567.     }    
  568.     
  569.     return theApp.m_pAddressWindow; 
  570. }
  571.  
  572.  
  573. CAddrFrame::CAddrFrame()
  574. {
  575.     CString msg;
  576.     INTL_CharSetInfo csi = LO_GetDocumentCharacterSetInfo(GetContext());
  577.  
  578.     m_cxType = AddressCX;
  579.  
  580.     GetContext()->type = MWContextAddressBook;
  581.     GetContext()->fancyFTP = TRUE;
  582.     GetContext()->fancyNews = TRUE;
  583.     GetContext()->intrupt = FALSE;
  584.     GetContext()->reSize = FALSE;
  585.     INTL_SetCSIWinCSID(csi, CIntlWin::GetSystemLocaleCsid());
  586.  
  587.     m_pOutliner = NULL;
  588.     m_pOutlinerParent = NULL;
  589.     m_addrBookPane = NULL;
  590.     m_bSearching = FALSE;
  591.     m_iProgress = 0;
  592.     m_iWidth = 0;
  593.     m_pSplitter = NULL;
  594.  
  595.     CAddrEntryList *pInstance = new CAddrEntryList( this );
  596.     pInstance->QueryInterface( IID_IMsgList, (LPVOID *) &m_pIAddrList );
  597. }
  598.  
  599.  
  600. CAddrFrame::~CAddrFrame()
  601. {
  602.     if (m_pIAddrList)
  603.         m_pIAddrList->Release();
  604.  
  605.     if (m_addrBookPane)
  606.         HandleErrorReturn(AB_CloseAddressBookPane(&m_addrBookPane));
  607.  
  608.     theApp.m_pAddressWindow = NULL;
  609. }
  610.  
  611. /////////////////////////////////////////////////////////////////////////////
  612. // CAddrFrame Overloaded methods
  613.  
  614. BOOL CAddrFrame::PreCreateWindow(CREATESTRUCT& cs) 
  615. {
  616.     cs.hwndParent = NULL;
  617.  
  618.     cs.x = cs.y = 0;
  619.     cs.cx = cs.cy = 300; // Arbitrary
  620.  
  621.     BOOL bRet = CGenericFrame::PreCreateWindow(cs);
  622.  
  623. #ifdef _WIN32
  624.     cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
  625. #endif
  626.  
  627.     return bRet;
  628. }
  629.  
  630.  
  631. BOOL CAddrFrame::LoadFrame( UINT nIDResource, DWORD dwDefaultStyle, 
  632.         CWnd* pParentWnd, CCreateContext* pContext)
  633. {
  634.     BOOL ret = CGenericFrame::LoadFrame(nIDResource, dwDefaultStyle, pParentWnd, pContext);
  635.  
  636.     if (ret) {
  637.  
  638.         WINDOWPLACEMENT wp;
  639.         wp.length = sizeof(WINDOWPLACEMENT);
  640.         GetWindowPlacement(&wp);
  641.  
  642.         if (wp.rcNormalPosition.left < 0 || wp.rcNormalPosition.top < 0) {
  643.             SetWindowPos( NULL, 0 , 0, 0, 0, SWP_NOSIZE);
  644.             GetWindowPlacement(&wp);
  645.             SetWindowPos( NULL, abs (wp.rcNormalPosition.left) , abs (wp.rcNormalPosition.top),
  646.                 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE);
  647.         }
  648.         else
  649.             ShowWindow(SW_SHOW);
  650.     }
  651.  
  652.     return ret;
  653. }
  654.  
  655.  
  656. BOOL CAddrFrame::OnCreateClient( LPCREATESTRUCT lpcs, CCreateContext* pContext )
  657. {
  658.     BOOL res = CGenericFrame::OnCreateClient(lpcs, pContext);
  659.     if (res) {
  660.  
  661.         m_pSplitter = (CMailNewsSplitter *) RUNTIME_CLASS(CMailNewsSplitter)->CreateObject();
  662.  
  663.         ASSERT(m_pSplitter);
  664.  
  665. #ifdef _WIN32
  666.         m_pSplitter->CreateEx(0, NULL, NULL,
  667.                                   WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS,
  668.                                   0,0,0,0, this->m_hWnd, (HMENU)AFX_IDW_PANE_FIRST, pContext );
  669. #else
  670.         m_pSplitter->Create( NULL, NULL,
  671.                                  WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS,
  672.                                  CRect(0,0,0,0), this, AFX_IDW_PANE_FIRST, pContext ); 
  673. #endif
  674.                 
  675.         m_pOutlinerParent = new CAddrOutlinerParent;
  676. #ifdef _WIN32
  677.         m_pOutlinerParent->CreateEx(WS_EX_CLIENTEDGE, NULL, NULL,
  678.                                   WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,
  679.                                   0,0,0,0, m_pSplitter->m_hWnd, (HMENU) IDW_RESULTS_PANE, NULL );
  680. #else
  681.         m_pOutlinerParent->Create( NULL, NULL,
  682.                                  WS_BORDER|WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS,
  683.                                  CRect(0,0,0,0), m_pSplitter, IDW_RESULTS_PANE );
  684. #endif
  685.  
  686.         m_pOutliner = (CAddrOutliner *) m_pOutlinerParent->m_pOutliner;
  687.         m_pOutlinerParent->CreateColumns ( );
  688.         m_pOutlinerParent->EnableFocusFrame(TRUE);
  689.         m_pOutliner->SetContext( GetContext() );
  690.         SetMainContext (this);
  691.         SetActiveContext (this);
  692.  
  693.         m_pDirOutlinerParent = new CDirOutlinerParent;
  694. #ifdef _WIN32
  695.         m_pDirOutlinerParent->CreateEx(WS_EX_CLIENTEDGE, NULL, NULL,
  696.                                   WS_CHILD|WS_VISIBLE|WS_CLIPCHILDREN|WS_CLIPSIBLINGS,
  697.                                   0,0,0,0, m_pSplitter->m_hWnd, (HMENU) IDW_RESULTS_PANE, NULL );
  698. #else
  699.         m_pDirOutlinerParent->Create( NULL, NULL,
  700.                                  WS_BORDER|WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS,
  701.                                  CRect(0,0,0,0), m_pSplitter, IDW_RESULTS_PANE );
  702. #endif
  703.  
  704.         m_pDirOutliner = (CDirOutliner *) m_pDirOutlinerParent->m_pOutliner;
  705.         m_pDirOutlinerParent->CreateColumns ( );
  706.         m_pDirOutlinerParent->EnableFocusFrame(TRUE);
  707.         m_pDirOutliner->SetContext( GetContext() );
  708.  
  709.         int32 prefInt = -1;
  710.         PREF_GetIntPref("mail.addr_book.sliderwidth", &prefInt);
  711.         RECT rect;
  712.         GetClientRect(&rect);
  713.         m_pSplitter->AddPanes(m_pDirOutlinerParent, m_pOutlinerParent, prefInt, TRUE);
  714.     }
  715.     
  716.     return res;
  717. }
  718.  
  719.  
  720. BOOL CAddrFrame::PreTranslateMessage( MSG* pMsg )
  721. {
  722.     if (pMsg->message == WM_KEYDOWN)
  723.     {
  724.         if (pMsg->wParam == VK_DELETE)
  725.         {
  726.             if (GetFocus() == m_barAddr.GetDlgItem(IDC_ADDRNAME)) {
  727.                 return FALSE;
  728.             }
  729.         }
  730.  
  731.         if (pMsg->wParam == VK_TAB) {
  732.             HWND hwndNext = NULL;
  733.             HWND hwndFocus = ::GetFocus();
  734.  
  735.             HWND hwndDirOutliner = m_pDirOutliner ? m_pDirOutliner->m_hWnd : NULL;
  736.             HWND hwndOutliner = m_pOutliner ? m_pOutliner->m_hWnd : NULL;
  737.     
  738.             HWND hwndAddrBarFirst = ::GetNextDlgTabItem( m_barAddr.m_hWnd, NULL, FALSE );
  739.  
  740.             HWND hwndAddrBarLast = ::GetNextDlgTabItem( m_barAddr.m_hWnd, hwndAddrBarFirst, TRUE );
  741.  
  742.             if ( GetKeyState(VK_SHIFT) & 0x8000 ) {
  743.  
  744.                 // Tab backward
  745.                 if ( hwndFocus == hwndAddrBarFirst ) {
  746.                     // Handle tabbing into outliner
  747.                     hwndNext = hwndOutliner;
  748.                 } else if (hwndFocus == hwndOutliner) {
  749.                     // Handle tabbing out of outliner into the directory list
  750.                     if (m_pSplitter->IsOnePaneClosed())
  751.                         hwndNext = hwndAddrBarLast;
  752.                     else
  753.                         hwndNext = hwndDirOutliner;
  754.                 } else if ( hwndFocus == hwndDirOutliner ) {
  755.                     // Handle tabbing into the outliner
  756.                     hwndNext = hwndAddrBarLast;
  757.                 }
  758.  
  759.             } else {
  760.  
  761.                 // Tab forward
  762.                 if (hwndFocus == hwndOutliner) {
  763.                     // Handle tabbing out of outliner
  764.                     hwndNext = hwndAddrBarFirst;
  765.                 } else if ( hwndFocus == hwndAddrBarLast ) {
  766.                     // handle tabbing into the directory list
  767.                     if (m_pSplitter->IsOnePaneClosed())
  768.                         hwndNext = hwndOutliner;
  769.                     else
  770.                         hwndNext = hwndDirOutliner;
  771.                 } else if (hwndFocus == hwndDirOutliner) {
  772.                     // Handle tabbing out of the directory list
  773.                     hwndNext = hwndOutliner;
  774.                 }
  775.  
  776.             }
  777.             if ( hwndNext ) {
  778.                 ::SetFocus( hwndNext );
  779.                 return TRUE;
  780.             }
  781.         } // if tab
  782.     } // if keydown
  783.     return CGenericFrame::PreTranslateMessage(pMsg);
  784. }
  785.  
  786.  
  787. void CAddrFrame::OnHelpMenu()
  788. {
  789.     NetHelp(HELP_ADDRESS_BOOK);
  790. }
  791.  
  792.  
  793. void CAddrFrame::Progress(MWContext *pContext, const char *pMessage)
  794. {
  795.     LPNSSTATUSBAR pIStatusBar = NULL;
  796.     m_pChrome->QueryInterface( IID_INSStatusBar, (LPVOID *) &pIStatusBar );
  797.     if ( pIStatusBar ) {
  798.         pIStatusBar->SetStatusText(pMessage);
  799.         pIStatusBar->Release();
  800.     }
  801. }
  802.  
  803.  
  804. void CAddrFrame::SetProgressBarPercent(MWContext *pContext, int32 lPercent)
  805. {
  806.     lPercent = lPercent < 0 ? 0 : ( lPercent > 100 ? 100 : lPercent );
  807.  
  808.     if ( m_iProgress == lPercent ) {
  809.         return;
  810.     }
  811.  
  812.     m_iProgress = lPercent;
  813.     if (GetChrome()) {
  814.         LPNSSTATUSBAR pIStatusBar = NULL;
  815.         GetChrome()->QueryInterface( IID_INSStatusBar, (LPVOID *) &pIStatusBar );
  816.         if ( pIStatusBar ) {
  817.             pIStatusBar->SetProgress( CASTINT(lPercent) );
  818.             pIStatusBar->Release();
  819.         }
  820.     }
  821.  
  822.  
  823. STDMETHODIMP CAddrFrame::QueryInterface(REFIID refiid, LPVOID * ppv)
  824. {
  825.     *ppv = NULL;
  826.     if (IsEqualIID(refiid,IID_IUnknown))
  827.            *ppv = (LPUNKNOWN) (LPMSGLIST) m_pIAddrList;
  828.     else if (IsEqualIID(refiid,IID_IMailFrame))
  829.         *ppv = (LPMAILFRAME) this;
  830.     else if (IsEqualIID(refiid,IID_IMsgList))
  831.            *ppv = (LPMSGLIST) m_pIAddrList;
  832.  
  833.     if (*ppv != NULL) {
  834.            AddRef();
  835.         return NOERROR;
  836.     }
  837.             
  838.     return ResultFromScode(E_NOINTERFACE);
  839. }
  840.  
  841. STDMETHODIMP_(ULONG) CAddrFrame::AddRef(void)
  842. {
  843.     return 0; // Not a real component
  844. }
  845.  
  846. STDMETHODIMP_(ULONG) CAddrFrame::Release(void)
  847. {
  848.     return 0; // Not a real component
  849. }
  850.  
  851. // IMailFrame interface
  852. CMailNewsFrame *CAddrFrame::GetMailNewsFrame()
  853. {
  854.     return (CMailNewsFrame *) NULL; 
  855. }
  856.  
  857. MSG_Pane *CAddrFrame::GetPane()
  858. {
  859.     return (MSG_Pane*) m_addrBookPane;
  860. }
  861.  
  862. void CAddrFrame::PaneChanged(MSG_Pane *pane, XP_Bool asynchronous, 
  863.                                  MSG_PANE_CHANGED_NOTIFY_CODE notify, int32 value)
  864. {
  865.     if (notify == MSG_PaneDirectoriesChanged) {
  866.         // stop an ldap search if we need to 
  867.         if (m_bSearching) 
  868.             OnStopSearch();
  869.         UpdateDirectories();
  870.     }
  871. }
  872.  
  873.  
  874. #ifdef FEATURE_ADDRESS_BOOK
  875. #include "addrfrm.i00"
  876. #endif
  877.  
  878. /////////////////////////////////////////////////////////////////////////////
  879. // CAddrFrame message handlers
  880.  
  881. BEGIN_MESSAGE_MAP(CAddrFrame, CGenericFrame)
  882.     //{{AFX_MSG_MAP(CAddrFrame)
  883.     ON_WM_CREATE()
  884.     ON_WM_CLOSE()
  885.     ON_WM_SHOWWINDOW( )
  886.     ON_WM_DESTROY()
  887.     ON_WM_GETMINMAXINFO()
  888.     ON_UPDATE_COMMAND_UI(ID_VIEW_ABTOOLBAR, OnUpdateViewCommandToolbar)
  889.     ON_COMMAND(ID_VIEW_ABTOOLBAR, OnViewCommandToolbar)
  890.     ON_UPDATE_COMMAND_UI(ID_TOOLS_ADDRESSBOOK, OnUpdateShowAddressBookWindow)
  891.     ON_UPDATE_COMMAND_UI(IDS_SECURITY_STATUS, OnUpdateSecureStatus)
  892.     ON_COMMAND(ID_FILE_IMPORT, OnImportFile)
  893.     ON_UPDATE_COMMAND_UI( ID_FILE_IMPORT, OnUpdateImport )
  894.     ON_COMMAND(ID_FILE_SAVEAS, OnExportFile)
  895.     ON_UPDATE_COMMAND_UI( ID_FILE_SAVEAS, OnUpdateExport )
  896.     ON_COMMAND(ID_FILE_CLOSE, OnFileClose)
  897.     ON_UPDATE_COMMAND_UI( IDC_DIRSEARCH, OnUpdateSearch )
  898.     ON_COMMAND(IDC_DIRSEARCH, OnExtDirectorySearch)
  899.     ON_COMMAND(ID_NAVIGATE_INTERRUPT, OnStopSearch)
  900.     ON_UPDATE_COMMAND_UI(ID_NAVIGATE_INTERRUPT, OnUpdateStopSearch)
  901.     ON_COMMAND(ID_FILE_NEWMESSAGE, OnComposeMsg)
  902.     ON_UPDATE_COMMAND_UI(ID_FILE_NEWMESSAGE, OnUpdateComposeMsg)
  903.     ON_COMMAND(ID_LIVE_CALL, OnCall)
  904.     ON_UPDATE_COMMAND_UI(ID_LIVE_CALL, OnUpdateCall)
  905.     ON_COMMAND(ID_ITEM_ADDUSER, OnAddUser)
  906.     ON_UPDATE_COMMAND_UI(ID_ITEM_ADDUSER, OnUpdateAddUser)
  907.     ON_COMMAND(ID_FILE_NEWAB, OnAddAB)
  908.     ON_UPDATE_COMMAND_UI(ID_FILE_NEWAB, OnUpdateAddAB)
  909.     ON_COMMAND(ID_FILE_NEWDIR, OnAddDir)
  910.     ON_UPDATE_COMMAND_UI(ID_FILE_NEWDIR, OnUpdateAddDir)
  911.     ON_COMMAND(ID_EDIT_DOMAINS, OnHTMLDomains)
  912.     ON_UPDATE_COMMAND_UI(ID_EDIT_DOMAINS, OnUpdateHTMLDomains)
  913.     ON_COMMAND(ID_ITEM_ADDLIST, OnAddList)
  914.     ON_UPDATE_COMMAND_UI(ID_ITEM_ADDLIST, OnUpdateAddList)
  915.     ON_COMMAND(ID_SWITCH_SORT, OnSwitchSortFirstLast)
  916.     ON_UPDATE_COMMAND_UI(ID_SWITCH_SORT, OnUpdateSwitchSort)
  917.     ON_COMMAND(ID_EDIT_DELETE, OnDeleteItem)
  918.     ON_UPDATE_COMMAND_UI(ID_EDIT_DELETE, OnUpdateDeleteItem)
  919.     ON_COMMAND(ID_EDIT_UNDO, OnUndo)
  920.     ON_UPDATE_COMMAND_UI(ID_EDIT_UNDO, OnUpdateUndo)
  921.     ON_COMMAND(ID_EDIT_REDO, OnRedo)
  922.     ON_UPDATE_COMMAND_UI(ID_EDIT_REDO, OnUpdateRedo)
  923.     ON_COMMAND(ID_ITEM_PROPERTIES, OnItemProperties)
  924.     ON_UPDATE_COMMAND_UI(ID_ITEM_PROPERTIES, OnUpdateItemProperties)
  925.     ON_COMMAND(ID_SORT_TYPE, OnSortType)
  926.     ON_UPDATE_COMMAND_UI(ID_SORT_TYPE, OnUpdateSortType)
  927.     ON_COMMAND(ID_SORT_NAME, OnSortName)
  928.     ON_UPDATE_COMMAND_UI(ID_SORT_NAME, OnUpdateSortName)
  929.     ON_COMMAND(ID_SORT_NICKNAME, OnSortNickName)
  930.     ON_UPDATE_COMMAND_UI(ID_SORT_NICKNAME, OnUpdateSortNickName)
  931.     ON_COMMAND(ID_SORT_EMAILADDRESS, OnSortEmailAddress)
  932.     ON_UPDATE_COMMAND_UI(ID_SORT_EMAILADDRESS, OnUpdateSortEmailAddress)
  933.     ON_COMMAND(ID_SORT_COMPANY, OnSortCompany)
  934.     ON_UPDATE_COMMAND_UI(ID_SORT_COMPANY, OnUpdateSortCompany)
  935.     ON_COMMAND(ID_SORT_LOCALITY, OnSortLocality)
  936.     ON_UPDATE_COMMAND_UI(ID_SORT_LOCALITY, OnUpdateSortLocality)
  937.     ON_COMMAND(ID_ASCENDING, OnSortAscending)
  938.     ON_UPDATE_COMMAND_UI(ID_ASCENDING, OnUpdateSortAscending)
  939.     ON_COMMAND(ID_DECENDING, OnSortDescending)
  940.     ON_UPDATE_COMMAND_UI(ID_DECENDING, OnUpdateSortDescending)
  941.     ON_COMMAND(ID_CREATE_CARD, OnCreateCard)
  942.     //}}AFX_MSG_MAP
  943. END_MESSAGE_MAP()
  944.  
  945. int CAddrFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  946. {
  947.     void    WFE_AddNewFrameToFrameList(CGenericFrame * pFrame);
  948.     int res = CGenericFrame::OnCreate(lpCreateStruct);
  949.  
  950.     unsigned long sortby;
  951.     int32 prefInt;
  952.     PREF_GetIntPref("mail.addr_book.sortby",&prefInt);
  953.     switch (prefInt) {
  954.     case ID_COLADDR_TYPE:
  955.     case ID_COLADDR_COMPANY:
  956.     case ID_COLADDR_LOCALITY:
  957.         sortby = ABFullName;
  958.         break;
  959.     case ID_COLADDR_NAME:
  960.         sortby = ABFullName;
  961.         break;
  962.     case ID_COLADDR_EMAIL:
  963.         sortby = ABEmailAddress;
  964.         break;
  965.     case ID_COLADDR_NICKNAME:
  966.         sortby = ABNickname;
  967.         break;
  968.     default:
  969.         sortby = ABFullName;
  970.         break;
  971.     }
  972.  
  973.     int result = 0;
  974.  
  975.     DIR_Server* dir = (DIR_Server*)XP_ListGetObjectNum(theApp.m_directories, 1);
  976.  
  977.     XP_ASSERT (dir);
  978.  
  979.     if (!dir)
  980.         return -1;
  981.  
  982.     XP_Bool prefBool;
  983.     PREF_GetBoolPref("mail.addr_book.sort_ascending",&prefBool);
  984.  
  985.     HandleErrorReturn((result = AB_CreateAddressBookPane(&m_addrBookPane,
  986.             GetContext(),
  987.             WFE_MSGGetMaster())));
  988.  
  989.     if (result)
  990.         return -1;
  991.  
  992.     HandleErrorReturn((result = AB_InitializeAddressBookPane(m_addrBookPane,
  993.                                 dir,
  994.                                 theApp.m_pABook,
  995.                                 sortby,
  996.                                 prefBool)));
  997.     if (result)
  998.         return -1;
  999.  
  1000.     //I'm hardcoding because I don't want this translated
  1001.     GetChrome()->CreateCustomizableToolbar("Address_Book"/*ID_ADDRESS_BOOK*/, 3, TRUE);
  1002.     CButtonToolbarWindow *pWindow;
  1003.     BOOL bOpen, bShowing;
  1004.  
  1005.     int32 nPos;
  1006.  
  1007.     //I'm hardcoding because I don't want this translated
  1008.     GetChrome()->LoadToolbarConfiguration(ID_ADDRESS_BOOK_TOOLBAR, CString("Address_Book_Toolbar"), nPos, bOpen, bShowing);
  1009.  
  1010.     LPNSTOOLBAR pIToolBar = NULL;
  1011.     GetChrome()->QueryInterface( IID_INSToolBar, (LPVOID *) &pIToolBar );
  1012.     if ( pIToolBar ) {
  1013.         pIToolBar->Create( this, WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE | CBRS_TOP | WS_BORDER);
  1014.         pIToolBar->SetButtons( AddrCodes, sizeof(AddrCodes)/sizeof(UINT) );
  1015.         pIToolBar->SetSizes( CSize( 30, 27 ), CSize( 23, 21 ) );
  1016.         pIToolBar->LoadBitmap( MAKEINTRESOURCE( IDB_ADDRESSTOOLBARP ) );
  1017.         pIToolBar->SetToolbarStyle( theApp.m_pToolbarStyle );
  1018.         pWindow = new CButtonToolbarWindow(CWnd::FromHandlePermanent(pIToolBar->GetHWnd()), theApp.m_pToolbarStyle, 43, 27, eLARGE_HTAB);
  1019.         GetChrome()->GetCustomizableToolbar()->AddNewWindow(ID_ADDRESS_BOOK_TOOLBAR, pWindow,nPos, 50, 37, 0, CString(szLoadString(ID_ADDRESS_BOOK_TOOLBAR)),theApp.m_pToolbarStyle, bOpen, FALSE);
  1020.         GetChrome()->ShowToolbar(ID_ADDRESS_BOOK_TOOLBAR, bShowing);
  1021. #ifdef XP_WIN16
  1022.         GetChrome()->GetCustomizableToolbar()->SetBottomBorder(TRUE);
  1023. #endif
  1024.  
  1025.         pIToolBar->Release();
  1026.     }
  1027.  
  1028.     LPNSSTATUSBAR pIStatusBar = NULL;
  1029.     GetChrome()->QueryInterface( IID_INSStatusBar, (LPVOID *) &pIStatusBar );
  1030.     if ( pIStatusBar ) {
  1031.         pIStatusBar->Create( this );
  1032.         pIStatusBar->Release();
  1033.     }
  1034.  
  1035.  
  1036.     m_barAddr.Create( this, IDD_ADDRESSBOOK, CBRS_TOP, 1 );
  1037.  
  1038.     // Initially size window to only dialog + title bar.
  1039.     int BorderX = GetSystemMetrics(SM_CXFRAME);
  1040.  
  1041.     CRect rect;
  1042.     m_barAddr.GetWindowRect(rect);
  1043. #ifdef _WIN32
  1044.     CSize size = m_barAddr.CalcFixedLayout(FALSE, FALSE);
  1045. #else
  1046.     CSize size = m_barAddr.m_sizeDefault;
  1047. #endif
  1048.  
  1049.     // Figure height of title bar + bottom border
  1050.     m_iWidth = size.cx;
  1051.  
  1052.     int16 iLeft,iRight,iTop,iBottom;
  1053.     PREF_GetRectPref("mail.addr_book_window_rect", &iLeft, &iTop, &iRight, &iBottom);
  1054.     int screenY = ::GetSystemMetrics(SM_CYFULLSCREEN);
  1055.     int screenX = ::GetSystemMetrics(SM_CXFULLSCREEN);
  1056.  
  1057.     if ((iLeft >= 0) && (iTop >= 0) && (iRight < screenX) && (iBottom < screenY))
  1058.     {
  1059.         if (iRight - iLeft > m_iWidth)
  1060.             size.cx = iRight - iLeft;
  1061.         size.cy = iBottom - iTop;
  1062.         SetWindowPos( NULL, iLeft, iTop, size.cx, size.cy,
  1063.                   SWP_HIDEWINDOW);
  1064.     }
  1065.     else {
  1066.         size.cy = 300;
  1067.         SetWindowPos( NULL, 0, 0, size.cx, size.cy,
  1068.                   SWP_HIDEWINDOW);
  1069.  
  1070.     }
  1071.  
  1072.     m_barAddr.UpdateDirectories();
  1073.     m_pOutliner->SetPane(m_addrBookPane);
  1074.     m_pDirOutliner->SetPane(m_addrBookPane);
  1075.     MSG_SetFEData( (MSG_Pane*) m_addrBookPane, (void *) m_pIAddrList );
  1076.  
  1077.     WFE_AddNewFrameToFrameList(this);
  1078.  
  1079.     CFrameWnd::RecalcLayout();
  1080.  
  1081.     if (m_barAddr.m_pFont)
  1082.         ::SendMessage(::GetDlgItem(m_barAddr.GetSafeHwnd(), IDC_ADDRNAME),
  1083.                       WM_SETFONT, (WPARAM)m_barAddr.m_pFont, FALSE);
  1084.     if (m_barAddr.m_bRemoveLDAPDir)
  1085.         m_barAddr.GetDlgItem(IDC_DIRSEARCH)->ShowWindow(SW_HIDE);
  1086.     m_barAddr.GetDlgItem(IDC_ADDRNAME)->SetFocus();
  1087.  
  1088.     return res;
  1089. }
  1090.  
  1091. void CAddrFrame::UpdateDirectories ( void )
  1092. {
  1093.     m_barAddr.SetDirectoryIndex(0);
  1094.     m_barAddr.OnChangeDirectory();
  1095.     m_barAddr.UpdateDirectories();
  1096.     m_pDirOutliner->UpdateCount();
  1097. }
  1098.  
  1099. void CAddrFrame::OnFileClose ( void )
  1100. {
  1101.     PostMessage ( WM_CLOSE );
  1102. }
  1103.  
  1104. void CAddrFrame::OnViewCommandToolbar()
  1105. {
  1106.     GetChrome()->ShowToolbar(ID_ADDRESS_BOOK_TOOLBAR, !GetChrome()->GetToolbarVisible(ID_ADDRESS_BOOK_TOOLBAR));
  1107. }
  1108.  
  1109. void CAddrFrame::OnUpdateViewCommandToolbar(CCmdUI *pCmdUI)
  1110. {
  1111.     BOOL bShow = GetChrome()->GetToolbarVisible(ID_ADDRESS_BOOK_TOOLBAR);
  1112.     if( pCmdUI->m_pMenu ){
  1113.         pCmdUI->m_pMenu->ModifyMenu(CASTUINT(ID_VIEW_ABTOOLBAR), CASTUINT(MF_BYCOMMAND | MF_STRING), CASTUINT(ID_VIEW_ABTOOLBAR),
  1114.                                     szLoadString(CASTUINT(bShow ? IDS_HIDE_ABTOOLBAR : IDS_SHOW_ABTOOLBAR)) );
  1115.     } else {
  1116.         pCmdUI->SetCheck(bShow);
  1117.     }
  1118. }
  1119.  
  1120. void CAddrFrame::OnGetMinMaxInfo( MINMAXINFO FAR* lpMMI )
  1121. {
  1122.     CGenericFrame::OnGetMinMaxInfo( lpMMI );
  1123.  
  1124.     if (m_iWidth) {
  1125.         lpMMI->ptMinTrackSize.x = m_iWidth;
  1126.     }
  1127. }
  1128.  
  1129.  
  1130. void CAddrFrame::OnDestroy()
  1131. {
  1132.     // DestroyContext will call Interrupt, but if we wait until after DestroyContext
  1133.     // to call MSG_SearchFree, the MWContext will be gone, and we'll be reading freed memory
  1134.     if (XP_IsContextBusy (GetContext()))
  1135.         XP_InterruptContext (GetContext());
  1136.  
  1137.     if (m_addrBookPane)
  1138.         MSG_SearchFree ((MSG_Pane*) m_addrBookPane);
  1139.  
  1140.      CGenericFrame::OnDestroy();
  1141.  
  1142.     if(!IsDestroyed()) {
  1143.         DestroyContext();
  1144.     }
  1145. }
  1146.  
  1147.  
  1148. void CAddrFrame::OnClose()
  1149. {
  1150.     CRect rect;
  1151.     WINDOWPLACEMENT wp;
  1152.     int i;
  1153.     wp.length = sizeof(WINDOWPLACEMENT);
  1154.     GetWindowPlacement(&wp);
  1155.  
  1156.     ASSERT(theApp.m_pAddressWindow == this);
  1157.                   
  1158.     if ( !IsIconic() && !IsZoomed() )
  1159.     {
  1160.         GetWindowRect ( &rect );
  1161.         PREF_SetRectPref("mail.addr_book_window_rect", 
  1162.             (int16) rect.left, (int16) rect.top, (int16) rect.right, (int16) rect.bottom);
  1163.     }
  1164.     
  1165.     PREF_SetIntPref("mail.wfe.addr_book.show_value",(int)wp.showCmd);
  1166.     PREF_SetIntPref("mail.addr_book.sliderwidth", m_pSplitter->GetPaneSize());
  1167.  
  1168.     // we should prompt if changes aren't saved
  1169.     // MW fix
  1170.     for (i = 0; i < m_listPropList.GetSize(); i++) {
  1171.         ((CWnd*) m_listPropList.GetAt(i))->DestroyWindow();
  1172.     }
  1173.  
  1174.     for (i = 0; i < m_userPropList.GetSize(); i++) {
  1175.         ((CWnd*) m_userPropList.GetAt(i))->DestroyWindow();
  1176.     }
  1177.  
  1178.     //I'm hardcoding because I don't want this translated
  1179.     GetChrome()->SaveToolbarConfiguration(ID_ADDRESS_BOOK_TOOLBAR, CString("Address_Book_Toolbar"));
  1180.  
  1181.     CGenericFrame::OnClose();
  1182. }
  1183.  
  1184.  
  1185.  
  1186. void CAddrFrame::ListChangeStarting( MSG_Pane* pane, XP_Bool asynchronous,
  1187.                                         MSG_NOTIFY_CODE notify, MSG_ViewIndex where,
  1188.                                         int32 num)
  1189. {
  1190.     if ( pane == (MSG_Pane*) m_addrBookPane ) {
  1191.         if ( m_pOutliner ) {
  1192.             m_pOutliner->MysticStuffStarting( asynchronous, notify,
  1193.                                                    where, num );
  1194.         }
  1195.     }
  1196. }
  1197.  
  1198. void CAddrFrame::ListChangeFinished( MSG_Pane* pane, XP_Bool asynchronous,
  1199.                                         MSG_NOTIFY_CODE notify, MSG_ViewIndex where,
  1200.                                         int32 num)
  1201. {
  1202.     if ( pane == (MSG_Pane*) m_addrBookPane ) {
  1203.         if ( m_pOutliner ) {
  1204.             m_pOutliner->MysticStuffFinishing( asynchronous, notify,
  1205.                                                     where, num );
  1206.         }
  1207.     }
  1208. }
  1209.  
  1210.  
  1211. void CAddrFrame::SetSearchResults(MSG_ViewIndex index, int32 num)
  1212. {
  1213.  
  1214.     CString csStatus;
  1215.  
  1216.     ASSERT(m_pOutliner);
  1217.     AB_LDAPSearchResults(m_addrBookPane, index, num);
  1218.     if (num > 1) {
  1219.         csStatus.Format( szLoadString(IDS_SEARCHHITS), num );
  1220.     } else if ( num > 0 ) {
  1221.         csStatus.LoadString( IDS_SEARCHONEHIT );
  1222.     } else {
  1223.         csStatus.LoadString( IDS_SEARCHNOHITS );
  1224.     }
  1225.  
  1226.     if (GetChrome()) {
  1227.         LPNSSTATUSBAR pIStatusBar = NULL;
  1228.         GetChrome()->QueryInterface( IID_INSStatusBar, (LPVOID *) &pIStatusBar );
  1229.         if ( pIStatusBar ) {
  1230.             pIStatusBar->SetStatusText(csStatus);
  1231.             pIStatusBar->Release();
  1232.         }
  1233.     }
  1234. }
  1235.  
  1236.  
  1237. void CAddrFrame::AllConnectionsComplete( MWContext *pContext )
  1238. {
  1239.     CStubsCX::AllConnectionsComplete( pContext );
  1240.  
  1241.     if (m_bSearching) {
  1242.  
  1243.         OnStopSearch();
  1244.  
  1245.         int32 total = m_pOutliner->GetTotalLines();
  1246.         CString csStatus;
  1247.         if ( total > 1 ) {
  1248.             csStatus.Format( szLoadString( IDS_SEARCHHITS ), total );
  1249.         } else if ( total > 0 ) {
  1250.             csStatus.LoadString( IDS_SEARCHONEHIT );
  1251.         } else {
  1252.             csStatus.LoadString( IDS_SEARCHNOHITS );
  1253.             CString s;
  1254.             if (s.LoadString( IDS_BOOKMARK_ADDRESSPROPERTIES ))
  1255.                 MessageBox(csStatus, s, MB_OK | MB_APPLMODAL);
  1256.         }
  1257.  
  1258.         LPNSSTATUSBAR pIStatusBar = NULL;
  1259.         m_pChrome->QueryInterface( IID_INSStatusBar, (LPVOID *) &pIStatusBar );
  1260.         if ( pIStatusBar ) {
  1261.             pIStatusBar->SetStatusText( csStatus );
  1262.             pIStatusBar->SetProgress( 0 );
  1263.             pIStatusBar->Release();
  1264.         }
  1265.     
  1266.         SendMessageToDescendants(WM_IDLEUPDATECMDUI, (WPARAM)TRUE, (LPARAM)0);
  1267.     }
  1268. }
  1269.  
  1270. void CAddrFrame::Close()
  1271. {
  1272.     if (theApp.m_pAddressWindow) {
  1273.         theApp.m_pAddressWindow->PostMessage(WM_CLOSE);
  1274.     }       
  1275. }
  1276.  
  1277. void CAddrFrame::OnImportFile()
  1278. {
  1279.     HandleErrorReturn(AB_ImportFromFile(m_addrBookPane, GetContext()), this);
  1280. }
  1281.  
  1282. void CAddrFrame::OnExportFile()
  1283. {
  1284.     HandleErrorReturn(AB_ExportToFile(m_addrBookPane, GetContext()), this);
  1285. }
  1286.  
  1287.  
  1288. void CAddrFrame::OnTypedown (char* name)
  1289. {
  1290.     DIR_Server* dir = GetCurrentDirectoryServer();
  1291.  
  1292.     if (dir->dirType == LDAPDirectory)    {
  1293.         OnDirectoryList(name);
  1294.     }
  1295.     else
  1296.         m_pOutliner->OnTypedown (name);
  1297. }
  1298.  
  1299.  
  1300. void CAddrFrame::DoUpdateAddressBook( CCmdUI* pCmdUI, AB_CommandType cmd, BOOL bUseCheck )
  1301. {
  1302.     if(!pCmdUI)
  1303.         return;
  1304.  
  1305.     XP_Bool bSelectable = FALSE, bPlural = FALSE;
  1306.     MSG_COMMAND_CHECK_STATE sState;
  1307.  
  1308.     if (m_addrBookPane) {
  1309.         if (m_pOutliner) {
  1310.             MSG_ViewIndex *indices;
  1311.             int count;
  1312.             m_pOutliner->GetSelection(indices, count);
  1313.             AB_CommandStatus(m_addrBookPane,
  1314.                               cmd,
  1315.                               indices, count,
  1316.                               &bSelectable,
  1317.                               &sState,
  1318.                               NULL,
  1319.                               &bPlural);
  1320.         } else {
  1321.             AB_CommandStatus(m_addrBookPane,
  1322.                               cmd,
  1323.                               NULL, 0,
  1324.                               &bSelectable,
  1325.                               &sState,
  1326.                               NULL,
  1327.                               &bPlural);
  1328.         }
  1329.     }
  1330.     pCmdUI->Enable(bSelectable);
  1331.     if (bUseCheck)
  1332.         pCmdUI->SetCheck(sState == MSG_Checked);
  1333.     else
  1334.         pCmdUI->SetRadio(sState == MSG_Checked);
  1335. }
  1336.  
  1337.  
  1338. void CAddrFrame::OnExtDirectorySearch()
  1339. {
  1340.     m_barAddr.OnExtDirectorySearch();
  1341. }
  1342.  
  1343. void CAddrFrame::OnUpdateShowAddressBookWindow( CCmdUI *pCmdUI )
  1344. {
  1345.     pCmdUI->Enable(FALSE);
  1346. }
  1347.  
  1348. void CAddrFrame::OnUpdateSecureStatus(CCmdUI *pCmdUI)
  1349. {
  1350.     DIR_Server* dir = GetCurrentDirectoryServer();
  1351.  
  1352.     if (dir->isSecure)
  1353.         pCmdUI->Enable(TRUE);
  1354.     else
  1355.         pCmdUI->Enable(FALSE);
  1356. }
  1357.  
  1358.  
  1359. void CAddrFrame::OnUpdateSearch( CCmdUI *pCmdUI )
  1360. {
  1361.     DoUpdateAddressBook(pCmdUI, AB_LDAPSearchCmd, TRUE);
  1362. }
  1363.  
  1364.  
  1365. void CAddrFrame::OnUpdateImport(CCmdUI* pCmdUI)
  1366. {
  1367.     DoUpdateAddressBook(pCmdUI, AB_ImportCmd, TRUE);
  1368. }
  1369.  
  1370. void CAddrFrame::OnUpdateExport(CCmdUI* pCmdUI)
  1371. {
  1372.     DoUpdateAddressBook(pCmdUI, AB_SaveCmd, TRUE);
  1373. }
  1374.  
  1375. void CAddrFrame::OnUpdateSortType(CCmdUI* pCmdUI)
  1376. {
  1377.     DoUpdateAddressBook(pCmdUI, AB_SortByTypeCmd, TRUE);
  1378. }
  1379.  
  1380. void CAddrFrame::OnUpdateSortName(CCmdUI* pCmdUI)
  1381. {
  1382.     DoUpdateAddressBook(pCmdUI, AB_SortByFullNameCmd, TRUE);
  1383. }
  1384.  
  1385. void CAddrFrame::OnUpdateSortNickName(CCmdUI* pCmdUI)
  1386. {
  1387.     DoUpdateAddressBook(pCmdUI, AB_SortByNickname, TRUE);
  1388. }
  1389.  
  1390. void CAddrFrame::OnUpdateSortEmailAddress(CCmdUI* pCmdUI)
  1391. {
  1392.     DoUpdateAddressBook(pCmdUI, AB_SortByEmailAddress, TRUE);
  1393. }
  1394.  
  1395. void CAddrFrame::OnUpdateSortCompany(CCmdUI* pCmdUI)
  1396. {
  1397.     DoUpdateAddressBook(pCmdUI, AB_SortByCompanyName, TRUE);
  1398. }
  1399.  
  1400. void CAddrFrame::OnUpdateSortLocality(CCmdUI* pCmdUI)
  1401. {
  1402.     DoUpdateAddressBook(pCmdUI, AB_SortByLocality, TRUE);
  1403. }
  1404.  
  1405. void CAddrFrame::OnUpdateSortAscending(CCmdUI* pCmdUI)
  1406. {
  1407.     DoUpdateAddressBook(pCmdUI, AB_SortAscending, TRUE);
  1408. }
  1409.  
  1410. void CAddrFrame::OnUpdateSortDescending(CCmdUI* pCmdUI)
  1411. {
  1412.     DoUpdateAddressBook(pCmdUI, AB_SortDescending, TRUE);
  1413. }
  1414.  
  1415. void CAddrFrame::OnUpdateComposeMsg(CCmdUI* pCmdUI)
  1416. {
  1417.     DoUpdateAddressBook(pCmdUI, AB_NewMessageCmd);
  1418. }
  1419.  
  1420. void CAddrFrame::OnUpdateStopSearch(CCmdUI* pCmdUI)
  1421. {
  1422.     DoUpdateAddressBook(pCmdUI, AB_LDAPSearchCmd);
  1423. }
  1424.  
  1425. void CAddrFrame::OnUpdateAddUser(CCmdUI* pCmdUI)
  1426. {
  1427.     DoUpdateAddressBook(pCmdUI, AB_AddUserCmd);
  1428. }
  1429.  
  1430. void CAddrFrame::OnUpdateAddList(CCmdUI* pCmdUI)
  1431. {
  1432.     DoUpdateAddressBook(pCmdUI, AB_AddMailingListCmd);
  1433. }
  1434.  
  1435. void CAddrFrame::OnUpdateAddAB(CCmdUI* pCmdUI)
  1436. {
  1437.     DoUpdateAddressBook(pCmdUI, AB_NewAddressBook);
  1438. }
  1439.  
  1440. void CAddrFrame::OnUpdateAddDir(CCmdUI* pCmdUI)
  1441. {
  1442.     DoUpdateAddressBook(pCmdUI, AB_NewLDAPDirectory);
  1443. }
  1444.  
  1445. void CAddrFrame::OnUpdateItemProperties(CCmdUI* pCmdUI)
  1446. {
  1447.     DoUpdateAddressBook(pCmdUI, AB_PropertiesCmd);
  1448. }
  1449.  
  1450. void CAddrFrame::OnUpdateCall(CCmdUI* pCmdUI)
  1451. {
  1452.     DoUpdateAddressBook(pCmdUI, AB_CallCmd);
  1453. }
  1454.  
  1455. void CAddrFrame::OnUpdateSwitchSort(CCmdUI* pCmdUI)
  1456. {
  1457.     DoUpdateAddressBook(pCmdUI, AB_AddUserCmd);
  1458. }
  1459.  
  1460. void CAddrFrame::OnUpdateDeleteItem(CCmdUI* pCmdUI)
  1461. {
  1462.     DoUpdateAddressBook(pCmdUI, AB_DeleteCmd);
  1463. }
  1464.  
  1465. void CAddrFrame::OnUpdateUndo(CCmdUI* pCmdUI)
  1466. {
  1467.     DoUpdateAddressBook(pCmdUI, AB_UndoCmd);
  1468. }
  1469.  
  1470. void CAddrFrame::OnUpdateRedo(CCmdUI* pCmdUI)
  1471. {
  1472.     DoUpdateAddressBook(pCmdUI, AB_RedoCmd);
  1473. }
  1474.  
  1475. void CAddrFrame::OnSwitchSortFirstLast()
  1476. {
  1477.     SetCursor ( theApp.LoadStandardCursor ( IDC_WAIT ) );
  1478.  
  1479.     AB_SetSortByFirstName(theApp.m_pABook, !AB_GetSortByFirstName(theApp.m_pABook));
  1480.  
  1481.     SetCursor ( theApp.LoadStandardCursor ( IDC_ARROW ) );
  1482. }
  1483.  
  1484.  
  1485. void CAddrFrame::OnAddUser ( void )
  1486. {    
  1487. #ifdef FEATURE_ADDRPROP
  1488.     CAddrEditProperties* prop;
  1489.     prop = new CAddrEditProperties (this,
  1490.     GetCurrentDirectoryServer(),
  1491.     XP_GetString (MK_ADDR_NEW_CARD), this, 0, NULL, GetContext());
  1492.  
  1493.     prop->SetCurrentPage(0);
  1494.     if (prop->Create(this, WS_SYSMENU | WS_POPUP | WS_CAPTION | WS_VISIBLE,
  1495.         WS_EX_DLGMODALFRAME)) {
  1496.         m_userPropList.Add (prop);    
  1497.     } 
  1498. #endif
  1499. }
  1500.  
  1501. void CAddrFrame::OnAddAB ( void )
  1502. {
  1503.     HandleErrorReturn(AB_Command (m_addrBookPane, AB_NewAddressBook, 0, 0), this);
  1504. }
  1505.  
  1506.  
  1507. void CAddrFrame::OnAddDir ( void )
  1508. {
  1509. #ifdef FEATURE_ADDRPROP
  1510.     CString label;
  1511.     label.LoadString(IDS_ADD_LDAP_SERVER);
  1512.     CAddrLDAPProperties serverProperties(this, GetContext(), NULL, label);
  1513.     if (IDOK == serverProperties.DoModal())
  1514.     {
  1515.         DIR_Server* pServer = &serverProperties.m_serverInfo;
  1516.         DIR_Server *pNewServer = (DIR_Server *) XP_ALLOC(sizeof(DIR_Server));
  1517.         if (pNewServer)
  1518.         {
  1519.             DIR_InitServer(pNewServer);
  1520.             DIR_CopyServer(pServer, &pNewServer);
  1521.             if (pNewServer->dirType == LDAPDirectory) {
  1522.                 DIR_SetServerFileName(pNewServer, pNewServer->serverName);
  1523.             }
  1524.         }
  1525.         XP_ListAddObjectToEnd(theApp.m_directories, pNewServer);
  1526.            DIR_SaveServerPreferences (theApp.m_directories); 
  1527.     }
  1528. #endif
  1529. }
  1530.  
  1531.  
  1532. void CAddrFrame::OnHTMLDomains ( void )
  1533. {
  1534.     MSG_DisplayHTMLDomainsDialog(GetContext());
  1535. }
  1536.  
  1537. void CAddrFrame::OnUpdateHTMLDomains( CCmdUI *pCmdUI )
  1538. {
  1539.     pCmdUI->Enable( TRUE );
  1540. }
  1541.  
  1542. void CAddrFrame::OnCreateCard ( void )
  1543. {
  1544. #ifdef FEATURE_ADDRPROP
  1545.     CAddrEditProperties* prop;
  1546.     char* email = NULL;
  1547.     char* name = NULL;
  1548.     DIR_Server* pab  = NULL;
  1549.     PersonEntry person;
  1550.     person.Initialize();
  1551.     ABID entryID = MSG_MESSAGEIDNONE;
  1552.     INTL_CharSetInfo csi = LO_GetDocumentCharacterSetInfo(GetContext());
  1553.  
  1554.     if (FE_UsersMailAddress())
  1555.         email = XP_STRDUP (FE_UsersMailAddress());
  1556.     if (FE_UsersFullName())
  1557.         name = XP_STRDUP (FE_UsersFullName());
  1558.     person.pGivenName = name;
  1559.     person.pEmailAddress = email;
  1560.     person.WinCSID = INTL_GetCSIWinCSID(csi);
  1561.  
  1562.     DIR_GetPersonalAddressBook (theApp.m_directories, &pab);
  1563.     XP_ASSERT (pab);
  1564.  
  1565.     if (pab) {
  1566.  
  1567.         AB_GetEntryIDForPerson(pab,
  1568.             theApp.m_pABook, &entryID, &person);
  1569.  
  1570.         if (entryID != MSG_MESSAGEIDNONE) {
  1571.             // see it it is already opened 
  1572.             if (m_userPropList.GetSize()) { 
  1573.                 // try to find it
  1574.                 for (int i = 0; i < m_userPropList.GetSize(); i++) {
  1575.                     if (((CAddrEditProperties*)m_userPropList.GetAt(i))->GetEntryID() == entryID) {
  1576.                         ((CAddrEditProperties*)m_userPropList.GetAt(i))->BringWindowToTop();
  1577.                         return;
  1578.                     }
  1579.                 }            
  1580.             }
  1581.  
  1582.             // otherwise open the window
  1583.             CString formattedString;
  1584.             char fullname [kMaxFullNameLength];
  1585.             AB_GetFullName(pab, theApp.m_pABook, entryID, fullname);
  1586.             formattedString.Format(XP_GetString (MK_ADDR_BOOK_CARD), fullname);
  1587.             prop = new CAddrEditProperties(this,
  1588.                 pab, (const char *) formattedString, this, entryID, NULL, GetContext());
  1589.  
  1590.             prop->SetCurrentPage(0);
  1591.             if (prop->Create(this, WS_SYSMENU | WS_POPUP | WS_CAPTION | WS_VISIBLE,
  1592.                 WS_EX_DLGMODALFRAME)) {
  1593.                 m_userPropList.Add (prop);    
  1594.             }
  1595.         }
  1596.         else {
  1597.             CString formattedString;
  1598.             formattedString.Format(XP_GetString (MK_ADDR_BOOK_CARD), name);
  1599.             prop = new CAddrEditProperties (this,
  1600.                 pab, formattedString, this, 0, &person, GetContext());
  1601.             prop->SetCurrentPage(0);
  1602.             if (prop->Create(this, WS_SYSMENU | WS_POPUP | WS_CAPTION | WS_VISIBLE,
  1603.                     WS_EX_DLGMODALFRAME)) {
  1604.                 m_userPropList.Add (prop);    
  1605.             }
  1606.         }
  1607.     }
  1608.     if (email)
  1609.         XP_FREE (email);
  1610.     if (name)
  1611.         XP_FREE (name);
  1612. #endif
  1613. }
  1614.  
  1615.  
  1616. DIR_Server * CAddrFrame::GetCurrentDirectoryServer()
  1617. {
  1618.     return (DIR_Server*)XP_ListGetObjectNum(theApp.m_directories, m_pOutliner->GetDirectoryIndex() + 1);
  1619. }
  1620.  
  1621. void CAddrFrame::OnAddList ( void )
  1622. {
  1623.     CABMLDialog* dialog;
  1624.  
  1625.     dialog = new CABMLDialog (GetCurrentDirectoryServer(),
  1626.         this, 0, GetContext());
  1627.  
  1628.     if (dialog->Create(this)) {
  1629.         m_listPropList.Add (dialog);    
  1630.     }  
  1631. }
  1632.  
  1633.  
  1634. void CAddrFrame::OnDeleteItem()
  1635. {
  1636. #ifdef FEATURE_ADDRPROP
  1637.     MSG_ViewIndex *indices;
  1638.     int count;
  1639.     m_pOutliner->GetSelection(indices, count);
  1640.     for (int i = 0; i < count; i++)
  1641.     {
  1642.         ABID type;
  1643.         ABID entryID;
  1644.         // check the entry type and add/remove pages
  1645.         entryID  = AB_GetEntryIDAt((AddressPane*)m_addrBookPane, indices[i]);
  1646.  
  1647.         AB_GetType(GetCurrentDirectoryServer(), theApp.m_pABook, 
  1648.             entryID, &type);
  1649.         if (m_userPropList.GetSize() && type == ABTypePerson) { 
  1650.             // try to find 
  1651.             for (int i = 0; i < m_userPropList.GetSize(); i++) {
  1652.                 if (((CAddrEditProperties*)m_userPropList.GetAt(i))->GetEntryID() == entryID) {
  1653.                     ((CAddrEditProperties*)m_userPropList.GetAt(i))->DestroyWindow();
  1654.                 }
  1655.             }            
  1656.         }
  1657.  
  1658.         if (m_listPropList.GetSize() && type == ABTypeList) { 
  1659.             for (int i = 0; i < m_listPropList.GetSize(); i++) {
  1660.                 if (((CABMLDialog*)m_listPropList.GetAt(i))->GetEntryID() == entryID) {
  1661.                     ((CABMLDialog*)m_listPropList.GetAt(i))->DestroyWindow();
  1662.                 }
  1663.             }            
  1664.         }
  1665.     }
  1666.  
  1667.     SetCursor ( theApp.LoadStandardCursor ( IDC_WAIT ) );
  1668.  
  1669.     HandleErrorReturn(AB_Command (m_addrBookPane, AB_DeleteCmd, indices, count), this);
  1670.     m_pOutliner->UpdateCount();
  1671.     if ((m_pOutliner->GetFocusLine() > m_pOutliner->GetTotalLines() - 1))
  1672.         m_pOutliner->SelectItem(m_pOutliner->GetTotalLines() - 1);
  1673.     else
  1674.         m_pOutliner->SelectItem(m_pOutliner->GetFocusLine());
  1675.     SetCursor ( theApp.LoadStandardCursor ( IDC_ARROW ) );
  1676. #endif
  1677. }
  1678.  
  1679.  
  1680. void CAddrFrame::OnUndo()
  1681. {
  1682.     SetCursor ( theApp.LoadStandardCursor ( IDC_WAIT ) );
  1683.     HandleErrorReturn(AB_Command (m_addrBookPane, AB_UndoCmd, 0, 0), this);
  1684.     m_pOutliner->UpdateCount();
  1685.     if ((m_pOutliner->GetFocusLine() > m_pOutliner->GetTotalLines() - 1))
  1686.         m_pOutliner->SelectItem(m_pOutliner->GetTotalLines() - 1);
  1687.     else
  1688.         m_pOutliner->SelectItem(m_pOutliner->GetFocusLine());
  1689.     SetCursor ( theApp.LoadStandardCursor ( IDC_ARROW ) );
  1690. }
  1691.  
  1692.  
  1693. void CAddrFrame::OnRedo()
  1694. {
  1695.     SetCursor ( theApp.LoadStandardCursor ( IDC_WAIT ) );
  1696.     HandleErrorReturn(AB_Command (m_addrBookPane, AB_RedoCmd, 0, 0), this);
  1697.     m_pOutliner->UpdateCount();
  1698.     if ((m_pOutliner->GetFocusLine() > m_pOutliner->GetTotalLines() - 1))
  1699.         m_pOutliner->SelectItem(m_pOutliner->GetTotalLines() - 1);
  1700.     else
  1701.         m_pOutliner->SelectItem(m_pOutliner->GetFocusLine());
  1702.     SetCursor ( theApp.LoadStandardCursor ( IDC_ARROW ) );
  1703. }
  1704.  
  1705. void CAddrFrame::OnComposeMsg()
  1706. {
  1707.     MSG_ViewIndex *indices;
  1708.     int count;
  1709.     m_pOutliner->GetSelection(indices, count);
  1710.     HandleErrorReturn(AB_Command (m_addrBookPane, AB_NewMessageCmd, indices, count), this);
  1711. }
  1712.  
  1713.  
  1714. void CAddrFrame::CloseUserProperties (CAddrEditProperties* wnd, ABID entryID) 
  1715. {
  1716. #ifdef FEATURE_ADDRPROP
  1717.     CAddrEditProperties* prop;
  1718.     for (int i = 0; i < m_userPropList.GetSize(); i++) {
  1719.         prop = (CAddrEditProperties*) (m_userPropList.GetAt(i));
  1720.         if (prop->GetEntryID() == entryID && prop == wnd) {
  1721.             m_userPropList.RemoveAt(i);
  1722.             break;
  1723.         }
  1724.     }            
  1725. #endif
  1726. }
  1727.  
  1728.  
  1729. void CAddrFrame::CloseListProperties (CABMLDialog* wnd, ABID entryID) 
  1730. {
  1731.     CABMLDialog* prop;
  1732.     for (int i = 0; i < m_listPropList.GetSize(); i++) {
  1733.         prop = (CABMLDialog*) (m_listPropList.GetAt(i));
  1734.         if (prop->GetEntryID() == entryID && prop == wnd) {
  1735.             m_listPropList.RemoveAt(i);
  1736.             break;
  1737.         }
  1738.     }
  1739. }
  1740.  
  1741.  
  1742. void CAddrFrame::OnItemProperties()
  1743. {
  1744. #ifdef FEATURE_ADDRPROP
  1745.     if (GetCurrentDirectoryServer()->dirType == LDAPDirectory) {
  1746.         MSG_ViewIndex *indices;
  1747.         int count;
  1748.         m_pOutliner->GetSelection(indices, count);
  1749.         HandleErrorReturn(AB_Command (m_addrBookPane, AB_PropertiesCmd, indices, count), this);
  1750.     }
  1751.     else {
  1752.         MSG_ViewIndex *indices;
  1753.         int count;
  1754.         m_pOutliner->GetSelection(indices, count);
  1755.         for (int i = 0; i < count; i++) {
  1756.             ABID type;
  1757.             ABID entryID;
  1758.             // check the entry type and add/remove pages
  1759.             entryID  = AB_GetEntryIDAt((AddressPane*)m_addrBookPane, indices[i]);
  1760.  
  1761.             AB_GetType(GetCurrentDirectoryServer(), theApp.m_pABook, 
  1762.                 entryID, &type);
  1763.             if (m_userPropList.GetSize() && type == ABTypePerson) { 
  1764.                 // try to find 
  1765.                 for (int i = 0; i < m_userPropList.GetSize(); i++) {
  1766.                     if (((CAddrEditProperties*)m_userPropList.GetAt(i))->GetEntryID() == entryID) {
  1767.                         ((CAddrEditProperties*)m_userPropList.GetAt(i))->BringWindowToTop();
  1768.                         return;
  1769.                     }
  1770.                 }            
  1771.             }
  1772.  
  1773.             if (m_listPropList.GetSize() && type == ABTypeList) { 
  1774.                 for (int i = 0; i < m_listPropList.GetSize(); i++) {
  1775.                     if (((CABMLDialog*)m_listPropList.GetAt(i))->GetEntryID() == entryID) {
  1776.                         ((CABMLDialog*)m_listPropList.GetAt(i))->BringWindowToTop();
  1777.                         return;
  1778.                     }
  1779.                 }            
  1780.             }
  1781.  
  1782.             // otherwise open an new property sheet
  1783.             if (type == ABTypePerson) {
  1784.                 CAddrEditProperties* prop = NULL;
  1785.                 CString formattedString;
  1786.                 char fullname [kMaxFullNameLength];
  1787.                 AB_GetFullName(GetCurrentDirectoryServer(), theApp.m_pABook, entryID, fullname);
  1788.                 formattedString.Format(XP_GetString (MK_ADDR_BOOK_CARD), fullname);
  1789.                 prop = new CAddrEditProperties(this,
  1790.                 GetCurrentDirectoryServer(),
  1791.                 (const char *) formattedString, this, entryID, NULL, GetContext());
  1792.  
  1793.                 prop->SetCurrentPage(0);
  1794.                 if (prop->Create(this, WS_SYSMENU | WS_POPUP | WS_CAPTION | WS_VISIBLE,
  1795.                         WS_EX_DLGMODALFRAME)) {
  1796.                     m_userPropList.Add (prop);    
  1797.                 }
  1798.             }
  1799.             else {
  1800.                 CABMLDialog* dialog;
  1801.                 dialog = new CABMLDialog (GetCurrentDirectoryServer(),
  1802.                     this, entryID, GetContext());
  1803.                 if (dialog->Create(this)) {
  1804.                     dialog->ShowWindow(SW_SHOW);
  1805.                     m_listPropList.Add (dialog);    
  1806.                 }  
  1807.             }
  1808.         }
  1809.     }
  1810. #endif
  1811. }
  1812.  
  1813.  
  1814. void CAddrFrame::OnCall()
  1815. {
  1816.     ABID type;
  1817.     ABID entryID;
  1818.     CString ipAddress;
  1819.     CString emailAddress;
  1820.     short useServer = 0;
  1821.  
  1822.     char szCommandLine[_MAX_PATH];
  1823.  
  1824.     // check the entry type and add/remove pages
  1825.     entryID  = AB_GetEntryIDAt((AddressPane*)m_addrBookPane, m_pOutliner->GetFocusLine());
  1826.  
  1827.     AB_GetType(GetCurrentDirectoryServer(), theApp.m_pABook, 
  1828.         entryID, &type);
  1829.  
  1830.     if (type != ABTypePerson) {
  1831.         CString s;
  1832.         if (s.LoadString( IDS_BOOKMARK_ADDRESSPROPERTIES ))
  1833.             MessageBox(XP_GetString (MK_MSG_CANT_CALL_MAILING_LIST), s, MB_OK | MB_APPLMODAL);
  1834.         return;
  1835.     }
  1836.  
  1837.     // check that info exists for this person
  1838.     AB_GetCoolAddress (GetCurrentDirectoryServer(),
  1839.         theApp.m_pABook, entryID, ipAddress.GetBuffer(kMaxCoolAddress));
  1840.     ipAddress.ReleaseBuffer(-1);
  1841.     AB_GetEmailAddress (GetCurrentDirectoryServer(),
  1842.         theApp.m_pABook, entryID, emailAddress.GetBuffer(kMaxEmailAddressLength));
  1843.     emailAddress.ReleaseBuffer(-1);
  1844.     AB_GetUseServer (GetCurrentDirectoryServer(),
  1845.         theApp.m_pABook, entryID, &useServer);
  1846.  
  1847.     if ((useServer == kSpecificDLS || useServer == kHostOrIPAddress) && !ipAddress.GetLength()) {
  1848.         CString s;
  1849.         if (s.LoadString( IDS_BOOKMARK_ADDRESSPROPERTIES ))
  1850.             MessageBox(XP_GetString (MK_MSG_CALL_NEEDS_IPADDRESS), s, MB_OK | MB_APPLMODAL);
  1851.         OnItemProperties();
  1852.         return;
  1853.     }
  1854.  
  1855.     if ((useServer == kSpecificDLS || useServer == kDefaultDLS) && !emailAddress.GetLength()) {
  1856.         CString s;
  1857.         if (s.LoadString( IDS_BOOKMARK_ADDRESSPROPERTIES ))
  1858.             MessageBox(XP_GetString (MK_MSG_CALL_NEEDS_EMAILADDRESS), s, MB_OK | MB_APPLMODAL);
  1859.         OnItemProperties();
  1860.         return;
  1861.     }
  1862.  
  1863.     strcpy (szCommandLine, "");
  1864.  
  1865.         if (useServer == 0) 
  1866.         {
  1867.             CString emailFlag = FEU_GetConfAppProfileString(IDS_CONFAPP_EMAIL);
  1868.  
  1869.             if (!emailFlag.IsEmpty())
  1870.             {
  1871.                 strcat(szCommandLine, emailFlag);
  1872.                 strcat(szCommandLine, " ");
  1873.                 strcat(szCommandLine, emailAddress);
  1874.             }
  1875.         }
  1876.         else {
  1877.             if (useServer == 1) 
  1878.             {
  1879.                 CString emailFlag = FEU_GetConfAppProfileString(IDS_CONFAPP_EMAIL);
  1880.                 if (!emailFlag.IsEmpty())
  1881.                 {
  1882.                     strcat(szCommandLine, emailFlag);
  1883.                     strcat(szCommandLine, " ");
  1884.                     strcat(szCommandLine, emailAddress);
  1885.                     strcat(szCommandLine, " ");
  1886.                 }
  1887.  
  1888.                 CString serverFlag = FEU_GetConfAppProfileString(IDS_CONFAPP_SERVER);
  1889.                 if (!serverFlag.IsEmpty())
  1890.                 {
  1891.                     strcat(szCommandLine, serverFlag);
  1892.                     strcat(szCommandLine, " ");
  1893.                     strcat(szCommandLine, ipAddress);
  1894.                 }
  1895.             }
  1896.             else {
  1897.                 CString directFlag = FEU_GetConfAppProfileString(IDS_CONFAPP_DIRECTIP);
  1898.  
  1899.                 if (!directFlag.IsEmpty())
  1900.                 {
  1901.                     strcat(szCommandLine, directFlag);
  1902.                     strcat(szCommandLine, " ");
  1903.                     strcat(szCommandLine, ipAddress);
  1904.                 }
  1905.             }
  1906.         }
  1907.  
  1908.         // 
  1909.         // Something a bit new...this will be here for passing a users name at the
  1910.         // end of a command line.
  1911.         //
  1912.         CString userNameFlag = FEU_GetConfAppProfileString(IDS_CONFAPP_USERNAME);
  1913.         
  1914.         if (!userNameFlag.IsEmpty())
  1915.         {
  1916.             CString szFullUserName;
  1917.             AB_GetFullName (GetCurrentDirectoryServer(),
  1918.                 theApp.m_pABook, entryID, szFullUserName.GetBuffer(kMaxFullNameLength));
  1919.             strcat(szCommandLine, " ");
  1920.             strcat(szCommandLine, userNameFlag);
  1921.             strcat(szCommandLine, " ");
  1922.             strcat(szCommandLine, szFullUserName);
  1923.         }
  1924.     //
  1925.     //RHP - Launch conference app
  1926.     //
  1927.     LaunchConfEndpoint(szCommandLine, GetSafeHwnd());
  1928.  
  1929. }
  1930.  
  1931.  
  1932. void CAddrFrame::OnSortName()
  1933. {
  1934.     m_pOutlinerParent->ColumnCommand ( ID_COLADDR_NAME );
  1935. }
  1936.  
  1937. void CAddrFrame::OnSortType()
  1938. {
  1939.     m_pOutlinerParent->ColumnCommand ( ID_COLADDR_TYPE );
  1940. }
  1941.  
  1942. void CAddrFrame::OnSortNickName()
  1943. {
  1944.     m_pOutlinerParent->ColumnCommand ( ID_COLADDR_NICKNAME );
  1945. }
  1946.  
  1947. void CAddrFrame::OnSortEmailAddress()
  1948. {
  1949.     m_pOutlinerParent->ColumnCommand ( ID_COLADDR_EMAIL );
  1950. }
  1951.  
  1952. void CAddrFrame::OnSortCompany()
  1953. {
  1954.     m_pOutlinerParent->ColumnCommand ( ID_COLADDR_COMPANY );
  1955. }
  1956.  
  1957. void CAddrFrame::OnSortLocality()
  1958. {
  1959.     m_pOutlinerParent->ColumnCommand ( ID_COLADDR_LOCALITY );
  1960. }
  1961.  
  1962. void CAddrFrame::OnSortAscending()
  1963. {
  1964.     m_pOutlinerParent->ColumnCommand ( m_pOutliner->GetSortBy() );
  1965. }
  1966.  
  1967. void CAddrFrame::OnSortDescending()
  1968. {
  1969.     m_pOutlinerParent->ColumnCommand ( m_pOutliner->GetSortBy() );
  1970. }
  1971.  
  1972. void CAddrFrame::HandleErrorReturn(int XPErrorId, CWnd* parent, int errorid)
  1973. {    
  1974.     if (errorid) {
  1975.         CString s;
  1976.         HWND parentWnd = NULL;
  1977.         if (parent)
  1978.             parentWnd = parent->m_hWnd;
  1979.         if (s.LoadString( IDS_BOOKMARK_ADDRESSPROPERTIES )) {
  1980.             if (XPErrorId)
  1981.             ::MessageBox(parentWnd, XP_GetString(XPErrorId), s, MB_OK | MB_APPLMODAL);
  1982.             else {
  1983.                 CString s2;
  1984.                 s2.LoadString (errorid);
  1985.                 ::MessageBox(parentWnd, s2, s, MB_OK | MB_APPLMODAL);
  1986.             }
  1987.         }
  1988.     }
  1989. }
  1990.  
  1991.  
  1992. void CAddrFrame::OnSave()
  1993. {
  1994. }
  1995.  
  1996.  
  1997. void CAddrFrame::OnChangeDirectory (int dirIndex)
  1998. {
  1999.     m_pDirOutliner->SetDirectoryIndex(dirIndex);
  2000. }
  2001.  
  2002. void CAddrFrame::OnShowWindow( BOOL bShow, UINT nStatus )
  2003. {
  2004.     CFrameWnd::OnShowWindow (bShow, nStatus);
  2005.     if (bShow && (nStatus == 0)) {
  2006.         m_pOutliner->SetDirectoryIndex(0);
  2007.         m_pDirOutliner->SetDirectoryIndex(0);
  2008.     }
  2009. }
  2010.  
  2011.  
  2012. void CAddrFrame::OnUpdateDirectorySelection (int dirIndex)
  2013. {
  2014.     // the user has selected a different directory in the left pane
  2015.     m_barAddr.SetDirectoryIndex(dirIndex);
  2016.     m_pOutliner->SetDirectoryIndex(dirIndex);
  2017.     HandleErrorReturn(AB_ChangeDirectory(m_addrBookPane, GetCurrentDirectoryServer()), this);
  2018. }
  2019.  
  2020.  
  2021. void CAddrFrame::OnStopSearch ()
  2022. {
  2023.     CWnd* widget = m_barAddr.GetDlgItem(IDC_DIRECTORIES);
  2024.     CWnd* widget2 = m_barAddr.GetDlgItem (IDC_DIRSEARCH);
  2025.     // We've turned into stop button
  2026.     HandleErrorReturn(AB_FinishSearch(m_addrBookPane, GetContext()), this);
  2027.     m_bSearching = FALSE;
  2028.     GetChrome()->StopAnimation();
  2029.     widget->EnableWindow(TRUE);
  2030.     widget2->EnableWindow(TRUE);
  2031.     m_pDirOutliner->EnableWindow(TRUE);
  2032.  
  2033.     MSG_ViewIndex *indices = NULL;
  2034.     int count = 0;
  2035.     m_pOutliner->GetSelection(indices, count);
  2036.     if (!count)
  2037.         m_pOutliner->SelectItem (0);
  2038.     return;
  2039. }
  2040.  
  2041. void CAddrFrame::OnExtendedDirectorySearch ()
  2042. {
  2043.     CWnd* widget = m_barAddr.GetDlgItem(IDC_DIRECTORIES);
  2044.     CWnd* widget2 = m_barAddr.GetDlgItem (IDC_DIRSEARCH);
  2045.  
  2046.     if (m_bSearching) {
  2047.         OnStopSearch();
  2048.         return;
  2049.     }
  2050.  
  2051.     CUIntArray buttonLabels;
  2052.     buttonLabels.SetSize (4, 1);
  2053.     buttonLabels [0] = IDS_ADRSEARCH;
  2054.     buttonLabels [1] = IDS_CANCEL_BUTTON;
  2055.     buttonLabels [2] = IDS_HELP_BUTTON;
  2056.     buttonLabels [3] = IDS_ADVSEARCH;
  2057.  
  2058.     CSearchDialog searchDlg ((UINT) IDS_ADRSEARCH, 
  2059.         (MSG_Pane*) m_addrBookPane, 
  2060.         GetCurrentDirectoryServer(),
  2061.         this, 4, BUTTON_RIGHT, &buttonLabels);
  2062.     int result = searchDlg.DoModal(); 
  2063.  
  2064.     // Build Search
  2065.     if (result == IDOK)
  2066.     {
  2067.         GetChrome()->StartAnimation();
  2068.         LPNSSTATUSBAR pIStatusBar = NULL;
  2069.         m_pChrome->QueryInterface( IID_INSStatusBar, (LPVOID *) &pIStatusBar );
  2070.         if ( pIStatusBar ) {
  2071.             pIStatusBar->SetStatusText(szLoadString( IDS_SEARCHING ));
  2072.             pIStatusBar->Release();
  2073.         }
  2074.  
  2075.         m_barAddr.GetDlgItem(IDC_ADDRNAME)->SetWindowText("");
  2076.         m_bSearching = TRUE;
  2077.         widget->EnableWindow(FALSE);
  2078.         widget2->EnableWindow(FALSE);
  2079.         m_pOutliner->SetTotalLines(0);
  2080.         m_pOutliner->SetFocus();
  2081.         m_pOutliner->SetFocusLine(0);
  2082.         m_pDirOutliner->EnableWindow(FALSE);
  2083.  
  2084.         HandleErrorReturn(AB_SearchDirectory(m_addrBookPane, NULL), this);
  2085.     }
  2086.  
  2087. }
  2088.  
  2089. void CAddrFrame::OnDirectoryList (char * name)
  2090. {
  2091.     CWnd* widget;
  2092.     CWnd* widget2;
  2093.     CString cs;
  2094.     widget = m_barAddr.GetDlgItem(IDC_DIRECTORIES);
  2095.     widget2 = m_barAddr.GetDlgItem(IDC_DIRSEARCH);
  2096.  
  2097.     // Build Search
  2098.     GetChrome()->StartAnimation();
  2099.     LPNSSTATUSBAR pIStatusBar = NULL;
  2100.     m_pChrome->QueryInterface( IID_INSStatusBar, (LPVOID *) &pIStatusBar );
  2101.     if ( pIStatusBar ) {
  2102.         pIStatusBar->SetStatusText(szLoadString( IDS_SEARCHING ));
  2103.         pIStatusBar->Release();
  2104.     }
  2105.     m_bSearching = TRUE;
  2106.     widget->EnableWindow(FALSE);
  2107.     widget2->EnableWindow(FALSE);
  2108.     m_pDirOutliner->EnableWindow(FALSE);
  2109.  
  2110.     HandleErrorReturn(AB_SearchDirectory(m_addrBookPane, name), this);
  2111.     m_pOutliner->UpdateCount();
  2112. }
  2113.  
  2114. //////////////////////////////////////////////////////////////////////////////
  2115. // CAddrOutliner
  2116. BEGIN_MESSAGE_MAP(CAddrOutliner, CMSelectOutliner)
  2117.     //{{AFX_MSG_MAP(CAddrOutliner)
  2118.     ON_WM_KEYDOWN()
  2119.     ON_WM_TIMER()
  2120.     ON_WM_KILLFOCUS()
  2121.     //}}AFX_MSG_MAP
  2122. END_MESSAGE_MAP()
  2123.  
  2124. CAddrOutliner::CAddrOutliner ( )
  2125. {
  2126.     int32 prefInt;
  2127.     PREF_GetIntPref("mail.addr_book.sortby",&prefInt);
  2128.     if (prefInt != ID_COLADDR_NAME && prefInt != ID_COLADDR_EMAIL
  2129.         && prefInt != ID_COLADDR_NICKNAME)
  2130.         prefInt = ID_COLADDR_NAME;
  2131.  
  2132.     m_attribSortBy = CASTINT(prefInt);
  2133.     ApiApiPtr(api);
  2134.     m_pUnkUserImage = api->CreateClassInstance(APICLASS_IMAGEMAP);
  2135.     if (m_pUnkUserImage) {
  2136.         m_pUnkUserImage->QueryInterface(IID_IImageMap,(LPVOID*)&m_pIUserImage);
  2137.         ASSERT(m_pIUserImage);
  2138.         m_pIUserImage->Initialize(IDB_ADDRESSBOOK,16,16);
  2139.     }
  2140.     XP_Bool prefBool;
  2141.     PREF_GetBoolPref("mail.addr_book.sort_ascending",&prefBool);
  2142.     m_bSortAscending = prefBool;
  2143.     m_iMysticPlane = 0;
  2144.     m_dirIndex = 0;
  2145.     m_hFont = NULL;
  2146.     m_psTypedown = "";
  2147.     m_uTypedownClock = 0;
  2148. }
  2149.  
  2150. CAddrOutliner::~CAddrOutliner ( )
  2151. {
  2152.     if (m_pUnkUserImage) {
  2153.         if (m_pIUserImage)
  2154.             m_pUnkUserImage->Release();
  2155.     }
  2156.     if (m_hFont) {
  2157.         theApp.ReleaseAppFont(m_hFont);
  2158.     }
  2159.  
  2160. }
  2161.  
  2162. void CAddrOutliner::OnKillFocus( CWnd* pNewWnd )
  2163. {
  2164.     CMSelectOutliner::OnKillFocus (pNewWnd );
  2165.     m_psTypedown = "";    
  2166.     KillTimer(m_uTypedownClock);
  2167. }
  2168.  
  2169. void CAddrOutliner::OnTypedown (char* name)
  2170. {
  2171.     MSG_ViewIndex    index;
  2172.     int    startIndex;
  2173.     
  2174.     if (GetFocusLine() != -1)
  2175.         startIndex = GetFocusLine();
  2176.     else
  2177.         startIndex = 0;
  2178.  
  2179.     AB_GetIndexMatchingTypedown(m_pane, &index, 
  2180.         (LPCTSTR) name, startIndex);
  2181.  
  2182.     ScrollIntoView(CASTINT(index));
  2183.     SelectItem (CASTINT(index));
  2184. }
  2185.  
  2186. HFONT CAddrOutliner::GetLineFont(void *pLineData)
  2187. {
  2188.     if (!m_hFont)
  2189.     {
  2190.         HDC hDC = ::GetDC(m_hWnd);
  2191.         LOGFONT lf;  
  2192.         memset(&lf,0,sizeof(LOGFONT));
  2193.  
  2194.         lf.lfPitchAndFamily = FF_SWISS;
  2195.         lf.lfWeight = FW_NORMAL;
  2196.         lf.lfCharSet = IntlGetLfCharset(CIntlWin::GetSystemLocaleCsid());
  2197.         if (CIntlWin::GetSystemLocaleCsid() == CS_LATIN1)
  2198.              _tcscpy(lf.lfFaceName, "MS Sans Serif");
  2199.         else
  2200.              _tcscpy(lf.lfFaceName, IntlGetUIPropFaceName(CIntlWin::GetSystemLocaleCsid()));
  2201.         lf.lfHeight = -MulDiv(9, ::GetDeviceCaps(hDC, LOGPIXELSY), 72);
  2202.         m_hFont = theApp.CreateAppFont( lf );
  2203.         ::ReleaseDC(m_hWnd,hDC);
  2204.     }
  2205.     return m_hFont;
  2206. }
  2207.  
  2208.  
  2209. DIR_Server* CAddrOutliner::GetCurrentDirectoryServer ()
  2210. {
  2211.     return (DIR_Server*)XP_ListGetObjectNum(theApp.m_directories, m_dirIndex + 1);
  2212. }
  2213.  
  2214.  
  2215. void CAddrOutliner::SetDirectoryIndex (int dirIndex)
  2216. {
  2217.     m_dirIndex = dirIndex;
  2218.     DIR_Server* pServer = GetCurrentDirectoryServer ();
  2219.     int iCount = GetNumColumns();
  2220.     for (int i = 0; i < iCount; i++) {
  2221.         CString cs;
  2222.         int iColumn = GetColumnAtPos(i);
  2223.         if (pServer->dirType == LDAPDirectory)
  2224.         {
  2225.             DIR_AttributeId id;
  2226.             const char *text = NULL;
  2227.             switch (iColumn) {
  2228.             case ID_COLADDR_TYPE:
  2229.                 text = NULL;
  2230.                 break;
  2231.             case ID_COLADDR_NAME:
  2232.                 MSG_SearchAttribToDirAttrib(attribCommonName, &id);        
  2233.                 text = DIR_GetAttributeName(pServer, id);
  2234.                 break;
  2235.             case ID_COLADDR_EMAIL:
  2236.                 MSG_SearchAttribToDirAttrib(attrib822Address, &id);    
  2237.                 text = DIR_GetAttributeName(pServer, id);
  2238.                 break;
  2239.             case ID_COLADDR_COMPANY:
  2240.                 MSG_SearchAttribToDirAttrib(attribOrganization, &id);    
  2241.                 text = DIR_GetAttributeName(pServer, id);
  2242.                 break;
  2243.             case ID_COLADDR_LOCALITY:
  2244.                 MSG_SearchAttribToDirAttrib(attribLocality, &id);                
  2245.                 text = DIR_GetAttributeName(pServer, id);
  2246.                 break;
  2247.             case ID_COLADDR_PHONE:
  2248.                 MSG_SearchAttribToDirAttrib(attribPhoneNumber, &id);                
  2249.                 text = DIR_GetAttributeName(pServer, id);
  2250.                 break;
  2251.             case ID_COLADDR_NICKNAME:
  2252.                 text = NULL;    
  2253.                 break;
  2254.             default:
  2255.                 break;
  2256.             }
  2257.             if (text)
  2258.                 SetColumnName(iColumn, text);
  2259.         }
  2260.         else
  2261.         {
  2262.             switch (iColumn) {
  2263.             case ID_COLADDR_TYPE:
  2264.                 cs = "";
  2265.                 break;
  2266.             case ID_COLADDR_NAME:
  2267.                 cs.LoadString(IDS_USERNAME);        
  2268.                 break;
  2269.             case ID_COLADDR_EMAIL:
  2270.                 cs.LoadString(IDS_EMAILADDRESS);
  2271.                 break;
  2272.             case ID_COLADDR_COMPANY:
  2273.                 cs.LoadString(IDS_COMPANYNAME);    
  2274.                 break;
  2275.             case ID_COLADDR_PHONE:
  2276.                 cs.LoadString(IDS_PHONE);    
  2277.                 break;
  2278.             case ID_COLADDR_LOCALITY:
  2279.                 cs.LoadString(IDS_LOCALITY);                
  2280.                 break;
  2281.             case ID_COLADDR_NICKNAME:
  2282.                 cs.LoadString(IDS_NICKNAME);    
  2283.                 break;
  2284.             default:
  2285.                 break;
  2286.             }
  2287.         if (cs.GetLength())
  2288.             SetColumnName(iColumn, cs);
  2289.         }
  2290.     }
  2291.     GetParent()->Invalidate();
  2292.     GetParent()->UpdateWindow();
  2293.     ClearSelection();
  2294.     SelectItem(dirIndex);
  2295. }
  2296.  
  2297. void CAddrOutliner::UpdateCount( )
  2298. {
  2299.     uint32 count;
  2300.  
  2301.     AB_GetEntryCount(GetCurrentDirectoryServer (), theApp.m_pABook, &count, ABTypeAll, NULL);
  2302.     m_iTotalLines = CASTINT(count);
  2303.     if (!m_iTotalLines)
  2304.         ClearSelection();
  2305. }
  2306.  
  2307.  
  2308. BOOL CAddrOutliner::DeleteItem ( int iLine )
  2309. {
  2310.     XP_Bool bSelectable, bPlural;
  2311.     MSG_ViewIndex indices[1];
  2312.     indices[0] = (MSG_ViewIndex) iLine;
  2313.     MSG_COMMAND_CHECK_STATE sState;
  2314.     AB_CommandStatus( m_pane, 
  2315.                        AB_DeleteCmd,
  2316.                        indices, 1,
  2317.                        &bSelectable, 
  2318.                        &sState, 
  2319.                        NULL,
  2320.                        &bPlural);
  2321.     if (bSelectable) {
  2322.         AB_Command ( m_pane, AB_DeleteCmd, indices, 1 );
  2323.         return TRUE;
  2324.     }
  2325.     else
  2326.         MessageBeep(0);
  2327.     return FALSE;
  2328. }
  2329.  
  2330. void CAddrOutliner::SetPane(ABPane *pane)
  2331. {
  2332.     m_pane = pane;
  2333.     uint32 count;
  2334.  
  2335.     if (m_pane) {
  2336.         AB_GetEntryCount(GetCurrentDirectoryServer (), theApp.m_pABook, &count, ABTypeAll, NULL);
  2337.         SetTotalLines(CASTINT(count));
  2338.         Invalidate();
  2339.         UpdateWindow();
  2340.     }
  2341. }
  2342.  
  2343. void CAddrOutliner::MysticStuffStarting( XP_Bool asynchronous,
  2344.                                             MSG_NOTIFY_CODE notify, 
  2345.                                             MSG_ViewIndex where,
  2346.                                             int32 num )
  2347. {
  2348.     ++m_iMysticPlane;
  2349. }
  2350.  
  2351. void CAddrOutliner::MysticStuffFinishing( XP_Bool asynchronous,
  2352.                                              MSG_NOTIFY_CODE notify, 
  2353.                                              MSG_ViewIndex where,
  2354.                                              int32 num )
  2355. {
  2356.     switch ( notify ) {
  2357.     case MSG_NotifyNone:
  2358.         break;
  2359.  
  2360.     case MSG_NotifyInsertOrDelete:
  2361.         // if its insert or delete then tell my frame to add the next chunk of values
  2362.         // from the search
  2363.         if (notify == MSG_NotifyInsertOrDelete 
  2364.             && ((CAddrFrame*) GetParentFrame())->IsSearching() && num > 0) 
  2365.         {
  2366.             ((CAddrFrame*) GetParentFrame())->SetSearchResults(where, num);
  2367.             HandleInsert(where, num);
  2368.             // Invalidate();
  2369.         }
  2370.         else
  2371.         {
  2372.             if (num > 0)
  2373.                 HandleInsert(where, num);
  2374.             else
  2375.                 HandleDelete(where, -num);
  2376.         }
  2377.         break;
  2378.  
  2379.     case MSG_NotifyChanged:
  2380.         InvalidateLines( (int) where, (int) num );
  2381.         break;
  2382.  
  2383.     case MSG_NotifyAll:
  2384.     case MSG_NotifyScramble:
  2385.         Invalidate();
  2386.         break;
  2387.     }
  2388.  
  2389.     if (( !--m_iMysticPlane && m_pane)) {
  2390.         uint32 count;
  2391.         AB_GetEntryCount(GetCurrentDirectoryServer (), theApp.m_pABook, &count, ABTypeAll, NULL);
  2392.         SetTotalLines(CASTINT(count));
  2393.         Invalidate();
  2394.         UpdateWindow();
  2395.     }
  2396. }
  2397.  
  2398. void CAddrOutliner::PropertyMenu ( int iSel, UINT flags )    
  2399. {
  2400.     BOOL bHasItems = FALSE;
  2401.     CMenu cmPopup;
  2402.     CString cs;
  2403.     
  2404.     if(cmPopup.CreatePopupMenu() == 0) 
  2405.         return;
  2406.  
  2407.     if (iSel < m_iTotalLines) {
  2408.         cs.LoadString(ID_POPUP_MAILNEW);
  2409.         cmPopup.AppendMenu(MF_ENABLED, ID_FILE_NEWMESSAGE, cs);
  2410.         cmPopup.AppendMenu(MF_SEPARATOR);
  2411.         cs.LoadString(IDS_AB_NEW_USER);
  2412.         cmPopup.AppendMenu(MF_ENABLED, ID_ITEM_ADDUSER, cs);
  2413.         cs.LoadString(IDS_AB_NEW_LIST);
  2414.         cmPopup.AppendMenu(MF_ENABLED, ID_ITEM_ADDLIST, cs);
  2415.         cmPopup.AppendMenu(MF_SEPARATOR);
  2416.         cs.LoadString(IDS_COMPOSE_REMOVE);
  2417.         cmPopup.AppendMenu(MF_ENABLED, ID_EDIT_DELETE, cs);
  2418.         cmPopup.AppendMenu(MF_SEPARATOR);
  2419.         cs.LoadString(IDS_AB_PROPERTIES);
  2420.         cmPopup.AppendMenu(MF_ENABLED, ID_ITEM_PROPERTIES, cs);
  2421.         bHasItems = TRUE;
  2422.     }
  2423.  
  2424.  
  2425.     //    Track the popup now.
  2426.     POINT pt = m_ptHit;
  2427.     ClientToScreen(&pt);
  2428.  
  2429.     cmPopup.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, 
  2430.                            GetParentFrame(), NULL);
  2431.  
  2432.     //  Cleanup
  2433.     cmPopup.DestroyMenu();
  2434. }
  2435.  
  2436. void CAddrOutliner::AcceptDrop( int iLineNo, COleDataObject *pDataObject,
  2437.                                 DROPEFFECT dropEffect )
  2438. {
  2439.     if(!pDataObject)
  2440.         return;
  2441.  
  2442.     // Dont allow us to drop on ourselves
  2443.     if(pDataObject->IsDataAvailable(m_cfSourceTarget))
  2444.        return;
  2445.  
  2446.     if(!pDataObject->IsDataAvailable(m_cfAddresses) &&
  2447.        !pDataObject->IsDataAvailable(CF_TEXT))
  2448.        return;
  2449.  
  2450.         if(pDataObject->IsDataAvailable(m_cfAddresses)) {
  2451.             HGLOBAL hAddresses = pDataObject->GetGlobalData(m_cfAddresses);
  2452.             LPSTR pAddresses = (LPSTR)GlobalLock(hAddresses);
  2453.             ASSERT(pAddresses);
  2454.             // Parse the vcards and add them to the address book
  2455.             AB_ImportFromVcard((AddressPane*) m_pane, pAddresses);
  2456.             GlobalUnlock(hAddresses);
  2457.         }
  2458.         else {
  2459.             HGLOBAL hString = pDataObject->GetGlobalData(CF_TEXT);
  2460.             char * pAddress = (char*)GlobalLock(hString);
  2461.             ASSERT(pAddress);
  2462.             // parse the vcard from the text
  2463.             AB_ImportFromVcard((AddressPane*) m_pane, pAddress);
  2464.             GlobalUnlock(hString);
  2465.         }
  2466. }
  2467.  
  2468. void CAddrOutliner::InitializeClipFormats(void)
  2469. {
  2470.      m_cfAddresses = (CLIPFORMAT)RegisterClipboardFormat(vCardClipboardFormat);
  2471.      m_cfSourceTarget = (CLIPFORMAT)RegisterClipboardFormat(ADDRESSBOOK_SOURCETARGET_FORMAT);
  2472. }
  2473.  
  2474. CLIPFORMAT * CAddrOutliner::GetClipFormatList(void)
  2475. {
  2476.     static CLIPFORMAT cfFormatList[3];
  2477.     cfFormatList[0] = m_cfAddresses;
  2478.     cfFormatList[1] = m_cfSourceTarget;
  2479.     cfFormatList[2] = 0;
  2480.     return cfFormatList;
  2481. }
  2482.  
  2483.  
  2484. COleDataSource * CAddrOutliner::GetDataSource(void)
  2485. {
  2486.     COleDataSource * pDataSource = new COleDataSource;
  2487.     ABID    entryID;
  2488.     char* pVcard = NULL;
  2489.     char* pVcards = XP_STRDUP("");
  2490.     char  szTemp[10];
  2491.     char  szEntryID[20];
  2492.     char* pEntryIDs = XP_STRDUP("");
  2493.     HANDLE hString = 0;
  2494.     MSG_ViewIndex *indices;
  2495.     int count;
  2496.  
  2497.     GetSelection(indices, count);
  2498.  
  2499.     for (int i = 0 ; i < count; i++) {
  2500.         if ((entryID = AB_GetEntryIDAt((AddressPane*) m_pane, indices[i])) != 0) {
  2501.             AB_ExportToVCard(theApp.m_pABook, 
  2502.                 GetCurrentDirectoryServer (), entryID, &pVcard);
  2503.             pVcards = StrAllocCat(pVcards, pVcard);
  2504.             XP_FREE(pVcard);
  2505.             pVcard = NULL;
  2506.  
  2507.             ltoa(entryID, szTemp, 10);
  2508.             sprintf(szEntryID, "%s-", szTemp);
  2509.             pEntryIDs = StrAllocCat(pEntryIDs, szEntryID);
  2510.         }
  2511.     }
  2512.  
  2513.     if (pVcards) {
  2514.         hString = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE|GMEM_ZEROINIT,strlen(pVcards)+1);
  2515.         LPSTR lpszString = (LPSTR)GlobalLock(hString);
  2516.         strcpy(lpszString,pVcards);
  2517.         XP_FREE (pVcards);
  2518.         GlobalUnlock(hString);
  2519.  
  2520.         HANDLE hEntryID = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE|GMEM_ZEROINIT,strlen(pEntryIDs)+1);
  2521.         LPSTR lpszEntryID = (LPSTR)GlobalLock(hEntryID);
  2522.         strcpy(lpszEntryID,pEntryIDs);
  2523.         XP_FREE (pEntryIDs);
  2524.         GlobalUnlock(hEntryID);
  2525.         pDataSource->CacheGlobalData(m_cfAddresses, hString);
  2526.         pDataSource->CacheGlobalData(m_cfSourceTarget, hEntryID);
  2527.         pDataSource->CacheGlobalData(CF_TEXT, hString);
  2528.     }
  2529.  
  2530.     return pDataSource;
  2531. }
  2532.  
  2533.  
  2534. BOOL CAddrOutliner::RenderData  ( UINT iColumn, CRect &rect, CDC &dc, const char * text )
  2535. {
  2536.     if ( iColumn != ID_COLADDR_TYPE )
  2537.         return CMSelectOutliner::RenderData ( iColumn, rect, dc, text );
  2538.     int idxImage;
  2539.  
  2540.     if (m_EntryLine.entryType == ABTypeList)
  2541.         idxImage = IDX_ADDRESSBOOKLIST;
  2542.     else
  2543.         idxImage = IDX_ADDRESSBOOKPERSON;
  2544.  
  2545.     m_pIUserImage->DrawImage ( idxImage,
  2546.         rect.left + ( ( rect.Width ( ) - 16 ) / 2 ), rect.top, &dc, FALSE );
  2547.     return TRUE;
  2548. }
  2549.  
  2550.  
  2551. int CAddrOutliner::TranslateIcon ( void * pLineData )
  2552. {
  2553.     AB_EntryLine* line = (AB_EntryLine*) pLineData;
  2554.     int idxImage = 0;
  2555.  
  2556.     if (line->entryType == ABTypeList)
  2557.         idxImage = IDX_ADDRESSBOOKLIST;
  2558.     else
  2559.         idxImage = IDX_ADDRESSBOOKPERSON;
  2560.     return idxImage;
  2561. }
  2562.  
  2563. int CAddrOutliner::TranslateIconFolder (void * pData)
  2564. {
  2565.     // We're a flat list, so we're never a folder
  2566.     return ( OUTLINER_ITEM );
  2567. }
  2568.  
  2569.  
  2570. BOOL CAddrOutliner::ColumnCommand ( int iColumn, int iLine )
  2571. {
  2572.     // We have no column commands
  2573.     return FALSE;
  2574. }
  2575.  
  2576. void * CAddrOutliner::AcquireLineData ( int line )
  2577. {
  2578.     m_lineindex = line + 1;
  2579.     if ( line >= m_iTotalLines)
  2580.         return NULL;
  2581.     if (!AB_GetEntryLine(m_pane, line, &m_EntryLine ))
  2582.         return NULL;
  2583.  
  2584.     return &m_EntryLine;
  2585. }
  2586.  
  2587. void CAddrOutliner::GetTreeInfo ( int iLine, uint32 * pFlags, int * pDepth, OutlinerAncestorInfo ** pAncestor )
  2588. {
  2589.     if ( pFlags ) *pFlags = 0; // Flags? 
  2590.     if ( pDepth ) *pDepth = 0; // We're flat, remember?
  2591. }
  2592.  
  2593. void CAddrOutliner::ReleaseLineData ( void * )
  2594. {
  2595. }
  2596.  
  2597. LPCTSTR CAddrOutliner::GetColumnText ( UINT iColumn, void * pLineData )
  2598. {
  2599.     AB_EntryLine* line = (AB_EntryLine*) pLineData;
  2600.  
  2601.     switch (iColumn) {
  2602.         case ID_COLADDR_NAME:
  2603.             return line->fullname;
  2604.             break;
  2605.         case ID_COLADDR_EMAIL:
  2606.             return line->emailAddress;
  2607.             break;
  2608.         case ID_COLADDR_COMPANY:
  2609.             return line->companyName;
  2610.             break;
  2611.         case ID_COLADDR_PHONE:
  2612.             if (line->entryType == ABTypePerson)
  2613.                 return line->workPhone;
  2614.             break;
  2615.         case ID_COLADDR_LOCALITY:
  2616.             return line->locality;
  2617.             break;
  2618.         case ID_COLADDR_NICKNAME:
  2619.             return line->nickname;
  2620.             break;
  2621.         default:
  2622.             break;
  2623.     }
  2624.     return ("");
  2625. }
  2626.  
  2627. void CAddrOutliner::OnSelChanged()
  2628. {
  2629.     // No Op
  2630. }
  2631.  
  2632. void CAddrOutliner::OnSelDblClk()
  2633. {
  2634.     GetParentFrame()->SendMessage(WM_COMMAND, ID_ITEM_PROPERTIES, 0);
  2635. }
  2636.  
  2637.  
  2638. void CAddrOutliner::OnTimer(UINT nID)
  2639. {
  2640.     CMSelectOutliner::OnTimer(nID);
  2641.     if (nID == OUTLINER_TYPEDOWN_TIMER) {
  2642.         KillTimer(m_uTypedownClock);
  2643.         m_psTypedown = "";
  2644.     }
  2645. }
  2646.  
  2647. void CAddrOutliner::OnKeyDown ( UINT nChar, UINT nRepCnt, UINT nFlags )
  2648. {
  2649.     CMSelectOutliner::OnKeyDown ( nChar, nRepCnt, nFlags );
  2650.     KillTimer(m_uTypedownClock);
  2651.     if (nChar > VK_HELP) {
  2652.         KillTimer(m_uTypedownClock);
  2653.         m_psTypedown += nChar;
  2654.         OnTypedown (m_psTypedown.GetBuffer (0));
  2655.         m_psTypedown.ReleaseBuffer(-1);
  2656.         int32 prefInt = OUTLINER_TYPEDOWN_SPEED;
  2657.         PREF_GetIntPref("ldap_1.autoComplete.interval", &prefInt);
  2658.         m_uTypedownClock = SetTimer(OUTLINER_TYPEDOWN_TIMER, prefInt, NULL);
  2659.     }
  2660. }
  2661.  
  2662. /////////////////////////////////////////////////////////////////////////////
  2663. // CAddrOutlinerParent
  2664.  
  2665. BEGIN_MESSAGE_MAP(CAddrOutlinerParent, COutlinerParent)
  2666.     //{{AFX_MSG_MAP(CAddrOutlinerParent)
  2667.     ON_WM_DESTROY()
  2668.     ON_WM_LBUTTONUP()
  2669.     //}}AFX_MSG_MAP
  2670. END_MESSAGE_MAP()
  2671.  
  2672. CAddrOutlinerParent::CAddrOutlinerParent()
  2673. {
  2674.  
  2675. }
  2676.  
  2677.  
  2678. CAddrOutlinerParent::~CAddrOutlinerParent()
  2679. {
  2680.  
  2681. }
  2682.  
  2683.  
  2684. BOOL CAddrOutlinerParent::RenderData ( int idColumn, CRect & rect, CDC &dc, const char * text )
  2685. {
  2686.     int cx = 3, cy = 0;
  2687.     CAddrOutliner *pOutliner = (CAddrOutliner *) m_pOutliner;
  2688.     
  2689.     // Calculate text offset from top using font height.
  2690.     TEXTMETRIC tm;
  2691.     dc.GetTextMetrics ( &tm );
  2692.     cy = ( rect.bottom - rect.top - tm.tmHeight ) / 2;
  2693.         
  2694.     // Draw Text String
  2695.     dc.TextOut (rect.left + cx, rect.top + cy, text, _tcslen(text) );
  2696.     
  2697.     // Draw Sort Indicator
  2698.     MSG_COMMAND_CHECK_STATE sortType = pOutliner->m_attribSortBy == idColumn ? MSG_Checked : MSG_Unchecked;
  2699.  
  2700.     int idxImage = pOutliner->m_bSortAscending ? IDX_SORTINDICATORDOWN : IDX_SORTINDICATORUP;
  2701.     CSize cs = dc.GetTextExtent(text, _tcslen(text));
  2702.  
  2703.     if (idColumn == pOutliner->m_attribSortBy && cs.cx + 22 <= rect.Width()) {
  2704.         m_pIImage->DrawTransImage( idxImage,
  2705.                                    rect.left + 8 + cs.cx,
  2706.                                    (rect.top + rect.bottom) / 2 - 4,
  2707.                                    &dc );
  2708.     }
  2709.  
  2710.     return TRUE;
  2711. }
  2712.  
  2713. COutliner * CAddrOutlinerParent::GetOutliner ( void )
  2714. {
  2715.     return new CAddrOutliner;
  2716. }
  2717.  
  2718. void CAddrOutlinerParent::CreateColumns ( void )
  2719. {
  2720.     int iCol0 = 0,
  2721.         iCol1 = 0,
  2722.         iCol2 = 0,
  2723.         iCol3 = 0,
  2724.         iCol4 = 0,
  2725.         iCol5 = 0;
  2726.     CString cs; 
  2727.  
  2728.     m_pOutliner->AddColumn ("",            ID_COLADDR_TYPE,        24, 0, ColumnFixed, 0, TRUE );
  2729.     cs.LoadString(IDS_USERNAME);
  2730.     m_pOutliner->AddColumn (cs,            ID_COLADDR_NAME,        1500, 0, ColumnVariable, iCol0 ? iCol0 : 1500 );
  2731.     cs.LoadString(IDS_EMAILADDRESS);
  2732.     m_pOutliner->AddColumn (cs,            ID_COLADDR_EMAIL,        1500, 0, ColumnVariable, iCol2 ? iCol2 : 1500 ); 
  2733.     cs.LoadString(IDS_COMPANYNAME);
  2734.     m_pOutliner->AddColumn (cs,            ID_COLADDR_COMPANY,        1500, 0, ColumnVariable, iCol5 ? iCol5 : 1500 ); 
  2735.     cs.LoadString(IDS_PHONE);
  2736.     m_pOutliner->AddColumn (cs,            ID_COLADDR_PHONE,        1500, 0, ColumnVariable, iCol4 ? iCol4 : 1500, FALSE);
  2737.     cs.LoadString(IDS_LOCALITY);
  2738.     m_pOutliner->AddColumn (cs,            ID_COLADDR_LOCALITY,    1500, 0, ColumnVariable, iCol4 ? iCol4 : 1500 );
  2739.     cs.LoadString(IDS_NICKNAME);
  2740.     m_pOutliner->AddColumn (cs,            ID_COLADDR_NICKNAME,    1500, 0, ColumnVariable, iCol3 ? iCol3 : 1500 );
  2741.     m_pOutliner->SetHasPipes( FALSE );
  2742.  
  2743.     m_pOutliner->SetVisibleColumns(DEF_VISIBLE_COLUMNS);
  2744.     m_pOutliner->LoadXPPrefs("mailnews.abook_columns_win");
  2745. }
  2746.  
  2747. void CAddrOutlinerParent::OnDestroy()
  2748. {
  2749.     int32 prefInt = ((CAddrOutliner*)m_pOutliner)->GetSortBy();
  2750.     if (prefInt != ID_COLADDR_NAME && prefInt != ID_COLADDR_EMAIL
  2751.         && prefInt != ID_COLADDR_NICKNAME)
  2752.         prefInt = ID_COLADDR_NAME;
  2753.  
  2754.     PREF_SetIntPref("mail.addr_book.sortby", prefInt);
  2755.     PREF_SetBoolPref("mail.addr_book.sort_ascending",((CAddrOutliner*)m_pOutliner)->GetSortAscending());
  2756.     
  2757.     COutlinerParent::OnDestroy();
  2758. }
  2759.  
  2760. void CAddrOutlinerParent::OnLButtonUp( UINT nFlags, CPoint point )
  2761. {
  2762.     BOOL bSaveColumns = (m_pOutliner && 
  2763.         (m_bResizeColumn || m_bDraggingHeader || m_iPusherHit))? TRUE : FALSE;
  2764.     COutlinerParent::OnLButtonUp(nFlags, point);
  2765.     if (bSaveColumns)
  2766.         m_pOutliner->SaveXPPrefs("mailnews.abook_columns_win");
  2767. }
  2768.  
  2769. BOOL CAddrOutlinerParent::ColumnCommand ( int idColumn )
  2770. {    
  2771.     ABID lastSelection;
  2772.  
  2773.     CAddrOutliner *pOutliner = (CAddrOutliner *) m_pOutliner;
  2774.     
  2775.     if (pOutliner->GetFocusLine() != -1)
  2776.         lastSelection = AB_GetEntryIDAt((AddressPane*) pOutliner->GetPane(), pOutliner->GetFocusLine());
  2777.  
  2778.     SetCursor ( theApp.LoadStandardCursor ( IDC_WAIT ) );
  2779.  
  2780.     if (idColumn == pOutliner->m_attribSortBy) {
  2781.         pOutliner->m_bSortAscending = !pOutliner->m_bSortAscending; 
  2782.     }
  2783.     else
  2784.         pOutliner->m_bSortAscending = TRUE;
  2785.  
  2786.     pOutliner->m_attribSortBy = idColumn;
  2787.  
  2788.     switch (idColumn) {
  2789.         case ID_COLADDR_TYPE:
  2790.             AB_Command(pOutliner->GetPane(), AB_SortByTypeCmd, 0, 0);
  2791.             break;
  2792.         case ID_COLADDR_NAME:
  2793.             AB_Command(pOutliner->GetPane(), AB_SortByFullNameCmd, 0, 0);
  2794.             break;
  2795.         case ID_COLADDR_NICKNAME:
  2796.             AB_Command(pOutliner->GetPane(), AB_SortByNickname, 0, 0);
  2797.             break;
  2798.         case ID_COLADDR_LOCALITY:
  2799.             AB_Command(pOutliner->GetPane(), AB_SortByLocality, 0, 0);
  2800.             break;
  2801.         case ID_COLADDR_COMPANY:
  2802.             AB_Command(pOutliner->GetPane(), AB_SortByCompanyName, 0, 0);
  2803.             break;
  2804.         case ID_COLADDR_EMAIL:
  2805.             AB_Command(pOutliner->GetPane(), AB_SortByEmailAddress, 0, 0);
  2806.             break;
  2807.         default:
  2808.             AB_Command(pOutliner->GetPane(), AB_SortByFullNameCmd, 0, 0);
  2809.             break;
  2810.     }
  2811.     
  2812.  
  2813.     if (pOutliner->GetFocusLine() != -1) {
  2814.         uint32 index = AB_GetIndexOfEntryID ((AddressPane *) pOutliner->GetPane(), lastSelection);
  2815.         pOutliner->SelectItem (CASTINT(index));
  2816.         pOutliner->ScrollIntoView(CASTINT(index));
  2817.     }
  2818.  
  2819.     Invalidate();
  2820.     pOutliner->Invalidate();
  2821.     SetCursor ( theApp.LoadStandardCursor ( IDC_ARROW ) );
  2822.     return TRUE;
  2823. }
  2824.  
  2825.  
  2826.  
  2827.  
  2828. //////////////////////////////////////////////////////////////////////////////
  2829. // CAddrOutliner
  2830. BEGIN_MESSAGE_MAP(CDirOutliner, CMSelectOutliner)
  2831.     //{{AFX_MSG_MAP(CDirOutliner)
  2832.     //}}AFX_MSG_MAP
  2833. END_MESSAGE_MAP()
  2834.  
  2835. CDirOutliner::CDirOutliner ( )
  2836. {
  2837.     m_attribSortBy = 0;
  2838.     ApiApiPtr(api);
  2839.     m_pUnkUserImage = api->CreateClassInstance(APICLASS_IMAGEMAP);
  2840.     if (m_pUnkUserImage) {
  2841.         m_pUnkUserImage->QueryInterface(IID_IImageMap,(LPVOID*)&m_pIUserImage);
  2842.         ASSERT(m_pIUserImage);
  2843.         m_pIUserImage->Initialize(IDB_DIRLIST,16,16);
  2844.     }
  2845.     
  2846.     m_attribSortBy = 1;
  2847.     m_bSortAscending = TRUE;
  2848.     m_iMysticPlane = 0;
  2849.     m_dirIndex = 0;
  2850.     m_hFont = NULL;
  2851.     m_pDirLine = NULL;
  2852. }
  2853.  
  2854. CDirOutliner::~CDirOutliner ( )
  2855. {
  2856.     if (m_pUnkUserImage) {
  2857.         if (m_pIUserImage)
  2858.             m_pUnkUserImage->Release();
  2859.     }
  2860.     if (m_hFont) {
  2861.         theApp.ReleaseAppFont(m_hFont);
  2862.     }
  2863.  
  2864. }
  2865.  
  2866.  
  2867. HFONT CDirOutliner::GetLineFont(void *pLineData)
  2868. {
  2869.     if (!m_hFont)
  2870.     {
  2871.         HDC hDC = ::GetDC(m_hWnd);
  2872.         LOGFONT lf;  
  2873.         memset(&lf,0,sizeof(LOGFONT));
  2874.  
  2875.         lf.lfPitchAndFamily = FF_SWISS;
  2876.         lf.lfWeight = FW_NORMAL;
  2877.         lf.lfCharSet = IntlGetLfCharset(CIntlWin::GetSystemLocaleCsid());
  2878.         if (CIntlWin::GetSystemLocaleCsid() == CS_LATIN1)
  2879.              _tcscpy(lf.lfFaceName, "MS Sans Serif");
  2880.         else
  2881.              _tcscpy(lf.lfFaceName, IntlGetUIPropFaceName(CIntlWin::GetSystemLocaleCsid()));
  2882.         lf.lfHeight = -MulDiv(9, ::GetDeviceCaps(hDC, LOGPIXELSY), 72);
  2883.         m_hFont = theApp.CreateAppFont( lf );
  2884.         ::ReleaseDC(m_hWnd,hDC);
  2885.     }
  2886.     return m_hFont;
  2887. }
  2888.  
  2889. void CDirOutliner::SetDirectoryIndex (int dirIndex)
  2890. {
  2891.     m_dirIndex = dirIndex;
  2892.     SelectItem (CASTINT(m_dirIndex));
  2893. }
  2894.  
  2895. void CDirOutliner::UpdateCount( )
  2896. {
  2897.     m_iTotalLines = XP_ListCount (theApp.m_directories);
  2898.     if (!m_iTotalLines)
  2899.         ClearSelection();
  2900.     Invalidate();
  2901.     UpdateWindow();
  2902. }
  2903.  
  2904.  
  2905. BOOL CDirOutliner::DeleteItem ( int iLine )
  2906. {
  2907.     MSG_ViewIndex indices[1];
  2908.     indices[0] = (MSG_ViewIndex) iLine;
  2909.     MessageBeep(0);
  2910.     return TRUE;
  2911. }
  2912.  
  2913. void CDirOutliner::SetPane(ABPane *pane)
  2914. {
  2915.     m_pane = pane;
  2916.  
  2917.     if (m_pane) {
  2918.         SetTotalLines(XP_ListCount (theApp.m_directories));
  2919.         Invalidate();
  2920.         UpdateWindow();
  2921.     }
  2922. }
  2923.  
  2924. void CDirOutliner::MysticStuffStarting( XP_Bool asynchronous,
  2925.                                             MSG_NOTIFY_CODE notify, 
  2926.                                             MSG_ViewIndex where,
  2927.                                             int32 num )
  2928. {
  2929.     ++m_iMysticPlane;
  2930. }
  2931.  
  2932. void CDirOutliner::MysticStuffFinishing( XP_Bool asynchronous,
  2933.                                              MSG_NOTIFY_CODE notify, 
  2934.                                              MSG_ViewIndex where,
  2935.                                              int32 num )
  2936. {
  2937.     switch ( notify ) {
  2938.     case MSG_NotifyNone:
  2939.         break;
  2940.  
  2941.     case MSG_NotifyInsertOrDelete:
  2942.         if (num > 0)
  2943.             HandleInsert(where, num);
  2944.         else
  2945.             HandleDelete(where, -num);
  2946.         break;
  2947.  
  2948.     case MSG_NotifyChanged:
  2949.         InvalidateLines( (int) where, (int) num );
  2950.         break;
  2951.  
  2952.     case MSG_NotifyAll:
  2953.     case MSG_NotifyScramble:
  2954.         Invalidate();
  2955.         break;
  2956.     }
  2957.  
  2958.     if (( !--m_iMysticPlane && m_pane)) {
  2959.         SetTotalLines(XP_ListCount (theApp.m_directories));
  2960.         Invalidate();
  2961.         UpdateWindow();
  2962.     }
  2963. }
  2964.  
  2965. void CDirOutliner::PropertyMenu ( int iSel, UINT flags )    
  2966. {
  2967.     BOOL bHasItems = FALSE;
  2968.     CMenu cmPopup;
  2969.     CString cs;
  2970.     
  2971.     if(cmPopup.CreatePopupMenu() == 0) 
  2972.         return;
  2973.  
  2974.     if (iSel < m_iTotalLines) {
  2975.         cs.LoadString(IDS_AB_NEW_USER);
  2976.         cmPopup.AppendMenu(MF_ENABLED, ID_ITEM_ADDUSER, cs);
  2977.         cs.LoadString(IDS_AB_NEW_LIST);
  2978.         cmPopup.AppendMenu(MF_ENABLED, ID_ITEM_ADDLIST, cs);
  2979.         cmPopup.AppendMenu(MF_SEPARATOR);
  2980.         cs.LoadString(IDS_COMPOSE_REMOVE);
  2981.         cmPopup.AppendMenu(MF_ENABLED, ID_EDIT_DELETE, cs);
  2982.         cmPopup.AppendMenu(MF_SEPARATOR);
  2983.         cs.LoadString(IDS_AB_PROPERTIES);
  2984.         cmPopup.AppendMenu(MF_ENABLED, ID_ITEM_PROPERTIES, cs);
  2985.         bHasItems = TRUE;
  2986.     }
  2987.  
  2988.  
  2989.     //    Track the popup now.
  2990.     POINT pt = m_ptHit;
  2991.     ClientToScreen(&pt);
  2992.  
  2993.     cmPopup.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, pt.x, pt.y, 
  2994.                            GetParentFrame(), NULL);
  2995.  
  2996.     //  Cleanup
  2997.     cmPopup.DestroyMenu();
  2998. }
  2999.  
  3000. void CDirOutliner::AcceptDrop( int iLineNo, COleDataObject *pDataObject,
  3001.                                 DROPEFFECT dropEffect )
  3002. {
  3003.     if(!pDataObject)
  3004.         return;
  3005.  
  3006.     // Dont allow us to drop on ourselves
  3007.     if(pDataObject->IsDataAvailable(m_cfSourceTarget))
  3008.        return;
  3009.  
  3010.     if(!pDataObject->IsDataAvailable(m_cfAddresses) &&
  3011.        !pDataObject->IsDataAvailable(CF_TEXT))
  3012.        return;
  3013.  
  3014.         if(pDataObject->IsDataAvailable(m_cfAddresses)) {
  3015.             HGLOBAL hAddresses = pDataObject->GetGlobalData(m_cfAddresses);
  3016.             LPSTR pAddresses = (LPSTR)GlobalLock(hAddresses);
  3017.             ASSERT(pAddresses);
  3018.             // Parse the vcards and add them to the address book
  3019.             // AB_ImportFromVcard((AddressPane*) m_pane, pAddresses);
  3020.             GlobalUnlock(hAddresses);
  3021.         }
  3022.         else {
  3023.             HGLOBAL hString = pDataObject->GetGlobalData(CF_TEXT);
  3024.             char * pAddress = (char*)GlobalLock(hString);
  3025.             ASSERT(pAddress);
  3026.             // parse the vcard from the text
  3027.             // AB_ImportFromVcard((AddressPane*) m_pane, pAddress);
  3028.             GlobalUnlock(hString);
  3029.         }
  3030. }
  3031.  
  3032. void CDirOutliner::InitializeClipFormats(void)
  3033. {
  3034.      m_cfAddresses = (CLIPFORMAT)RegisterClipboardFormat(vCardClipboardFormat);
  3035.      m_cfSourceTarget = (CLIPFORMAT)RegisterClipboardFormat(ADDRESSBOOK_SOURCETARGET_FORMAT);
  3036. }
  3037.  
  3038. CLIPFORMAT * CDirOutliner::GetClipFormatList(void)
  3039. {
  3040.     static CLIPFORMAT cfFormatList[3];
  3041.     cfFormatList[0] = m_cfAddresses;
  3042.     cfFormatList[1] = m_cfSourceTarget;
  3043.     cfFormatList[2] = 0;
  3044.     return cfFormatList;
  3045. }
  3046.  
  3047.  
  3048. COleDataSource * CDirOutliner::GetDataSource(void)
  3049. {
  3050.     COleDataSource * pDataSource = new COleDataSource;
  3051.     MSG_ViewIndex *indices;
  3052.     int count;
  3053.  
  3054.     /*
  3055.     ABID    entryID;
  3056.     char* pVcard = NULL;
  3057.     char* pVcards = XP_STRDUP("");
  3058.     char  szTemp[10];
  3059.     char  szEntryID[20];
  3060.     char* pEntryIDs = XP_STRDUP("");
  3061.     HANDLE hString = 0;
  3062.     */
  3063.  
  3064.     GetSelection(indices, count);
  3065.  
  3066.     /* for (int i = 0 ; i < count; i++) {
  3067.         if ((entryID = AB_GetEntryIDAt((AddressPane*) m_pane, indices[i])) != 0) {
  3068.             AB_ExportToVCard(theApp.m_pABook, 
  3069.                 (DIR_Server*)XP_ListGetObjectNum(theApp.m_directories, m_dirIndex + 1), entryID, &pVcard);
  3070.             pVcards = StrAllocCat(pVcards, pVcard);
  3071.             XP_FREE(pVcard);
  3072.             pVcard = NULL;
  3073.  
  3074.             ltoa(entryID, szTemp, 10);
  3075.             sprintf(szEntryID, "%s-", szTemp);
  3076.             pEntryIDs = StrAllocCat(pEntryIDs, szEntryID);
  3077.         }
  3078.     }
  3079.  
  3080.     if (pVcards) {
  3081.         hString = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE|GMEM_ZEROINIT,strlen(pVcards)+1);
  3082.         LPSTR lpszString = (LPSTR)GlobalLock(hString);
  3083.         strcpy(lpszString,pVcards);
  3084.         XP_FREE (pVcards);
  3085.         GlobalUnlock(hString);
  3086.  
  3087.         HANDLE hEntryID = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE|GMEM_ZEROINIT,strlen(pEntryIDs)+1);
  3088.         LPSTR lpszEntryID = (LPSTR)GlobalLock(hEntryID);
  3089.         strcpy(lpszEntryID,pEntryIDs);
  3090.         XP_FREE (pEntryIDs);
  3091.         GlobalUnlock(hEntryID);
  3092.         pDataSource->CacheGlobalData(m_cfAddresses, hString);
  3093.         pDataSource->CacheGlobalData(m_cfSourceTarget, hEntryID);
  3094.         pDataSource->CacheGlobalData(CF_TEXT, hString);
  3095.     } */
  3096.  
  3097.     return pDataSource;
  3098. }
  3099.  
  3100.  
  3101. BOOL CDirOutliner::RenderData  ( UINT iColumn, CRect &rect, CDC &dc, const char * text )
  3102. {
  3103.     if ( iColumn != ID_COLDIR_TYPE )
  3104.         return CMSelectOutliner::RenderData ( iColumn, rect, dc, text );
  3105.     int idxImage;
  3106.  
  3107.     if (m_pDirLine->dirType == LDAPDirectory)
  3108.         idxImage = IDX_DIRLDAPAB;
  3109.     else
  3110.         idxImage = IDX_DIRPERSONALAB;
  3111.  
  3112.     m_pIUserImage->DrawImage ( idxImage,
  3113.         rect.left + ( ( rect.Width ( ) - 16 ) / 2 ), rect.top, &dc, FALSE );
  3114.     return TRUE;
  3115. }
  3116.  
  3117.  
  3118. int CDirOutliner::TranslateIcon ( void * pLineData )
  3119. {
  3120.     DIR_Server* line = (DIR_Server*) pLineData;
  3121.     int idxImage = 0;
  3122.  
  3123.     if (m_pDirLine->dirType == ABTypeList)
  3124.         idxImage = IDX_DIRLDAPAB;
  3125.     else
  3126.         idxImage = IDX_DIRPERSONALAB;
  3127.     return idxImage;
  3128. }
  3129.  
  3130. int CDirOutliner::TranslateIconFolder (void * pData)
  3131. {
  3132.     // We're a flat list, so we're never a folder
  3133.     return ( OUTLINER_ITEM );
  3134. }
  3135.  
  3136.  
  3137. BOOL CDirOutliner::ColumnCommand ( int iColumn, int iLine )
  3138. {
  3139.     // We have no column commands
  3140.     return FALSE;
  3141. }
  3142.  
  3143. void * CDirOutliner::AcquireLineData ( int line )
  3144. {
  3145.     m_lineindex = line + 1;
  3146.     if ( line >= m_iTotalLines)
  3147.         return NULL;
  3148.     m_pDirLine = (DIR_Server*) XP_ListGetObjectNum(theApp.m_directories, line + 1);
  3149.  
  3150.     return m_pDirLine;
  3151. }
  3152.  
  3153. void CDirOutliner::GetTreeInfo ( int iLine, uint32 * pFlags, int * pDepth, OutlinerAncestorInfo ** pAncestor )
  3154. {
  3155.     if ( pFlags ) *pFlags = 0; // Flags? 
  3156.     if ( pDepth ) *pDepth = 0; // We're flat, remember?
  3157. }
  3158.  
  3159. void CDirOutliner::ReleaseLineData ( void * )
  3160. {
  3161. }
  3162.  
  3163. LPCTSTR CDirOutliner::GetColumnText ( UINT iColumn, void * pLineData )
  3164. {
  3165.     DIR_Server* line = (DIR_Server*) pLineData;
  3166.  
  3167.     switch (iColumn) {
  3168.         case ID_COLDIR_NAME:
  3169.             return line->description;
  3170.             break;
  3171.         default:
  3172.             break;
  3173.     }
  3174.     return ("");
  3175. }
  3176.  
  3177. void CDirOutliner::OnSelChanged()
  3178. {
  3179.     MSG_ViewIndex *indices;
  3180.     int count;
  3181.  
  3182.     CAddrFrame* frame = (CAddrFrame*) GetParentFrame();
  3183.     if (frame->IsSearching()) 
  3184.         return;
  3185.  
  3186.     GetSelection(indices, count);
  3187.  
  3188.     if (count == 1) {
  3189.         frame->OnUpdateDirectorySelection(indices[0]);
  3190.     }
  3191. }
  3192.  
  3193. void CDirOutliner::OnSelDblClk()
  3194. {
  3195.     GetParentFrame()->SendMessage(WM_COMMAND, ID_ITEM_PROPERTIES, 0);
  3196. }
  3197.  
  3198.  
  3199. /////////////////////////////////////////////////////////////////////////////
  3200. // CAddrOutlinerParent
  3201.  
  3202. BEGIN_MESSAGE_MAP(CDirOutlinerParent, COutlinerParent)
  3203.     //{{AFX_MSG_MAP(CDirOutlinerParent)
  3204.     ON_WM_DESTROY()
  3205.     ON_WM_LBUTTONUP()
  3206.     //}}AFX_MSG_MAP
  3207. END_MESSAGE_MAP()
  3208.  
  3209. CDirOutlinerParent::CDirOutlinerParent()
  3210. {
  3211.  
  3212. }
  3213.  
  3214.  
  3215. CDirOutlinerParent::~CDirOutlinerParent()
  3216. {
  3217.  
  3218. }
  3219.  
  3220.  
  3221. BOOL CDirOutlinerParent::RenderData ( int idColumn, CRect & rect, CDC &dc, const char * text )
  3222. {
  3223.     int cx = 3, cy = 0;
  3224.     CDirOutliner *pOutliner = (CDirOutliner *) m_pOutliner;
  3225.     
  3226.     // Calculate text offset from top using font height.
  3227.     TEXTMETRIC tm;
  3228.     dc.GetTextMetrics ( &tm );
  3229.     cy = ( rect.bottom - rect.top - tm.tmHeight ) / 2;
  3230.         
  3231.     // Draw Text String
  3232.     dc.TextOut (rect.left + cx, rect.top + cy, text, _tcslen(text) );
  3233.     
  3234.     // Draw Sort Indicator
  3235.     MSG_COMMAND_CHECK_STATE sortType = pOutliner->m_attribSortBy == idColumn ? MSG_Checked : MSG_Unchecked;
  3236.  
  3237.     int idxImage = pOutliner->m_bSortAscending ? IDX_SORTINDICATORDOWN : IDX_SORTINDICATORUP;
  3238.     CSize cs = dc.GetTextExtent(text, _tcslen(text));
  3239.  
  3240.     if (idColumn == pOutliner->m_attribSortBy && cs.cx + 22 <= rect.Width()) {
  3241.         m_pIImage->DrawTransImage( idxImage,
  3242.                                    rect.left + 8 + cs.cx,
  3243.                                    (rect.top + rect.bottom) / 2 - 4,
  3244.                                    &dc );
  3245.     }
  3246.  
  3247.     return TRUE;
  3248. }
  3249.  
  3250. COutliner * CDirOutlinerParent::GetOutliner ( void )
  3251. {
  3252.     return new CDirOutliner;
  3253. }
  3254.  
  3255. void CDirOutlinerParent::CreateColumns ( void )
  3256. {
  3257.     int iCol0 = 0,
  3258.         iCol1 = 0;
  3259.     CString cs; 
  3260.  
  3261.     m_pOutliner->AddColumn ("",            ID_COLDIR_TYPE,        24, 0, ColumnFixed, 0, TRUE );
  3262.     cs.LoadString(IDS_USERNAME);
  3263.     m_pOutliner->AddColumn (cs,            ID_COLDIR_NAME,        1500, 0, ColumnVariable, iCol0 ? iCol0 : 1500 );
  3264.     m_pOutliner->SetHasPipes( FALSE );
  3265.  
  3266.     m_pOutliner->SetVisibleColumns(DEF_DIRVISIBLE_COLUMNS);
  3267.     m_pOutliner->LoadXPPrefs("mailnews.abook_dir_columns_win");
  3268. }
  3269.  
  3270. void CDirOutlinerParent::OnDestroy()
  3271. {
  3272.     int32 prefInt = ((CDirOutliner*)m_pOutliner)->GetSortBy();
  3273.     
  3274.     COutlinerParent::OnDestroy();
  3275. }
  3276.  
  3277. void CDirOutlinerParent::OnLButtonUp( UINT nFlags, CPoint point )
  3278. {
  3279.     BOOL bSaveColumns = (m_pOutliner && 
  3280.         (m_bResizeColumn || m_bDraggingHeader || m_iPusherHit))? TRUE : FALSE;
  3281.     COutlinerParent::OnLButtonUp(nFlags, point);
  3282.     if (bSaveColumns)
  3283.         m_pOutliner->SaveXPPrefs("mailnews.abook_dir_columns_win");
  3284. }
  3285.  
  3286. BOOL CDirOutlinerParent::ColumnCommand ( int idColumn )
  3287. {    
  3288.     ABID lastSelection;
  3289.  
  3290.     // no sorting for right now
  3291.     return TRUE;
  3292.  
  3293.     CDirOutliner *pOutliner = (CDirOutliner *) m_pOutliner;
  3294.     
  3295.     if (pOutliner->GetFocusLine() != -1)
  3296.         lastSelection = AB_GetEntryIDAt((AddressPane*) pOutliner->GetPane(), pOutliner->GetFocusLine());
  3297.  
  3298.     SetCursor ( theApp.LoadStandardCursor ( IDC_WAIT ) );
  3299.  
  3300.     if (idColumn == pOutliner->m_attribSortBy) {
  3301.         pOutliner->m_bSortAscending = !pOutliner->m_bSortAscending; 
  3302.     }
  3303.     else
  3304.         pOutliner->m_bSortAscending = TRUE;
  3305.  
  3306.     pOutliner->m_attribSortBy = idColumn;
  3307.  
  3308.     switch (idColumn) {
  3309.         case ID_COLDIR_TYPE:
  3310.             AB_Command(pOutliner->GetPane(), AB_SortByTypeCmd, 0, 0);
  3311.             break;
  3312.         case ID_COLDIR_NAME:
  3313.             AB_Command(pOutliner->GetPane(), AB_SortByFullNameCmd, 0, 0);
  3314.             break;
  3315.         default:
  3316.             AB_Command(pOutliner->GetPane(), AB_SortByFullNameCmd, 0, 0);
  3317.             break;
  3318.     }
  3319.     
  3320.  
  3321.     if (pOutliner->GetFocusLine() != -1) {
  3322.         uint32 index = AB_GetIndexOfEntryID ((AddressPane *) pOutliner->GetPane(), lastSelection);
  3323.         pOutliner->SelectItem (CASTINT(index));
  3324.         pOutliner->ScrollIntoView(CASTINT(index));
  3325.     }
  3326.  
  3327.     Invalidate();
  3328.     pOutliner->Invalidate();
  3329.     SetCursor ( theApp.LoadStandardCursor ( IDC_ARROW ) );
  3330.     return TRUE;
  3331. }
  3332.  
  3333.  
  3334. void WFE_MSGOpenAB()
  3335. {
  3336.     CAddrFrame::Open();
  3337. }
  3338.  
  3339.  
  3340. void CAddrFrame::UpdateMenu(HMENU hMenu, UINT &nID)
  3341. {
  3342.     // *** If you change the way this menu is built, you also need to
  3343.     // change CAddrFrame::FolderInfoFromMenuID
  3344.  
  3345.     MSG_Master *pMaster = WFE_MSGGetMaster();
  3346.     int i, j;
  3347.     MSG_FolderInfo **folderInfos;
  3348.     int32 iCount;
  3349.     MSG_FolderLine folderLine;
  3350.     char buffer[_MAX_PATH];
  3351.  
  3352.     j = 0;
  3353.  
  3354.     iCount = MSG_GetFolderChildren( pMaster, NULL, NULL, NULL );
  3355.  
  3356.     folderInfos = new MSG_FolderInfo*[iCount];
  3357.     if (folderInfos) {
  3358.         MSG_GetFolderChildren( pMaster, NULL, folderInfos, iCount );
  3359.  
  3360.         for ( i = 0; i < iCount; i++) {
  3361.             if ( MSG_GetFolderLineById( pMaster, folderInfos[ i ], &folderLine ) ) {
  3362.                 if (j < 10) {
  3363.                     sprintf( buffer, "&%d %s", j, folderLine.name);
  3364.                 } else if ( j < 36 ) {
  3365.                     sprintf( buffer, "&%c %s", 'a' + j - 10, folderLine.name);
  3366.                 } else {
  3367.                     sprintf( buffer, "  %s", folderLine.name);
  3368.                 }
  3369.                 ::AppendMenu( hMenu, MF_STRING, nID, buffer);
  3370.                 nID++;
  3371.                 j++;
  3372.             }
  3373.         }
  3374.         delete [] folderInfos;
  3375.     }
  3376. }
  3377.  
  3378. void WFE_MSGBuildAddressBookPopup( HMENU hmenu, BOOL bAddSender )
  3379. {
  3380.     UINT nID;
  3381.     if (bAddSender)
  3382.         nID = FIRST_ADDSENDER_MENU_ID;
  3383.     else
  3384.         nID = FIRST_ADDALL_MENU_ID;
  3385.     HMENU hABAddMenu = CreatePopupMenu();
  3386.     HMENU hAddMenu = CreatePopupMenu();
  3387.  
  3388.     // ::AppendMenu( hmenu, MF_POPUP|MF_STRING, (UINT) hFileMenu, szLoadString( IDS_POPUP_FILE ) );
  3389.     ::AppendMenu( hAddMenu, MF_STRING, ID_MESSAGE_ADDSENDER, szLoadString( IDS_POPUP_ADDSENDER ) );
  3390.     ::AppendMenu( hAddMenu, MF_STRING, ID_MESSAGE_ADDALL, szLoadString( IDS_POPUP_ADDALL ) );
  3391.     ::AppendMenu( hmenu, MF_STRING|MF_POPUP, (UINT) hAddMenu, szLoadString( IDS_POPUP_ADDTOADDRESSBOOK ) );
  3392.     ::AppendMenu( hmenu, MF_SEPARATOR, 0, NULL );
  3393.     CAddrFrame::UpdateMenu( hABAddMenu, nID );
  3394. }
  3395.