home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / AB2PaneView.cpp next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  12.2 KB  |  456 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.    ABListSearchView.cpp -- view of user's mailfilters.
  20.    Created: Tao Cheng <tao@netscape.com>, 14-oct-97
  21.  */
  22.  
  23. #include "AB2PaneView.h"
  24. #include "ABDirListView.h"
  25. #include "AddrBookView.h"
  26. #include "ABAddrSearchView.h"
  27.  
  28. #include <Xfe/Pane.h>
  29.  
  30. XFE_AB2PaneView::XFE_AB2PaneView(XFE_Component *toplevel_component, 
  31.                                  Widget         parent, 
  32.                                  XFE_View      *parent_view, 
  33.                                  MWContext     *context,
  34.                                  eABViewMode    mode):
  35.     XFE_View(toplevel_component, parent_view, context)
  36. {
  37.     m_focusedView = NULL;
  38.     // data
  39.     m_expanded = (mode==AB_PICKER?False:True);
  40.     m_dir = 0;
  41.     m_directories = FE_GetDirServers();
  42.     if (m_directories)
  43.         m_nDirs = XP_ListCount(m_directories);
  44.     else
  45.         m_nDirs = 0;
  46.  
  47.     // UI
  48.     /* let's make a container here
  49.      */
  50.     Widget paneContainerForm = XtVaCreateManagedWidget("paneContainerForm",
  51.                                                        xmFormWidgetClass,
  52.                                                        parent,
  53.                                                        NULL);
  54.  
  55.     
  56.     Widget hpane;
  57.  
  58.     hpane = XtVaCreateWidget("hpane",
  59.                              xfePaneWidgetClass,
  60.                              paneContainerForm,
  61.                              XmNorientation,            XmHORIZONTAL,
  62.                              XmNsashPosition,            200,
  63.                              XmNsashThickness,            10,
  64.                              XmNsashShadowThickness,    1,
  65.                              XmNpaneSashType,            XmPANE_SASH_LIVE,
  66.                              NULL);
  67.  
  68.     // dir list
  69.     m_dirListView = new XFE_ABDirListView(toplevel_component, 
  70.                                           hpane, 
  71.                                           this,
  72.                                           context,
  73.                                           m_directories);
  74.  
  75.     // register
  76.     m_dirListView->registerInterest(XFE_ABDirListView::dirCollapse,
  77.                                     this,
  78.                                     (XFE_FunctionNotification)dirCollapse_cb);
  79.  
  80.     m_dirListView->registerInterest(XFE_ABDirListView::dirSelect,
  81.                                     this,
  82.                                     (XFE_FunctionNotification)dirSelect_cb);
  83.  
  84.     m_dirListView->registerInterest(XFE_MNListView::changeFocus,
  85.                                     this,
  86.                                     (XFE_FunctionNotification)changeFocus_cb);
  87.  
  88.     // entry list
  89.     if (mode == AB_BOOK)
  90.         m_entriesListView = (XFE_ABListSearchView *) 
  91.             new XFE_AddrBookView(toplevel_component, 
  92.                                  hpane,
  93.                                  this,
  94.                                  context,
  95.                                  m_directories);
  96.     else 
  97.         m_entriesListView = (XFE_ABListSearchView *) 
  98.             new XFE_AddrSearchView(toplevel_component, 
  99.                                    hpane,
  100.                                    this,
  101.                                    context,
  102.                                    m_directories);
  103.  
  104.  
  105.     /* get outliner
  106.      */
  107.     XFE_Outliner *outliner = m_entriesListView->getOutliner();
  108.     XP_ASSERT(outliner);
  109.  
  110.     // initialize the icons if they haven't already been
  111.     Pixel bg_pixel;
  112.     
  113.     XtVaGetValues(outliner->getBaseWidget(), XmNbackground, &bg_pixel, 0);
  114.     if (!XFE_ABListSearchView::m_personIcon.pixmap)
  115.         fe_NewMakeIcon(getToplevel()->getBaseWidget(),
  116.                        /* umm. fix me
  117.                         */
  118.                        BlackPixelOfScreen(XtScreen(outliner->getBaseWidget())),
  119.                        bg_pixel,
  120.                        &XFE_ABListSearchView::m_personIcon,
  121.                        NULL, 
  122.                        MN_Person.width, 
  123.                        MN_Person.height,
  124.                        MN_Person.mono_bits, 
  125.                        MN_Person.color_bits, 
  126.                        MN_Person.mask_bits, 
  127.                        FALSE);
  128.   
  129.     if (!XFE_ABListSearchView::m_listIcon.pixmap)
  130.         fe_NewMakeIcon(getToplevel()->getBaseWidget(),
  131.                        /* umm. fix me
  132.                         */
  133.                        BlackPixelOfScreen(XtScreen(outliner->getBaseWidget())),
  134.                        bg_pixel,
  135.                        &XFE_ABListSearchView::m_listIcon,
  136.                        NULL, 
  137.                        MN_People.width, 
  138.                        MN_People.height,
  139.                        MN_People.mono_bits, 
  140.                        MN_People.color_bits, 
  141.                        MN_People.mask_bits, 
  142.                        FALSE);
  143.  
  144. #if defined(USE_MOTIF_DND)
  145.     outliner->enableDragDrop(m_entriesListView,
  146.                              XFE_ABListSearchView::getDropTargets,
  147.                              XFE_ABListSearchView::getDragTargets,
  148.                              XFE_ABListSearchView::getDragIconData,
  149.                              XFE_ABListSearchView::dragConvert,
  150.                              XFE_ABListSearchView::processTargets);
  151.  
  152.     outliner = m_dirListView->getOutliner();
  153.     outliner->enableDragDrop(m_dirListView,
  154.                              XFE_ABDirListView::getDropTargets,
  155.                              XFE_ABDirListView::getDragTargets,
  156.                              XFE_ABDirListView::getDragIconData,
  157.                              XFE_ABDirListView::dragConvert,
  158.                              XFE_ABDirListView::processTargets);
  159.  
  160.  
  161. #else
  162.  
  163.  /* to replaced by new Dnd
  164.        */
  165.  
  166.     /* enable m_entriesListView drag & drop 
  167.      */
  168.     outliner->setDragType(FE_DND_ADDRESSBOOK, 
  169.                           &XFE_ABListSearchView::m_personIcon, 
  170.                           m_entriesListView);
  171.  
  172.     fe_dnd_CreateDrop(outliner->getBaseWidget(), 
  173.                       &XFE_ABListSearchView::entryListDropCallback, 
  174.                       m_entriesListView);
  175.  
  176.     /* enable m_dirListView drag & drop 
  177.      */
  178.     outliner = m_dirListView->getOutliner();
  179.     outliner->setDragType(FE_DND_BOOKS_DIRECTORIES,
  180.                           &XFE_ABListSearchView::m_listIcon, 
  181.                           m_dirListView);
  182.  
  183.     fe_dnd_CreateDrop(outliner->getBaseWidget(), 
  184.                       &XFE_ABDirListView::dirListDropCallback, 
  185.                       m_dirListView);
  186. #endif
  187.  
  188.     // register
  189.     m_entriesListView->registerInterest(XFE_ABListSearchView::dirExpand,
  190.                                         this,
  191.                                         (XFE_FunctionNotification)dirExpand_cb);
  192.  
  193.     m_entriesListView->registerInterest(XFE_ABListSearchView::dirsChanged,
  194.                                         this,
  195.                                         (XFE_FunctionNotification)dirsChanged_cb);
  196.  
  197.     m_entriesListView->registerInterest(XFE_ABListSearchView::dirSelect,
  198.                                         this,
  199.                                         (XFE_FunctionNotification)dirSelect_cb);
  200.  
  201.     m_entriesListView->registerInterest(XFE_MNListView::changeFocus,
  202.                                         this,
  203.                                         (XFE_FunctionNotification)changeFocus_cb);
  204.  
  205.     // add our subviews to the list of subviews for command dispatching and
  206.     // deletion.
  207.     addView(m_dirListView);
  208.     addView(m_entriesListView);
  209.     m_entriesListView->show();
  210.     
  211.     //
  212. #if defined(USE_ABCOM)
  213.     MSG_Pane *abContainerPane = m_dirListView->getPane();
  214.     m_entriesListView->setContainerPane(abContainerPane);
  215.  
  216.     /* get all root containers
  217.      */
  218.     uint32 nDirs = 0;
  219.     int error = AB_GetNumRootContainers(abContainerPane,
  220.                                         (int32 *) &nDirs);
  221.     m_rootContainers = 0;
  222.     if (nDirs) {
  223.         m_nDirs = nDirs;
  224.         m_rootContainers = 
  225.             (AB_ContainerInfo **) XP_CALLOC(nDirs, 
  226.                                             sizeof(AB_ContainerInfo *));
  227.         
  228.         error = 
  229.             AB_GetOrderedRootContainers(abContainerPane,
  230.                                         /* FE Allocated & Freed */
  231.                                         m_rootContainers, 
  232.                                         /* in  - # of elements in ctrArray.
  233.                                          * out - BE fills with # root 
  234.                                          * containers stored in ctrArray */
  235.                                         (int32 *) &nDirs);
  236.     }/* if */
  237.  
  238. #endif /* USE_ABCOM */
  239.     Widget filterBoxForm = 
  240.         m_entriesListView->makeFilterBox(paneContainerForm, 
  241.                                          (mode==AB_PICKER)?True:False);
  242.  
  243.     if (m_nDirs)
  244. #if defined(USE_ABCOM)
  245.         m_entriesListView->selectContainer(m_rootContainers[0]);
  246. #else
  247.         m_entriesListView->changeEntryCount();
  248. #endif
  249.     expandCollapse(m_expanded);
  250.     XtManageChild(hpane);
  251.     setBaseWidget(paneContainerForm);
  252.  
  253.     //
  254.     XtVaSetValues(hpane,
  255.                   XmNleftAttachment, XmATTACH_FORM,
  256.                   XmNtopAttachment, XmATTACH_WIDGET,
  257.                   XmNtopWidget, filterBoxForm,
  258.                   XmNtopOffset, 4,
  259.                   XmNrightAttachment, XmATTACH_FORM,
  260.                   XmNbottomAttachment, XmATTACH_FORM,
  261.                   NULL);
  262.  
  263. }
  264.  
  265. XFE_AB2PaneView::~XFE_AB2PaneView()
  266. {
  267.     // unregister
  268.     m_dirListView->unregisterInterest(XFE_ABDirListView::dirCollapse,
  269.                                       this,
  270.                                       (XFE_FunctionNotification)dirCollapse_cb);
  271.  
  272.     m_dirListView->unregisterInterest(XFE_ABDirListView::dirSelect,
  273.                                       this,
  274.                                       (XFE_FunctionNotification)dirSelect_cb);
  275.     //
  276.     m_entriesListView->unregisterInterest(XFE_ABListSearchView::dirExpand,
  277.                                           this,
  278.                                           (XFE_FunctionNotification)dirExpand_cb);
  279.     m_entriesListView->unregisterInterest(XFE_ABListSearchView::dirsChanged,
  280.                                           this,
  281.                                           (XFE_FunctionNotification)dirsChanged_cb);
  282.     m_entriesListView->unregisterInterest(XFE_ABListSearchView::dirSelect,
  283.                                           this,
  284.                                           (XFE_FunctionNotification)dirSelect_cb);
  285.  
  286. #if defined(USE_ABCOM)
  287.     // Free heap
  288.     XP_FREEIF(m_rootContainers);
  289. #endif /* USE_ABCOM */
  290.  
  291. }
  292.  
  293. //
  294. Boolean 
  295. XFE_AB2PaneView::isCommandEnabled(CommandType command, 
  296.                                   void *calldata,
  297.                                   XFE_CommandInfo* i)
  298. {
  299.     if (m_focusedView)
  300.         return m_focusedView->isCommandEnabled(command, calldata, i);
  301.     return FALSE;
  302. }
  303.  
  304. Boolean 
  305. XFE_AB2PaneView::isCommandSelected(CommandType command, 
  306.                                    void *calldata,
  307.                                    XFE_CommandInfo* i)
  308. {
  309.     if (m_focusedView)
  310.         return m_focusedView->isCommandSelected(command, calldata, i);
  311.     return FALSE;
  312. }
  313.  
  314. Boolean 
  315. XFE_AB2PaneView::handlesCommand(CommandType command, 
  316.                                 void *calldata,
  317.                                 XFE_CommandInfo* i)
  318. {
  319.     if (m_focusedView)
  320.         return m_focusedView->handlesCommand(command, calldata, i);
  321.     return FALSE;
  322. }
  323.  
  324. void 
  325. XFE_AB2PaneView::doCommand(CommandType command, 
  326.                            void *calldata,
  327.                            XFE_CommandInfo* i)
  328. {
  329.     if (m_focusedView)
  330.         m_focusedView->doCommand(command, calldata, i);
  331. }
  332.  
  333. //
  334. XFE_CALLBACK_DEFN(XFE_AB2PaneView, dirCollapse)(XFE_NotificationCenter */*obj*/, 
  335.                                                 void */*clientData*/, 
  336.                                                 void */* callData */)
  337. {
  338.     expandCollapse();
  339. }
  340.  
  341. XFE_CALLBACK_DEFN(XFE_AB2PaneView, dirExpand)(XFE_NotificationCenter */*obj*/, 
  342.                                               void */*clientData*/, 
  343.                                               void */* callData */)
  344. {
  345.     expandCollapse();
  346. }
  347.  
  348. XFE_CALLBACK_DEFN(XFE_AB2PaneView, dirSelect)(XFE_NotificationCenter */*obj*/, 
  349.                                               void */*clientData*/, 
  350.                                               void *callData)
  351. {
  352. #if defined(USE_ABCOM)
  353.     AB_ContainerInfo *containerInfo = (AB_ContainerInfo *) callData;
  354.     if (m_entriesListView) {
  355.         m_entriesListView->selectContainer(containerInfo);        
  356.     }/* if */
  357.  
  358.     if (m_dirListView) {
  359.         m_dirListView->selectContainer(containerInfo);        
  360.     }/* if */
  361. #else
  362.     DIR_Server *dir = (DIR_Server *) callData;
  363.     if (m_entriesListView)
  364.         m_entriesListView->selectDir(dir);
  365. #endif
  366. }
  367.  
  368. XFE_CALLBACK_DEFN(XFE_AB2PaneView, dirsChanged)(XFE_NotificationCenter */*obj*/, 
  369.                                               void */*clientData*/, 
  370.                                               void *callData)
  371. {
  372.     XP_List *dirs = (XP_List *) callData;
  373.     if (m_dirListView)
  374.         m_dirListView->setDirServers(dirs);
  375. }
  376.  
  377. XFE_CALLBACK_DEFN(XFE_AB2PaneView, changeFocus)(XFE_NotificationCenter *,
  378.                                                 void *, void* calldata)
  379. {    
  380.     XP_ASSERT(calldata != NULL);
  381.     XFE_MNListView *focusedView = (XFE_MNListView *) calldata;
  382.  
  383.     if (m_focusedView != focusedView) {
  384.         if (m_focusedView)
  385.             m_focusedView->setInFocus(False);
  386.  
  387.         focusedView->setInFocus(True);
  388.         m_focusedView = focusedView;
  389.  
  390.         //?? duplicate???
  391.         getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating);
  392.     }/* if */
  393. }
  394.  
  395. // callbacks
  396. void 
  397. XFE_AB2PaneView::propertiesCallback(Widget w, XtPointer clientData, 
  398.                                     XtPointer callData)
  399. {
  400.   XFE_AB2PaneView *obj = (XFE_AB2PaneView *) clientData;
  401.   obj->propertiesCB(w, callData);
  402. }
  403.  
  404. void 
  405. XFE_AB2PaneView::propertiesCB(Widget, XtPointer)
  406. {
  407.     if (m_focusedView == m_dirListView)
  408.         m_dirListView->propertiesCB();
  409.     else if (m_focusedView == m_entriesListView)
  410.         m_entriesListView->propertiesCB();
  411. }
  412.  
  413. // 
  414. void XFE_AB2PaneView::expandCollapse()
  415. {
  416.     m_expanded = m_expanded?False:True;
  417.     expandCollapse(m_expanded);
  418. }
  419.  
  420. void XFE_AB2PaneView::expandCollapse(XP_Bool expand)
  421. {
  422.     if (m_dirListView)
  423.         m_dirListView->expandCollapse(expand);
  424.  
  425.     if (m_entriesListView)
  426.         m_entriesListView->expandCollapse(expand);
  427. }
  428.  
  429. //
  430. void XFE_AB2PaneView::selectLine(int line)
  431. {
  432.     if (m_dirListView)
  433.         m_dirListView->selectLine(line);
  434.  
  435.     if (m_entriesListView)
  436.         m_entriesListView->selectLine(line);
  437. }
  438.  
  439. void XFE_AB2PaneView::selectDir(DIR_Server* dir)
  440. {
  441.     if (m_dirListView)
  442.         m_dirListView->selectDir(dir);
  443.  
  444.     if (m_entriesListView)
  445.         m_entriesListView->selectDir(dir);
  446. }
  447.  
  448. #if defined(USE_ABCOM)
  449. const AB_ContainerInfo**
  450. XFE_AB2PaneView::getRootContainers(uint32 &count) const {
  451.     count = m_nDirs;
  452.     return m_rootContainers;
  453. }
  454. #endif /* USE_ABCOM */
  455.  
  456.