home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / ABAddressingDlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  10.4 KB  |  385 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.    ABAddressingDlg.cpp -- address book window stuff.
  20.    Created: Tao Cheng <tao@netscape.com>, 20-nov-96
  21.  */
  22.  
  23. #include "ABAddressingDlg.h"
  24.  
  25. #include "AB2PaneView.h"
  26. #include "ABAddrSearchView.h"
  27.  
  28. #include "ABAddresseeView.h"
  29. #include "AddressFolderView.h"
  30.  
  31. #include "Frame.h"
  32. #include "ViewGlue.h"
  33.  
  34. #include <Xm/Form.h>
  35. #include <Xm/Label.h>
  36. #include <Xm/PushB.h>
  37. #include <Xm/TextF.h>
  38. #include <Xm/DialogS.h>
  39.  
  40. extern "C" {
  41. #include "xfe.h"
  42.  
  43. XP_List* FE_GetDirServers();
  44. };
  45.  
  46. #include "xpgetstr.h"
  47. #include "xp_mem.h"
  48. extern int XFE_AB_ADDRESSEE_PROMPT;
  49. extern int XFE_AB_SEARCH_PROMPT;
  50.  
  51. XFE_ABAddressingDlg::XFE_ABAddressingDlg(Widget                 parent,
  52.                      char                  *name,
  53.                      ABAddrMsgCBProc        proc, 
  54.                      void                  *callData,
  55.                      Boolean                modal,
  56.                      MWContext *context):
  57.   XFE_ViewDialog((XFE_View *) 0, parent, name,
  58.          context,
  59.          True, /* ok */
  60.          True, /* cancel */
  61.          True, /* help */
  62.          False, /* apply; remove */
  63.          False, /* separator */
  64.          modal),
  65.   m_cbProc(proc),
  66.   m_callData(callData)
  67. {
  68.   Arg av [20];
  69.   int ac = 0;
  70.  
  71.   /* Form: m_chrome is the dialog 
  72.    */
  73.   ac = 0;
  74.   XtSetArg (av [ac], XmNtopAttachment, XmATTACH_FORM); ac++;
  75.   XtSetArg (av [ac], XmNbottomAttachment, XmATTACH_FORM); ac++;
  76.   XtSetArg (av [ac], XmNleftAttachment, XmATTACH_FORM); ac++;
  77.   XtSetArg (av [ac], XmNrightAttachment, XmATTACH_FORM); ac++;
  78.   XtSetArg (av [ac], XmNresizePolicy, XmRESIZE_NONE); ac++;
  79.   Widget form = XmCreateForm (m_chrome, "addrMsgForm", av, ac);
  80.   XtManageChild (form);
  81.   XtVaSetValues(m_chrome, /* the dialog */
  82.                 // XmNallowShellResize, FALSE,
  83.                 // XmNnoResize, False,
  84.                 XmNdefaultButton, NULL,
  85.                 NULL);
  86.  
  87.   /* 2 sub forms
  88.    */
  89.   char genTabLabels[2][128];
  90.  
  91.   sprintf(genTabLabels[0], 
  92.       "%s", 
  93.        XP_GetString(XFE_AB_SEARCH_PROMPT));
  94.   sprintf(genTabLabels[1], 
  95.       "%s", 
  96.       XP_GetString(XFE_AB_ADDRESSEE_PROMPT));
  97.  
  98.   Widget subForms[AB_LAST], 
  99.          workForms[AB_LAST];
  100.  
  101.   for (int i=0; i < AB_LAST; i++) { 
  102.     ac = 0;
  103.     subForms[i] = XmCreateForm (form, "viewForm", av, ac);
  104.     /* Frame
  105.      */
  106.     ac = 0;
  107.     XtSetArg (av[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
  108.     XtSetArg (av[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
  109.     XtSetArg (av[ac], XmNbottomAttachment, XmATTACH_FORM); ac++;
  110.     XtSetArg (av[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
  111.     Widget frame = XmCreateFrame(subForms[i], "viewFrame", av, ac);
  112.     XtManageChild(frame);
  113.  
  114.     /* frame title
  115.      */
  116.     if (i > 0) {
  117.         Widget title;
  118.  
  119.         /* to satisfy gcc
  120.          */
  121.         title = XtVaCreateManagedWidget(genTabLabels[i],
  122.                                         xmLabelGadgetClass, frame,
  123.                                         XmNchildType, XmFRAME_TITLE_CHILD,
  124.                                         XmNalignment, XmALIGNMENT_CENTER, 
  125.                                         NULL);
  126.     }/* if */
  127.  
  128.     ac = 0;
  129.     XtSetArg (av[ac], XmNchildType, XmFRAME_WORKAREA_CHILD); ac++;
  130.     workForms[i] = XmCreateForm(frame, "workAreaForm", av, ac);
  131.     XtManageChild(workForms[i]);
  132.   }/* for i */
  133.  
  134.   XtVaSetValues(subForms[1],
  135.             XmNheight, 200,
  136.             XmNwidth, 640,
  137.             XmNtopAttachment, XmATTACH_NONE,
  138.             XmNbottomAttachment, XmATTACH_FORM,
  139.             XmNleftAttachment, XmATTACH_FORM,
  140.             XmNrightAttachment, XmATTACH_FORM,
  141.             NULL);
  142.   XtVaSetValues(subForms[0],
  143.             XmNheight, 300,
  144.             XmNwidth, 640,
  145.             XmNtopAttachment, XmATTACH_FORM,
  146.             XmNbottomAttachment, XmATTACH_WIDGET,
  147.             XmNbottomWidget, subForms[1],
  148.             XmNleftAttachment, XmATTACH_FORM,
  149.             XmNrightAttachment, XmATTACH_FORM,
  150.             NULL);
  151.   XtManageChild (subForms[1]);
  152.   XtManageChild (subForms[0]);
  153.  
  154.   /* Search UI
  155.    */
  156.   m_searchContext = XP_NewContext();
  157.   if (!m_searchContext)
  158.       return;
  159.  
  160.   XFE_Frame *f = ViewGlue_getFrame(context);
  161.   fe_ContextData *fec = XP_NEW_ZAP (fe_ContextData);
  162.   XP_ASSERT(fec);
  163.   CONTEXT_DATA(m_searchContext) = fec;
  164.   ViewGlue_addMapping(f, (void *)m_searchContext);
  165.   m_searchContext->funcs = fe_BuildDisplayFunctionTable();
  166.   CONTEXT_WIDGET(m_searchContext) = CONTEXT_WIDGET(m_context);
  167.   fe_InitRemoteServer (XtDisplay (m_widget));
  168.  
  169.   /* 2 pane
  170.    */
  171.   XFE_AB2PaneView  *TwoPaneView = 
  172.       new XFE_AB2PaneView(this, 
  173.                           workForms[AB_SEARCH_VIEW], 
  174.                           NULL, 
  175.                           m_searchContext,
  176.                           AB_PICKER);
  177.  
  178.   setView(TwoPaneView);
  179.  
  180.   m_addrSearchView = 
  181.       (XFE_AddrSearchView *) TwoPaneView->getEntriesListView();
  182.  
  183.   /* cmd group
  184.    */
  185.   ac = 0;
  186.   XtSetArg(av[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
  187.   XtSetArg(av[ac], XmNtopAttachment, XmATTACH_NONE); ac++;
  188.   XtSetArg(av[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
  189.   XtSetArg(av[ac], XmNbottomAttachment, XmATTACH_FORM); ac++;
  190.   Widget cmdGroupForm = XmCreateForm(workForms[AB_SEARCH_VIEW],
  191.                                       "cmdGroupForm", av, ac);
  192.  
  193.   Widget dummy = 
  194.       XtVaCreateManagedWidget("btnrowcol", 
  195.                               xmRowColumnWidgetClass, cmdGroupForm,
  196.                               XmNorientation, XmHORIZONTAL,
  197.                               XmNpacking, XmPACK_COLUMN,
  198.                               XmNleftAttachment, XmATTACH_FORM,
  199.                               XmNtopAttachment, XmATTACH_NONE,
  200.                               XmNrightAttachment, XmATTACH_NONE,
  201.                               XmNbottomAttachment, XmATTACH_FORM,
  202.                               NULL);
  203.   /* to button
  204.    */
  205.   ac = 0;
  206.  
  207.   XtSetArg(av[ac], XtNsensitive, False); ac++;
  208.   XtSetArg(av[ac], XmNwidth, 100); ac++;
  209.   Widget toBtn = XmCreatePushButton(dummy, 
  210.                                     "toBtn", 
  211.                                     av, ac);
  212.   XtManageChild(toBtn);
  213.   m_addrSearchView->setToBtn(toBtn);
  214.  
  215.   /* cc button
  216.    */
  217.   ac = 0;
  218.   XtSetArg(av[ac], XtNsensitive, False), ac++;
  219.   XtSetArg (av[ac], XmNwidth, 100); ac++;
  220.   Widget ccBtn = XmCreatePushButton(dummy, 
  221.                                     "ccBtn", 
  222.                                     av, ac);
  223.   XtManageChild(ccBtn);
  224.   m_addrSearchView->setCcBtn(ccBtn);
  225.  
  226.   /* bcc button
  227.    */
  228.   ac = 0;
  229.   XtSetArg(av[ac], XtNsensitive, False), ac++;
  230.   XtSetArg (av[ac], XmNwidth, 100); ac++;
  231.   Widget bccBtn = XmCreatePushButton(dummy, 
  232.                                      "bccBtn", 
  233.                                      av, ac);
  234.   XtManageChild(bccBtn);
  235.   m_addrSearchView->setBccBtn(bccBtn);
  236.  
  237.   /* button holder
  238.    */
  239.   Widget dummy2 = 
  240.       XtVaCreateManagedWidget("btnrowcol2", 
  241.                               xmRowColumnWidgetClass, cmdGroupForm,
  242.                               XmNorientation, XmHORIZONTAL,
  243.                               XmNleftAttachment, XmATTACH_NONE,
  244.                               XmNtopAttachment, XmATTACH_NONE,
  245.                               XmNrightAttachment, XmATTACH_FORM,
  246.                               XmNbottomAttachment, XmATTACH_FORM,
  247.                               NULL);
  248. #if 0
  249.   /* add to address button
  250.    */
  251.   ac = 0;
  252.   XtSetArg(av[ac], XtNsensitive, False), ac++;
  253.   Widget addToAddressBtn = XmCreatePushButton(dummy2, 
  254.                                               "addToAddressBtn", 
  255.                                               av, 
  256.                                               ac);
  257.   XtManageChild(addToAddressBtn);
  258.   m_addrSearchView->setAdd2ABBtn(addToAddressBtn);
  259. #endif
  260.   /* Properties
  261.    */
  262.   ac = 0;
  263.   XtSetArg(av[ac], XtNsensitive, False), ac++;
  264.   Widget propertiesBtn = XmCreatePushButton(dummy2, 
  265.                                             "propertiesBtn", 
  266.                                             av, 
  267.                                             ac);
  268.   XtManageChild(propertiesBtn);
  269.   m_addrSearchView->setPropertyBtn(propertiesBtn);
  270.  
  271.   /* outliner Attachment
  272.    */
  273.   XtVaSetValues(TwoPaneView->getBaseWidget(),
  274.                 XmNleftAttachment, XmATTACH_FORM,
  275.                 XmNtopAttachment, XmATTACH_FORM,
  276.                 XmNrightAttachment, XmATTACH_FORM,
  277.                 XmNbottomAttachment, XmATTACH_WIDGET,
  278.                 XmNbottomWidget, cmdGroupForm,
  279.                 NULL);
  280.  
  281.   XtManageChild(cmdGroupForm);
  282.  
  283.   /*
  284.    * Provide callbacks as for entries outside world
  285.    */
  286.   XtAddCallback(toBtn, 
  287.                 XmNactivateCallback, 
  288.                 XFE_AddrSearchView::toCallback, 
  289.                 m_addrSearchView);
  290.  
  291.   XtAddCallback(ccBtn, 
  292.                 XmNactivateCallback, 
  293.                 XFE_AddrSearchView::ccCallback, 
  294.                 m_addrSearchView);
  295.  
  296.   XtAddCallback(bccBtn, 
  297.                 XmNactivateCallback, 
  298.                 XFE_AddrSearchView::bccCallback, 
  299.                 m_addrSearchView);
  300. #if 1
  301.   XtAddCallback(propertiesBtn, 
  302.                 XmNactivateCallback, 
  303.                 XFE_AB2PaneView::propertiesCallback,
  304.                 TwoPaneView);
  305. #else
  306.   XtAddCallback(addToAddressBtn, 
  307.                 XmNactivateCallback, 
  308.                 XFE_AddrSearchView::addToAddressCallback, 
  309.                 m_addrSearchView);
  310. #endif
  311.   /* Addressee UI
  312.    */
  313.   m_addresseeView = 
  314.     new XFE_AddresseeView(this,
  315.               workForms[AB_ADDRESSEE_VIEW],
  316.               NULL, m_context);
  317.   Widget okBtn = XmSelectionBoxGetChild(m_chrome, XmDIALOG_OK_BUTTON);
  318.   XtSetSensitive(okBtn, False);        
  319.   m_addresseeView->setOKBtn(okBtn);
  320.  
  321.   m_addrSearchView->setAddressee(m_addresseeView);
  322.   if (callData) {
  323.       /*  Assume the caller is XFE_AddressFolderView
  324.        */      
  325.       ABAddrMsgCBProcStruc* clientData = 
  326.           ((XFE_AddressFolderView *)callData)->exportAddressees();
  327.       addAddressees(clientData);
  328.   }/* if */
  329. }
  330.  
  331. XFE_ABAddressingDlg::~XFE_ABAddressingDlg()
  332. {
  333. }
  334.  
  335. void XFE_ABAddressingDlg::cancel()
  336. {
  337.   XFE_ABListSearchView *searchView = (XFE_ABListSearchView *) m_view;
  338.   searchView->unRegisterInterested();
  339.   hide();
  340. }
  341.  
  342. void XFE_ABAddressingDlg::ok()
  343. {
  344.   if (m_addresseeView && m_cbProc) {
  345.     ABAddrMsgCBProcStruc *clientData = 
  346.       (ABAddrMsgCBProcStruc *) XP_CALLOC(1, sizeof(ABAddrMsgCBProcStruc));
  347.     clientData->m_pairs = m_addresseeView->getPairs(clientData->m_count); 
  348.     m_cbProc(clientData, m_callData);
  349.   }/* if */
  350.   cancel();
  351. }
  352.  
  353. void XFE_ABAddressingDlg::addAddressees(ABAddrMsgCBProcStruc *clientData)
  354. {
  355.     if (!m_addresseeView ||
  356.         !clientData)
  357.         return;
  358.  
  359.     int npairs = clientData->m_count;
  360.     for (int i=0; i < npairs; i++)
  361.         if (clientData->m_pairs[i]) {
  362.             m_addresseeView->addEntry(clientData->m_pairs[i]);
  363.         }/* if */
  364.     XP_FREEIF(clientData->m_pairs);
  365.     XP_FREEIF(clientData);
  366. }
  367.  
  368.  
  369. /* C API
  370.  */
  371. extern "C"  void
  372. fe_showAddrMSGDlg(Widget toplevel, 
  373.           ABAddrMsgCBProc proc, void* callData, MWContext *context)
  374. {
  375.   XFE_ABAddressingDlg *dlg =  
  376.     new XFE_ABAddressingDlg(toplevel, 
  377.                 "AddreMsgWin",
  378.                 proc,
  379.                 callData,
  380.                 True,
  381.                 context);
  382.   dlg->show();
  383. }
  384.  
  385.