home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / OptionFolderView.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  15.8 KB  |  556 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.    OptionFolderView.cpp -- presents view for option panel.
  20.    Created: Dora Hsu <dora@netscape.com>, 23-Sept-96.
  21.    */
  22.  
  23.  
  24.  
  25. #include "OptionFolderView.h"
  26. #include "ComposeView.h"
  27. #include <Xm/Xm.h>
  28. #include <Xm/ToggleBG.h>
  29. #include <Xm/Form.h>
  30. #include <xpgetstr.h> /* for XP_GetString() */
  31.  
  32. extern int XFE_MNC_OPTION_HIGHEST;
  33. extern int XFE_MNC_OPTION_HIGH;
  34. extern int XFE_MNC_OPTION_NORMAL;
  35. extern int XFE_MNC_OPTION_LOW;
  36. extern int XFE_MNC_OPTION_LOWEST;
  37.  
  38.  
  39. static fe_OptionMenuItemDescription fe_msg_encoding_menu_items[] =
  40. {
  41.     // name         label                data
  42.     { "8-bit",        "8-bit",             (void*)MSG_8bit},
  43.     { "MIME-compliant",    "MIME-compliant",        (void*)MSG_MimeCompliant},
  44.     { NULL }
  45. };
  46.  
  47. static fe_OptionMenuItemDescription fe_attach_encoding_menu_items[] =
  48. {
  49.     // name         label            data
  50.     { "MIME",        "MIME (base 64)",     (void*)MSG_Mime},
  51.     { "UUENCODE",    "UUENCODE",        (void*)MSG_UUencode},
  52.     { NULL }
  53. };
  54.  
  55.  
  56. #include "xpgetstr.h"
  57.  
  58. extern int XFE_MAIL_PRIORITY_LOWEST;
  59. extern int XFE_MAIL_PRIORITY_LOW;
  60. extern int XFE_MAIL_PRIORITY_NORMAL;
  61. extern int XFE_MAIL_PRIORITY_HIGH;
  62. extern int XFE_MAIL_PRIORITY_HIGHEST;
  63.  
  64. static
  65. Widget
  66. fe_OptionMenuCreate(Widget toplevel,  Widget parent, char *name,
  67.             fe_OptionMenuItemDescription *list,
  68.             XtCallbackProc option_proc, XtPointer option_clientdata)
  69. {
  70.   unsigned i;
  71.   Widget   popup_menu;
  72.   Widget   buttons[16];
  73.   Widget   option_menu;
  74.   Cardinal argc;
  75.   Arg      argv[8];
  76.   Visual*  v = 0;
  77.   Colormap cmap = 0;
  78.   Cardinal depth = 0;
  79.  
  80.   XtVaGetValues(toplevel, XtNvisual, &v, XtNcolormap, &cmap,
  81.     XtNdepth, &depth, 0);
  82.  
  83.   argc = 0;
  84.   XtSetArg (argv[argc], XmNvisual, v); argc++;
  85.   XtSetArg (argv[argc], XmNdepth, depth); argc++;
  86.   XtSetArg (argv[argc], XmNcolormap, cmap); argc++;
  87.  
  88.   popup_menu = XmCreatePulldownMenu(parent, name, argv, argc);
  89.  
  90.   for (i = 0; list[i].name; i++) {
  91.       argc = 0;
  92.       XtSetArg(argv[argc], XmNuserData, (XtPointer)list[i].data); argc++;
  93.       buttons[i] = XmCreatePushButtonGadget(popup_menu, list[i].name, argv, argc);
  94.       
  95.     XtAddCallback(
  96.             buttons[i],
  97.             XmNactivateCallback,
  98.             option_proc, option_clientdata);
  99.   }
  100.  
  101.   XtManageChildren(buttons, i);
  102.  
  103.   argc = 0;
  104.   XtSetArg(argv[argc], XmNsubMenuId, popup_menu); argc++;
  105.   option_menu = fe_CreateOptionMenu( parent, name, argv, argc);
  106.  
  107.   return option_menu;
  108. }
  109.  
  110. Boolean
  111. XFE_OptionFolderView::isPrioritySelected(MSG_PRIORITY priority)
  112. {
  113.     if ( m_selectedPriority == priority )
  114.         return True;
  115.     return False;
  116. }
  117.  
  118. void
  119. XFE_OptionFolderView::selectPriority(MSG_PRIORITY priority)
  120. {
  121.   MSG_Pane *comppane = (MSG_Pane*)getPane(); 
  122.   char *pPriority = priorityToString(priority);
  123.   int index = 0;
  124.  
  125.   MSG_SetCompHeader(comppane,MSG_PRIORITY_HEADER_MASK, pPriority);
  126.   if ( priority == MSG_HighestPriority )
  127.     index = 0;
  128.   else if ( priority == MSG_HighPriority)
  129.     index = 1;
  130.   else if ( priority == MSG_NormalPriority)
  131.     index = 2;
  132.   else if ( priority == MSG_LowPriority)
  133.     index = 3;
  134.   else if ( priority == MSG_LowestPriority)
  135.     index = 4;
  136.     
  137.   m_selectedPriority = priority;
  138.  
  139.   (void)fe_OptionMenuSetHistory(m_optionW, (int)index);
  140. }
  141.  
  142. void
  143. XFE_OptionFolderView::selectPriorityCallback(
  144.             Widget w, XtPointer client, XtPointer)
  145. {
  146.   
  147.     CommandType command;
  148.  
  149.  
  150.   XFE_OptionFolderView *obj = (XFE_OptionFolderView*)client;
  151.   MSG_PRIORITY priority = MSG_PriorityNotSet;
  152.  
  153.   XtVaGetValues(w, XmNuserData, &priority,  0);
  154.   obj->selectPriority(priority);
  155.   if ( priority == MSG_HighestPriority )
  156.     command = xfeCmdSetPriorityHighest;
  157.   else if ( priority == MSG_HighPriority )
  158.         command = xfeCmdSetPriorityHigh;
  159.   else if ( priority == MSG_NormalPriority )
  160.         command = xfeCmdSetPriorityNormal;
  161.   else if ( priority == MSG_LowPriority )
  162.         command = xfeCmdSetPriorityLow;
  163.   else if ( priority == MSG_LowestPriority )
  164.         command = xfeCmdSetPriorityLowest;
  165.   else
  166.       return;
  167.  
  168.   obj->getToplevel()->notifyInterested(XFE_View::commandNeedsUpdating,
  169.             (void*)command );
  170. }
  171.  
  172. void
  173. XFE_OptionFolderView::selectTextEncoding(MSG_TEXT_ENCODING encoding)
  174. {
  175.  
  176.   if ( encoding == MSG_8bit )
  177.      MIME_ConformToStandard(False);
  178.   else
  179.      MIME_ConformToStandard(True);
  180. }
  181.  
  182. void
  183. XFE_OptionFolderView::selectTextEncodingCallback(
  184.             Widget w, XtPointer client, XtPointer)
  185. {
  186.   XFE_OptionFolderView *obj = (XFE_OptionFolderView*)client;
  187.   MSG_TEXT_ENCODING encoding = MSG_TextEncodingNotSet;
  188.  
  189.   XtVaGetValues(w, XmNuserData, &encoding,  0);
  190.   obj->selectTextEncoding(encoding);
  191. }
  192.  
  193. void
  194. XFE_OptionFolderView::selectBinaryEncoding(MSG_BINARY_ENCODING encoding)
  195. {
  196.  
  197.   if ( encoding == MSG_Mime )
  198.        MSG_SetCompBoolHeader(getPane(), 
  199.         MSG_UUENCODE_BINARY_BOOL_HEADER_MASK, False);
  200.   else if ( encoding == MSG_UUencode )
  201.        MSG_SetCompBoolHeader(getPane(), 
  202.         MSG_UUENCODE_BINARY_BOOL_HEADER_MASK, True);
  203.   else 
  204.     XP_ASSERT(0); // Should never reach here.... because we only have two states
  205. }
  206.  
  207. void
  208. XFE_OptionFolderView::selectBinaryEncodingCallback(
  209.             Widget w, XtPointer client, XtPointer)
  210. {
  211.   XFE_OptionFolderView *obj = (XFE_OptionFolderView*)client;
  212.   MSG_BINARY_ENCODING encoding = MSG_BinaryEncodingNotSet;
  213.  
  214.   XtVaGetValues(w, XmNuserData, &encoding,  0);
  215.   obj->selectBinaryEncoding(encoding);
  216. }
  217.  
  218. //Destructor
  219. XFE_OptionFolderView::~XFE_OptionFolderView()
  220. {
  221. }
  222.  
  223. //Constructor
  224. XFE_OptionFolderView::XFE_OptionFolderView(
  225.         XFE_Component *toplevel_component,
  226.         XFE_View *parent_view,
  227.         MSG_Pane *p,
  228.         MWContext *context)
  229.     :XFE_MNView(toplevel_component, parent_view, context, p)
  230. {
  231.     setParent(parent_view);
  232.     // Initialize Data
  233.     m_bReturnReceipt = False;
  234.     m_bEncrypted = False;
  235.     m_bSigned = False;
  236.     m_selectedPriority = MSG_NormalPriority;
  237.  
  238.     parent_view->getToplevel()->
  239.         registerInterest(XFE_ComposeView::updateSecurityOption,
  240.             this,
  241.             (XFE_FunctionNotification)updateSecurityOption_cb);
  242. }
  243.  
  244. XFE_CALLBACK_DEFN(XFE_OptionFolderView,updateSecurityOption)(XFE_NotificationCenter *, void *, void*)
  245. {
  246.   Boolean set = False;
  247.   Boolean notify = False;
  248.  
  249.   
  250.   XtVaGetValues(m_encryptedW, XmNset, &set, 0 );
  251.  
  252.   // Encrypted
  253.   if ( !set && MSG_GetCompBoolHeader(getPane(), MSG_ENCRYPTED_BOOL_HEADER_MASK) )
  254.   {
  255.     notify = True;
  256.         XmToggleButtonSetState (m_encryptedW, True, False);
  257.   }
  258.   else if ( set && !MSG_GetCompBoolHeader(getPane(), MSG_ENCRYPTED_BOOL_HEADER_MASK) )
  259.   {
  260.     notify = True;
  261.         XmToggleButtonSetState (m_encryptedW, False, False);
  262.   }
  263.  
  264.  
  265.   XtVaGetValues(m_signedW, XmNset, &set, 0 );
  266.  
  267.   // Signed
  268.   if ( !set && MSG_GetCompBoolHeader(getPane(), MSG_SIGNED_BOOL_HEADER_MASK) )
  269.   {
  270.        notify = True;
  271.        XmToggleButtonSetState (m_signedW, True, False);
  272.   }
  273.   else if ( set && !MSG_GetCompBoolHeader(getPane(), MSG_SIGNED_BOOL_HEADER_MASK) )
  274.   {
  275.        notify = True;
  276.        XmToggleButtonSetState (m_signedW, False, False);
  277.   }
  278.  
  279.   if ( notify )
  280.     getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating,
  281.             (void*)NULL);
  282. }
  283.  
  284. void
  285. XFE_OptionFolderView::createWidgets(Widget parent_widget)
  286. {
  287.     Arg av[10];
  288.     int ac = 0;
  289.  
  290.     static fe_OptionMenuItemDescription fe_priority_menu_items[] =
  291.     {
  292.         // name                     label           data
  293.         { "setPriorityHighest",    (char*)NULL,     (void*)MSG_HighestPriority},
  294.         { "setPriorityHigh",    (char*)NULL,     (void*)MSG_HighPriority},
  295.         { "setPriorityNormal",     (char*)NULL,     (void*)MSG_NormalPriority},
  296.         { "setPriorityLow",      (char*)NULL,     (void*)MSG_LowPriority},
  297.         { "setPriorityLowest",     (char*)NULL,     (void*)MSG_LowestPriority},
  298.         { NULL }
  299.     };
  300.  
  301.     // HP-UX 9.03 won't let us assign these values inside the initializer list.
  302.     fe_priority_menu_items[0].label = XP_GetString(XFE_MNC_OPTION_HIGHEST);
  303.     fe_priority_menu_items[1].label = XP_GetString(XFE_MNC_OPTION_HIGH);
  304.     fe_priority_menu_items[2].label = XP_GetString(XFE_MNC_OPTION_NORMAL);
  305.     fe_priority_menu_items[3].label = XP_GetString(XFE_MNC_OPTION_LOW);
  306.     fe_priority_menu_items[4].label = XP_GetString(XFE_MNC_OPTION_LOWEST);
  307.  
  308.     Widget form = XmCreateForm(parent_widget, "optionForm", NULL, 0);
  309.     XtVaSetValues(form, XmNfractionBase, 3, 0);
  310.  
  311.     setBaseWidget(form);
  312.  
  313.     Widget RC0 = XmCreateRowColumn(form, "RC0", NULL, 0);
  314.     XtVaSetValues(RC0, XmNorientation, XmVERTICAL, 0);
  315.  
  316.     Widget RC1 = XmCreateRowColumn(form, "RC1", NULL, 0);
  317.     XtVaSetValues(RC1, XmNorientation, XmVERTICAL, 0);
  318.  
  319.     int num = 5;
  320.     for (int i=0; i < num; i++) {
  321.         fe_priority_menu_items[i].label = 
  322.             XP_GetString(XFE_MAIL_PRIORITY_LOWEST+num-1-i);
  323.     }/* for i */
  324.     m_optionW = fe_OptionMenuCreate(getToplevel()->getBaseWidget(),
  325.                         form,
  326.                         "PriorityOption",
  327.                         fe_priority_menu_items,
  328.                         &XFE_OptionFolderView::selectPriorityCallback,
  329.                         (void*) this);
  330.  
  331.     m_textEncodingOptionW = fe_OptionMenuCreate(getToplevel()->getBaseWidget(),
  332.                         RC1,
  333.                         "TextEncodingOption",
  334.                         fe_msg_encoding_menu_items,
  335.                         &XFE_OptionFolderView::selectTextEncodingCallback,
  336.                         (void*) this);
  337.     m_binaryEncodingOptionW = fe_OptionMenuCreate(getToplevel()->getBaseWidget(),
  338.                         RC1,
  339.                         "BinaryEncodingOption",
  340.                         fe_attach_encoding_menu_items,
  341.                         &XFE_OptionFolderView::selectBinaryEncodingCallback,
  342.                         (void*) this);
  343.  
  344.     m_returnReceiptW = XmCreateToggleButtonGadget( RC0,
  345.         "returnReceipt", av, ac );        
  346.     m_encryptedW = XmCreateToggleButtonGadget( RC0,
  347.         "encrypted", av, ac );        
  348.     m_signedW = XmCreateToggleButtonGadget( RC0,
  349.         "signed", av, ac );        
  350.  
  351.     XtManageChild(m_textEncodingOptionW);
  352.     XtManageChild(m_binaryEncodingOptionW);
  353.     XtManageChild(m_returnReceiptW);
  354.     XtAddCallback(m_returnReceiptW, XmNvalueChangedCallback, 
  355.         returnReceiptChangeCallback, (XtPointer)this);
  356.     XtManageChild(m_encryptedW);
  357.     XtAddCallback(m_encryptedW, XmNvalueChangedCallback, 
  358.         encryptedChangeCallback, (XtPointer)this);
  359.     XtManageChild(m_signedW);
  360.     XtAddCallback(m_signedW, XmNvalueChangedCallback, 
  361.         signedChangeCallback, (XtPointer)this);
  362.     // Do Some Attachments
  363.  
  364.  
  365.     XtVaSetValues( RC0,
  366.     XmNalignment, XmALIGNMENT_BEGINNING,
  367.         XmNleftAttachment, XmATTACH_FORM,
  368.         XmNrightAttachment, XmATTACH_NONE,
  369.         XmNtopAttachment, XmATTACH_FORM,
  370.         XmNbottomAttachment, XmATTACH_NONE,
  371.     NULL);
  372.  
  373.     XtManageChild(RC0);
  374.  
  375.     XtVaSetValues( RC1,
  376.     XmNalignment, XmALIGNMENT_BEGINNING,
  377.         XmNleftAttachment, XmATTACH_WIDGET,
  378.         XmNleftWidget, RC0,
  379.         XmNleftOffset, 5,
  380.         XmNrightAttachment, XmATTACH_NONE,
  381.         XmNtopAttachment, XmATTACH_FORM,
  382.         XmNbottomAttachment, XmATTACH_NONE,
  383.     NULL);
  384.     XtManageChild(RC1);
  385.  
  386.     XtVaSetValues( m_optionW,
  387.     XmNalignment, XmALIGNMENT_BEGINNING,
  388.         XmNleftAttachment, XmATTACH_WIDGET,
  389.         XmNleftWidget, RC1,
  390.         XmNleftOffset, 5,
  391.         XmNrightAttachment, XmATTACH_NONE,
  392.         XmNtopAttachment, XmATTACH_FORM,
  393.         XmNbottomAttachment, XmATTACH_NONE,
  394.     NULL);
  395.     XtManageChild(m_optionW);
  396.  
  397.     // Text Encoding .... 
  398.     // Initially, get the default setting from the preferences
  399.     // question - do we do this for each option tab click ???? 
  400.     if (fe_globalPrefs.qp_p)
  401.     {
  402.     int index = 0;
  403.     // do quotable print... encoding
  404.      index = (int) MSG_MimeCompliant - 1;
  405.          (void)fe_OptionMenuSetHistory(m_textEncodingOptionW, (int)index);
  406.          MIME_ConformToStandard(True);
  407.     }
  408.     else 
  409.     {
  410.     int index = 0;
  411.     // do 8bit... encoding
  412.      index = (int) MSG_8bit - 1;
  413.          (void)fe_OptionMenuSetHistory(m_textEncodingOptionW, (int)index);
  414.          MIME_ConformToStandard(False);
  415.     }
  416.  
  417.     updateAllOptions();
  418.  
  419.     XtManageChild(form);
  420. }
  421.  
  422. void
  423. XFE_OptionFolderView::updateAllOptions()
  424. {
  425.     // Will decide the state of these buttons
  426.  
  427.     // Return Receipt
  428.     if ( MSG_GetCompBoolHeader(getPane(), MSG_RETURN_RECEIPT_BOOL_HEADER_MASK) )
  429.     {
  430.         XtVaSetValues (m_returnReceiptW, XmNset, True, 0);
  431.     }
  432.     else 
  433.         XtVaSetValues (m_returnReceiptW, XmNset, False, 0);
  434.  
  435.     // Encrypted
  436.     if ( MSG_GetCompBoolHeader(getPane(), MSG_ENCRYPTED_BOOL_HEADER_MASK) )
  437.     {
  438.         XtVaSetValues (m_encryptedW, XmNset, True, 0);
  439.     }
  440.     else 
  441.         XtVaSetValues (m_encryptedW, XmNset, False, 0);
  442.  
  443.  
  444.     // Signed
  445.     if ( MSG_GetCompBoolHeader(getPane(), MSG_SIGNED_BOOL_HEADER_MASK) )
  446.     {
  447.         XtVaSetValues (m_signedW, XmNset, True, 0);
  448.     }
  449.     else 
  450.         XtVaSetValues (m_signedW, XmNset, False, 0);
  451.  
  452.  
  453.    // Binary encoding...
  454.    int index = 0;
  455.    if ( MSG_GetCompBoolHeader(getPane(), MSG_UUENCODE_BINARY_BOOL_HEADER_MASK) )
  456.     {
  457.      index = (int) MSG_UUencode - 1;
  458.          (void)fe_OptionMenuSetHistory(m_binaryEncodingOptionW, (int)index);
  459.     }
  460.   else
  461.     {
  462.      index = (int) MSG_Mime - 1;
  463.          (void)fe_OptionMenuSetHistory(m_binaryEncodingOptionW, (int)index);
  464.     }
  465. }
  466.  
  467. void
  468. XFE_OptionFolderView::handleReturnReceipt(Boolean set)
  469. {
  470.   if (set)
  471.     MSG_SetCompBoolHeader(getPane(), MSG_RETURN_RECEIPT_BOOL_HEADER_MASK, True);
  472.   else
  473.     MSG_SetCompBoolHeader(getPane(), MSG_RETURN_RECEIPT_BOOL_HEADER_MASK, False);
  474. }
  475.  
  476. void
  477. XFE_OptionFolderView::returnReceiptChangeCallback( Widget w, XtPointer client, XtPointer)
  478. {
  479.     XFE_OptionFolderView *obj = (XFE_OptionFolderView*)client;
  480.     Boolean set = False;
  481.  
  482.     XtVaGetValues(w, XmNset, &set, 0 );
  483.         obj->handleReturnReceipt(set);
  484. }
  485.  
  486. void
  487. XFE_OptionFolderView::handleEncrypted(Boolean set)
  488. {
  489.   Boolean notify = False;
  490.   if ((set) && !MSG_GetCompBoolHeader(getPane(), 
  491.                 MSG_ENCRYPTED_BOOL_HEADER_MASK))
  492.   {
  493.     MSG_SetCompBoolHeader(getPane(), MSG_ENCRYPTED_BOOL_HEADER_MASK, True);
  494.     notify = True;
  495.   }
  496.   else if ((!set) && MSG_GetCompBoolHeader(getPane(), 
  497.                 MSG_ENCRYPTED_BOOL_HEADER_MASK))
  498.   {
  499.     MSG_SetCompBoolHeader(getPane(), MSG_ENCRYPTED_BOOL_HEADER_MASK, False);
  500.     notify = True;
  501.   }
  502.  
  503.   if (notify) 
  504.   {
  505.     getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating,
  506.             (void*)NULL);
  507.   } 
  508.  
  509. }
  510.  
  511.  
  512. void
  513. XFE_OptionFolderView::encryptedChangeCallback( Widget w, XtPointer client, XtPointer)
  514. {
  515.     XFE_OptionFolderView *obj = (XFE_OptionFolderView*)client;
  516.     Boolean set = False;
  517.  
  518.     XtVaGetValues(w, XmNset, &set, 0 );
  519.         obj->handleEncrypted(set);
  520. }
  521.  
  522. void
  523. XFE_OptionFolderView::handleSigned(Boolean set)
  524. {
  525.   Boolean notify = False;
  526.   if ((set) && !MSG_GetCompBoolHeader(getPane(), MSG_SIGNED_BOOL_HEADER_MASK))
  527.   {
  528.     MSG_SetCompBoolHeader(getPane(), MSG_SIGNED_BOOL_HEADER_MASK, True);
  529.     notify = True;
  530.   }
  531.   else if ((!set) && MSG_GetCompBoolHeader(getPane(), 
  532.                 MSG_SIGNED_BOOL_HEADER_MASK))
  533.   {
  534.     MSG_SetCompBoolHeader(getPane(), MSG_SIGNED_BOOL_HEADER_MASK, False);
  535.     notify = True;
  536.  
  537.   }
  538.   if (notify)
  539.   {
  540.     getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating,
  541.             (void*)NULL);
  542.   }
  543.  
  544. }
  545.  
  546. void
  547. XFE_OptionFolderView::signedChangeCallback( Widget w, XtPointer client, XtPointer)
  548. {
  549.     XFE_OptionFolderView *obj = (XFE_OptionFolderView*)client;
  550.     Boolean set = False;
  551.  
  552.     XtVaGetValues(w, XmNset, &set, 0 );
  553.         obj->handleSigned(set);
  554. }
  555.  
  556.