home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / SubSearchView.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  9.3 KB  |  345 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.    SubSearchView.h -- 4.x subscribe view, search tab.
  20.    Created: Chris Toshok <toshok@netscape.com>, 18-Oct-1996.
  21.    */
  22.  
  23.  
  24.  
  25. #include "SubSearchView.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 <Xm/Label.h>
  34. #include <Xm/PushB.h>
  35. #include <Xm/TextF.h>
  36. #include "DtWidgets/ComboBox.h"
  37. #include <Xfe/Xfe.h>
  38. #include "felocale.h"
  39.  
  40. #ifdef DEBUG_toshok
  41. #define D(x) x
  42. #else
  43. #define D(x)
  44. #endif
  45.  
  46. extern int XFE_SEARCH_FOR_NEWSGROUP_TAB;
  47.  
  48. #define OUTLINER_GEOMETRY_PREF "mail.subscribepane.search_groups.outliner_geometry"
  49.  
  50. XFE_SubSearchView::XFE_SubSearchView(XFE_Component *toplevel_component, 
  51.                                      Widget parent, XFE_View *parent_view,
  52.                                      MWContext *context, MSG_Pane *p)
  53.     : XFE_SubTabView(toplevel_component, parent, parent_view, context, XFE_SEARCH_FOR_NEWSGROUP_TAB, p)
  54. {
  55.     int num_columns = 3;
  56.     static int column_widths[] = {40, 3, 9};
  57.  
  58.     m_outliner = new XFE_Outliner("subscribeSearchList",
  59.                                   this,
  60.                                   getToplevel(),
  61.                                   m_form,
  62.                                   False, // constantSize
  63.                                   True, //hasHeadings
  64.                                   num_columns,
  65.                                   3,
  66.                                   column_widths,
  67.                                   OUTLINER_GEOMETRY_PREF);
  68.  
  69.     XtVaSetValues(m_outliner->getBaseWidget(),
  70.                   XmNvisibleRows, 15,
  71.                   NULL);
  72.  
  73.     init_outliner_icons(m_outliner->getBaseWidget());
  74.  
  75.     m_outliner->setHideColumnsAllowed( True );
  76.     m_outliner->setMultiSelectAllowed( True );
  77.     m_outliner->setColumnWidth(OUTLINER_COLUMN_SUBSCRIBE, subscribedIcon.width + 2 /* for the outliner's shadow */);
  78.     m_outliner->setColumnResizable(OUTLINER_COLUMN_SUBSCRIBE, False);
  79.  
  80.     m_topForm = XtCreateManagedWidget("topForm",
  81.                                       xmFormWidgetClass,
  82.                                       m_form,
  83.                                       NULL, 0);
  84.  
  85.     m_searchForm = XtCreateManagedWidget("searchForm",
  86.                                          xmFormWidgetClass,
  87.                                          m_topForm,
  88.                                          NULL, 0);
  89.   
  90.     m_searchLabel = XtCreateManagedWidget("searchLabel",
  91.                                           xmLabelWidgetClass,
  92.                                           m_searchForm,
  93.                                           NULL, 0);
  94.  
  95.     m_searchText = fe_CreateTextField(m_searchForm, "searchText", NULL, 0);
  96.     XtManageChild(m_searchText);
  97.  
  98.     m_onserverForm = XtCreateManagedWidget("onserverForm",
  99.                                            xmFormWidgetClass,
  100.                                            m_topForm,
  101.                                            NULL, 0);
  102.  
  103.     m_onserverLabel = XtCreateManagedWidget("onserverLabel",
  104.                                             xmLabelWidgetClass,
  105.                                             m_onserverForm,
  106.                                             NULL, 0);
  107.  
  108.     initializeServerCombo(m_onserverForm);
  109.  
  110.     m_buttonForm = XtCreateManagedWidget("buttonForm",
  111.                                          xmFormWidgetClass,
  112.                                          m_form, NULL, 0);
  113.  
  114.     m_searchnowButton = XtCreateManagedWidget(xfeCmdSearch,
  115.                                               xmPushButtonWidgetClass,
  116.                                               m_buttonForm,
  117.                                               NULL, 0);
  118.  
  119.     m_subscribeButton = XtCreateManagedWidget(xfeCmdToggleSubscribe,
  120.                                               xmPushButtonWidgetClass,
  121.                                               m_buttonForm,
  122.                                               NULL, 0);
  123.  
  124.     m_sep1 = XtVaCreateManagedWidget("sep1",
  125.                                      xmSeparatorWidgetClass,
  126.                                      m_buttonForm,
  127.                                      XmNleftAttachment, XmATTACH_FORM,
  128.                                      XmNrightAttachment, XmATTACH_FORM,
  129.                                      XmNtopAttachment, XmATTACH_WIDGET,
  130.                                      XmNtopWidget, m_subscribeButton,
  131.                                      XmNbottomAttachment, XmATTACH_NONE,
  132.                                      NULL);
  133.     
  134.     m_stopButton = XtVaCreateManagedWidget(xfeCmdStopLoading,
  135.                                            xmPushButtonWidgetClass,
  136.                                            m_buttonForm,
  137.                                            XmNleftAttachment, XmATTACH_FORM,
  138.                                            XmNrightAttachment, XmATTACH_FORM,
  139.                                            XmNtopAttachment, XmATTACH_WIDGET,
  140.                                            XmNtopWidget, m_sep1,
  141.                                            XmNbottomAttachment, XmATTACH_NONE,
  142.                                            NULL);
  143.  
  144.     /* search text stuff. */
  145.     XtVaSetValues(m_searchLabel,
  146.                   XmNleftAttachment, XmATTACH_FORM,
  147.                   XmNrightAttachment, XmATTACH_NONE,
  148.                   XmNtopAttachment, XmATTACH_FORM,
  149.                   XmNbottomAttachment, XmATTACH_FORM,
  150.                   NULL);
  151.  
  152.     XtVaSetValues(m_searchText,
  153.                   XmNleftAttachment, XmATTACH_WIDGET,
  154.                   XmNleftWidget, m_searchLabel,
  155.                   XmNrightAttachment, XmATTACH_FORM,
  156.                   XmNbottomAttachment, XmATTACH_FORM,
  157.                   XmNtopAttachment, XmATTACH_FORM,
  158.                   NULL);
  159.  
  160.     /* server selection stuff. */
  161.     XtVaSetValues(m_onserverLabel,
  162.                   XmNleftAttachment, XmATTACH_FORM,
  163.                   XmNrightAttachment, XmATTACH_NONE,
  164.                   XmNbottomAttachment, XmATTACH_FORM,
  165.                   XmNtopAttachment, XmATTACH_FORM,
  166.                   NULL);
  167.  
  168.     XtVaSetValues(m_serverCombo,
  169.                   XmNleftAttachment, XmATTACH_WIDGET,
  170.                   XmNleftWidget, m_onserverLabel,
  171.                   XmNrightAttachment, XmATTACH_FORM,
  172.                   XmNbottomAttachment, XmATTACH_FORM,
  173.                   XmNtopAttachment, XmATTACH_FORM,
  174.                   NULL);
  175.         
  176.     /* button attachments. */
  177.     XtVaSetValues(m_searchnowButton,
  178.                   XmNleftAttachment, XmATTACH_FORM,
  179.                   XmNrightAttachment, XmATTACH_FORM,
  180.                   XmNtopAttachment, XmATTACH_FORM,
  181.                   XmNbottomAttachment, XmATTACH_NONE,
  182.                   NULL);
  183.  
  184.     XtVaSetValues(m_subscribeButton,
  185.                   XmNleftAttachment, XmATTACH_FORM,
  186.                   XmNrightAttachment, XmATTACH_FORM,
  187.                   XmNtopAttachment, XmATTACH_WIDGET,
  188.                   XmNtopWidget, m_searchnowButton,
  189.                   XmNbottomAttachment, XmATTACH_NONE,
  190.                   NULL);
  191.  
  192.     /* attachments for the forms and outliner */
  193.     XtVaSetValues(m_searchForm,
  194.                   XmNleftAttachment, XmATTACH_FORM,
  195.                   XmNrightAttachment, XmATTACH_FORM,
  196.                   XmNtopAttachment, XmATTACH_FORM,
  197.                   XmNbottomAttachment, XmATTACH_NONE,
  198.                   NULL);
  199.  
  200.     XtVaSetValues(m_onserverForm,
  201.                   XmNleftAttachment, XmATTACH_FORM,
  202.                   XmNrightAttachment, XmATTACH_FORM,
  203.                   XmNtopAttachment, XmATTACH_WIDGET,
  204.                   XmNtopWidget, m_searchForm,
  205.                   XmNbottomAttachment, XmATTACH_FORM,
  206.                   NULL);
  207.  
  208.     XtVaSetValues(m_outliner->getBaseWidget(),
  209.                   XmNleftAttachment, XmATTACH_FORM,
  210.                   XmNrightAttachment, XmATTACH_WIDGET,
  211.                   XmNrightWidget, m_buttonForm,
  212.                   XmNtopAttachment, XmATTACH_WIDGET,
  213.                   XmNtopWidget, m_topForm,
  214.                   XmNbottomAttachment, XmATTACH_FORM,
  215.                   NULL);
  216.  
  217.     XtVaSetValues(m_topForm,
  218.                   XmNleftAttachment, XmATTACH_FORM,
  219.                   XmNrightAttachment, XmATTACH_WIDGET,
  220.                   XmNrightWidget, m_buttonForm,
  221.                   XmNtopAttachment, XmATTACH_FORM,
  222.                   XmNbottomAttachment, XmATTACH_NONE,
  223.                   NULL);
  224.  
  225.     XtVaSetValues(m_buttonForm,
  226.                   XmNleftAttachment, XmATTACH_NONE,
  227.                   XmNrightAttachment, XmATTACH_FORM,
  228.                   XmNbottomAttachment, XmATTACH_FORM,
  229.                   XmNtopAttachment, XmATTACH_FORM,
  230.                   NULL);
  231.  
  232.  
  233.  
  234.     XtAddCallback(m_subscribeButton, XmNactivateCallback, button_callback, this);
  235.     XtAddCallback(m_searchnowButton, XmNactivateCallback, button_callback, this);
  236.     XtAddCallback(m_searchText, XmNactivateCallback, search_activate_callback, this);
  237.  
  238.     m_outliner->show();  
  239.  
  240.     // setBaseWidget happens in SubTabView.
  241. }
  242.  
  243. XFE_SubSearchView::~XFE_SubSearchView()
  244. {
  245. }
  246.  
  247. Boolean
  248. XFE_SubSearchView::handlesCommand(CommandType command, void *calldata, XFE_CommandInfo*)
  249. {
  250.     if (command == xfeCmdSearch)
  251.         {
  252.             return True;
  253.         }
  254.     else
  255.         {
  256.             return XFE_SubTabView::handlesCommand(command, calldata);
  257.         }
  258. }
  259.  
  260. Boolean
  261. XFE_SubSearchView::isCommandEnabled(CommandType command, void *calldata, XFE_CommandInfo*)
  262. {
  263.     if (command == xfeCmdSearch)
  264.         {
  265.             return !XP_IsContextBusy(MSG_GetContext(m_pane));
  266.         }
  267.     else
  268.         {
  269.             return XFE_SubTabView::isCommandEnabled(command, calldata);
  270.         }
  271. }
  272.  
  273. void
  274. XFE_SubSearchView::defaultFocus()
  275. {
  276.     XmProcessTraversal(m_searchText, XmTRAVERSE_CURRENT);
  277. }
  278.  
  279. void
  280. XFE_SubSearchView::doCommand(CommandType command, void *calldata, XFE_CommandInfo*)
  281. {
  282.     if (command == xfeCmdSearch)
  283.         {
  284.             /* bstell: do we need to fix this ? */
  285.             const char *str = fe_GetTextField(m_searchText);
  286.  
  287.             MSG_SubscribeFindAll(m_pane, str);
  288.  
  289.             XtFree((char*)str);
  290.         }
  291.     else
  292.         {
  293.             XFE_SubTabView::doCommand(command, calldata);
  294.         }
  295. }
  296.  
  297. void
  298. XFE_SubSearchView::updateButtons()
  299. {
  300. #define S(x) XtSetSensitive((x), isCommandEnabled(Command::intern(XtName((x)))))
  301.     S(m_searchnowButton);
  302.     S(m_subscribeButton);
  303.     S(m_stopButton);
  304. #undef S
  305. }
  306.  
  307. void
  308. XFE_SubSearchView::serverSelected()
  309. {
  310.     doCommand(xfeCmdSearch);
  311.  
  312.     notifyInterested(XFE_View::chromeNeedsUpdating);
  313. }
  314.  
  315. void
  316. XFE_SubSearchView::search_activate_callback(Widget /*w*/,
  317.                                             XtPointer clientData,
  318.                                             XtPointer /*calldata*/)
  319. {
  320.     XFE_SubSearchView *obj = (XFE_SubSearchView*)clientData;
  321.  
  322.     obj->doCommand(xfeCmdSearch);
  323. }
  324.  
  325. int
  326. XFE_SubSearchView::getButtonsMaxWidth()
  327. {
  328.   return XfeVaGetWidestWidget(m_subscribeButton, 
  329.                               m_searchnowButton,
  330.                               m_stopButton,
  331.                               NULL);
  332. }
  333.  
  334. void
  335. XFE_SubSearchView::setButtonsWidth(int width)
  336. {
  337.   Arg args[1];
  338.   
  339.   XtSetArg(args[0], XmNwidth, width);
  340.  
  341.   XtSetValues(m_subscribeButton, args, 1);
  342.   XtSetValues(m_searchnowButton, args, 1);
  343.   XtSetValues(m_stopButton, args, 1);
  344. }
  345.