home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / MNListView.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  7.4 KB  |  285 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.    MNListView.cpp - Mail/News panes that are displayed using an outliner.
  20.    Created: Chris Toshok <toshok@netscape.com>, 25-Aug-96.
  21.  */
  22.  
  23.  
  24.  
  25. #include "MNListView.h"
  26. #include "MozillaApp.h"
  27.  
  28. #include "xpgetstr.h"
  29.  
  30. const char* XFE_MNListView::changeFocus = "XFE_MNListView::changeFocus";
  31.  
  32. extern int XFE_INBOX_DOESNT_EXIST;
  33.  
  34. extern "C" void fe_mailfilter_cb(Widget w, XtPointer closure, XtPointer call_data);
  35.  
  36. XFE_MNListView::XFE_MNListView(XFE_Component *toplevel_component,
  37.                    XFE_View *parent_view, MWContext *context, MSG_Pane *p) 
  38.   : XFE_MNView(toplevel_component, parent_view, context, p)
  39. {
  40.   m_outliner = NULL;
  41. }
  42.  
  43. XFE_MNListView::~XFE_MNListView()
  44. {
  45.   /* nothing to do here either. */
  46. }
  47.  
  48. XFE_Outliner *
  49. XFE_MNListView::getOutliner()
  50. {
  51.   return m_outliner;
  52. }
  53.  
  54. Boolean
  55. XFE_MNListView::handlesCommand(CommandType cmd, void *calldata, XFE_CommandInfo*)
  56. {
  57. #define IS_CMD(command) cmd == (command)
  58.  
  59.   if (IS_CMD(xfeCmdSelectAll)
  60.       || cmd == xfeCmdEditMailFilterRules
  61.       )
  62.     {
  63.       return True;
  64.     }
  65.   else
  66.     {
  67.       return XFE_MNView::handlesCommand(cmd, calldata);
  68.     }
  69. #undef IS_CMD
  70. }
  71.  
  72. Boolean 
  73. XFE_MNListView::isCommandSelected(CommandType cmd, void *calldata, XFE_CommandInfo*)
  74. {
  75.   MSG_CommandType msg_cmd = commandToMsgCmd(cmd);
  76.   XP_Bool selectable = False;
  77.  
  78.   if (handlesCommand(cmd, calldata))
  79.   {
  80.       msg_cmd = commandToMsgCmd(cmd);
  81.  
  82.       if (msg_cmd != (MSG_CommandType)~0)
  83.       {
  84.  
  85.         if ( MSG_GetToggleStatus(m_pane, msg_cmd, NULL, 0 ) == MSG_Checked) 
  86.                     selectable = True;
  87.             return (Boolean)selectable;
  88.       }
  89.   }
  90.   return XFE_MNView::isCommandSelected(cmd, calldata);
  91. }
  92. Boolean
  93. XFE_MNListView::isCommandEnabled(CommandType cmd, void *calldata, XFE_CommandInfo* info)
  94. {
  95. #define IS_CMD(command) cmd == (command)
  96.   MSG_CommandType msg_cmd = commandToMsgCmd(cmd);
  97.   const int *selected;
  98.   int count = 0;
  99.   XP_Bool selectable = False;
  100.  
  101.   m_outliner->getSelection(&selected, &count);
  102.   
  103.   if (msg_cmd != (MSG_CommandType)~0)
  104.     {
  105.         if (IS_CMD(xfeCmdGetNewMessages)) {
  106.             int num_inboxes = MSG_GetFoldersWithFlag(XFE_MNView::getMaster(),
  107.                                                      MSG_FOLDER_FLAG_INBOX,
  108.                                                      NULL, 0);
  109.  
  110.             /* 5.0 will support more than one imap server. 
  111.                There is an inbox per server. Therefore, we
  112.                should not constrain the num_inboxes to be just 1. 
  113.                Otherwise, we will see some button being
  114.                disabled for the wrong reason */  
  115.             if (num_inboxes > 0) 
  116.                 MSG_CommandStatus(m_pane, msg_cmd, 
  117.                                   /* just need some integer pointer here...*/
  118.                                   (MSG_ViewIndex*)&count,
  119.                                   0, &selectable, NULL, NULL, NULL);
  120.         }/* else */
  121.         else if (count == 0 || 
  122.                  (m_pane && MSG_GetNumLines(m_pane) == 0))
  123.             {
  124.                 MSG_CommandStatus(m_pane, msg_cmd, 
  125.                                   /* just need some integer pointer here...*/
  126.                                   (MSG_ViewIndex*)&count,
  127.                                   0, &selectable, NULL, NULL, NULL);
  128.             }
  129.         else
  130.             {
  131.                 MSG_CommandStatus(m_pane, msg_cmd,
  132.                                   (MSG_ViewIndex*)selected, count, 
  133.                                   &selectable, NULL, NULL, NULL);
  134.             }
  135.         return selectable;
  136.       
  137.     }
  138.   else if (IS_CMD(xfeCmdEditMailFilterRules)
  139.        ||IS_CMD(xfeCmdSearch))
  140.     {
  141.       /* Get thread view context
  142.        */
  143.       /* Get mozilla app first
  144.        */
  145.       XFE_MozillaApp *mozilla = theMozillaApp();
  146.  
  147.       /* then FRAME_MAILNEWS_THREAD frame
  148.        */
  149.       XP_List *threadList = mozilla->getFrameList(FRAME_MAILNEWS_THREAD);
  150.       int count; 
  151.       Boolean enabled = True;
  152.       if (threadList && 
  153.       (count=XP_ListCount(threadList))) {
  154.     MWContext *context;
  155.     for (int i=0; i < count; i++) {
  156.       XFE_Frame *frame = (XFE_Frame *) XP_ListGetObjectNum(threadList,
  157.                                    i+1);
  158.       if (frame && (context=frame->getContext())) {
  159.         if (XP_IsContextBusy(context)) {
  160.           /* As long as one thread window is reading messages
  161.            */
  162.           enabled = False;
  163.           break;
  164.         }/* if */
  165.       }/* if */
  166.       
  167.     }/* for i */
  168.       }/* if */
  169.       return enabled;
  170.     }
  171.   else if (IS_CMD(xfeCmdAddNewsgroup)
  172.            || IS_CMD(xfeCmdInviteToNewsgroup)
  173.            )
  174.     {
  175.       return !XP_IsContextBusy(m_contextData);
  176.     }
  177.   else if (IS_CMD(xfeCmdSelectAll))
  178.     {
  179.       return True; // not sure I feel comfortable with such extremes
  180.     }
  181.   else
  182.     {
  183.       return XFE_View::isCommandEnabled(cmd, calldata, info);
  184.     }
  185. #undef IS_CMD
  186. }
  187.  
  188. void
  189. XFE_MNListView::doCommand(CommandType cmd, void *calldata, 
  190.                           XFE_CommandInfo* info)
  191. {
  192. #define IS_CMD(command) cmd == (command)
  193.   if (IS_CMD(xfeCmdSelectAll))
  194.     {
  195.       m_outliner->selectAllItems();
  196.     }
  197.   else if (IS_CMD(xfeCmdEditMailFilterRules))
  198.     {
  199.       fe_mailfilter_cb(getToplevel()->getBaseWidget(), 
  200.                (XtPointer) m_contextData, 
  201.                (XtPointer) NULL);
  202.  
  203.     }
  204.   else
  205.     {
  206.       XFE_MNView::doCommand(cmd, calldata, info);
  207.     }
  208. #undef IS_CMD  
  209. }
  210.  
  211. char*
  212. XFE_MNListView::commandToString(CommandType cmd, void *calldata, XFE_CommandInfo *info)
  213. {
  214. #define IS_CMD(command) cmd == (command)
  215.     MSG_CommandType msg_cmd = commandToMsgCmd(cmd);
  216.     MSG_MotionType msg_nav = commandToMsgNav(cmd);
  217.     const int *selected;
  218.     int count;
  219.     const char *display_string = NULL;
  220.     
  221.     if (!m_outliner)
  222.         return NULL;
  223.     
  224.     m_outliner->getSelection(&selected, &count);
  225.     
  226.     if (msg_cmd != (MSG_CommandType)~0)
  227.         {
  228.             if (IS_CMD(xfeCmdGetNewMessages)) {
  229.                 int num_inboxes = MSG_GetFoldersWithFlag(XFE_MNView::getMaster(),
  230.                                                          MSG_FOLDER_FLAG_INBOX,
  231.                                                          NULL, 0);
  232.                 if (num_inboxes > 0 || 
  233.                     (MSG_CommandStatus(m_pane, msg_cmd, 
  234.                                        (MSG_ViewIndex*)selected, 
  235.                                        count, NULL, NULL, 
  236.                                        (const char **)&display_string, NULL) < 0)) {
  237.                     return NULL;
  238.                 }/* if */
  239.             }/* else */
  240.             else if (MSG_CommandStatus(m_pane, msg_cmd, 
  241.                                        (MSG_ViewIndex*)selected, 
  242.                                        count, NULL, NULL, 
  243.                                        (const char **)&display_string, NULL) < 0)
  244.                 return NULL;
  245.             else
  246.                 {
  247.                     if ( (cmd == xfeCmdComposeMessageHTML ) ||
  248.                          ( cmd == xfeCmdComposeMessagePlain)  ||
  249.                          ( cmd == xfeCmdComposeArticleHTML)  ||
  250.                          ( cmd == xfeCmdComposeArticlePlain) )
  251.                         {
  252.                             return NULL;
  253.                         }
  254.                 }
  255.         }
  256.     else if (msg_nav != (MSG_MotionType)~0)
  257.         {
  258.             if (count < 1
  259.                 || MSG_NavigateStatus(m_pane, msg_nav, 
  260.                                       (MSG_ViewIndex)selected[0],
  261.                                       NULL, (const char **)&display_string) < 0)
  262.                 return NULL;
  263.         }
  264.  
  265.  
  266.     if (display_string)
  267.         return  (char*)display_string;
  268.     else
  269.         return XFE_MNView::commandToString(cmd, calldata, info);
  270. #undef IS_CMD  
  271. }
  272.  
  273.  
  274. void
  275. XFE_MNListView::setInFocus(XP_Bool infocus)
  276. {
  277.     m_outliner->setInFocus(infocus);
  278. }
  279.  
  280. XP_Bool
  281. XFE_MNListView::isFocus()
  282. {
  283.    return m_outliner->isFocus();
  284. }
  285.