home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / SubNewView.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  8.4 KB  |  284 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.    SubNewView.cpp -- 4.x subscribe view, new newsgroup tab.
  20.    Created: Chris Toshok <toshok@netscape.com>, 20-Oct-1996.
  21.    */
  22.  
  23.  
  24.  
  25. #include "SubNewView.h"
  26. #include "Outliner.h"
  27. #include "Command.h"
  28.  
  29. #include "xfe.h"
  30. #include "msgcom.h"
  31. #include "xp_mem.h"
  32.  
  33. #include "xpgetstr.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 <Xfe/Xfe.h>
  41.  
  42. #ifdef DEBUG_toshok
  43. #define D(x) x
  44. #else
  45. #define D(x)
  46. #endif
  47.  
  48. extern int XFE_NEW_NEWSGROUP_TAB;
  49. extern int XFE_NEW_NEWSGROUP_TAB_INFO_MSG;
  50.  
  51. #define OUTLINER_GEOMETRY_PREF "mail.subscribepane.new_groups.outliner_geometry"
  52.  
  53. XFE_SubNewView::XFE_SubNewView(XFE_Component *toplevel_component,
  54.                                Widget parent, XFE_View *parent_view,
  55.                                MWContext *context, MSG_Pane *p)
  56.     : XFE_SubTabView(toplevel_component, parent, parent_view, context, XFE_NEW_NEWSGROUP_TAB, p)
  57. {
  58.     int num_columns = 3;
  59.     static int column_widths[] = {40, 3, 9};
  60.     XmString info_label_str;
  61.  
  62.     m_outliner = new XFE_Outliner("subscribeNewList",
  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.     m_outliner->setHideColumnsAllowed( True );
  80.     m_outliner->setMultiSelectAllowed( True );
  81.     m_outliner->setColumnWidth(OUTLINER_COLUMN_SUBSCRIBE, subscribedIcon.width + 2 /* for the outliner's shadow */);
  82.     m_outliner->setColumnResizable(OUTLINER_COLUMN_SUBSCRIBE, False);
  83.   
  84.     m_buttonForm = XtCreateManagedWidget("buttonForm",
  85.                                          xmFormWidgetClass,
  86.                                          m_form,
  87.                                          NULL, 0);
  88.  
  89.     m_subscribeButton = XtVaCreateManagedWidget(xfeCmdToggleSubscribe,
  90.                                                 xmPushButtonWidgetClass,
  91.                                                 m_buttonForm,
  92.                                                 XmNleftAttachment, XmATTACH_FORM,
  93.                                                 XmNrightAttachment, XmATTACH_FORM,
  94.                                                 XmNtopAttachment, XmATTACH_FORM,
  95.                                                 XmNbottomAttachment, XmATTACH_NONE,
  96.                                                 NULL);
  97.     m_sep1 = XtVaCreateManagedWidget("sep1",
  98.                                      xmSeparatorWidgetClass,
  99.                                      m_buttonForm,
  100.                                      XmNleftAttachment, XmATTACH_FORM,
  101.                                      XmNrightAttachment, XmATTACH_FORM,
  102.                                      XmNtopAttachment, XmATTACH_WIDGET,
  103.                                      XmNtopWidget, m_subscribeButton,
  104.                                      XmNbottomAttachment, XmATTACH_NONE,
  105.                                      NULL);
  106.  
  107.     m_getnewButton = XtVaCreateManagedWidget(xfeCmdGetNewGroups,
  108.                                              xmPushButtonWidgetClass,
  109.                                              m_buttonForm,
  110.                                              XmNleftAttachment, XmATTACH_FORM,
  111.                                              XmNrightAttachment, XmATTACH_FORM,
  112.                                              XmNtopAttachment, XmATTACH_WIDGET,
  113.                                              XmNtopWidget, m_sep1,
  114.                                              XmNbottomAttachment, XmATTACH_NONE,
  115.                                              NULL);
  116.  
  117.     m_clearnewButton = XtVaCreateManagedWidget(xfeCmdClearNewGroups,
  118.                                                xmPushButtonWidgetClass,
  119.                                                m_buttonForm,
  120.                                                XmNleftAttachment, XmATTACH_FORM,
  121.                                                XmNrightAttachment, XmATTACH_FORM,
  122.                                                XmNtopAttachment, XmATTACH_WIDGET,
  123.                                                XmNtopWidget, m_getnewButton,
  124.                                                XmNbottomAttachment, XmATTACH_NONE,
  125.                                                NULL);
  126.  
  127.     m_sep2 = XtVaCreateManagedWidget("sep2",
  128.                                      xmSeparatorWidgetClass,
  129.                                      m_buttonForm,
  130.                                      XmNleftAttachment, XmATTACH_FORM,
  131.                                      XmNrightAttachment, XmATTACH_FORM,
  132.                                      XmNtopAttachment, XmATTACH_WIDGET,
  133.                                      XmNtopWidget, m_clearnewButton,
  134.                                      XmNbottomAttachment, XmATTACH_NONE,
  135.                                      NULL);
  136.  
  137.     m_stopButton = XtVaCreateManagedWidget(xfeCmdStopLoading,
  138.                                            xmPushButtonWidgetClass,
  139.                                            m_buttonForm,
  140.                                            XmNleftAttachment, XmATTACH_FORM,
  141.                                            XmNrightAttachment, XmATTACH_FORM,
  142.                                            XmNtopAttachment, XmATTACH_WIDGET,
  143.                                            XmNtopWidget, m_sep2,
  144.                                            XmNbottomAttachment, XmATTACH_NONE,
  145.                                            NULL);
  146.  
  147.     info_label_str = XmStringCreateLtoR(XP_GetString( XFE_NEW_NEWSGROUP_TAB_INFO_MSG ),
  148.                                         XmFONTLIST_DEFAULT_TAG);
  149.  
  150.     m_infoLabel = XtVaCreateManagedWidget("subNewInfoLabel",
  151.                                           xmLabelWidgetClass,
  152.                                           m_form,
  153.                                           XmNlabelString, info_label_str,
  154.                                           NULL);
  155.   
  156.     XmStringFree(info_label_str);
  157.  
  158.     m_serverForm = XtCreateManagedWidget("serverForm",
  159.                                          xmFormWidgetClass,
  160.                                          m_form,
  161.                                          NULL, 0);
  162.  
  163.     m_serverLabel = XtVaCreateManagedWidget("serverLabel",
  164.                                             xmLabelWidgetClass,
  165.                                             m_serverForm,
  166.                                             XmNleftAttachment, XmATTACH_FORM,
  167.                                             XmNrightAttachment, XmATTACH_NONE,
  168.                                             XmNtopAttachment, XmATTACH_FORM,
  169.                                             XmNbottomAttachment, XmATTACH_FORM,
  170.                                             NULL);
  171.  
  172.     initializeServerCombo(m_serverForm);
  173.  
  174.     XtVaSetValues(m_serverCombo,
  175.                   XmNleftAttachment, XmATTACH_WIDGET,
  176.                   XmNleftWidget, m_serverLabel,
  177.                   XmNrightAttachment, XmATTACH_FORM,
  178.                   XmNtopAttachment, XmATTACH_FORM,
  179.                   XmNbottomAttachment, XmATTACH_FORM,
  180.                   NULL);
  181.  
  182.     XtVaSetValues(m_buttonForm,
  183.                   XmNleftAttachment, XmATTACH_NONE,
  184.                   XmNrightAttachment, XmATTACH_FORM,
  185.                   XmNtopAttachment, XmATTACH_FORM,
  186.                   XmNbottomAttachment, XmATTACH_FORM,
  187.                   NULL);
  188.  
  189.     XtVaSetValues(m_serverForm,
  190.                   XmNleftAttachment, XmATTACH_FORM,
  191.                   XmNrightAttachment, XmATTACH_WIDGET,
  192.                   XmNrightWidget, m_buttonForm,
  193.                   XmNtopAttachment, XmATTACH_NONE,
  194.                   XmNbottomAttachment, XmATTACH_FORM,
  195.                   NULL);
  196.  
  197.     XtVaSetValues(m_infoLabel,
  198.                   XmNleftAttachment, XmATTACH_FORM,
  199.                   XmNrightAttachment, XmATTACH_WIDGET,
  200.                   XmNrightWidget, m_buttonForm,
  201.                   XmNtopAttachment, XmATTACH_NONE,
  202.                   XmNbottomAttachment, XmATTACH_WIDGET,
  203.                   XmNbottomWidget, m_serverForm,
  204.                   NULL);
  205.  
  206.     XtVaSetValues(m_outliner->getBaseWidget(),
  207.                   XmNleftAttachment, XmATTACH_FORM,
  208.                   XmNrightAttachment, XmATTACH_WIDGET,
  209.                   XmNrightWidget, m_buttonForm,
  210.                   XmNtopAttachment, XmATTACH_FORM,
  211.                   XmNbottomAttachment, XmATTACH_WIDGET,
  212.                   XmNbottomWidget, m_infoLabel,
  213.                   NULL);
  214.  
  215.     XtAddCallback(m_subscribeButton, XmNactivateCallback, XFE_SubTabView::button_callback, this);
  216.     XtAddCallback(m_getnewButton, XmNactivateCallback, XFE_SubTabView::button_callback, this);
  217.     XtAddCallback(m_clearnewButton, XmNactivateCallback, XFE_SubTabView::button_callback, this);
  218.     XtAddCallback(m_stopButton, XmNactivateCallback, XFE_SubTabView::button_callback, this);
  219.  
  220.     m_outliner->show();  
  221.  
  222.     // setBaseWidget is done in SubTabView.
  223. }
  224.  
  225. XFE_SubNewView::~XFE_SubNewView()
  226. {
  227. }
  228.  
  229. Boolean
  230. XFE_SubNewView::handlesCommand(CommandType command, void *calldata, XFE_CommandInfo*)
  231. {
  232.     if (command == xfeCmdClearNewGroups
  233.         || command == xfeCmdGetNewGroups)
  234.         {
  235.             return True;
  236.         }
  237.     else
  238.         {
  239.             return XFE_SubTabView::handlesCommand(command, calldata);
  240.         }
  241. }
  242.  
  243. void
  244. XFE_SubNewView::updateButtons()
  245. {
  246. #define S(x) XtSetSensitive((x), isCommandEnabled(Command::intern(XtName((x)))))
  247.     S(m_subscribeButton);
  248.     S(m_getnewButton);
  249.     S(m_clearnewButton);
  250.     S(m_stopButton);
  251. #undef S
  252. }
  253.  
  254. void
  255. XFE_SubNewView::serverSelected()
  256. {
  257.     doCommand(xfeCmdGetNewGroups);
  258.  
  259.     notifyInterested(XFE_View::chromeNeedsUpdating);
  260. }
  261.  
  262. int
  263. XFE_SubNewView::getButtonsMaxWidth()
  264. {
  265.   return XfeVaGetWidestWidget(m_subscribeButton, 
  266.                               m_getnewButton,
  267.                               m_clearnewButton,
  268.                               m_stopButton,
  269.                               NULL);
  270. }
  271.  
  272. void
  273. XFE_SubNewView::setButtonsWidth(int width)
  274. {
  275.   Arg args[1];
  276.   
  277.   XtSetArg(args[0], XmNwidth, width);
  278.  
  279.   XtSetValues(m_subscribeButton, args, 1);
  280.   XtSetValues(m_getnewButton, args, 1);
  281.   XtSetValues(m_clearnewButton, args, 1);
  282.   XtSetValues(m_stopButton, args, 1);
  283. }
  284.