home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / dlghtmrp.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  10.2 KB  |  436 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. // dlghtmrp.cpp : implementation file
  20. //
  21.  
  22. #include "stdafx.h"
  23. #include "msgcom.h"
  24. #include "dlghtmrp.h"
  25. #include "nethelp.h"
  26. #include "xp_help.h"
  27.  
  28. #ifdef _DEBUG
  29. #define new DEBUG_NEW
  30. #undef THIS_FILE
  31. static char THIS_FILE[] = __FILE__;
  32. #endif
  33.  
  34.  
  35. /////////////////////////////////////////////////////////////////////////////////////
  36. ///CListBoxRecipients list box for Prefers HTML and Does not Prefer HTML
  37.  
  38. CListBoxRecipients::CListBoxRecipients(): CListBox()
  39. {
  40. }
  41.  
  42. int CListBoxRecipients::CompareItem(LPCOMPAREITEMSTRUCT lpCompareItemStruct)
  43. {
  44.     int value1 = ((MSG_RecipientList*)(lpCompareItemStruct->itemData1))->value;
  45.     int value2 = ((MSG_RecipientList*)(lpCompareItemStruct->itemData2))->value;
  46.  
  47.     if (value1 < value2)
  48.     {
  49.         return -1; //sorts before
  50.     }
  51.     else if (value1 == value2)
  52.         {    
  53.             return  0; //sorts same
  54.         }    
  55.     else 
  56.     {
  57.         return 1;   //sorts after
  58.     }
  59. }
  60.  
  61. void CListBoxRecipients::DeleteItem( LPDELETEITEMSTRUCT lpDeleteItemStruct)
  62. {
  63.     //not implemented
  64. }
  65.  
  66. void CListBoxRecipients::SetColumnPositions(int iPosIndex, int iPosName, int iPosStatus)
  67. {
  68.     m_iPosIndex = iPosIndex;
  69.     m_iPosName = iPosName;
  70.     m_iPosStatus = iPosStatus;
  71. }
  72.  
  73.  
  74. void CListBoxRecipients::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct )
  75. {
  76.     HDC hDC = lpDrawItemStruct->hDC;
  77.     RECT rcItem = lpDrawItemStruct->rcItem;
  78.     MSG_RecipientList *itemData = (MSG_RecipientList *) lpDrawItemStruct->itemData;
  79.     HBRUSH hBrushFill = NULL;
  80.     COLORREF oldBk, oldText;
  81.  
  82.     if ( lpDrawItemStruct->itemState & ODS_SELECTED ) {
  83.         hBrushFill = ::CreateSolidBrush( GetSysColor( COLOR_HIGHLIGHT ) );
  84.         oldBk = ::SetBkColor( hDC, GetSysColor( COLOR_HIGHLIGHT ) );
  85.         oldText = ::SetTextColor( hDC, GetSysColor( COLOR_HIGHLIGHTTEXT ) );
  86.     } else {
  87.         hBrushFill = ::CreateSolidBrush( GetSysColor( COLOR_WINDOW ) );
  88.         oldBk = ::SetBkColor( hDC, GetSysColor( COLOR_WINDOW ) );
  89.         oldText = ::SetTextColor( hDC, GetSysColor( COLOR_WINDOWTEXT ) );
  90.     }
  91.  
  92.     if ( lpDrawItemStruct->itemID != -1 && itemData) {
  93.         RECT rcTemp = rcItem;
  94.         ::FillRect( hDC, &rcItem, hBrushFill );
  95.  
  96.         ::DrawText( hDC, itemData->name, -1, 
  97.                     &rcTemp, DT_VCENTER|DT_LEFT );
  98.     }
  99.  
  100.     if ( lpDrawItemStruct->itemAction & ODA_FOCUS ) {
  101.         ::DrawFocusRect( hDC, &lpDrawItemStruct->rcItem );
  102.     }
  103.  
  104.     if (hBrushFill)
  105.         VERIFY( ::DeleteObject( hBrushFill ) );
  106.  
  107.     ::SetBkColor( hDC, oldBk );
  108.     ::SetTextColor( hDC, oldText ); 
  109. }
  110.  
  111. /////////////////////////////////////////////////////////////////////////////
  112. // CHtmlRecipientsDlg dialog
  113.  
  114. CHtmlRecipientsDlg::CHtmlRecipientsDlg(MSG_Pane* pComposePane, 
  115.                                           MSG_RecipientList* nohtml,
  116.                                        MSG_RecipientList* htmlok,
  117.                                        CWnd* pParent /*=NULL*/)
  118.     : CDialog(CHtmlRecipientsDlg::IDD, pParent)
  119. {
  120.     //{{AFX_DATA_INIT(CHtmlRecipientsDlg)
  121.         // NOTE: the ClassWizard will add member initialization here
  122.     //}}AFX_DATA_INIT
  123.     m_pComposePane = pComposePane;
  124.     m_pNoHtml = nohtml;
  125.     m_pHtmlOk = htmlok;
  126. }
  127.  
  128.  
  129. void CHtmlRecipientsDlg::DoDataExchange(CDataExchange* pDX)
  130. {
  131.     CDialog::DoDataExchange(pDX);
  132.     //{{AFX_DATA_MAP(CHtmlRecipientsDlg)
  133.         // NOTE: the ClassWizard will add DDX and DDV calls here
  134.     //}}AFX_DATA_MAP
  135. }
  136.  
  137.  
  138. BEGIN_MESSAGE_MAP(CHtmlRecipientsDlg, CDialog)
  139.     //{{AFX_MSG_MAP(CHtmlRecipientsDlg)
  140.     ON_BN_CLICKED(IDC_HELP_RECIPIENTS, OnHelp)
  141.     ON_BN_CLICKED(ID_BTN_ADD, OnBtnAdd)
  142.     ON_BN_CLICKED(ID_BTN_REMOVE, OnBtnRemove)
  143.     ON_LBN_SETFOCUS(IDC_LIST1, OnSetfocusList1)
  144.     ON_LBN_SETFOCUS(IDC_LIST2, OnSetfocusList2)
  145.     //}}AFX_MSG_MAP
  146. END_MESSAGE_MAP()
  147.  
  148. /////////////////////////////////////////////////////////////////////////////
  149. // CHtmlRecipientsDlg message handlers
  150.  
  151. void CHtmlRecipientsDlg::OnSetfocusList1() 
  152. {
  153.     // TODO: Add your control notification handler code here
  154.     CWnd *pWnd = GetDlgItem(ID_BTN_ADD);
  155.     if (pWnd)
  156.         pWnd->EnableWindow(TRUE);
  157.     pWnd = GetDlgItem(ID_BTN_REMOVE);
  158.     if (pWnd)
  159.         pWnd->EnableWindow(FALSE);
  160.     
  161. }
  162.  
  163.  
  164.  
  165. void CHtmlRecipientsDlg::OnSetfocusList2() 
  166. {
  167.     CWnd *pWnd = GetDlgItem(ID_BTN_REMOVE);
  168.     if (pWnd)
  169.         pWnd->EnableWindow(TRUE);
  170.     pWnd = GetDlgItem(ID_BTN_ADD);
  171.     if (pWnd)
  172.         pWnd->EnableWindow(FALSE);
  173.     
  174. }
  175.  
  176.  
  177. void CHtmlRecipientsDlg::OnCancel() 
  178. {
  179.     MSG_ResultsRecipients(m_pComposePane,
  180.                          TRUE,
  181.                          0, /* List of IDs, terminated
  182.                                           with a negative entry. */
  183.                          0/* Another list of IDs. */
  184.                          );
  185.     CDialog::OnCancel();
  186. }
  187.  
  188.  
  189. void CHtmlRecipientsDlg::OnOK() 
  190. {
  191.     BOOL bFailure = FALSE;
  192.  
  193.     int nCount1 = m_ListBox1.GetCount();
  194.     int nCount2 = m_ListBox2.GetCount();
  195.  
  196.     int32 *pNoHTML = new int32[nCount1 +1];
  197.     int32 *pHtmlOK = new int32[nCount2 +1];
  198.     
  199.     MSG_RecipientList *itemData = NULL;
  200.  
  201.     if (!pNoHTML || !pHtmlOK)
  202.         bFailure = TRUE;
  203.     else
  204.     {
  205.         //get the first list
  206.         for ( int i = 0; i < nCount1; i++)
  207.         {
  208.             itemData = (MSG_RecipientList *)m_ListBox1.GetItemData(i);
  209.             if (itemData)
  210.                 pNoHTML[i] = itemData->value;
  211.             else
  212.             {
  213.                 bFailure = TRUE;
  214.                 break;
  215.             }
  216.         }
  217.         //terminate the array
  218.         if (!bFailure)
  219.             pNoHTML[nCount1] = -1;
  220.  
  221.         
  222.         //get the second list
  223.         for ( i = 0; i < nCount2; i++)
  224.         {
  225.             itemData = (MSG_RecipientList *)m_ListBox2.GetItemData(i);
  226.             if (itemData)
  227.                 pHtmlOK[i] = itemData->value;
  228.             else
  229.             {
  230.                 bFailure = TRUE;
  231.                 break;
  232.             }
  233.         }
  234.         //terminate the second array
  235.         if (!bFailure)
  236.             pHtmlOK[nCount2] = -1;
  237.  
  238.     }
  239.  
  240.  
  241.  
  242.     if (!bFailure)
  243.     {    //send back the lists
  244.         MSG_ResultsRecipients(m_pComposePane,
  245.                          FALSE,
  246.                          pNoHTML, /* List of IDs, terminated
  247.                                       with a negative entry. */
  248.                          pHtmlOK/* Another list of IDs. */
  249.                          );
  250.         CDialog::OnOK();
  251.     }
  252.     else
  253.     {
  254.         MSG_ResultsRecipients(m_pComposePane,
  255.                          TRUE,
  256.                          0, /* List of IDs, terminated
  257.                                       with a negative entry. */
  258.                          0/* Another list of IDs. */
  259.                          );
  260.         CDialog::OnOK();
  261.         //Failed to modify recipients list!
  262.     }
  263.     //clean up the lists
  264.     if (pNoHTML && pHtmlOK)
  265.     {
  266.         delete [] pNoHTML;
  267.         delete [] pHtmlOK;
  268.     }
  269. }
  270.  
  271. void CHtmlRecipientsDlg::OnHelp() 
  272. {
  273.     NetHelp(HELP_HTML_MAIL_QUESTION_RECIPIENT);    
  274. }
  275.  
  276. void CHtmlRecipientsDlg::OnBtnAdd() 
  277. {
  278.     CWnd *pWnd = GetDlgItem(ID_BTN_ADD);
  279.     CWnd *pListWnd2 = GetDlgItem(IDC_LIST2);
  280.  
  281.     if (pWnd)
  282.     {
  283.         if (pWnd->IsWindowEnabled())
  284.         {
  285.             int nCount = m_ListBox1.GetSelCount();
  286.             if (nCount <= 0 || nCount == LB_ERR) 
  287.                 return;
  288.             
  289.             LPINT lpIndexes = new int[nCount];
  290.             
  291.             int err = m_ListBox1.GetSelItems(nCount,lpIndexes);
  292.             
  293.             if (err == LB_ERR)
  294.             {
  295.                 if (lpIndexes)
  296.                     delete  [] lpIndexes;
  297.                 return;
  298.             }
  299.             if (lpIndexes && pListWnd2)
  300.             {
  301.                 MSG_RecipientList* itemData = NULL;
  302.                 for (int i = 0; i < nCount; i++)
  303.                 {
  304.                     itemData = (MSG_RecipientList*)m_ListBox1.GetItemData(lpIndexes[i]);
  305.                     if (itemData)
  306.                     {
  307.                         ::SendMessage( pListWnd2->m_hWnd, LB_ADDSTRING, (WPARAM) 0, (LPARAM) itemData);
  308.                     }
  309.                 }
  310.  
  311.                 for ( i = nCount -1 ; i >= 0; i--)
  312.                 {
  313.                     ::SendMessage(m_ListBox1.m_hWnd, LB_DELETESTRING, lpIndexes[i], (LPARAM) NULL);
  314.                 }
  315.  
  316.                 delete  [] lpIndexes;
  317.             }
  318.         }
  319.     }
  320. }
  321.  
  322. void CHtmlRecipientsDlg::OnBtnRemove() 
  323. {
  324.     CWnd *pWnd = GetDlgItem(ID_BTN_REMOVE);
  325.     CWnd *pListWnd1 = GetDlgItem(IDC_LIST1);
  326.  
  327.     if (pWnd)
  328.     {
  329.         if (pWnd->IsWindowEnabled())
  330.         {
  331.             int nCount = m_ListBox2.GetSelCount();
  332.             if (nCount <= 0 || nCount == LB_ERR) 
  333.                 return;
  334.             
  335.             LPINT lpIndexes = new int[nCount];
  336.             
  337.             int err = m_ListBox2.GetSelItems(nCount,lpIndexes);
  338.             
  339.             if (err == LB_ERR)
  340.             {
  341.                 if (lpIndexes)
  342.                     delete [] lpIndexes;
  343.                 return;
  344.             }
  345.             if (lpIndexes && pListWnd1)
  346.             {
  347.                 MSG_RecipientList* itemData = NULL;
  348.                 for (int i = 0; i < nCount; i++)
  349.                 {
  350.                     itemData = (MSG_RecipientList*)m_ListBox2.GetItemData(lpIndexes[i]);
  351.                     if (itemData)
  352.                     {
  353.                         ::SendMessage( pListWnd1->m_hWnd, LB_ADDSTRING, (WPARAM) 0, (LPARAM) itemData);
  354.                     }
  355.  
  356.                 }
  357.  
  358.                 for ( i = nCount -1 ; i >= 0; i--)
  359.                 {
  360.                     ::SendMessage(m_ListBox2.m_hWnd, LB_DELETESTRING, lpIndexes[i], (LPARAM) NULL);
  361.  
  362.                 }
  363.  
  364.                 delete [] lpIndexes;
  365.             }
  366.         }
  367.     }
  368.     
  369. }
  370.  
  371. BOOL CHtmlRecipientsDlg::OnInitDialog() 
  372. {
  373.     BOOL ret = CDialog::OnInitDialog();
  374.     
  375.     m_ListBox1.SubclassDlgItem( IDC_LIST1, this );
  376.     m_ListBox2.SubclassDlgItem( IDC_LIST2, this);
  377.  
  378.     RECT rcText;
  379.     int iPosName;
  380.  
  381.     ::SetRect( &rcText, 0, 0, 64, 64 );
  382.  
  383.     iPosName = rcText.right;;
  384.  
  385.     m_ListBox1.SetColumnPositions( 0, iPosName, 0 );
  386.     m_ListBox2.SetColumnPositions( 0, iPosName, 0 );
  387.     
  388.     PopulateLists();
  389.     return TRUE;  
  390. }
  391.  
  392. BOOL CHtmlRecipientsDlg::PopulateLists()
  393. {
  394.  
  395.     CWnd *pList1 = (CListBox *)GetDlgItem(IDC_LIST1);
  396.     CWnd *pList2 = (CListBox *)GetDlgItem(IDC_LIST2);
  397.  
  398.     if (!pList1 || !pList2)
  399.         return 0;
  400.  
  401.     int i = 0; //array index into recipient list
  402.     int err;
  403.     for (; m_pNoHtml[i].name != NULL; i++)
  404.     {
  405.         if (m_pNoHtml[i].value == -1 || m_pNoHtml[i].name == NULL)
  406.             break;
  407.  
  408.         err = ::SendMessage( pList1->m_hWnd, LB_ADDSTRING, (WPARAM) 0, (LPARAM) &(m_pNoHtml[i]));
  409.     }
  410.  
  411.     //i is reset in the for loop
  412.     for (i = 0;    m_pHtmlOk[i].name != NULL; i++)
  413.     {
  414.         if (m_pHtmlOk[i].value == -1 || m_pHtmlOk[i].name == NULL)
  415.             break;
  416.         err = ::SendMessage( pList2->m_hWnd, LB_ADDSTRING, (WPARAM) 0, (LPARAM) &(m_pHtmlOk[i]));
  417.     }
  418.     return TRUE;
  419.  
  420. }
  421.  
  422.  
  423. //Used to launch the dialog when passed in as a callback
  424. int CreateRecipientsDialog(MSG_Pane* composepane, void* closure,
  425.                                   MSG_RecipientList* nohtml,
  426.                                   MSG_RecipientList* htmlok,
  427.                                   void *pWnd)
  428. {
  429.     CHtmlRecipientsDlg rRecipientsDlg(composepane, nohtml, htmlok, (CWnd*)pWnd);
  430.  
  431.     int ret = rRecipientsDlg.DoModal();
  432.  
  433.     return ret;
  434. }
  435.  
  436.