home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / ComposeFolderView.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  14.3 KB  |  487 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.    ComposeFolderView.cpp -- presents view for addressing and attachment .
  20.    Created: Dora Hsu <dora@netscape.com>, 23-Sept-96.
  21.    */
  22.  
  23.  
  24.  
  25. #include "ComposeView.h"
  26. #include "ComposeFolderView.h"
  27. #include "AddressFolderView.h"
  28. #include "ComposeAttachFolderView.h"
  29. #include "AddressOutliner.h"
  30. #include "xfe.h"
  31. #include "IconGroup.h"
  32. #include "xp_mem.h"
  33. #include <xpgetstr.h> /* for XP_GetString() */
  34.  
  35. #include <Xm/Xm.h>
  36. #include <Xm/Frame.h>
  37. #include <XmL/XmL.h>
  38. #include <Xm/DrawnB.h>
  39. #include <Xm/ArrowB.h>
  40. #include <Xm/LabelG.h>
  41. #include <XmL/Folder.h>
  42. #include <Xfe/Button.h>
  43.  
  44. extern int XFE_MNC_ADDRESS;
  45. extern int XFE_MNC_ATTACHMENT;
  46. extern int XFE_MNC_OPTION;
  47.  
  48. #ifdef DEBUG_dora
  49. #define XDEBUG(x) x
  50. #else
  51. #define XDEBUG(x)
  52. #endif
  53.  
  54. extern "C" {
  55.   Widget fe_EditorCreateComposeToolbar(MWContext*, Widget, char*);
  56. }
  57.  
  58. extern "C" 
  59. Widget fe_MailComposeWin_Create(MWContext* context, Widget parent);
  60.  
  61. extern "C" Widget
  62. fe_MailComposeAddress_CreateManaged(MWContext* context, Widget parent);
  63.  
  64. extern "C" Widget
  65. fe_MailComposeAttach_CreateManaged(MWContext* context, Widget parent);
  66.  
  67. extern "C" Widget 
  68. makeOptionMenu(MWContext *context, Widget parent);
  69.  
  70.  
  71. Boolean
  72. XFE_ComposeFolderView::isPrioritySelected(MSG_PRIORITY priority)
  73. {
  74.         return m_optionFolderViewAlias->isPrioritySelected(priority);
  75. }
  76.  
  77. void
  78. XFE_ComposeFolderView::selectPriority(MSG_PRIORITY priority)
  79. {
  80.   m_optionFolderViewAlias->selectPriority(priority);
  81. }
  82.  
  83.  
  84. /* Constructor */
  85. XFE_ComposeFolderView::XFE_ComposeFolderView(
  86.             XFE_Component *toplevel_component,
  87.             XFE_View *parent_view,
  88.             MSG_Pane *p,
  89.             MWContext *context) 
  90.   : XFE_MNView(toplevel_component, parent_view, context, p)
  91. {
  92.   //XP_ASSERT(p==NULL);
  93.  
  94.   setParent(parent_view);
  95.   /* Create Widgets */
  96.  
  97.   // Initialize necessary data
  98.   m_addressFormW = 0;
  99.   m_attachFormW = 0;
  100.   m_optionFormW = 0;
  101.   m_frameW = 0;
  102.   m_optionW = 0;
  103.  
  104.  // m_expanded = True;
  105.   m_tabNumber = 0;
  106.   m_selectedPriority = MSG_NormalPriority;
  107.   m_attachFolderViewAlias = NULL;
  108.   m_addressFolderViewAlias = NULL;
  109. }
  110.  
  111. XP_Bool
  112. XFE_ComposeFolderView::isCommandSelected(CommandType command,
  113.                                          void* calldata,
  114.                                          XFE_CommandInfo* info)
  115. {
  116.   if ((command == xfeCmdViewAddresses)
  117.       || (command == xfeCmdViewOptions)
  118.       || (command == xfeCmdViewAttachments)) {
  119.  
  120.       int tab_number;
  121.  
  122.       XtVaGetValues(m_tabGroupW, XmNactiveTab, &tab_number, 0);
  123.  
  124.       if (command == xfeCmdViewAddresses)
  125.           return (tab_number == 0);
  126.       else if (command == xfeCmdViewAttachments)
  127.           return (tab_number == 1);
  128.       else // if (command == xfeCmdViewOptions)
  129.           return (tab_number == 2);
  130.  
  131.   } else {
  132.       return XFE_MNView::isCommandSelected(command, calldata, info);
  133.   }
  134. }
  135.  
  136. Boolean
  137. XFE_ComposeFolderView::isCommandEnabled(CommandType command,
  138.                                         void *, XFE_CommandInfo* )
  139. {
  140.   if ((command == xfeCmdViewAddresses)
  141.     ||  (command == xfeCmdViewOptions)
  142.         || (command == xfeCmdViewAttachments))
  143.      return True;
  144.   else if (m_addressFolderViewAlias &&
  145.       m_addressFolderViewAlias->isCommandEnabled(command))
  146.     return True;
  147.   else if ( m_attachFolderViewAlias &&
  148.      m_attachFolderViewAlias->isCommandEnabled(command))
  149.     return True;
  150.  
  151.   return False;
  152. }
  153.  
  154. Boolean
  155. XFE_ComposeFolderView::handlesCommand(CommandType command,
  156.                                       void *, XFE_CommandInfo*)
  157. {
  158. XDEBUG(    printf ("in XFE_ComposeFolderView::handlesCommand(%s)\n", Command::getString(command));)
  159.   if ((command == xfeCmdViewAddresses)
  160.     || (command == xfeCmdViewOptions)
  161.         || (command == xfeCmdViewAttachments))
  162.      return True;
  163.   else if (m_addressFolderViewAlias && 
  164.     m_addressFolderViewAlias->handlesCommand(command))
  165.     return True;
  166.   else if ( m_attachFolderViewAlias &&
  167.       m_attachFolderViewAlias->handlesCommand(command))
  168.     return True;
  169.  
  170. XDEBUG(    printf ("leaving XFE_ComposeFolderView::handlesCommand(%s), Command::getString(command)\n");)
  171.   return False;
  172. }
  173.  
  174. void
  175. XFE_ComposeFolderView::doCommand(CommandType command,
  176.                                  void *, XFE_CommandInfo* )
  177. {
  178.   if (command == xfeCmdViewAddresses)
  179.     {
  180.       XDEBUG(    printf ("XFE_ComposeFolderView::xfeCmdViewAddresses()\n");)
  181.       XmLFolderSetActiveTab(m_tabGroupW, 0, True);
  182.     }
  183.   else if (command == xfeCmdViewAttachments)
  184.     {
  185.       XDEBUG(    printf ("XFE_ComposeFolderView::xfeCmdViewAttachments()\n");)
  186.       XmLFolderSetActiveTab(m_tabGroupW, 1, True);
  187.     }
  188.   else if (command == xfeCmdViewOptions)
  189.     {
  190.       XDEBUG(    printf ("XFE_ComposeFolderView::xfeCmdViewOptions()\n");)
  191.       XmLFolderSetActiveTab(m_tabGroupW, 2, True);
  192.     }
  193.   else if ( command == xfeCmdAttachFile)
  194.     {
  195.        if (m_attachFolderViewAlias)
  196.        m_attachFolderViewAlias->doCommand(command);
  197.     }
  198.   else if ( command == xfeCmdAttachWebPage )
  199.     {
  200.        if (m_attachFolderViewAlias)
  201.        m_attachFolderViewAlias->doCommand(command);
  202.     }
  203.   else if ( command == xfeCmdDeleteAttachment )
  204.     {
  205.        if (m_attachFolderViewAlias)
  206.        m_attachFolderViewAlias->doCommand(command);
  207.     }
  208.   else if ( command == xfeCmdDelete )
  209.     {
  210.        if (m_attachFolderViewAlias)
  211.        m_attachFolderViewAlias->doCommand(command);
  212.     }
  213.   else if ( command == xfeCmdAddresseePicker )
  214.     {
  215.         if (m_addressFolderViewAlias)
  216.             m_addressFolderViewAlias->doCommand(command);
  217.     }
  218.  
  219. XDEBUG(    printf ("leaving XFE_ComposeFolderView::doCommand()\n");)
  220. }
  221.  
  222. // called when any compose folder tab is pressed
  223. void
  224. XFE_ComposeFolderView::folderActivate(int tabPosition)
  225. {
  226.     // ASSUMPTION: Tab #1 is 'Attachments'
  227.     // Allow Attach folder to track its state
  228.     if (m_attachFolderViewAlias) {
  229.         m_attachFolderViewAlias->folderVisible(tabPosition==1 ? TRUE : FALSE);
  230.     }
  231.     else if ( tabPosition == 2 ) // ASSUMPTION: Tab #2 is 'Options'
  232.     {
  233.     if (m_optionFolderViewAlias)
  234.         m_optionFolderViewAlias->updateAllOptions();
  235.     }
  236. }
  237.  
  238.  
  239. void
  240. XFE_ComposeFolderView::createWidgets(Widget parent_widget, XP_Bool /*usePlainText*/)
  241. {
  242.  
  243.    XmString str;
  244.    Widget formBaseW;
  245.  
  246.   XDEBUG( printf("enter XFE_ComposeFolderView::createWidgets()\n");)
  247.    
  248.    Visual *v =0;
  249.    Colormap cmap = 0;
  250.    Cardinal depth = 0;
  251.  
  252.    XtVaGetValues(getToplevel()->getBaseWidget(),
  253.     XmNvisual, &v,
  254.     XmNcolormap, &cmap,
  255.     XmNdepth, &depth, 0);
  256.  
  257.    formBaseW = XtVaCreateManagedWidget("addressBaseForm",
  258.                 xmFormWidgetClass, parent_widget, 
  259.                 XmNcolormap, cmap,
  260.                 XmNdepth, depth,
  261.                 XmNvisual, v, 0);
  262.  
  263.    setBaseWidget(formBaseW);
  264.    setupIcons(); //- don't do icon for now
  265.    
  266.  
  267.    {
  268.  
  269.    m_frameW = XtVaCreateManagedWidget("newAddressFrame",
  270.             xmFrameWidgetClass, formBaseW, 
  271.             XmNshadowType, XmSHADOW_IN, 
  272.             XmNtopAttachment, XmATTACH_FORM,
  273.             XmNbottomAttachment, XmATTACH_FORM,
  274.             XmNleftAttachment, XmATTACH_FORM,
  275.             XmNrightAttachment, XmATTACH_FORM, 
  276.                 XmNcolormap, cmap,
  277.                 XmNdepth, depth,
  278.                 XmNvisual, v, 0);
  279.  
  280.    m_tabGroupW =  XtVaCreateWidget("newComposeFolder",
  281.                           xmlFolderWidgetClass,
  282.                           m_frameW, 
  283.             XmNcolormap, cmap,
  284.             XmNtabPlacement, XmFOLDER_LEFT,
  285.             XmNtabWidgetClass, xfeButtonWidgetClass,
  286.                                 XmNdepth, depth,
  287.                                 XmNvisual, v, 0);
  288.    XtAddCallback(m_tabGroupW,XmNactivateCallback,folderActivateCallback,(XtPointer)this);
  289.  
  290.    XtManageChild(m_tabGroupW);
  291.  
  292.    Pixel bg;
  293.    XtVaGetValues(m_tabGroupW, XmNbackground, &bg, 0);
  294.  
  295.    str = XmStringCreateSimple(XP_GetString(XFE_MNC_ADDRESS));
  296.    Widget m_addressTab = XmLFolderAddTabFromClass(m_tabGroupW, str);
  297.    XtVaSetValues(m_addressTab, XmNbuttonLayout, XmBUTTON_PIXMAP_ONLY,
  298.         XmNpixmap,  MNC_AddressSmall_group.pixmap_icon.pixmap,
  299.      NULL);
  300.    XmStringFree(str);
  301.  
  302.    m_addressFormW = XtVaCreateManagedWidget("form_addr",
  303.                                  xmFormWidgetClass, m_tabGroupW,
  304.                                  XmNbackground, bg ,
  305.                                  NULL);
  306.  
  307.    XtVaSetValues(m_addressTab, XmNtabManagedWidget, m_addressFormW, NULL);
  308.  
  309.    str = XmStringCreateSimple(XP_GetString(XFE_MNC_ATTACHMENT));
  310.    //m_attachFormW = XmLFolderAddTabForm(m_tabGroupW, str);
  311.    Widget m_attachTab = XmLFolderAddTabFromClass(m_tabGroupW, str);
  312.    XtVaSetValues(m_attachTab, XmNbuttonLayout, XmBUTTON_PIXMAP_ONLY,
  313.         XmNpixmap,  MNC_AttachSmall_group.pixmap_icon.pixmap, NULL);
  314.    XmStringFree(str);
  315.    m_attachFormW = XtVaCreateManagedWidget("form_attach",
  316.                                  xmFormWidgetClass, m_tabGroupW,
  317.                                  XmNbackground, bg,
  318.                                  NULL);
  319.  
  320.    XtVaSetValues(m_attachTab, XmNtabManagedWidget, m_attachFormW, NULL);
  321.  
  322.  
  323.    str = XmStringCreateSimple(XP_GetString(XFE_MNC_OPTION));
  324.    //m_optionFormW = XmLFolderAddTabForm(m_tabGroupW, str);
  325.    Widget m_optionTab = XmLFolderAddTabFromClass(m_tabGroupW, str);
  326.    XtVaSetValues(m_optionTab, XmNbuttonLayout, XmBUTTON_PIXMAP_ONLY,
  327.         XmNpixmap,  MNC_Options_group.pixmap_icon.pixmap, NULL);
  328.    XmStringFree(str);
  329.    m_optionFormW = XtVaCreateManagedWidget("form_attach",
  330.                        xmFormWidgetClass, m_tabGroupW,
  331.                         XmNbackground, bg,
  332.                         NULL);
  333.  
  334.    XtVaSetValues(m_optionTab, XmNtabManagedWidget, m_optionFormW, NULL);
  335.  
  336.    { // Addressing Folder
  337.      XFE_AddressFolderView *addressFolderView = 
  338.          new XFE_AddressFolderView( getToplevel(), (XFE_View*)this, getPane(), getContext());
  339.  
  340.      addView(addressFolderView);
  341.  
  342.      m_addressFolderViewAlias = addressFolderView;
  343.  
  344.      addressFolderView->createWidgets(m_addressFormW);
  345.      Widget addressContent;
  346.  
  347.      addressContent = addressFolderView->getBaseWidget();
  348.      XtVaSetValues(addressContent, XmNtopAttachment, XmATTACH_FORM,
  349.             XmNbottomAttachment, XmATTACH_FORM,
  350.             XmNleftAttachment, XmATTACH_FORM,
  351.             XmNrightAttachment, XmATTACH_FORM, NULL);
  352.      addressFolderView->show();
  353.    }
  354.    {// Attachment Folder
  355.      XFE_ComposeAttachFolderView *attachFolderView = 
  356.          new XFE_ComposeAttachFolderView(getToplevel(),(XFE_View*)this,getPane(), getContext());
  357.      addView(attachFolderView);
  358.      m_attachFolderViewAlias = attachFolderView;
  359.  
  360.      attachFolderView->createWidgets(m_attachFormW);
  361.      Widget attachContent;
  362.  
  363.      attachContent = attachFolderView->getBaseWidget();
  364.      XtVaSetValues(attachContent, XmNtopAttachment, XmATTACH_FORM,
  365.             XmNbottomAttachment, XmATTACH_FORM,
  366.             XmNleftAttachment, XmATTACH_FORM,
  367.             XmNrightAttachment, XmATTACH_FORM, NULL);
  368.      attachFolderView->show();
  369.    }
  370.  
  371.    { // Option Folder
  372.      XFE_OptionFolderView *optionFolderView = 
  373.          new XFE_OptionFolderView( getToplevel(), (XFE_View*)this, getPane(), getContext());
  374.  
  375.      addView(optionFolderView);
  376.  
  377.      m_optionFolderViewAlias = optionFolderView;
  378.  
  379.      optionFolderView->createWidgets(m_optionFormW);
  380.      Widget optionContent;
  381.  
  382.      optionContent = optionFolderView->getBaseWidget();
  383.      XtVaSetValues(optionContent, XmNtopAttachment, XmATTACH_FORM,
  384.             XmNbottomAttachment, XmATTACH_FORM,
  385.             XmNleftAttachment, XmATTACH_FORM,
  386.             XmNrightAttachment, XmATTACH_FORM, NULL);
  387.      optionFolderView->show();
  388.    }
  389.  
  390.    } // End of Address Frame
  391.   XDEBUG( printf("leave XFE_ComposeFolderView::createWidgets()\n");)
  392. }
  393.  
  394. void
  395. XFE_ComposeFolderView::folderActivateCallback(Widget, XtPointer clientData, XtPointer callData)
  396. {
  397.   XFE_ComposeFolderView *obj = (XFE_ComposeFolderView*)clientData;
  398.   XmLFolderCallbackStruct *fcb=(XmLFolderCallbackStruct*)callData;
  399.  
  400.   if (obj && fcb)
  401.       obj->folderActivate(fcb->pos);
  402. }
  403.  
  404.  
  405. //-------------NEW code ---------------------------------------
  406.  
  407. #ifndef EDITOR
  408. Widget
  409. fe_OptionMenuSetHistory(Widget menu, unsigned index)
  410. {
  411.     Arg        args[4];
  412.     Cardinal   n;
  413.     Widget     cascade;
  414.     Widget     popup_menu;
  415.     WidgetList children;
  416.     Cardinal   nchildren;
  417.  
  418.     /*
  419.      *   Update the label, and set the position of the popup.
  420.      */
  421.     cascade = XmOptionButtonGadget(menu);
  422.  
  423.     /*
  424.      *    Get the popup menu from the cascade.
  425.      */
  426.     n = 0;
  427.     XtSetArg(args[n], XmNsubMenuId, &popup_menu); n++;
  428.     XtGetValues(cascade, args, n);
  429.  
  430.     /*
  431.      *    Get the children of the popup.
  432.      */
  433.     n = 0;
  434.     XtSetArg(args[n], XmNchildren, &children); n++;
  435.     XtSetArg(args[n], XmNnumChildren, &nchildren); n++;
  436.     XtGetValues(popup_menu, args, n);
  437.     if (index < nchildren) {
  438.         /*
  439.          *    Finally, set the Nth button as history.
  440.          */
  441.         n = 0;
  442.         XtSetArg(args[n], XmNmenuHistory, children[index]); n++;
  443.         /* NOTE: set it on the top level menu (strange) */
  444.         XtSetValues(menu, args, n);
  445.  
  446.         return children[index];
  447.     }
  448.     return NULL;
  449. }
  450.  
  451. #endif
  452.  
  453. void
  454. XFE_ComposeFolderView::updateHeaderInfo(void)
  455. {
  456.  
  457.   
  458.   if ( m_addressFolderViewAlias )
  459.     m_addressFolderViewAlias->updateHeaderInfo();
  460.  
  461. }
  462.  
  463. void
  464. XFE_ComposeFolderView::setupIcons()
  465. {
  466.   Widget base = getToplevel()->getBaseWidget();
  467.  
  468.   Pixel bg_pixel;
  469.  
  470.   XtVaGetValues(base,  XmNbackground, &bg_pixel, 0);
  471.  
  472.   IconGroup_createAllIcons(&MNC_AddressSmall_group,
  473.                             getToplevel()->getBaseWidget(),
  474.                             BlackPixelOfScreen(XtScreen(base)), // hack. :(
  475.                             bg_pixel);
  476.  
  477.   IconGroup_createAllIcons(&MNC_AttachSmall_group,
  478.                             getToplevel()->getBaseWidget(),
  479.                             BlackPixelOfScreen(XtScreen(base)), // hack. :(
  480.                             bg_pixel);
  481.  
  482.   IconGroup_createAllIcons(&MNC_Options_group,
  483.                             getToplevel()->getBaseWidget(),
  484.                             BlackPixelOfScreen(XtScreen(base)), // hack. :(
  485.                             bg_pixel);
  486. }
  487.