home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / ABMListDlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  11.0 KB  |  420 lines

  1. /* -*- Mode: C++; tab-width: 8; 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.    ABMListDlg.cpp -- class definition for ABMListDlg
  20.    Created: Chris Toshok <toshok@netscape.com>, 7-Aug-96.
  21.    Revised: Tao Cheng <tao@netscape.com>, 19-nov-96
  22.  */
  23.  
  24. #include "AddrBookView.h"
  25. #include "ABMListDlg.h"
  26. #include "ABMListView.h"
  27. #include "MNView.h"
  28.  
  29. #include <Xm/Form.h>
  30. #include <Xm/Frame.h>
  31. #include <Xm/TextF.h> 
  32. #include <Xm/LabelG.h> 
  33. #include "felocale.h"
  34.  
  35. #include "xpgetstr.h"
  36. extern "C" {
  37. #include "xfe.h"
  38. };
  39.  
  40. extern int XFE_AB_MLIST_TITLE;
  41. extern int XFE_AB_MLIST_LISTNAME;
  42. extern int XFE_AB_MLIST_NICKNAME;
  43. extern int XFE_AB_MLIST_DESCRIPTION;
  44. extern int XFE_AB_MLIST_PROMPT;
  45. extern int XFE_AB_REMOVE;
  46.  
  47. #define MAX_LISTNAME_LEN 31
  48.  
  49. XFE_ABMListDlg::XFE_ABMListDlg(XFE_View *view, /* the parent view */
  50.                    Widget    parent,
  51.                    char     *name,
  52.                    Boolean   modal,
  53.                    MWContext *context):
  54.   XFE_ViewDialog((XFE_View *) 0, parent, name,
  55.          context,
  56.          True, /* ok */
  57.          True, /* cancel */
  58.          True, /* help */
  59.          True, /* apply ; remove */
  60.          False, /* separator */
  61.          modal),
  62.   m_mListPane(NULL)
  63.   
  64. {
  65.   m_abView = (XFE_AddrBookView *) view;
  66.   m_AddrBook = m_abView->getAddrBook();
  67.   m_dir = m_abView->getDir();
  68.   m_mailListEntry.Initialize();
  69.   createUI();
  70. }
  71.  
  72. #if defined(USE_ABCOM)
  73. XFE_ABMListDlg::XFE_ABMListDlg(MSG_Pane  *pane,
  74.                                MWContext *context):
  75.     XFE_ViewDialog((XFE_View *) 0, 
  76.                    CONTEXT_WIDGET(context), 
  77.                    "abMListProperties",
  78.                    context,
  79.                    True, /* ok */
  80.                    True, /* cancel */
  81.                    True, /* help */
  82.                    True, /* apply ; remove */
  83.                    False, /* separator */
  84.                    True),
  85.     m_pane(pane)
  86. {
  87.     /*
  88.      */
  89.   createUI();
  90. }
  91. #endif /* USE_ABCOM */
  92.  
  93. XFE_ABMListDlg::~XFE_ABMListDlg() 
  94. {
  95.     m_mailListEntry.CleanUp();
  96. }/* XFE_ABMListDlg() */
  97.  
  98. void 
  99. XFE_ABMListDlg::createUI()
  100. {
  101.   Arg av[8];
  102.   int ac;
  103.  
  104.   /* Form: m_chrome is the dialog 
  105.    */
  106.   ac = 0;
  107.   XtSetArg (av [ac], XmNtopAttachment, XmATTACH_FORM); ac++;
  108.   XtSetArg (av [ac], XmNbottomAttachment, XmATTACH_FORM); ac++;
  109.   XtSetArg (av [ac], XmNleftAttachment, XmATTACH_FORM); ac++;
  110.   XtSetArg (av [ac], XmNrightAttachment, XmATTACH_FORM); ac++;
  111.   Widget form = XmCreateForm (m_chrome, "mailListForm", av, ac);
  112.   XtManageChild (form);
  113.  
  114.   /* Frame: 
  115.    */
  116.   XtSetArg (av [ac], XmNwidth, 500); ac++;
  117.   Widget frame =  XmCreateFrame(form, "mailListFrame", av, ac);
  118.   XtManageChild (frame);
  119.  
  120.   Widget labelTitle;
  121.   labelTitle= XtVaCreateManagedWidget(XP_GetString(XFE_AB_MLIST_TITLE),
  122.                       xmLabelGadgetClass, frame,
  123.                       XmNchildType, XmFRAME_TITLE_CHILD,
  124.                       XmNalignment, XmALIGNMENT_CENTER, 
  125.                       NULL);
  126.   ac = 0;
  127.   XtSetArg (av[ac], XmNchildType, XmFRAME_WORKAREA_CHILD); ac++;
  128.   Widget workForm = XmCreateForm(frame, "workAreaForm", av, ac);
  129.   XtManageChild(workForm);
  130.  
  131.   /* Inside the frame
  132.    */
  133.   char *genTabLabels[4];
  134.  
  135.   genTabLabels[0] = XP_GetString(XFE_AB_MLIST_LISTNAME);
  136.   genTabLabels[1] = XP_GetString(XFE_AB_MLIST_NICKNAME);
  137.   genTabLabels[2] = XP_GetString(XFE_AB_MLIST_DESCRIPTION);
  138.   genTabLabels[3] = XP_GetString(XFE_AB_MLIST_PROMPT);
  139.  
  140.   Widget stripForm[4], 
  141.          label;
  142.   for (int i = 0; i < 4; i++) {
  143.     ac = 0;
  144.     stripForm[i] = XmCreateForm(workForm, "lisNameForm", av, ac);
  145.  
  146.  
  147.     /* Label/ attachment
  148.      */
  149.     label = XtVaCreateManagedWidget (genTabLabels[i],
  150.                      xmLabelGadgetClass, stripForm[i],
  151.                      XmNalignment, 
  152.                      (i < 3)?
  153.                      XmALIGNMENT_END:
  154.                      XmALIGNMENT_BEGINNING, 
  155.                      NULL);
  156.     if (i != 3) {
  157.       XtVaSetValues(label, 
  158.             XmNleftAttachment, XmATTACH_FORM,
  159.             XmNtopAttachment, XmATTACH_FORM,
  160.             XmNrightAttachment, XmATTACH_NONE,
  161.             XmNbottomAttachment, XmATTACH_FORM,
  162.             0);
  163.     }/* if */
  164.     else {
  165.       XtVaSetValues(label, 
  166.             XmNleftAttachment, XmATTACH_FORM,
  167.             XmNtopAttachment, XmATTACH_FORM,
  168.             XmNrightAttachment, XmATTACH_FORM,
  169.             XmNbottomAttachment, XmATTACH_NONE,
  170.             0);
  171.     }/* else */
  172.  
  173.  
  174.     /* textF / attachment
  175.      */
  176.      if (i != 3) {
  177.       /* TextF
  178.        */
  179.       ac = 0;
  180.       m_textFs[i] = fe_CreateTextField(stripForm[i], (char *) genTabLabels[i],
  181.                       av, ac);
  182.       XtVaSetValues(m_textFs[i], 
  183.             XmNleftAttachment, XmATTACH_WIDGET,
  184.             XmNleftWidget, label,
  185.             XmNtopAttachment, XmATTACH_FORM,
  186.             XmNrightAttachment, XmATTACH_FORM,
  187.             XmNbottomAttachment, XmATTACH_FORM,
  188.             0);
  189.       XtManageChild(m_textFs[i]);
  190.  
  191.       // callbacks
  192.       if (i == 0)
  193.           XtAddCallback(m_textFs[i], 
  194.                         XmNvalueChangedCallback, 
  195.                         XFE_ABMListDlg::entryTTYValChgCallback, 
  196.                         this);
  197.  
  198.  
  199.     }/* if */
  200.     else {
  201.       /* TextF
  202.        */
  203.       ac = 0;
  204.       //XtSetArg (av [ac], XmNwidth, 180); ac++;
  205.       m_textFs[i] = fe_CreateTextField(stripForm[i], (char *) genTabLabels[i],
  206.                       av, ac);
  207.       XtVaSetValues(m_textFs[i], 
  208.             XmNleftAttachment, XmATTACH_FORM,
  209.             XmNtopAttachment, XmATTACH_WIDGET,
  210.             XmNtopWidget, label,
  211.             XmNrightAttachment, XmATTACH_FORM,
  212.             XmNbottomAttachment, XmATTACH_NONE,
  213.             0);
  214.       XtManageChild(m_textFs[i]);
  215.   
  216.       /* mailing list view
  217.        */
  218.       XFE_ABMListView *listView = new XFE_ABMListView((XFE_Component *)this, 
  219.                               stripForm[i],
  220.                               m_abView->getDir(), 
  221.                               m_abView->getAddrBook(),
  222.                               NULL,
  223.                               m_abView->getContext(),
  224.                               fe_getMNMaster());
  225.       XtVaSetValues(listView->getBaseWidget(),
  226.             XmNleftAttachment, XmATTACH_FORM,
  227.             XmNtopAttachment, XmATTACH_WIDGET,
  228.             XmNtopWidget, m_textFs[i],
  229.             XmNrightAttachment, XmATTACH_FORM,
  230.             XmNbottomAttachment, XmATTACH_FORM,
  231.             NULL);
  232.  
  233.       setView(listView);
  234.       listView->show();
  235.  
  236.       // callbacks
  237.       XtAddCallback(m_textFs[i], 
  238.             XmNvalueChangedCallback, 
  239.             XFE_ABMListView::entryTTYValChgCallback, 
  240.             listView);
  241.  
  242.       XtAddCallback(m_textFs[i], 
  243.             XmNactivateCallback, 
  244.             XFE_ABMListView::entryTTYActivateCallback, 
  245.             listView);
  246.     }/* else */
  247.      
  248.     /* form attachment
  249.      */
  250.     if (!i)
  251.       XtVaSetValues(stripForm[i],
  252.             XmNleftAttachment, XmATTACH_FORM,
  253.             XmNtopAttachment, XmATTACH_FORM,
  254.             XmNrightAttachment, XmATTACH_FORM,
  255.             XmNbottomAttachment, XmATTACH_NONE,
  256.             NULL);
  257.     else
  258.       XtVaSetValues(stripForm[i],
  259.             XmNleftAttachment, XmATTACH_FORM,
  260.             XmNtopAttachment, XmATTACH_WIDGET,
  261.             XmNtopWidget, stripForm[i-1],
  262.             XmNrightAttachment, XmATTACH_FORM,
  263.             XmNbottomAttachment, XmATTACH_NONE,
  264.             NULL);
  265.  
  266.     XtManageChild(stripForm[i]);
  267.   }/* for i */
  268.  
  269.   //
  270.   // we don't want a default value, since return does other stuff for
  271.   // us.
  272.   XtVaSetValues(m_chrome, /* the dialog */
  273.         XmNdefaultButton, NULL,
  274.         NULL);
  275.  
  276.  
  277.   // Set Apply to Remove
  278.   fe_SetString(m_applyButton, XmNlabelString, XP_GetString(XFE_AB_REMOVE));
  279.   
  280. }/* createUI */
  281.  
  282. void XFE_ABMListDlg::cancel()
  283. {
  284.   hide();
  285. }
  286.  
  287. void XFE_ABMListDlg::apply()
  288. {
  289.   /* remove 
  290.    */
  291.   ((XFE_ABMListView *)m_view)->remove();
  292. }
  293.  
  294. void XFE_ABMListDlg::ok()
  295. {
  296.     getDlgValues();
  297.  
  298.     if (!(((XFE_ABMListView *)m_view)->apply(m_mailListEntry.pNickName, 
  299.                                              m_mailListEntry.pFullName, 
  300.                                              m_mailListEntry.pInfo))) {
  301.         m_abView->changeEntryCount();
  302.         m_okToDestroy = TRUE;
  303.         cancel();
  304.     }/* if */
  305.     m_okToDestroy = FALSE;
  306. }
  307.  
  308. void 
  309. XFE_ABMListDlg::setDlgValues()
  310. {
  311. }
  312.  
  313. void XFE_ABMListDlg::setDlgValues(ABID entry, Boolean newList)
  314. {
  315.   m_newList = newList;
  316.   m_entry = entry;
  317.  
  318.   /* The dialog
  319.    */
  320.   if (entry != MSG_VIEWINDEXNONE && !newList) {
  321.     char        a_line[AB_MAX_STRLEN];
  322.  
  323.     a_line[0] = '\0';
  324.     if (AB_GetFullName(m_dir, m_AddrBook, entry, a_line) != MSG_VIEWINDEXNONE) 
  325.       m_mailListEntry.pFullName = XP_STRDUP(a_line);
  326.  
  327.     a_line[0] = '\0';
  328.     if (AB_GetNickname(m_dir, m_AddrBook, entry, a_line)!= MSG_VIEWINDEXNONE)
  329.       m_mailListEntry.pNickName = XP_STRDUP(a_line);
  330.  
  331.     a_line[0] = '\0';
  332.     if (AB_GetInfo(m_dir, m_AddrBook, entry, a_line)!= MSG_VIEWINDEXNONE)
  333.       m_mailListEntry.pInfo = XP_STRDUP(a_line);
  334.   }/* if */
  335.   else {
  336.     /* New list
  337.      */
  338.     //Initialize();
  339.     m_mailListEntry.pFullName = XP_STRDUP("New Mailing List");
  340.   }/* else */
  341.  
  342.   fe_SetTextField(m_textFs[0],
  343.         m_mailListEntry.pFullName?m_mailListEntry.pFullName:"");
  344.   fe_SetTextField(m_textFs[1],
  345.         m_mailListEntry.pNickName?m_mailListEntry.pNickName:"");
  346.   fe_SetTextField(m_textFs[2],
  347.         m_mailListEntry.pInfo?m_mailListEntry.pInfo:"");
  348.  
  349.   /* the view
  350.    */
  351.   /* mlist entry
  352.    */
  353.   m_entry = ((XFE_ABMListView *)m_view)->setValues(newList?0:m_entry);
  354.   m_mListPane = ((XFE_ABMListView *)m_view)->getMListPane();
  355. }
  356.  
  357. void XFE_ABMListDlg::getDlgValues()
  358. {
  359.   char *tmp;
  360.   tmp = fe_GetTextField(m_textFs[0]);
  361.   if (tmp && strlen(tmp))
  362.       m_mailListEntry.pFullName = tmp;
  363.   else
  364.       m_mailListEntry.pFullName = XP_STRDUP("");
  365.  
  366.   tmp = fe_GetTextField(m_textFs[1]);
  367.   if (tmp && strlen(tmp))
  368.       m_mailListEntry.pNickName = tmp;
  369.   else
  370.       m_mailListEntry.pNickName = XP_STRDUP("");
  371.  
  372.   tmp = fe_GetTextField(m_textFs[2]);
  373.   if (tmp && strlen(tmp))
  374.       m_mailListEntry.pInfo = tmp;
  375.   else
  376.       m_mailListEntry.pInfo = XP_STRDUP("");
  377. }
  378.  
  379. void XFE_ABMListDlg::Initialize()
  380. {
  381.   XP_STRCPY(m_mailListEntry.pFullName, "");
  382.   XP_STRCPY(m_mailListEntry.pNickName, "");
  383.   XP_STRCPY(m_mailListEntry.pInfo, "");
  384.   XP_STRCPY(m_mailListEntry.pDistName, "");
  385. }/* XFE_ABMListDlg::Initialize() */
  386.  
  387. void XFE_ABMListDlg::entryTTYValChgCallback(Widget w, 
  388.                                             XtPointer clientData, 
  389.                                             XtPointer callData)
  390. {
  391.   XFE_ABMListDlg *obj = (XFE_ABMListDlg *) clientData;
  392.   obj->entryTTYValChgCB(w, callData);
  393. }
  394.  
  395. void
  396. XFE_ABMListDlg::entryTTYValChgCB(Widget w, XtPointer /* callData */)
  397. {
  398.   char *str;
  399.   str = fe_GetTextField(w);
  400.   if (str && XP_STRLEN(str) > MAX_LISTNAME_LEN) {
  401.       str[MAX_LISTNAME_LEN] = '\0';
  402.       fe_SetTextField(w, str);
  403.       XmTextFieldSetCursorPosition(w, MAX_LISTNAME_LEN);
  404.       XBell(XtDisplay(w), 100);
  405.   }/* if */
  406. }
  407.  
  408. #if defined(USE_ABCOM)
  409. extern "C" int
  410. fe_ShowPropertySheetForMList(MSG_Pane *pane, MWContext *context)
  411. {
  412.     XFE_ABMListDlg* listDlg = 
  413.         new XFE_ABMListDlg(pane, context);
  414.     listDlg->setDlgValues();
  415.     listDlg->show();
  416.     return 1;
  417. }
  418. #endif
  419. /* XFE_ABListSearchView::popupListPropertyWindow() */
  420.