home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / MailDownloadFrame.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  11.8 KB  |  449 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.    MailDownloadFrame.cpp -- class definition for the mail download window.
  20.    Created: Chris Toshok <toshok@netscape.com>, 22-Jan-97
  21.  */
  22.  
  23.  
  24.  
  25. #include "MailDownloadFrame.h"
  26. #include "MNView.h"
  27. #include "MozillaApp.h"
  28. #include "Dashboard.h"
  29. #include "Logo.h"
  30.  
  31. #include <Xm/Label.h>
  32. #include <Xm/Form.h>
  33. #include <Xm/PushB.h>
  34.  
  35. #include "xpgetstr.h"
  36.  
  37. extern int XFE_DOWNLOADING_NEW_MESSAGES;
  38. extern int XFE_PURGING_NEWS_MESSAGES;
  39.  
  40. extern "C" {
  41.   void fe_set_scrolled_default_size(MWContext *context);
  42. }
  43.  
  44. #ifdef DEBUG_toshok
  45. #define D(x) x
  46. #else
  47. #define D(x)
  48. #endif
  49.  
  50. const char *XFE_MailDownloadView::pastPasswordCheck = "XFE_MailDownloadView::pastPasswordCheck";
  51. const char *XFE_MailDownloadView::progressDone = "XFE_MailDownloadView::progressDone";
  52.  
  53. XFE_MailDownloadView::XFE_MailDownloadView(XFE_Component *toplevel_component, 
  54.                                            Widget parent, 
  55.                                            XFE_View *parent_view, 
  56.                                            MWContext *context, 
  57.                                            MSG_Pane *parent_pane,
  58.                                            MSG_Pane *p)
  59.     : XFE_MNView(toplevel_component, parent_view, context, p)
  60. {
  61.     Widget form;
  62.     XmString xmstr = XmStringCreate(XP_GetString(XFE_DOWNLOADING_NEW_MESSAGES), XmFONTLIST_DEFAULT_TAG);
  63.     XmFontList fontList;
  64.  
  65.     form = XtCreateWidget("topArea",
  66.                           xmFormWidgetClass,
  67.                           parent,
  68.                           NULL, 0);
  69.  
  70.     m_label = XtVaCreateManagedWidget("label",
  71.                                     xmLabelWidgetClass,
  72.                                     form,
  73.                                     XmNlabelString, xmstr,
  74.                                     NULL);
  75.  
  76.     m_logo = new XFE_Logo((XFE_Frame*)toplevel_component, form, "logo");
  77.  
  78.     XtVaGetValues(m_label,
  79.                   XmNfontList, &fontList,
  80.                   NULL);
  81.  
  82.     // we need more space, or else the window is *tiny*
  83.     XtVaSetValues(m_label,
  84.                   XmNwidth, XmStringWidth(fontList, xmstr) * 2,
  85.                   NULL);
  86.  
  87.     XmStringFree(xmstr);
  88.  
  89.     /* now do the attachments. */
  90.  
  91.     XtVaSetValues(m_label,
  92.                   XmNleftAttachment, XmATTACH_FORM,
  93.                   XmNrightAttachment, XmATTACH_WIDGET,
  94.                   XmNrightWidget, m_logo->getBaseWidget(),
  95.                   XmNtopAttachment, XmATTACH_OPPOSITE_WIDGET,
  96.                   XmNtopWidget, m_logo->getBaseWidget(),
  97.                   XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
  98.                   XmNbottomWidget, m_logo->getBaseWidget(),
  99.                   NULL);
  100.  
  101.     XtVaSetValues(m_logo->getBaseWidget(),
  102.                   XmNleftAttachment, XmATTACH_NONE,
  103.                   XmNrightAttachment, XmATTACH_FORM,
  104.                   XmNbottomAttachment, XmATTACH_NONE,
  105.                   XmNtopAttachment, XmATTACH_FORM,
  106.                   NULL);
  107.  
  108.     m_logo->show();
  109.  
  110.     if (!p)
  111.         setPane(MSG_CreateProgressPane(m_contextData, XFE_MNView::getMaster(), parent_pane));
  112.  
  113.     setBaseWidget(form);
  114. }
  115.  
  116. XFE_MailDownloadView::~XFE_MailDownloadView()
  117. {
  118.     destroyPane();
  119.  
  120.     XFE_MozillaApp::theApp()->notifyInterested(XFE_MNView::MNChromeNeedsUpdating);
  121. }
  122.  
  123. void
  124. XFE_MailDownloadView::startDownload()
  125. {
  126.     XmString xmstr = XmStringCreate(XP_GetString(XFE_DOWNLOADING_NEW_MESSAGES), XmFONTLIST_DEFAULT_TAG);
  127.     XtVaSetValues(m_label, XmNlabelString, xmstr, 0);
  128.     XmStringFree(xmstr);
  129.  
  130.     XFE_MozillaApp::theApp()->notifyInterested(XFE_MNView::MNChromeNeedsUpdating);
  131.     
  132.     MSG_Command (m_pane, MSG_GetNewMail, NULL, 0);
  133. }
  134.  
  135. void
  136. XFE_MailDownloadView::startNewsDownload()
  137. {
  138.     XmString xmstr = XmStringCreate(XP_GetString(XFE_DOWNLOADING_NEW_MESSAGES), XmFONTLIST_DEFAULT_TAG);
  139.     XtVaSetValues(m_label, XmNlabelString, xmstr, 0);
  140.     XmStringFree(xmstr);
  141.  
  142.     XFE_MozillaApp::theApp()->notifyInterested(XFE_MNView::MNChromeNeedsUpdating);
  143.     
  144.     MSG_Command (m_pane, MSG_GetNextChunkMessages, NULL, 0);
  145. }
  146.  
  147. void
  148. XFE_MailDownloadView::cleanUpNews()
  149. {
  150.     // Change the label string, since we're not actually downloading:
  151.     XmString xmstr = XmStringCreate(XP_GetString(XFE_PURGING_NEWS_MESSAGES),
  152.                                     XmFONTLIST_DEFAULT_TAG);
  153.     XtVaSetValues(m_label, XmNlabelString, xmstr, 0);
  154.     XmStringFree(xmstr);
  155.  
  156.     XFE_MozillaApp::theApp()->notifyInterested(XFE_MNView::MNChromeNeedsUpdating);
  157.     
  158.     MSG_CleanupFolders(m_pane);
  159. }
  160.  
  161. void
  162. XFE_MailDownloadView::paneChanged(XP_Bool,
  163.                                   MSG_PANE_CHANGED_NOTIFY_CODE notify_code,
  164.                                   int32)
  165. {
  166.     if (notify_code == MSG_PanePastPasswordCheck)
  167.         {
  168.             D( printf ("Showing maildownload frame.\n");)
  169.             notifyInterested(pastPasswordCheck);
  170.         }
  171.     else if (notify_code == MSG_PaneProgressDone)
  172.         {
  173.             notifyInterested(progressDone);
  174.         }
  175. }
  176.  
  177. XFE_Logo *
  178. XFE_MailDownloadView::getLogo()
  179. {
  180.     return m_logo;
  181. }
  182.  
  183. XFE_MailDownloadFrame::XFE_MailDownloadFrame(Widget            toplevel,
  184.                                              XFE_Frame *    parent_frame,
  185.                                              MSG_Pane *        parent_pane)
  186.     : XFE_Frame("MessageDownload",            // name
  187.                 toplevel,                    // top level
  188.                 parent_frame,                // parent frame
  189.                 FRAME_MAILNEWS_DOWNLOAD,    // frame type
  190.                 NULL,                        // chrome
  191.                 False,                        // have html display
  192.                 False,                        // have menu bar
  193.                 False,                        // have toolbar
  194.                 False,                        // have dashboard (we'll do it)
  195.                 True)                        // destroy on close
  196. {
  197.     Widget form;
  198.  
  199.     XFE_MailDownloadView *v = new XFE_MailDownloadView(this, getViewParent(),
  200.                                                        NULL, m_context, parent_pane);
  201.     XFE_Component *belowView;
  202.  
  203.     m_being_deleted = False;
  204.  
  205.     form = XtVaCreateManagedWidget("stopButtonForm",
  206.                                    xmFormWidgetClass,
  207.                                    getChromeParent(),
  208.                                    XmNfractionBase, 8,
  209.                                    NULL);
  210.  
  211.     m_stopButton = XtVaCreateManagedWidget(xfeCmdStopLoading,
  212.                                            xmPushButtonWidgetClass,
  213.                                            form,
  214.                                            XmNleftAttachment, XmATTACH_POSITION,
  215.                                            XmNleftPosition, 3,
  216.                                            XmNrightAttachment, XmATTACH_POSITION,
  217.                                            XmNrightPosition, 5,
  218.                                            XmNtopAttachment, XmATTACH_NONE,
  219.                                            XmNbottomAttachment, XmATTACH_FORM,
  220.                                            NULL);
  221.  
  222.     XtAddCallback(m_stopButton, XmNactivateCallback, activate_cb, this);
  223.  
  224.     belowView = new XFE_Component(form);
  225.  
  226.     setView(v);
  227.     setBelowViewArea(belowView);
  228.  
  229.     m_dashboard = new XFE_Dashboard(this,                // top level
  230.                                     getChromeParent(),    // parent
  231.                                     this,                // parent frame
  232.                                     False);                // have task bar
  233.  
  234.     m_dashboard->setShowStatusBar(True);
  235.     m_dashboard->setShowProgressBar(True);
  236.  
  237.     v->registerInterest(XFE_MailDownloadView::pastPasswordCheck,
  238.                         this,
  239.                         (XFE_FunctionNotification)pastPassword_cb);
  240.     v->registerInterest(XFE_MailDownloadView::progressDone,
  241.                         this,
  242.                         (XFE_FunctionNotification)progressDone_cb);
  243.  
  244.     fe_set_scrolled_default_size(m_context);
  245.     v->show();
  246.     belowView->show();
  247.     m_dashboard->show();
  248.  
  249.     // Register the logo animation notifications with ourselves
  250.     // We need to do this, cause the XFE_Frame class only does so
  251.     // if the have_toolbars ctor parameter is true and in our case
  252.     // it is not.
  253.     registerInterest(XFE_Frame::logoStartAnimation,
  254.                      this,
  255.                      &XFE_Frame::logoAnimationStartNotice_cb);
  256.     
  257.     registerInterest(XFE_Frame::logoStopAnimation,
  258.                      this,
  259.                      &XFE_Frame::logoAnimationStopNotice_cb);
  260. }
  261.  
  262. XFE_MailDownloadFrame::~XFE_MailDownloadFrame()
  263. {
  264.     // Unregister the logo animation notifications with ourselves
  265.     // We need to do this, cause the XFE_Frame class only does so
  266.     // if the have_toolbars ctor parameter is true and in our case
  267.     // it is not.
  268.     unregisterInterest(XFE_Frame::logoStartAnimation,
  269.                        this,
  270.                        &XFE_Frame::logoAnimationStartNotice_cb);
  271.     
  272.     unregisterInterest(XFE_Frame::logoStopAnimation,
  273.                        this,
  274.                        &XFE_Frame::logoAnimationStopNotice_cb);
  275. }
  276.  
  277. XFE_Logo *
  278. XFE_MailDownloadFrame::getLogo()
  279. {
  280.     XFE_Logo *                logo = NULL;
  281.     XFE_MailDownloadView *    view = (XFE_MailDownloadView *) getView();
  282.     
  283.     if (view)
  284.     {
  285.         logo = view->getLogo();
  286.     }
  287.  
  288.     return logo;
  289. }
  290. //////////////////////////////////////////////////////////////////////////
  291. void
  292. XFE_MailDownloadFrame::configureLogo()
  293. {
  294. }
  295.  
  296. XP_Bool
  297. XFE_MailDownloadFrame::isCommandEnabled(CommandType cmd,
  298.                                         void */*calldata*/, XFE_CommandInfo*)
  299. {
  300.     if (cmd == xfeCmdStopLoading)
  301.         return fe_IsContextStoppable(m_context);
  302.     else
  303.         return False;
  304. }
  305.  
  306. void
  307. XFE_MailDownloadFrame::doCommand(CommandType cmd,
  308.                                  void */*calldata*/, XFE_CommandInfo*)
  309. {
  310.     if (cmd == xfeCmdStopLoading)
  311.         {
  312.             D( printf ("Canceling.\n"); )
  313.             XP_InterruptContext(m_context);
  314.             // allConnectionsComplete will destroy this frame.
  315.         }
  316. }
  317.  
  318. XP_Bool
  319. XFE_MailDownloadFrame::handlesCommand(CommandType cmd,
  320.                                       void */*calldata*/, XFE_CommandInfo*)
  321. {
  322.     if (cmd == xfeCmdStopLoading)
  323.         return True;
  324.     else
  325.         return False;
  326. }
  327.  
  328. void
  329. XFE_MailDownloadFrame::app_delete_response()
  330. {
  331.     D(printf ("In XFE_MailDownloadFrame::app_delete_response()\n");)
  332.     if (!m_being_deleted)
  333.         m_being_deleted = TRUE;
  334.     XFE_Frame::app_delete_response();
  335. }
  336.  
  337. void
  338. XFE_MailDownloadFrame::allConnectionsComplete()
  339. {
  340.     D(printf ("All Connections Complete in mail download frame.\n");)
  341.  
  342.     if (!m_being_deleted)
  343.         app_delete_response();
  344. }
  345.  
  346. void
  347. XFE_MailDownloadFrame::show()
  348. {
  349.     XFE_Frame *active_frame = XFE_Frame::getActiveFrame();
  350.  
  351.     if (active_frame)
  352.         {
  353.             Position x, y;
  354.             Widget parent = active_frame->getBaseWidget();
  355.             Screen *screen = XtScreen(m_widget);
  356.             Dimension screen_width = WidthOfScreen (screen);
  357.             Dimension screen_height = HeightOfScreen (screen);
  358.             Dimension parent_width = 0;
  359.             Dimension parent_height = 0;
  360.             Dimension child_width = 0;
  361.             Dimension child_height = 0;
  362.             
  363.             /* we were already realized in the startDownload function below.
  364.                Being realized is a requirement for some of the stuff we
  365.                have to do here. */
  366.  
  367.             XtVaGetValues(m_widget,
  368.                           XtNwidth, &child_width, XtNheight, &child_height, 0);
  369.             XtVaGetValues (parent,
  370.                            XtNwidth, &parent_width, XtNheight, &parent_height, 0);
  371.  
  372.             x = (((Position)parent_width) - ((Position)child_width)) / 2;
  373.             y = (((Position)parent_height) - ((Position)child_height)) / 2;
  374.             XtTranslateCoords (parent, x, y, &x, &y);
  375.  
  376.             if ((Dimension) (x + child_width) > screen_width)
  377.                 x = screen_width - child_width;
  378.             if (x < 0)
  379.                 x = 0;
  380.             
  381.             if ((Dimension) (y + child_height) > screen_height)
  382.                 y = screen_height - child_height;
  383.             if (y < 0)
  384.                 y = 0;
  385.             
  386.             position(x, y);
  387.         }
  388.  
  389.     XFE_Frame::show();
  390. }
  391.  
  392. void
  393. XFE_MailDownloadFrame::startDownload()
  394. {
  395.     XFE_MailDownloadView *v = (XFE_MailDownloadView*)m_view;
  396.  
  397.     realize();
  398.  
  399.     v->startDownload();
  400. }
  401.  
  402. void
  403. XFE_MailDownloadFrame::startNewsDownload()
  404. {
  405.     XFE_MailDownloadView *v = (XFE_MailDownloadView*)m_view;
  406.  
  407.     realize();
  408.  
  409.     v->startNewsDownload();
  410. }
  411.  
  412. void
  413. XFE_MailDownloadFrame::cleanUpNews()
  414. {
  415.     XFE_MailDownloadView *v = (XFE_MailDownloadView*)m_view;
  416.  
  417.     realize();
  418.     show();
  419.  
  420.     v->cleanUpNews();
  421. }
  422.  
  423. void
  424. XFE_MailDownloadFrame::activate_cb(Widget w, XtPointer clientData, XtPointer)
  425. {
  426.     CommandType cmd = Command::intern(XtName(w));
  427.     XFE_MailDownloadFrame *obj = (XFE_MailDownloadFrame*)clientData;
  428.  
  429.     if (obj->handlesCommand(cmd) && obj->isCommandEnabled(cmd))
  430.         obj->doCommand(cmd);
  431. }
  432.  
  433. XFE_CALLBACK_DEFN(XFE_MailDownloadFrame, pastPassword)(XFE_NotificationCenter*,
  434.                                                        void *,
  435.                                                        void *)
  436. {
  437.     D(printf ("Showing MailDownloadFrame()\n");)
  438.     show();
  439. }
  440.  
  441. XFE_CALLBACK_DEFN(XFE_MailDownloadFrame, progressDone)(XFE_NotificationCenter*,
  442.                                                        void *,
  443.                                                        void *)
  444. {
  445.     D(printf ("Deleting MailDownloadFrame()\n");)
  446.     if (!m_being_deleted)
  447.         app_delete_response();
  448. }
  449.