home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / SubAllView.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  12.3 KB  |  411 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.    SubAllView.cpp -- 4.x subscribe view, all newsgroup tab.
  20.    Created: Chris Toshok <toshok@netscape.com>, 18-Oct-1996.
  21.    */
  22.  
  23.  
  24.  
  25. #include "SubAllView.h"
  26. #include "NewsServerDialog.h"
  27. #include "Outliner.h"
  28. #include "Command.h"
  29. #include "ViewGlue.h"
  30.  
  31. #include "xfe.h"
  32. #include "msgcom.h"
  33. #include "xp_mem.h"
  34.  
  35. #include <Xm/Label.h>
  36. #include <Xm/PushB.h>
  37. #include <Xm/Separator.h>
  38. #include <Xm/TextF.h>
  39. #include "DtWidgets/ComboBox.h"
  40. #include "felocale.h"
  41.  
  42. #include <Xfe/Xfe.h>
  43.  
  44. #ifdef DEBUG_toshok
  45. #define D(x) x
  46. #else
  47. #define D(x)
  48. #endif
  49.  
  50. extern int XFE_ALL_NEWSGROUP_TAB;
  51.  
  52. #define OUTLINER_GEOMETRY_PREF "mail.subscribepane.all_groups.outliner_geometry"
  53.  
  54. XFE_SubAllView::XFE_SubAllView(XFE_Component *toplevel_component,
  55.                                Widget parent, XFE_View *parent_view,
  56.                                MWContext *context, MSG_Pane *p)
  57.     : XFE_SubTabView(toplevel_component, parent, parent_view, context, XFE_ALL_NEWSGROUP_TAB, p)
  58. {
  59.     int num_columns = 3;
  60.     static int column_widths[] = {40, 3, 9};
  61.  
  62.     m_outliner = new XFE_Outliner("subscribeAllList",
  63.                                   this,
  64.                                   getToplevel(),
  65.                                   m_form,
  66.                                   False, // constantSize
  67.                                   True, //hasHeadings
  68.                                   num_columns,
  69.                                   num_columns,
  70.                                   column_widths,
  71.                                   OUTLINER_GEOMETRY_PREF);
  72.  
  73.     XtVaSetValues(m_outliner->getBaseWidget(),
  74.                   XmNvisibleRows, 15,
  75.                   NULL);
  76.  
  77.     init_outliner_icons(m_outliner->getBaseWidget());
  78.  
  79.     // the all newsgroups view is hierarchical
  80.     m_outliner->setPipeColumn(OUTLINER_COLUMN_NAME);
  81.     m_outliner->setHideColumnsAllowed( True );
  82.     m_outliner->setMultiSelectAllowed( True );
  83.     m_outliner->setColumnWidth(OUTLINER_COLUMN_SUBSCRIBE, subscribedIcon.width + 2 /* for the outliner's shadow */);
  84.     m_outliner->setColumnResizable(OUTLINER_COLUMN_SUBSCRIBE, False);
  85.     
  86.     m_newsgroupForm = XtCreateManagedWidget("newsgroupForm",
  87.                                             xmFormWidgetClass,
  88.                                             m_form,
  89.                                             NULL, 0);
  90.   
  91.     m_newsgroupLabel = XtVaCreateManagedWidget("newsgroupLabel",
  92.                                                xmLabelWidgetClass,
  93.                                                m_newsgroupForm,
  94.                                                XmNleftAttachment, XmATTACH_FORM,
  95.                                                XmNrightAttachment, XmATTACH_NONE,
  96.                                                XmNbottomAttachment, XmATTACH_FORM,
  97.                                                XmNtopAttachment, XmATTACH_FORM,
  98.                                                NULL);
  99.   
  100.     m_newsgroupText = fe_CreateTextField(m_newsgroupForm,
  101.                                          "newsgroupText",
  102.                                          NULL, 0);
  103.     XtVaSetValues(m_newsgroupText,
  104.                   XmNleftAttachment, XmATTACH_WIDGET,
  105.                   XmNleftWidget, m_newsgroupLabel,
  106.                   XmNrightAttachment, XmATTACH_FORM,
  107.                   XmNtopAttachment, XmATTACH_FORM,
  108.                   XmNbottomAttachment, XmATTACH_FORM,
  109.                   NULL);
  110.     XtManageChild(m_newsgroupText);
  111.  
  112.     m_buttonForm = XtCreateManagedWidget("buttonForm",
  113.                                          xmFormWidgetClass,
  114.                                          m_form,
  115.                                          NULL, 0);
  116.  
  117.     m_subscribeButton = XtVaCreateManagedWidget(xfeCmdToggleSubscribe,
  118.                                                 xmPushButtonWidgetClass,
  119.                                                 m_buttonForm,
  120.                                                 XmNleftAttachment, XmATTACH_FORM,
  121.                                                 XmNrightAttachment, XmATTACH_FORM,
  122.                                                 XmNtopAttachment, XmATTACH_FORM,
  123.                                                 XmNbottomAttachment, XmATTACH_NONE,
  124.                                                 NULL);
  125.     m_sep1 = XtVaCreateManagedWidget("sep1",
  126.                                      xmSeparatorWidgetClass,
  127.                                      m_buttonForm,
  128.                                      XmNleftAttachment, XmATTACH_FORM,
  129.                                      XmNrightAttachment, XmATTACH_FORM,
  130.                                      XmNtopAttachment, XmATTACH_WIDGET,
  131.                                      XmNtopWidget, m_subscribeButton,
  132.                                      XmNbottomAttachment, XmATTACH_NONE,
  133.                                      NULL);
  134.  
  135.     m_expandallButton = XtVaCreateManagedWidget(xfeCmdExpandAll,
  136.                                                 xmPushButtonWidgetClass,
  137.                                                 m_buttonForm,
  138.                                                 XmNleftAttachment, XmATTACH_FORM,
  139.                                                 XmNrightAttachment, XmATTACH_FORM,
  140.                                                 XmNtopAttachment, XmATTACH_WIDGET,
  141.                                                 XmNtopWidget, m_sep1,
  142.                                                 XmNbottomAttachment, XmATTACH_NONE,
  143.                                                 NULL);
  144.  
  145.     m_collapseallButton = XtVaCreateManagedWidget(xfeCmdCollapseAll,
  146.                                                   xmPushButtonWidgetClass,
  147.                                                   m_buttonForm,
  148.                                                   XmNleftAttachment, XmATTACH_FORM,
  149.                                                   XmNrightAttachment, XmATTACH_FORM,
  150.                                                   XmNtopAttachment, XmATTACH_WIDGET,
  151.                                                   XmNtopWidget, m_expandallButton,
  152.                                                   XmNbottomAttachment, XmATTACH_NONE,
  153.                                                   NULL);
  154.  
  155.     m_sep2 = XtVaCreateManagedWidget("sep2",
  156.                                      xmSeparatorWidgetClass,
  157.                                      m_buttonForm,
  158.                                      XmNleftAttachment, XmATTACH_FORM,
  159.                                      XmNrightAttachment, XmATTACH_FORM,
  160.                                      XmNtopAttachment, XmATTACH_WIDGET,
  161.                                      XmNtopWidget, m_collapseallButton,
  162.                                      XmNbottomAttachment, XmATTACH_NONE,
  163.                                      NULL);
  164.                  
  165.     m_getdeletionsButton = XtVaCreateManagedWidget(xfeCmdFetchGroupList,
  166.                                                    xmPushButtonWidgetClass,
  167.                                                    m_buttonForm,
  168.                                                    XmNleftAttachment, XmATTACH_FORM,
  169.                                                    XmNrightAttachment, XmATTACH_FORM,
  170.                                                    XmNtopAttachment, XmATTACH_WIDGET,
  171.                                                    XmNtopWidget, m_sep2,
  172.                                                    XmNbottomAttachment, XmATTACH_NONE,
  173.                                                    NULL);
  174.   
  175.     m_stopButton = XtVaCreateManagedWidget(xfeCmdStopLoading,
  176.                                            xmPushButtonWidgetClass,
  177.                                            m_buttonForm,
  178.                                            XmNleftAttachment, XmATTACH_FORM,
  179.                                            XmNrightAttachment, XmATTACH_FORM,
  180.                                            XmNtopAttachment, XmATTACH_WIDGET,
  181.                                            XmNtopWidget, m_getdeletionsButton,
  182.                                            XmNbottomAttachment, XmATTACH_NONE,
  183.                                            NULL);
  184.  
  185.     m_addserverButton = XtVaCreateManagedWidget(xfeCmdAddNewsServer,
  186.                                                 xmPushButtonWidgetClass,
  187.                                                 m_buttonForm,
  188.                                                 XmNleftAttachment, XmATTACH_FORM,
  189.                                                 XmNrightAttachment, XmATTACH_FORM,
  190.                                                 XmNtopAttachment, XmATTACH_NONE,
  191.                                                 XmNbottomAttachment, XmATTACH_FORM,
  192.                                                 NULL);
  193.  
  194.     m_serverForm = XtCreateManagedWidget("serverForm",
  195.                                          xmFormWidgetClass,
  196.                                          m_form,
  197.                                          NULL, 0);
  198.  
  199.     m_serverLabel = XtVaCreateManagedWidget("serverLabel",
  200.                                             xmLabelWidgetClass,
  201.                                             m_serverForm,
  202.                                             XmNleftAttachment, XmATTACH_FORM,
  203.                                             XmNrightAttachment, XmATTACH_NONE,
  204.                                             XmNtopAttachment, XmATTACH_FORM,
  205.                                             XmNbottomAttachment, XmATTACH_FORM,
  206.                                             NULL);
  207.  
  208.     initializeServerCombo(m_serverForm);
  209.     XtVaSetValues(m_serverCombo,
  210.                   XmNleftAttachment, XmATTACH_WIDGET,
  211.                   XmNleftWidget, m_serverLabel,
  212.                   XmNrightAttachment, XmATTACH_FORM,
  213.                   XmNtopAttachment, XmATTACH_FORM,
  214.                   XmNbottomAttachment, XmATTACH_FORM,
  215.                   NULL);
  216.  
  217.     XtVaSetValues(m_buttonForm,
  218.                   XmNleftAttachment, XmATTACH_NONE,
  219.                   XmNrightAttachment, XmATTACH_FORM,
  220.                   XmNtopAttachment, XmATTACH_FORM,
  221.                   XmNbottomAttachment, XmATTACH_FORM,
  222.                   NULL);
  223.  
  224.     XtVaSetValues(m_newsgroupForm,
  225.                   XmNleftAttachment, XmATTACH_FORM,
  226.                   XmNrightAttachment, XmATTACH_WIDGET,
  227.                   XmNrightWidget, m_buttonForm,
  228.                   XmNtopAttachment, XmATTACH_FORM,
  229.                   XmNbottomAttachment, XmATTACH_NONE,
  230.                   NULL);
  231.  
  232.     XtVaSetValues(m_serverForm,
  233.                   XmNleftAttachment, XmATTACH_FORM,
  234.                   XmNrightAttachment, XmATTACH_WIDGET,
  235.                   XmNrightWidget, m_buttonForm,
  236.                   XmNtopAttachment, XmATTACH_NONE,
  237.                   XmNbottomAttachment, XmATTACH_FORM,
  238.                   NULL);
  239.  
  240.     XtVaSetValues(m_outliner->getBaseWidget(),
  241.                   XmNleftAttachment, XmATTACH_FORM,
  242.                   XmNrightAttachment, XmATTACH_WIDGET,
  243.                   XmNrightWidget, m_buttonForm,
  244.                   XmNtopAttachment, XmATTACH_WIDGET,
  245.                   XmNtopWidget, m_newsgroupForm,
  246.                   XmNbottomAttachment, XmATTACH_WIDGET,
  247.                   XmNbottomWidget, m_serverForm,
  248.                   NULL);
  249.  
  250.     XtAddCallback(m_newsgroupText, XmNvalueChangedCallback, newsgroup_typedown_callback, this);
  251.     XtAddCallback(m_subscribeButton, XmNactivateCallback, XFE_SubTabView::button_callback, this);
  252.     XtAddCallback(m_expandallButton, XmNactivateCallback, XFE_SubTabView::button_callback, this);
  253.     XtAddCallback(m_collapseallButton, XmNactivateCallback, XFE_SubTabView::button_callback, this);
  254.     XtAddCallback(m_getdeletionsButton, XmNactivateCallback, XFE_SubTabView::button_callback, this);
  255.     XtAddCallback(m_stopButton, XmNactivateCallback, XFE_SubTabView::button_callback, this);
  256.     XtAddCallback(m_addserverButton, XmNactivateCallback, XFE_SubTabView::button_callback, this);
  257.  
  258.     m_outliner->show();  
  259.  
  260.     // setBaseWidget is done in SubTabView.
  261. }
  262.  
  263. XFE_SubAllView::~XFE_SubAllView()
  264. {
  265. }
  266.  
  267. Boolean
  268. XFE_SubAllView::handlesCommand(CommandType command, void *calldata, XFE_CommandInfo*)
  269. {
  270.     if (command == xfeCmdExpandAll
  271.         || command == xfeCmdCollapseAll
  272.         || command == xfeCmdFetchGroupList
  273.         || command == xfeCmdAddNewsServer)
  274.         {
  275.             return True;
  276.         }
  277.     else
  278.         {
  279.             return XFE_SubTabView::handlesCommand(command, calldata);
  280.         }
  281. }
  282.  
  283. void
  284. XFE_SubAllView::updateButtons()
  285. {
  286. #define S(x) XtSetSensitive((x), isCommandEnabled(Command::intern(XtName((x)))))
  287.     S(m_subscribeButton);
  288.     S(m_expandallButton);
  289.     S(m_collapseallButton);
  290.     S(m_getdeletionsButton);
  291.     S(m_stopButton);
  292. #undef S
  293. }
  294.  
  295. void
  296. XFE_SubAllView::defaultFocus()
  297. {
  298.     XmProcessTraversal(m_newsgroupText, XmTRAVERSE_CURRENT);
  299. }
  300.  
  301. void
  302. XFE_SubAllView::doCommand(CommandType command, void *calldata, XFE_CommandInfo*)
  303. {
  304.     if (command == xfeCmdFetchGroupList)
  305.         m_outliner->deselectAllItems();
  306.     // Then fall through -- MNView maps this cmd to MSG_FetchGroupList.
  307.  
  308.     if (command == xfeCmdAddNewsServer)
  309.         {
  310.             XFE_NewsServerDialog *d = new XFE_NewsServerDialog(getToplevel()->getBaseWidget(),
  311.                                                                "addServer",
  312.                                                                ViewGlue_getFrame(m_contextData));
  313.             XP_Bool ok_pressed = d->post();
  314.  
  315.             if (ok_pressed)
  316.                 {
  317.                     const char *serverName = d->getServer();
  318.                     int serverPort = d->getPort();
  319.                     XP_Bool isSecure = d->isSecure();
  320.                     MSG_NewsHost *newshost;
  321.  
  322.                     newshost = MSG_CreateNewsHost(XFE_MNView::getMaster(),
  323.                                                   serverName,
  324.                                                   isSecure,
  325.                                                   serverPort);
  326.                     MSG_SubscribeSetHost(m_pane,
  327.                                          MSG_GetMSGHostFromNewsHost(newshost));
  328.                     
  329.                     syncServerList();
  330.                     syncServerCombo();
  331.                     
  332.                     serverSelected();
  333.                 }
  334.  
  335.             delete d;
  336.         }
  337.     else
  338.         {
  339.             XFE_SubTabView::doCommand(command, calldata);
  340.         }
  341. }
  342.  
  343. void
  344. XFE_SubAllView::serverSelected()
  345. {
  346.     doCommand(xfeCmdFetchGroupList);
  347.  
  348.     notifyInterested(XFE_View::chromeNeedsUpdating);
  349. }
  350.  
  351. void
  352. XFE_SubAllView::newsgroup_typedown()
  353. {
  354.     MSG_ViewIndex index;
  355.     const char *str;
  356.  
  357.     /* bstell: do we need to fix this ? */
  358.     str = fe_GetTextField(m_newsgroupText);
  359.  
  360.     index = MSG_SubscribeFindFirst(m_pane, str);
  361.  
  362.     XtFree((char*)str);
  363.  
  364.     if (index == MSG_VIEWINDEXNONE)
  365.         {
  366.             m_outliner->deselectAllItems();
  367.         }
  368.     else
  369.         {
  370.             m_outliner->selectItemExclusive(index);
  371.             m_outliner->makeVisible(index);
  372.         }
  373. }
  374.  
  375. void
  376. XFE_SubAllView::newsgroup_typedown_callback(Widget /*w*/,
  377.                                             XtPointer clientData,
  378.                                             XtPointer /*callData*/)
  379. {
  380.     XFE_SubAllView *obj = (XFE_SubAllView*)clientData;
  381.   
  382.     obj->newsgroup_typedown();
  383. }
  384.  
  385. int
  386. XFE_SubAllView::getButtonsMaxWidth()
  387. {
  388.   return XfeVaGetWidestWidget(m_subscribeButton, 
  389.                               m_expandallButton, 
  390.                               m_collapseallButton,
  391.                               m_getdeletionsButton,
  392.                               m_stopButton,
  393.                               m_addserverButton,
  394.                               NULL);
  395. }
  396.  
  397. void
  398. XFE_SubAllView::setButtonsWidth(int width)
  399. {
  400.   Arg args[1];
  401.   
  402.   XtSetArg(args[0], XmNwidth, width);
  403.  
  404.   XtSetValues(m_subscribeButton, args, 1);
  405.   XtSetValues(m_expandallButton, args, 1);
  406.   XtSetValues(m_collapseallButton, args, 1);
  407.   XtSetValues(m_getdeletionsButton, args, 1);
  408.   XtSetValues(m_stopButton, args, 1);
  409.   XtSetValues(m_addserverButton, args, 1);
  410. }
  411.