home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / SubscribeDialog.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  7.5 KB  |  273 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.    SubscribeDialog.cpp -- 4.x Subscribe UI dialog.
  20.    Created: Chris Toshok <toshok@netscape.com>, 16-Oct-96.
  21.  */
  22.  
  23.  
  24.  
  25. #include "SubscribeDialog.h"
  26. #include "SubscribeView.h"
  27. #include "ViewGlue.h"
  28. #include "msgcom.h"
  29.  
  30. static Widget create_chrome_widget(Widget   parent, char    *name,
  31.                                    Boolean  ok, Boolean  cancel,
  32.                                    Boolean  help, Boolean  apply,
  33.                                    Boolean  separator, Boolean  modal);
  34.  
  35. static XFE_SubscribeDialog *theDialog;
  36.  
  37. XFE_SubscribeDialog::XFE_SubscribeDialog(char *name, XFE_NotificationCenter *toplevel,
  38.                                          Widget parent, MWContext *context, MSG_Host *host)
  39.     : XFE_ViewDialog(NULL, parent, name,
  40.                      context,
  41.                      FALSE, // ok
  42.                      FALSE, // cancel
  43.                      FALSE, // help
  44.                      FALSE, // apply
  45.                      FALSE, // separator
  46.                      FALSE, // modal
  47.                      create_chrome_widget(parent,
  48.                                           name, TRUE, TRUE, FALSE, FALSE, FALSE, TRUE))
  49. {
  50.     XFE_SubscribeView *subscribeview;
  51.     Widget button_area;
  52.  
  53.     m_okToDestroy = FALSE;
  54.  
  55.     m_toplevelNotifier = toplevel;
  56.  
  57.     m_dashboard = new XFE_Dashboard(this,
  58.                                     m_chrome,
  59.                                     NULL,   // XFE_Frame
  60.                                     False     /* taskbar */);
  61.  
  62.     m_dashboard->setShowStatusBar(True);
  63.     m_dashboard->setShowProgressBar(True);
  64.  
  65.     subscribeview = new XFE_SubscribeView(this, m_chrome, NULL, m_context, host);
  66.  
  67.     button_area = createButtonArea(m_chrome, TRUE, TRUE, FALSE, FALSE);
  68.  
  69.     XtVaSetValues(m_dashboard->getBaseWidget(),
  70.                   XmNleftAttachment, XmATTACH_FORM,
  71.                   XmNrightAttachment, XmATTACH_FORM,
  72.                   XmNtopAttachment, XmATTACH_NONE,
  73.                   XmNbottomAttachment, XmATTACH_FORM,
  74.                   NULL);
  75.  
  76.     XtVaSetValues(button_area,
  77.                   XmNleftAttachment, XmATTACH_FORM,
  78.                   XmNrightAttachment, XmATTACH_FORM,
  79.                   XmNtopAttachment, XmATTACH_NONE,
  80.                   XmNbottomAttachment, XmATTACH_WIDGET,
  81.                   XmNbottomWidget, m_dashboard->getBaseWidget(),
  82.                   XmNmarginWidth, 0,
  83.                   XmNmarginHeight, 0,
  84.                   NULL);
  85.                   
  86.     XtVaSetValues(subscribeview->getBaseWidget(),
  87.                   XmNleftAttachment, XmATTACH_FORM,
  88.                   XmNleftOffset, 3,
  89.                   XmNrightAttachment, XmATTACH_FORM,
  90.                   XmNrightOffset, 3,
  91.                   XmNtopAttachment, XmATTACH_FORM,
  92.                   XmNtopOffset, 3,
  93.                   XmNbottomAttachment, XmATTACH_WIDGET,
  94.                   XmNbottomWidget, button_area,
  95.                   NULL);
  96.  
  97.     XtManageChild(button_area);
  98.     m_dashboard->show();
  99.     subscribeview->show();
  100.  
  101.     setView(subscribeview);
  102. }
  103.  
  104. XFE_SubscribeDialog::~XFE_SubscribeDialog()
  105. {
  106.     unregisterInterest(XFE_Frame::frameNotBusyCallback,
  107.                        m_toplevelNotifier,
  108.                        (XFE_FunctionNotification)XFE_Frame::updateBusyState_cb,
  109.                        (void*)False);
  110.  
  111.     // Resotore the original notifier
  112.     m_toplevelNotifier->setForwarder(m_oldForwarder);
  113.  
  114.     theDialog = NULL;
  115. }
  116.  
  117. void
  118. XFE_SubscribeDialog::show()
  119. {
  120.     XFE_ViewDialog::show();
  121.  
  122.     // Save the old notifier
  123.     m_oldForwarder = m_toplevelNotifier->getForwarder();
  124.  
  125.     // Set up the forwarder
  126.     m_toplevelNotifier->setForwarder(this);
  127.  
  128.     registerInterest(XFE_Frame::frameNotBusyCallback,
  129.                      m_toplevelNotifier,
  130.                      (XFE_FunctionNotification)XFE_Frame::updateBusyState_cb,
  131.                      (void*)False);
  132. }
  133.  
  134. Widget
  135. XFE_SubscribeDialog::createButtonArea(Widget parent,
  136.                                       Boolean ok, Boolean cancel,
  137.                                       Boolean help, Boolean /*apply*/)
  138. {
  139.   Widget msgb;
  140.   Widget button;
  141.  
  142.   msgb = XmCreateMessageBox(parent, "messagebox", NULL, 0);
  143.  
  144.   /* We have to do this explicitly because of AIX versions come
  145.      with these buttons by default */
  146.   fe_UnmanageChild_safe(XmMessageBoxGetChild(msgb, XmDIALOG_SEPARATOR));
  147.   if (!ok)
  148.     fe_UnmanageChild_safe(XmMessageBoxGetChild(msgb, XmDIALOG_OK_BUTTON));
  149.   else
  150.     {
  151.       button = XmMessageBoxGetChild(msgb, XmDIALOG_OK_BUTTON);
  152.  
  153.       if (button)
  154.         {
  155.           XtManageChild(button);
  156.           XtAddCallback(msgb, XmNokCallback, ok_cb, this);
  157.         }
  158.     }
  159.   if (!cancel)
  160.     fe_UnmanageChild_safe(XmMessageBoxGetChild(msgb, XmDIALOG_CANCEL_BUTTON));
  161.   else
  162.     {
  163.       button = XmMessageBoxGetChild(msgb, XmDIALOG_CANCEL_BUTTON);
  164.  
  165.       if (button)
  166.         {
  167.           XtManageChild(button);
  168.           XtAddCallback(msgb, XmNcancelCallback, cancel_cb, this);
  169.         }
  170.     }
  171.  
  172.   if (!help)
  173.     fe_UnmanageChild_safe(XmMessageBoxGetChild(msgb, XmDIALOG_HELP_BUTTON));
  174.   else
  175.     {
  176.       button = XmMessageBoxGetChild(msgb, XmDIALOG_HELP_BUTTON);
  177.  
  178.       if (button)
  179.         {
  180.           XtManageChild(button);
  181.           XtAddCallback(msgb, XmNhelpCallback, help_cb, this);
  182.         }
  183.     }
  184.  
  185.   return msgb;
  186. }
  187.  
  188. static Widget
  189. create_chrome_widget(Widget   parent,    
  190.                      char    *name,
  191.                      Boolean /* ok */,
  192.                      Boolean /* cancel */,
  193.                      Boolean /* help */,
  194.                      Boolean /* apply */,
  195.                      Boolean /* separator */,
  196.                      Boolean  modal)
  197. {
  198.     Visual   *v = 0;
  199.     Colormap  cmap = 0;
  200.     Cardinal  depth = 0;
  201.     Arg       av[20];
  202.     int       ac;
  203.     Widget chrome;
  204.  
  205.     XtVaGetValues (parent, 
  206.                    XtNvisual, &v, 
  207.                    XtNcolormap, &cmap,
  208.                    XtNdepth, &depth,
  209.                    0);
  210.  
  211.     ac = 0;
  212.     XtSetArg (av[ac], XmNvisual, v); ac++;
  213.     XtSetArg (av[ac], XmNdepth, depth); ac++;
  214.     XtSetArg (av[ac], XmNcolormap, cmap); ac++;
  215.     XtSetArg (av[ac], XmNallowShellResize, TRUE); ac++;
  216.     XtSetArg (av[ac], XmNtransientFor, parent); ac++;
  217.     if (modal) {
  218.         XtSetArg (av[ac], XmNdialogStyle, XmDIALOG_PRIMARY_APPLICATION_MODAL); ac++;
  219.     }
  220.     XtSetArg (av[ac], XmNdeleteResponse, XmDESTROY); ac++;
  221.     XtSetArg (av[ac], XmNautoUnmanage, False); ac++;
  222.  
  223.     chrome = XmCreateFormDialog(parent, name, av, ac);
  224.  
  225.     return chrome;
  226. }
  227.  
  228. void
  229. XFE_SubscribeDialog::ok()
  230. {
  231.     registerInterest(XFE_Frame::allConnectionsCompleteCallback,
  232.                      this,
  233.                      (XFE_FunctionNotification)allConnectionsComplete_cb);
  234.     XFE_ViewDialog::ok();
  235. }
  236.  
  237. void
  238. fe_showSubscribeDialog(XFE_NotificationCenter *toplevel,
  239.                        Widget parent,
  240.                        MWContext *context,
  241.                        MSG_Host *host)
  242. {
  243.     // The widget tree gets destroyed by ViewDialog's ok_cb and cancel_cb,
  244.     // so we'd better start over if we've shown the dialog before:
  245.     if (theDialog)
  246.         delete theDialog;
  247.  
  248.     theDialog = new XFE_SubscribeDialog("SubscribeDialog", 
  249.                                         toplevel, parent,
  250.                                         context,
  251.                                         host);
  252.     theDialog->show();
  253. }
  254.  
  255. // Tells the FEs to bring up the subscribe UI on the given news or imap host.
  256. XP_Bool FE_CreateSubscribePaneOnHost(MSG_Master* /*master*/,
  257.                                      MWContext* parentContext,
  258.                                      MSG_Host* host)
  259. {
  260.     XFE_Component* toplevel = ViewGlue_getFrame(parentContext)->getToplevel();
  261.     fe_showSubscribeDialog(toplevel, toplevel->getBaseWidget(),
  262.                            parentContext, host);
  263.     return True;
  264. }
  265.  
  266. XFE_CALLBACK_DEFN(XFE_SubscribeDialog, allConnectionsComplete)(XFE_NotificationCenter *,
  267.                                                           void *,
  268.                                                           void *)
  269. {
  270.     hide();
  271. }
  272.  
  273.