home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / MNSearchView.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  59.9 KB  |  2,142 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.    MNSearchView.h -- user's mail search view.
  20.    Created: Dora Hsu <dora@netscape.com>, 15-Dec-96.
  21. */
  22.  
  23.  
  24. #include "MozillaApp.h"
  25. #include "MNSearchView.h"
  26. #include "AdvSearchDialog.h"
  27. #include "SearchRuleView.h"
  28. #include "MsgFrame.h"
  29. #include "MsgView.h"
  30. #include "ViewGlue.h"
  31. #include "FolderDropdown.h"
  32. #include "FolderMenu.h"
  33. #include "Dashboard.h"
  34. #include "xfe2_extern.h"
  35. #include <Xm/Form.h>
  36. #include <Xm/LabelG.h>
  37. #include <Xm/RowColumn.h>
  38. #include <Xm/TextF.h>
  39. #include <Xm/SelectioB.h>
  40. #include <Xm/Frame.h>
  41. #include <Xm/LabelG.h>
  42. #include <Xm/PushBG.h>
  43. #include <Xm/DrawnB.h>
  44. #include "Xfe/Xfe.h"
  45.  
  46. #include "libi18n.h"
  47. #include "intl_csi.h"
  48. #include "felocale.h"
  49.  
  50. #ifdef DEBUG_dora
  51. #define DD(x) x
  52. #else
  53. #define DD(x)
  54. #endif
  55.  
  56. #define OUTLINER_GEOMETRY_PREF "mail.searchpane.outliner_geometry"
  57.  
  58. // Maximum number of rules can be created
  59. #define MAX_RULES_ALLOWED 5
  60. extern "C" Widget
  61. fe_make_option_menu(Widget toplevel, 
  62.     Widget parent, char* widgetName, Widget *popup);
  63. extern "C" void
  64. fe_get_option_size ( Widget optionMenu, 
  65.                         Dimension *retWidth, Dimension *retHeight );
  66.  
  67. #define TOTAL_DEFAULT_FOLDER_OPTIONS    3
  68.  
  69. const char* XFE_MNSearchView::CloseSearch    = "XFE_MNSearchView::CloseSearch";
  70. const char* XFE_MNSearchView::STOP    = "Stop";
  71. const char* XFE_MNSearchView::SEARCH    = "Search";
  72.  
  73. const int XFE_MNSearchView::kStop    = 0;
  74. const int XFE_MNSearchView::kSearch    = 1;
  75.  
  76. // For Column Header to use
  77. const int XFE_MNSearchView::MAILSEARCH_OUTLINER_COLUMN_SUBJECT= 0;
  78. const int XFE_MNSearchView::MAILSEARCH_OUTLINER_COLUMN_SENDER= 1;
  79. const int XFE_MNSearchView::MAILSEARCH_OUTLINER_COLUMN_DATE= 2;
  80. const int XFE_MNSearchView::MAILSEARCH_OUTLINER_COLUMN_PRIORITY= 3;
  81. const int XFE_MNSearchView::MAILSEARCH_OUTLINER_COLUMN_LOCATION= 4;
  82. const char *XFE_MNSearchView::scopeChanged = "XFE_MNSearchView::scopeChanged";
  83.  
  84. #include "xpgetstr.h"
  85.  
  86. extern int XFE_SEARCH_LOCATION;
  87. extern int XFE_SEARCH_SUBJECT;
  88. extern int XFE_SEARCH_SENDER;
  89. extern int XFE_SEARCH_DATE;
  90. extern int XFE_SEARCH_ALLMAILFOLDERS;
  91. extern int XFE_SEARCH_AllNEWSGROUPS;
  92. extern int XFE_SEARCH_LDAPDIRECTORY;
  93. extern int XFE_AB_STOP;
  94. extern int XFE_AB_SEARCH;
  95. extern int XFE_PRI_PRIORITY;
  96. extern int XFE_SEARCH_NO_MATCHES;
  97. extern int XFE_VIRTUALNEWSGROUP;
  98. extern int XFE_VIRTUALNEWSGROUPDESC;
  99.  
  100. MenuSpec XFE_MNSearchView::popup_spec[] = {
  101.   { "fileSubmenu", DYNA_CASCADEBUTTON, NULL, NULL, False,
  102.     (void*)xfeCmdMoveMessage, XFE_FolderMenu::generate },
  103.   { "copySubmenu", DYNA_CASCADEBUTTON, NULL, NULL, False,
  104.     (void*)xfeCmdCopyMessage, XFE_FolderMenu::generate },
  105.   { xfeCmdDeleteMessage,    PUSHBUTTON },
  106.   { xfeCmdSaveMessagesAs,    PUSHBUTTON },
  107.   { NULL }
  108. };
  109.  
  110. XFE_MNSearchView::XFE_MNSearchView(XFE_Component *toplevel_component,
  111.                                    Widget parent,
  112.                                    XFE_Frame * parent_frame,
  113.                                    XFE_MNView *mn_parentView,
  114.                                    MWContext *context, MSG_Pane *p, 
  115.                                    MSG_FolderInfo *selectedFolder,
  116.                                    Boolean AddGotoBtn)
  117.   : XFE_MNListView(toplevel_component, mn_parentView, context, p)
  118. {
  119.     m_parentFrame = parent_frame;
  120.  
  121.   // Initialize private member now...
  122.   initialize();
  123.   m_addGotoBtn = AddGotoBtn;
  124.  
  125.   if ( selectedFolder)
  126.   {
  127.     if( !isMailFolder(selectedFolder) )
  128.     m_rules.scope = scopeNewsgroup;
  129.  
  130.     m_folderInfo = selectedFolder;
  131.   }
  132.  
  133.   m_hasRightLabel = False;
  134.  
  135.   {
  136.   /* Get Visual, Colormap, and Depth */
  137.   XtVaGetValues(getToplevel()->getBaseWidget(),
  138.                  XmNvisual, &m_visual,
  139.                  XmNcolormap, &m_cmap,
  140.                  XmNdepth, &m_depth,
  141.                  NULL);
  142.   }
  143.   {
  144.      Widget w;
  145.  
  146.      w = XtVaCreateWidget("searchForm", xmFormWidgetClass, parent,
  147.             XmNautoUnmanage, False, 
  148.             XmNleftAttachment, XmATTACH_FORM,
  149.             XmNrightAttachment, XmATTACH_FORM,
  150.             XmNbottomAttachment, XmATTACH_FORM,
  151.             XmNtopAttachment, XmATTACH_FORM,
  152.             NULL);
  153.      setBaseWidget(w);
  154.   }
  155.  
  156.   if (!p) // Create SearchPane here
  157.   {
  158.     m_pane = MSG_CreateSearchPane(m_contextData, fe_getMNMaster());
  159.     setPane(m_pane);
  160.   }
  161.   getToplevel()->registerInterest(
  162.         XFE_Frame::allConnectionsCompleteCallback, this,
  163.                 (XFE_FunctionNotification)searchFinished_cb);
  164.  
  165.   getToplevel()->registerInterest(
  166.         XFE_SearchRuleView::activateSearch, this,
  167.         (XFE_FunctionNotification)searchStart_cb);
  168. }
  169.  
  170.  
  171. XFE_MNSearchView::~XFE_MNSearchView()
  172. {
  173.   getToplevel()->unregisterInterest(
  174.         XFE_Frame::allConnectionsCompleteCallback, this,
  175.                 (XFE_FunctionNotification)searchFinished_cb);
  176.  
  177.   getToplevel()->unregisterInterest(
  178.         XFE_SearchRuleView::activateSearch, this,
  179.         (XFE_FunctionNotification)searchStart_cb);
  180.  
  181.   if (m_popup)
  182.     delete m_popup;
  183.  
  184.   destroyPane();
  185. }
  186.  
  187. void
  188. XFE_MNSearchView::initialize()
  189. {
  190.   // Initialize private data member here
  191.   m_searchpane = NULL;
  192.   m_count = 0;
  193.   m_visual = NULL;
  194.   m_depth = 0;
  195.   m_content = NULL;
  196.   m_header = NULL;
  197.   m_displayArea = NULL;
  198.   m_popup = NULL;
  199.   m_ruleContent = NULL;
  200.   m_allocated = False;
  201.   m_hasRightLabel = False;
  202.   m_searchBtn = NULL;
  203.   m_newSearchBtn = NULL;
  204.   m_miscBtn = NULL;
  205.   m_closeBtn = NULL;
  206.   m_folderInfo = NULL;
  207.   m_hasResult = False;
  208.   m_searchAll = False;
  209.   m_gotoBtn = NULL;
  210.   m_fileBtn = NULL;
  211.   m_deleteBtn = NULL;
  212.   m_addGotoBtn = False;
  213.  
  214.   // XFE_SearchResult struct
  215.   m_rules.searchLabel = NULL;
  216.   m_rules.scopeOpt = NULL;
  217.   m_rules.whereLabel = NULL;
  218.   m_rules.searchCommand = NULL;
  219.   m_rules.more_btn = NULL;
  220.   m_rules.less_btn = NULL;
  221.   m_rules.commandGroup = NULL;
  222.   m_rules.frame = NULL;
  223.   m_rules.form = NULL;
  224.   m_rules.scope = (MSG_ScopeAttribute)scopeMailFolder;
  225.   m_dir = NULL;
  226.  
  227.   // Search Result
  228.  
  229.   m_result.container = NULL;
  230.   m_result.expand = False;
  231.  
  232.   // bstell: initialize doc_csid
  233.   INTL_CharSetInfo c = LO_GetDocumentCharacterSetInfo(m_contextData);
  234.   INTL_SetCSIDocCSID(c, fe_LocaleCharSetID);
  235.   INTL_SetCSIWinCSID(c, INTL_DocToWinCharSetID(INTL_GetCSIDocCSID(c)));
  236. }
  237.  
  238. Boolean
  239. XFE_MNSearchView::handlesCommand(CommandType cmd, void *calldata,
  240.                                  XFE_CommandInfo*)
  241. {
  242. #define IS_CMD(command) cmd == (command)
  243.   if (IS_CMD(xfeCmdMoveMessage)
  244.       || IS_CMD(xfeCmdCopyMessage)
  245.       || IS_CMD(xfeCmdDeleteMessage)
  246.       || IS_CMD(xfeCmdSaveMessagesAs)
  247.       || IS_CMD(xfeCmdShowPopup)
  248.       )
  249.       return TRUE;
  250.   else
  251.     {
  252.       return XFE_MNListView::handlesCommand(cmd, calldata);
  253.     }
  254. #undef IS_CMD
  255. }
  256.  
  257. Boolean
  258. XFE_MNSearchView::isCommandEnabled(CommandType cmd, void *calldata,
  259.                                    XFE_CommandInfo* info)
  260. {
  261. #define IS_CMD(command) cmd == (command)
  262.  
  263.     if (IS_CMD(xfeCmdShowPopup))
  264.         return (m_outliner != 0);
  265.  
  266.     const int *selected;
  267.     int count;
  268.     m_outliner->getSelection(&selected, &count);
  269.  
  270.     if (IS_CMD(xfeCmdMoveMessage)
  271.         || IS_CMD(xfeCmdCopyMessage)
  272.         || IS_CMD(xfeCmdDeleteMessage)
  273.         || IS_CMD(xfeCmdSaveMessagesAs)
  274.         )
  275.         return (count > 0);
  276.  
  277.     else
  278.         return XFE_MNListView::isCommandEnabled(cmd, calldata, info);
  279. }
  280.  
  281. void
  282. XFE_MNSearchView::doCommand(CommandType cmd,
  283.                             void *calldata, XFE_CommandInfo* info)
  284. {
  285. #define IS_CMD(command) cmd == (command)
  286.     if (IS_CMD(xfeCmdShowPopup) && m_outliner != 0)
  287.     {
  288.         XEvent *event = info->event;
  289.         int x, y, clickrow;
  290.         Widget w = XtWindowToWidget(event->xany.display, event->xany.window);
  291.         
  292.         if (m_popup)
  293.             delete m_popup;
  294.  
  295.         if (w == NULL) w = m_widget;
  296.         
  297.         m_popup = new XFE_PopupMenu("popup",(XFE_Frame*)m_toplevel, // XXXXXXX
  298.                         XfeAncestorFindApplicationShell(w));
  299.         
  300.         m_popup->addMenuSpec(popup_spec);
  301.  
  302.         m_outliner->translateFromRootCoords(event->xbutton.x_root,
  303.                                             event->xbutton.y_root,
  304.                                             &x, &y);
  305.       
  306.         clickrow = m_outliner->XYToRow(x, y);
  307.         
  308.         if (clickrow != -1) /* if it was actually in the outliner's content rows. */
  309.         {
  310.             if (! m_outliner->isSelected(clickrow))
  311.                 m_outliner->selectItemExclusive(clickrow);
  312.         }
  313.  
  314.         m_popup->position(event);
  315.         m_popup->show();
  316.     }
  317.  
  318.     else if (IS_CMD(xfeCmdMoveMessage) || IS_CMD(xfeCmdCopyMessage))
  319.     {
  320.         MSG_FolderInfo *info = (MSG_FolderInfo*)calldata;
  321.           
  322.         if (info)
  323.         {
  324.             const int *selected;
  325.             int count;
  326.             m_outliner->getSelection(&selected, &count);
  327.             if (IS_CMD(xfeCmdCopyMessage))
  328.                 MSG_CopyMessagesIntoFolder(m_pane, (MSG_ViewIndex*)selected,
  329.                                            count, info);
  330.             else
  331.                 MSG_MoveMessagesIntoFolder(m_pane, (MSG_ViewIndex*)selected,
  332.                                            count, info);
  333.         }
  334.     }
  335.     else if (IS_CMD(xfeCmdDeleteMessage))
  336.         deleteMsgs();
  337.  
  338.     else
  339.         XFE_MNListView::doCommand(cmd, calldata, info);
  340. }
  341.  
  342. void
  343. XFE_MNSearchView::addRules(char *title, 
  344.             MSG_ScopeAttribute  curScope, 
  345.             uint16 curAttr)
  346. {
  347.     XFE_SearchRuleView *ruleView;
  348.     void* folder_data = (void*)m_folderInfo;
  349.  
  350.        if (curScope == scopeLdapDirectory)
  351.        folder_data = (void*)m_dir;
  352.     ruleView = new XFE_SearchRuleView(getToplevel(),
  353.                     m_ruleContent,
  354.                     this,
  355.                     m_contextData,
  356.                     getPane(),
  357.                     title,
  358.                         folder_data,
  359.                     curScope,
  360.                     curAttr);
  361.     
  362.     addView(ruleView);
  363. }
  364.  
  365. void
  366. XFE_MNSearchView::createCommandButtons()
  367. {
  368.  
  369.   Arg av[20];
  370.   int ac = 0;
  371.  
  372.   ac = 0;
  373.   XtSetArg (av[ac], XmNnumColumns, 1); ac++;
  374.   XtSetArg (av[ac], XmNorientation, XmVERTICAL); ac++;
  375.   XtSetArg (av[ac], XmNadjustLast, False); ac++;
  376.   XtSetArg (av [ac], XmNtopAttachment, XmATTACH_FORM); ac++;
  377.   XtSetArg (av [ac], XmNleftAttachment, XmATTACH_NONE); ac++;
  378.   XtSetArg (av [ac], XmNrightAttachment, XmATTACH_FORM); ac++;
  379.   XtSetArg (av [ac], XmNbottomAttachment, XmATTACH_NONE); ac++;
  380.   XtSetArg (av [ac], XmNresizable, False); ac++;
  381.   m_rules.searchCommand = XmCreateRowColumn(m_content, "searchRC", av, ac);
  382.  
  383.   ac = 0;
  384.   m_searchBtn = XmCreatePushButton(m_rules.searchCommand, "SearchBtn", av, ac);
  385.   m_miscBtn = XmCreatePushButton(m_rules.searchCommand, "MiscBtn", av, ac);
  386.   m_closeBtn = XmCreatePushButton(m_rules.searchCommand, "CloseBtn", av, ac);
  387.  
  388.   XtVaSetValues( m_content,
  389.                 XmNdefaultButton, NULL,
  390.                 NULL);
  391.  
  392.   XtAddCallback (m_searchBtn, XmNactivateCallback, startCallback, this);
  393.   XtAddCallback(m_miscBtn, XmNactivateCallback, miscCallback, this);
  394.   XtAddCallback (m_closeBtn, XmNactivateCallback, closeCallback, this);
  395.  
  396.   XtManageChild(m_searchBtn);
  397.   XtManageChild(m_miscBtn);
  398.   XtManageChild(m_closeBtn);
  399.   XtManageChild(m_rules.searchCommand);
  400.  
  401.   // we have not start search, so don't turn on the stop button yet...
  402.   XtVaSetValues(m_searchBtn, XmNuserData, kSearch, 0 );
  403. }
  404.  
  405. //fe_search_get_name_from_scope(MSG_ScopeAttribute scope_num)
  406. char * 
  407. XFE_MNSearchView::getNameFromScope(MSG_ScopeAttribute scope_num)
  408. {
  409.     char *str = NULL;
  410.  
  411.     switch (scope_num)
  412.     {
  413.         case scopeMailFolder:
  414.         {
  415.                 str = (char*)malloc(120);
  416.                 strcpy(str,XP_GetString(XFE_SEARCH_ALLMAILFOLDERS));
  417.                 break;
  418.         }
  419.         case scopeNewsgroup:
  420.         {
  421.                 str = (char*)malloc(120);
  422.                 strcpy(str,XP_GetString(XFE_SEARCH_AllNEWSGROUPS));
  423.                 break;
  424.         }
  425.         case scopeLdapDirectory:
  426.         {
  427.                 str = (char*)malloc(120);
  428.                 strcpy(str,XP_GetString(XFE_SEARCH_LDAPDIRECTORY));
  429.                 break;
  430.         }
  431.         default : // Do we handle scopeAllSearchableGroups, 
  432.                 // scopeOfflineNewsgroup ???
  433.         break;
  434.     }
  435.  
  436.     return str;
  437. }
  438.  
  439. int
  440. XFE_MNSearchView::getNumFolderOptions()
  441. {
  442.  return TOTAL_DEFAULT_FOLDER_OPTIONS;
  443. }
  444.  
  445. void
  446. XFE_MNSearchView::addDefaultFolders()
  447. {
  448. }
  449.  
  450. Boolean
  451. XFE_MNSearchView::isMailFolder(MSG_FolderInfo *folderInfo)
  452. {
  453.   MSG_FolderLine folderLine;
  454.   MSG_GetFolderLineById(XFE_MNView::getMaster(), folderInfo, &folderLine);
  455.  
  456. DD(
  457.   if (folderLine.name) 
  458.     printf("select Folder with name....%s\n", folderLine.name);
  459.   else printf("select Folder has no name...\n");
  460.   if (folderLine.prettyName)
  461.     printf("select Folder with pretty name (%s)\n", folderLine.prettyName);
  462.   else printf("select Folder has no pretty name...\n");
  463. )
  464.  
  465.   if (folderLine.flags & 
  466.       (MSG_FOLDER_FLAG_NEWSGROUP | MSG_FOLDER_FLAG_NEWS_HOST))
  467.     return False;
  468.   return True;
  469. }
  470.  
  471. void
  472. XFE_MNSearchView::setFolderOption(MSG_FolderInfo *folderInfo)
  473. {
  474.    if ( m_folderInfo == folderInfo ) return;
  475.    m_rules.scopeOpt->selectFolder(folderInfo, True);
  476. }
  477.  
  478. void 
  479. XFE_MNSearchView::addFolderOption()
  480. {
  481. }
  482.  
  483. void
  484. XFE_MNSearchView::buildHeaderOption()
  485. {
  486.   int ac;
  487.   Arg av[10];
  488.   ac = 0;
  489.   Dimension width, height;
  490.  
  491.   m_rules.searchLabel = XmCreateLabelGadget(m_header, 
  492.                 "searchFolderLabel", av, ac);
  493.  
  494.   m_rules.scopeOpt = new XFE_FolderDropdown (getToplevel(),
  495.                     m_header,
  496.                     TRUE, /* server selection */
  497.                     TRUE ); /* show news */
  498.   m_rules.scopeOpt->setPopupServer(False);
  499.   m_rules.scopeOpt->registerInterest(XFE_FolderDropdown::folderSelected,
  500.                                      this,
  501.                                      (XFE_FunctionNotification)folderSelected_cb);
  502.  
  503.   if ( m_folderInfo ) /* set the m_rules.scope right here... */
  504.         m_rules.scopeOpt->selectFolder(m_folderInfo, False);
  505.  
  506.   XtVaGetValues(m_rules.scopeOpt->getBaseWidget(),
  507.                 XmNwidth, &width,
  508.                 XmNheight, &height, 0);
  509.  
  510.   ac = 0;
  511.   m_rules.whereLabel = XmCreateLabelGadget(m_header, "where", av, ac);
  512.   XtVaSetValues(m_rules.searchLabel, XmNheight, height, 0 );
  513.   XtVaSetValues(m_rules.whereLabel, XmNheight, height, 0 );
  514.  
  515.  
  516. }
  517.  
  518. XFE_CALLBACK_DEFN(XFE_MNSearchView, folderSelected)(XFE_NotificationCenter*,
  519.  
  520.                            void *, void *calldata)
  521. {
  522.         MSG_FolderInfo *info = (MSG_FolderInfo*)calldata;
  523.  
  524.         selectFolder(info);
  525. }
  526.  
  527.  
  528. void
  529. XFE_MNSearchView::selectFolder(MSG_FolderInfo *folderInfo)
  530. {
  531.  
  532.     if ( m_folderInfo == folderInfo) return;
  533.  
  534.     if ( isMailFolder(folderInfo) )
  535.     {
  536.              m_rules.scope = scopeMailFolder;
  537.          getToplevel()->notifyInterested(
  538.         XFE_MNSearchView::scopeChanged, (void*)folderInfo);
  539.     }
  540.     else {
  541.                m_rules.scope = scopeNewsgroup;
  542.              getToplevel()->notifyInterested(
  543.             XFE_MNSearchView::scopeChanged, (void*)folderInfo);
  544.  
  545.     }
  546.     m_folderInfo = folderInfo;
  547. }
  548.  
  549. void
  550. XFE_MNSearchView::andOrCB(Widget w, XtPointer clientData, XtPointer)
  551. {
  552.     XFE_MNSearchView* view = (XFE_MNSearchView*)clientData;
  553.     view->setAllBooleans((strcmp("matchAny", XtName(w)) != 0));
  554. }
  555.  
  556. // change all the the2 "ands" to "ors" or vice versa
  557. void
  558. XFE_MNSearchView::setAllBooleans(Boolean andP)
  559. {
  560.     m_booleanAnd = andP;
  561.     if (m_numsubviews <= 1)
  562.         return;
  563.     for (int i=1; i < m_numsubviews; ++i)
  564.         setOneBoolean(i);
  565. }
  566.  
  567. void
  568. XFE_MNSearchView::setOneBoolean(int which)
  569. {
  570.     extern int XFE_SEARCH_BOOL_AND_THE, XFE_SEARCH_BOOL_OR_THE;
  571.     char* newlabel;
  572.     if (m_booleanAnd)
  573.         newlabel = XP_GetString(XFE_SEARCH_BOOL_AND_THE);
  574.     else
  575.         newlabel = XP_GetString(XFE_SEARCH_BOOL_OR_THE);
  576.     XFE_SearchRuleView* curView = (XFE_SearchRuleView*)(m_subviews[which]);
  577.     curView->changeLabel(newlabel);
  578. }
  579.  
  580. void
  581. XFE_MNSearchView::createMoreLess(Widget parent)
  582. {
  583.   Dimension width;
  584.  
  585.   Widget form = XtVaCreateManagedWidget("_form", xmFormWidgetClass, parent, 0);
  586.  
  587.   Widget popup;
  588.   Widget option = fe_make_option_menu(getToplevel()->getBaseWidget(),
  589.                                       form, "optionAndOr", &popup);
  590.   XtVaSetValues(option,
  591.                 XmNtopAttachment, XmATTACH_FORM,
  592.                 XmNleftAttachment, XmATTACH_FORM,
  593.                 0);
  594.  
  595.   Widget btn = XmCreatePushButtonGadget(popup, "matchAll", 0, 0);
  596.   XtAddCallback(btn, XmNactivateCallback, andOrCB, this);
  597.   XtManageChild(btn);
  598.   btn = XmCreatePushButtonGadget(popup, "matchAny", 0, 0);
  599.   XtAddCallback(btn, XmNactivateCallback, andOrCB, this);
  600.   XtManageChild(btn);
  601.  
  602.   XtManageChild(option);
  603.  
  604.   XtVaCreateManagedWidget("where", xmLabelGadgetClass, form,
  605.                           XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
  606.                           XmNbottomWidget, option,
  607.                           XmNleftAttachment, XmATTACH_WIDGET,
  608.                           XmNleftWidget, option,
  609.                           0);
  610.  
  611.   m_ruleContent = XtVaCreateWidget("ruleContent", xmFormWidgetClass, form,
  612.             XmNresizePolicy, XmRESIZE_ANY,
  613.                                    XmNtopAttachment, XmATTACH_WIDGET,
  614.                                    XmNtopWidget, option,
  615.                                    XmNleftAttachment, XmATTACH_FORM,
  616.                                    XmNrightAttachment, XmATTACH_FORM,
  617.                                    XmNbottomAttachment, XmATTACH_FORM,
  618.             0);
  619.  
  620.   m_rules.commandGroup = XmCreateForm(m_ruleContent, "groupRC", NULL, 0 );
  621.   XtVaSetValues(m_rules.commandGroup,
  622.                 XmNleftAttachment, XmATTACH_FORM,
  623.                 XmNrightAttachment, XmATTACH_FORM,
  624.                 XmNbottomAttachment, XmATTACH_FORM,
  625.                 0);
  626.  
  627.   m_rules.more_btn = XmCreatePushButton(m_rules.commandGroup, "more", NULL, 0);
  628.   m_rules.less_btn = XmCreatePushButton(m_rules.commandGroup, "fewer", NULL,0);
  629.  
  630.   XtVaGetValues(m_rules.searchLabel, XmNwidth, &width, 0 );
  631.   XtVaSetValues(m_rules.more_btn,
  632.                 XmNtopAttachment, XmATTACH_FORM,
  633.                 XmNbottomAttachment, XmATTACH_FORM,
  634.                 XmNleftAttachment, XmATTACH_FORM,
  635.         XmNleftOffset, width,
  636.                 XmNrightAttachment, XmATTACH_NONE,
  637.                 0);
  638.  
  639.   XtVaSetValues(m_rules.less_btn,
  640.                 XmNtopAttachment, XmATTACH_FORM,
  641.                 XmNbottomAttachment, XmATTACH_FORM,
  642.                 XmNleftAttachment, XmATTACH_WIDGET,
  643.         XmNleftWidget, m_rules.more_btn,
  644.                 XmNrightAttachment, XmATTACH_NONE,
  645.                 0);
  646.  
  647.   XtManageChild(m_rules.more_btn);
  648.  
  649.   m_newSearchBtn=XmCreatePushButton(m_rules.commandGroup, "NewBtn", NULL, 0);
  650.   XtVaSetValues(m_newSearchBtn,
  651.                 XmNtopAttachment, XmATTACH_FORM,
  652.                 XmNbottomAttachment, XmATTACH_FORM,
  653.                 XmNleftAttachment, XmATTACH_NONE,
  654.                 XmNrightAttachment, XmATTACH_FORM,
  655.                 0);
  656.   XtManageChild(m_newSearchBtn);
  657.   XtAddCallback (m_newSearchBtn, XmNactivateCallback, newCallback, this);
  658.  
  659.   Dimension height1;
  660.   XtVaGetValues(m_rules.less_btn, XmNheight, &height1, 0);
  661.  
  662.   XtAddCallback(m_rules.more_btn, XmNactivateCallback, moreCallback, this);
  663.   XtAddCallback(m_rules.less_btn, XmNactivateCallback, lessCallback, this);
  664. }
  665.  
  666. void
  667. XFE_MNSearchView::doViewLayout()
  668. {
  669.   XFE_SearchRuleView *view;
  670.   int i;
  671.   Dimension lwidth;
  672.  
  673.   for ( i = 0; i < m_numsubviews; i++ )
  674.   {
  675.     view = (XFE_SearchRuleView*)m_subviews[i];
  676.     view->hide();
  677.     if ( i == 0 )
  678.         {
  679.         XtVaGetValues(m_rules.searchLabel, XmNwidth, &lwidth, 0);
  680.       XtVaSetValues(view->getBaseWidget(), 
  681.         XmNtopAttachment, XmATTACH_WIDGET,
  682.         XmNtopWidget, m_header, 0);
  683.       view->setLabelWidth(view->getLeadingWidth());
  684.         }
  685.     else
  686.       XtVaSetValues(view->getBaseWidget(), XmNtopWidget, 
  687.             (m_subviews[i-1])->getBaseWidget(), 0);
  688.         
  689.     XtVaSetValues(view->getBaseWidget(), 
  690.         XmNtopAttachment, XmATTACH_WIDGET,
  691.         XmNrightAttachment, XmATTACH_WIDGET,
  692.         XmNrightWidget, m_rules.searchCommand,
  693.         XmNleftAttachment, XmATTACH_FORM,
  694.         XmNbottomAttachment, XmATTACH_NONE,
  695.         0);
  696.     view->show();
  697.   }
  698. }
  699.  
  700. void
  701. XFE_MNSearchView::doLayout()
  702. {
  703.   XtVaSetValues(m_rules.searchLabel,             /* Search for Header*/
  704.                 XmNalignment, XmALIGNMENT_END,
  705.                 XmNtopAttachment, XmATTACH_FORM,
  706.                 XmNbottomAttachment, XmATTACH_NONE,
  707.                 XmNleftAttachment, XmATTACH_FORM,
  708.                 XmNrightAttachment, XmATTACH_NONE,
  709.                 0);
  710.  
  711.   XtVaSetValues(m_rules.scopeOpt->getBaseWidget(),    /* Search for Scope */
  712.                 XmNtopAttachment, XmATTACH_FORM,
  713.                 XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
  714.                 XmNbottomWidget, m_rules.searchLabel,
  715.                 XmNleftAttachment, XmATTACH_WIDGET,
  716.                 XmNleftWidget, m_rules.searchLabel,
  717.                 XmNrightAttachment, XmATTACH_NONE,
  718.                 0);
  719.  
  720.   XtVaSetValues(m_rules.whereLabel,            /* Search for Where */
  721.                 XmNalignment, XmALIGNMENT_BEGINNING,
  722.                 XmNtopAttachment, XmATTACH_FORM,
  723.                 XmNbottomAttachment, XmATTACH_OPPOSITE_WIDGET,
  724.                 XmNbottomWidget, m_rules.searchLabel,
  725.                 XmNleftAttachment, XmATTACH_WIDGET,
  726.                 XmNleftWidget, m_rules.scopeOpt->getBaseWidget(),
  727.                 XmNrightAttachment, XmATTACH_FORM,
  728.                 0);
  729.   doViewLayout();
  730.  
  731.  
  732.   XtVaSetValues(m_rules.commandGroup,    /* More/Less */
  733.                 XmNnoResize, True,
  734.                 XmNtopAttachment, XmATTACH_WIDGET,
  735.                 XmNtopWidget, m_subviews[0]->getBaseWidget(),
  736.                 XmNbottomAttachment, XmATTACH_NONE,
  737.                 XmNbottomOffset, 0,
  738.                 XmNleftAttachment, XmATTACH_FORM,
  739.                 XmNrightAttachment, XmATTACH_WIDGET,
  740.                 XmNrightWidget, m_rules.searchCommand,
  741.                 0);
  742.  
  743.  
  744.  
  745.   XtManageChild(m_rules.searchLabel);
  746.   m_rules.scopeOpt->show();
  747.   XtManageChild(m_rules.commandGroup);
  748.  
  749.   XtManageChild (m_ruleContent);
  750.   XtManageChild (m_content);
  751.  
  752.   // Now everything's managed; make sure the initial and/or is right:
  753.   setAllBooleans(m_booleanAnd);
  754. }
  755.  
  756. void
  757. XFE_MNSearchView::createDisplayArea()
  758. {
  759.   Cardinal ac;
  760.   Arg av[6];
  761.  
  762.   // Create Display area to display all the rules and results
  763.   ac = 0;
  764.   m_content = XtVaCreateWidget("searchContent", xmFormWidgetClass,
  765.             m_displayArea,
  766.                     XmNtopAttachment, XmATTACH_FORM,
  767.                     XmNbottomAttachment, XmATTACH_NONE,
  768.                     XmNleftAttachment, XmATTACH_FORM,
  769.                     XmNrightAttachment, XmATTACH_FORM,
  770.             0);
  771.  
  772.   /* Right side buttons group - Search, NewSearch, SaveAs, Close */
  773.   createCommandButtons();
  774.  
  775.   /* Scope Header Info  */
  776.  
  777.   ac = 0;
  778.   XtSetArg (av [ac], XmNtopAttachment, XmATTACH_FORM); ac++;
  779.   XtSetArg (av [ac], XmNleftAttachment, XmATTACH_FORM); ac++;
  780.   XtSetArg (av [ac], XmNrightAttachment, XmATTACH_WIDGET); ac++;
  781.   XtSetArg (av [ac], XmNrightWidget, m_rules.searchCommand); ac++;
  782.   m_header = XmCreateForm(m_content, "searchHeader", av, ac );
  783.  
  784.   buildHeaderOption();
  785.  
  786.   XtManageChild(m_header); /* Scope Header */
  787.  
  788.   Widget frame = XtVaCreateManagedWidget("moreLessFrame", xmFrameWidgetClass,
  789.                                          m_content,
  790.                                   XmNtopAttachment, XmATTACH_WIDGET,
  791.                                   XmNtopWidget, m_header,
  792.                                   XmNbottomAttachment, XmATTACH_NONE,
  793.                                   XmNleftAttachment, XmATTACH_FORM,
  794.                                   XmNrightAttachment, XmATTACH_WIDGET,
  795.                                   XmNrightWidget, m_rules.searchCommand,
  796.                                   0);
  797.  
  798.   /* Rule Control - More/Less  */
  799.   createMoreLess(frame);
  800.  
  801.   /* Add Initial Rules */ 
  802.   addRules("A_the1", m_rules.scope, 0); 
  803.  
  804.  
  805.   /* Start to Layout stuffs */
  806.   doLayout();
  807. }
  808.  
  809. void
  810. XFE_MNSearchView::createMiniDashboard(Widget dashboardParent)
  811. {
  812.   Arg av[20];
  813.   int ac;
  814.  
  815.   ac = 0;
  816.   Widget separator = XmCreateSeparatorGadget(dashboardParent, 
  817.             "separator", av, ac);
  818.   XtManageChild(separator);
  819.  
  820.  
  821.   XP_ASSERT( m_parentFrame != NULL );
  822.   XP_ASSERT( m_parentFrame->isAlive() );
  823.  
  824.   m_dashboard = new XFE_Dashboard(getToplevel(),    // top level
  825.                                   dashboardParent,    // parent
  826.                                   m_parentFrame,    // parent frame
  827.                                   False);            // have task bar
  828.  
  829.   m_dashboard->setShowStatusBar(True);
  830.   m_dashboard->setShowProgressBar(True);
  831.   
  832.   /* Set up attachments */
  833.   XtVaSetValues (separator,
  834.                  XmNtopAttachment, XmATTACH_FORM,
  835.                  XmNbottomAttachment, XmATTACH_NONE,
  836.                  XmNleftAttachment, XmATTACH_FORM,
  837.                  XmNrightAttachment, XmATTACH_FORM,
  838.                  0);
  839.  
  840.   XtVaSetValues (m_dashboard->getBaseWidget(),
  841.                  XmNtopAttachment, XmATTACH_WIDGET,
  842.                  XmNtopWidget, separator,
  843.                  XmNbottomAttachment, XmATTACH_FORM,
  844.                  XmNleftAttachment, XmATTACH_FORM,
  845.                  XmNrightAttachment, XmATTACH_FORM,
  846.                  0);
  847.   m_dashboard->show();
  848. }
  849.  
  850. void
  851. XFE_MNSearchView::createWidgets(Widget formParent)
  852. {
  853.   Cardinal ac;
  854.   Arg      av[20];
  855.   
  856.  
  857.   /* Build content */
  858.   ac = 0;
  859.   XtSetArg(av[ac], XmNautoUnmanage, False); ac++;
  860.   m_displayArea= XmCreateForm (formParent, 
  861.                 "searchDisplayArea", av, ac);
  862.   createDisplayArea();
  863.  
  864.   /* Build dashbord */
  865.   ac = 0;
  866.   Widget dashboard = XmCreateForm(formParent, 
  867.                 "searchDashboard", av, ac);
  868.   createMiniDashboard(dashboard);
  869.   XtManageChild(dashboard);
  870.   CONTEXT_DATA(m_contextData)->dashboard = dashboard;
  871.  
  872.   XtVaSetValues (dashboard,
  873.                  XmNtopAttachment, XmATTACH_NONE,
  874.                  XmNbottomAttachment, XmATTACH_FORM,
  875.                  XmNleftAttachment, XmATTACH_FORM,
  876.                  XmNrightAttachment, XmATTACH_FORM,
  877.                  0);
  878.  
  879.   XtVaSetValues(m_displayArea,
  880.         XmNtopAttachment,XmATTACH_FORM,
  881.         XmNbottomAttachment, XmATTACH_WIDGET,
  882.         XmNbottomWidget, dashboard,
  883.         XmNleftAttachment, XmATTACH_FORM,
  884.         XmNrightAttachment, XmATTACH_FORM,
  885.         0);
  886.  
  887.   XtManageChild(m_displayArea);
  888.   // Create layouts
  889.   XtManageChild (getBaseWidget());
  890. }
  891.  
  892.  
  893. XFE_CALLBACK_DEFN(XFE_MNSearchView, searchStart)(
  894.         XFE_NotificationCenter */*obj*/,
  895.                 void */*clientData*/,
  896.                 void */* callData */)
  897. {
  898.   startSearch(m_searchBtn);
  899. }
  900. //fe_search_start_cb(Widget w, XtPointer clientData, XtPointer callData)
  901. void
  902. XFE_MNSearchView::startCallback(Widget w, XtPointer clientData, XtPointer)
  903. {
  904.   XFE_MNSearchView *obj = (XFE_MNSearchView*)clientData;
  905.   obj->startSearch(w);
  906. }
  907.  
  908. //fe_search_result_reset(fe_search_data *fep)
  909. void
  910. XFE_MNSearchView::resetSearch()
  911. {
  912.   if (m_outliner)
  913.    m_outliner->deselectAllItems();
  914.   if ( m_outliner )
  915.      m_outliner->change(0, 0, 0);
  916.  
  917.   if (m_gotoBtn) /* Turn off the m_gotoBtn */
  918.   {
  919.     XtSetSensitive(m_gotoBtn, False);
  920.     XtSetSensitive(m_deleteBtn, False);
  921.     m_fileBtn->setSensitive(False);
  922.   }
  923.  
  924.   toggleActionButtonState(False);
  925.  
  926.   getToplevel()->notifyInterested(XFE_View::statusNeedsUpdating, (void*)"");
  927. }
  928.  
  929. //fe_search_createResultArea(MWContext *context)
  930. void
  931. XFE_MNSearchView::createResultArea()
  932. {
  933.    XtVaSetValues(m_content, XmNresizePolicy, XmRESIZE_ANY, 0);
  934.    //XtVaSetValues(getBaseWidget(), XmNresizePolicy, XmRESIZE_NONE, 0);
  935.  
  936.    XtVaSetValues(m_content, XmNbottomAttachment, XmATTACH_NONE, 0);
  937.  
  938.    XtVaSetValues(m_content, XmNresizePolicy, XmRESIZE_NONE, 0);
  939.    XtVaSetValues(getBaseWidget(), XmNresizePolicy, XmRESIZE_NONE, 0);
  940.    XtVaSetValues(getToplevel()->getBaseWidget(), 
  941.             XmNresizePolicy, XmRESIZE_ANY, 0);
  942.    doExpand(True);
  943. }
  944.  
  945. //fe_search_updateUI(MWContext *context, Boolean allowSearch)
  946. void
  947. XFE_MNSearchView::updateUI(Boolean allowSearch)
  948. {
  949.  
  950.   XtVaSetValues(m_rules.more_btn, XmNsensitive, allowSearch, 0);
  951.   XtVaSetValues(m_rules.less_btn, XmNsensitive, allowSearch, 0);
  952.   if (m_gotoBtn )
  953.   {
  954.    if ( !allowSearch ) /* disable gotoBtn so that user will not interrupt
  955.               current search. This is to be consistent with
  956.               "more btn" */
  957.    {
  958.       XtVaSetValues(m_gotoBtn, XmNsensitive, allowSearch, 0);
  959.       XtVaSetValues(m_deleteBtn, XmNsensitive, allowSearch, 0);
  960.       m_fileBtn->setSensitive(allowSearch);
  961.    }
  962.    else 
  963.    {
  964.        /* when search is done, don't enable this gotobtn until
  965.           there is something selected in the search result */ 
  966.  
  967.        int count;
  968.        const int *selected;
  969.  
  970.        if (m_outliner)
  971.        {
  972.             m_outliner->getSelection( &selected, &count);
  973.           if ((count == 1) && 
  974.               MSG_GoToFolderStatus (getPane(), (MSG_ViewIndex *)selected, count))
  975.           {
  976.              XtSetSensitive(m_gotoBtn, True);
  977.              XtSetSensitive(m_deleteBtn, True);
  978.              m_fileBtn->setSensitive(True);
  979.           }
  980.           else if (count > 1)
  981.           {
  982.              XtSetSensitive(m_gotoBtn, False);
  983.              XtSetSensitive(m_deleteBtn, True);
  984.              m_fileBtn->setSensitive(True);
  985.           }
  986.           else
  987.           {
  988.              XtSetSensitive(m_gotoBtn, False);
  989.              XtSetSensitive(m_deleteBtn, False);
  990.              m_fileBtn->setSensitive(False);
  991.           }
  992.        }
  993.        else
  994.        {
  995.          XtSetSensitive(m_gotoBtn, False);
  996.          XtSetSensitive(m_deleteBtn, False);
  997.          m_fileBtn->setSensitive(False);
  998.        }
  999.     }
  1000.   }
  1001.  
  1002.   if ( m_hasResult )
  1003.       XtVaSetValues(m_newSearchBtn, XmNsensitive, allowSearch, 0);
  1004.  
  1005. }
  1006.  
  1007. //fe_search_click_onStop(Widget w, MWContext *context)
  1008. Boolean
  1009. XFE_MNSearchView::isOnStop(Widget w)
  1010. {
  1011.   int data;
  1012.  
  1013.   XtVaGetValues(w, 
  1014.         XmNuserData, &data,  0);
  1015.  
  1016.  if ( data == kStop )
  1017.  {
  1018.     return True;
  1019.  }
  1020.  return False;
  1021.  
  1022. }
  1023.  
  1024.  
  1025.  
  1026. //fe_search_turnStopOn(MWContext* context, Widget w, Boolean turnOn)
  1027. void
  1028. XFE_MNSearchView::turnOnStop(Widget w, Boolean turnOn)
  1029. {
  1030.   XmString xmStr;
  1031.   char *string;
  1032.  
  1033.   if ( turnOn)
  1034.   {
  1035.     string = XP_STRDUP(XP_GetString(XFE_AB_STOP));
  1036.     xmStr = XmStringCreateSimple(string);
  1037.     XtVaSetValues(w, XmNlabelString, xmStr, 
  1038.                      XmNuserData, kStop,  0);
  1039.     updateUI(False);
  1040.     XP_FREE(string);
  1041.   }
  1042.   else
  1043.   {
  1044.     string = XP_STRDUP(XP_GetString(XFE_AB_SEARCH));
  1045.     xmStr = XmStringCreateSimple(string);
  1046.     XtVaSetValues(w, XmNlabelString, xmStr,
  1047.                 XmNuserData, kSearch,  0);
  1048.     updateUI(True);
  1049.     XP_FREE(string);
  1050.   }
  1051. }
  1052.  
  1053. void
  1054. XFE_MNSearchView::stopSearch()
  1055. {
  1056.     turnOnStop(m_searchBtn, False);
  1057.  
  1058.     if (m_outliner) {
  1059.         int count = m_outliner->getTotalLines();
  1060.         if (!count) {
  1061.             char tmp[128];
  1062.             XP_SAFE_SPRINTF(tmp, sizeof(tmp),
  1063.                             "%s",
  1064.                             XP_GetString(XFE_SEARCH_NO_MATCHES));
  1065.  
  1066.             XFE_Progress(m_contextData, tmp);
  1067.         }/* if */
  1068.     }/* if */
  1069. }
  1070.  
  1071. void
  1072. XFE_MNSearchView::prepSearchScope()
  1073. {
  1074.    if (m_searchAll )
  1075.    {
  1076.        MSG_AddAllScopes( getPane(), fe_getMNMaster(), m_rules.scope);
  1077.    }
  1078.    else
  1079.    {
  1080.        MSG_AddScopeTerm(getPane(), m_rules.scope, m_folderInfo);
  1081.    }
  1082. }
  1083.         
  1084.  
  1085. void
  1086. XFE_MNSearchView::startSearch(Widget w)
  1087. {
  1088.   XFE_SearchRuleView *subView;
  1089.   int i;
  1090.   int count = 0;
  1091.   MSG_SearchValue value;
  1092.   MSG_SearchAttribute attr;
  1093.   MSG_SearchOperator op;
  1094.  
  1095.   if ( isOnStop (w) )
  1096.   {
  1097.      /* We should stop the search action */
  1098.     XP_InterruptContext(m_contextData);
  1099.     turnOnStop(w, False);
  1100.     return;
  1101.   }
  1102.  
  1103.   resetSearch();
  1104.  
  1105.   if ( m_allocated )
  1106.   {
  1107.      MSG_SearchFree(getPane());
  1108.      m_allocated = 0;
  1109.      m_hasResult = False;
  1110.   }
  1111.  
  1112.   count = m_numsubviews;
  1113.  
  1114.   if ( count > 0 ) {
  1115.     MSG_SearchAlloc(getPane());
  1116.     m_allocated = 1;
  1117.     m_hasResult = True;
  1118.   }
  1119.  
  1120.   for (i = count-1; i >= 0 ; i-- )
  1121.   {
  1122.     subView = (XFE_SearchRuleView*)m_subviews[i];
  1123.  
  1124.     if ( subView ) 
  1125.     {
  1126.        char customHdr[160];
  1127.        if (subView->getSearchTerm(&attr, &op, &value, customHdr) )
  1128.           { 
  1129.               MSG_AddSearchTerm(getPane(), attr, op, &value, 
  1130.                                 m_booleanAnd, customHdr); 
  1131.           } 
  1132. /*
  1133. #else 
  1134.            MSG_AddSearchTerm(getPane(), attr, op, &value); 
  1135. #endif
  1136. */
  1137.        else 
  1138.        {
  1139.         turnOnStop(w, False);
  1140.         return;
  1141.        }
  1142.      }
  1143.    }
  1144.   /* Create the result area now... */
  1145.   createResultArea();
  1146.   prepSearchScope();
  1147.  
  1148.    if ( MSG_Search(getPane()) == SearchError_Success )
  1149.    {
  1150.            turnOnStop(w, True);
  1151.    }
  1152. }
  1153.  
  1154. //fe_search_new_cb(Widget w, XtPointer clientData, XtPointer callData)
  1155. void
  1156. XFE_MNSearchView::newCallback(Widget, XtPointer clientData, XtPointer)
  1157. {
  1158.   XFE_MNSearchView* obj = (XFE_MNSearchView*)clientData;
  1159.   obj->newSearch();
  1160. }
  1161.  
  1162. void
  1163. XFE_MNSearchView::newSearch()
  1164. {
  1165.   int i, count ;
  1166.   XFE_SearchRuleView *subView;
  1167.  
  1168.   if (m_allocated )
  1169.   {
  1170.     MSG_SearchFree(getPane());
  1171.     m_allocated = 0;
  1172.     m_hasResult = False;
  1173.   }
  1174.  
  1175.   count = m_numsubviews;
  1176.  
  1177.   // DORA rule.ruleList is obselete now it's view
  1178.   resetSearch();
  1179.   doExpand(False);
  1180.   for (i = count-1; i > 0 ; i-- )
  1181.   {
  1182.         lessRules();
  1183.   }
  1184.   subView = (XFE_SearchRuleView*)m_subviews[0];
  1185.   subView->resetSearchValue();
  1186.  
  1187. }
  1188.  
  1189. //fe_search_close_cb(Widget w, XtPointer clientData, XtPointer callData)
  1190. void
  1191. XFE_MNSearchView::closeCallback(Widget, XtPointer clientData, XtPointer)
  1192. {
  1193.   XFE_MNSearchView* obj = (XFE_MNSearchView*)clientData;
  1194.  
  1195.   obj->handleClose();
  1196. }
  1197.  
  1198. void
  1199. XFE_MNSearchView::handleClose()
  1200. {
  1201.   /* hide the frame for now*/
  1202.   getToplevel()->notifyInterested(XFE_MNSearchView::CloseSearch);
  1203.   //XtDestroyWidget(obj->getToplevel()->getBaseWidget());
  1204. }
  1205.  
  1206.  
  1207.  
  1208. //fe_search_save_as_cb(Widget w, XtPointer clientData, XtPointer callData)
  1209. void
  1210. XFE_MNSearchView::miscCallback(Widget /*w*/, 
  1211.             XtPointer clientData, XtPointer /*callData*/)
  1212. {
  1213.   XFE_MNSearchView* obj = (XFE_MNSearchView*)clientData;
  1214.   obj->miscCmd();
  1215. }
  1216.  
  1217. void
  1218. XFE_MNSearchView::miscCmd()
  1219. {
  1220.     // Bring up the Advanced Search dialog
  1221.     XFE_AdvSearchDialog* advDialog = new XFE_AdvSearchDialog
  1222.         (getToplevel()->getBaseWidget(),
  1223.          "advancedSearch",
  1224.          ViewGlue_getFrame(m_contextData));
  1225.     advDialog->post();
  1226.     //delete advDialog;   //this causes a core dump
  1227. }
  1228.  
  1229.  
  1230. //fe_search_more_rule_cb(Widget w, XtPointer clientData, XtPointer callData)
  1231. void
  1232. XFE_MNSearchView::moreCallback(
  1233.             Widget , XtPointer clientData, XtPointer )
  1234. {
  1235.    XFE_MNSearchView* obj = (XFE_MNSearchView*)clientData;
  1236.    obj->moreRules();
  1237. }
  1238.  
  1239. void
  1240. XFE_MNSearchView::moreRules()
  1241. {
  1242.    XFE_SearchRuleView *newView = NULL;
  1243.    XFE_SearchRuleView *curView = NULL;
  1244.    Dimension width, height;
  1245.    Dimension dheight = 0;
  1246.    Dimension minHeight = 0;
  1247.    Dimension delta = 0;
  1248.    Dimension mh, space;
  1249.  
  1250.    // Get the minimum height for the m_content by getting the
  1251.    // m_ruleContent height. We use this to control the content geometry
  1252.  
  1253.    XtVaGetValues(XtParent(m_ruleContent), XmNheight, &minHeight,
  1254.     XmNmarginHeight, &mh, XmNverticalSpacing, &space, 0 );
  1255.  
  1256.    XtVaSetValues(m_content, XmNresizePolicy, XmRESIZE_NONE, 0);
  1257.    // Get margin height of m_content so that we can use m_content's content
  1258.    // and m_content's margin height to calculate 
  1259.    // the exact height of m_content
  1260.    XtVaGetValues (m_content, XmNwidth, &width, 
  1261.         XmNheight, &height, 
  1262.         XmNmarginHeight, &mh,  // Need to get margin height
  1263.         0 );
  1264.  
  1265.    XtVaGetValues(getToplevel()->getBaseWidget(), XmNheight, &dheight, 0 );
  1266.  
  1267.  
  1268.    void* folder_data = (void*)m_folderInfo;
  1269.  
  1270.    if ( m_rules.scope == scopeLdapDirectory)
  1271.       folder_data = (void*)m_dir;
  1272.  
  1273.    if ( m_numsubviews== 0 )
  1274.    {
  1275.     // Add new view
  1276.      newView = new XFE_SearchRuleView(getToplevel(),
  1277.                     m_ruleContent,
  1278.                     this,
  1279.                     m_contextData,
  1280.                     getPane(),
  1281.                     "A_the2",
  1282.                     folder_data,
  1283.                     m_rules.scope,
  1284.                     0);
  1285.    }
  1286.    else 
  1287.    {
  1288.     // Append a new view
  1289.     curView = (XFE_SearchRuleView*)(m_subviews[m_numsubviews-1]);
  1290.     XP_ASSERT(curView!= NULL);
  1291.     newView = new XFE_SearchRuleView(getToplevel(),
  1292.             m_ruleContent,
  1293.             this,
  1294.             m_contextData,
  1295.             getPane(),
  1296.             "A_the2",
  1297.             folder_data,
  1298.             m_rules.scope,
  1299.             (curView->getAttributeIndex()+1));
  1300.    }
  1301.  
  1302.    // We only use a single margin height because the
  1303.    // attachments of m_content's children has bottomAttachment set to NONE.
  1304.    // Therefore, marginHeight at the bottom is not used.
  1305.  
  1306.      delta = newView->getHeight()+mh;
  1307.  
  1308.    addView(newView);
  1309.    if ( curView )
  1310.    {
  1311.     Dimension lwidth = newView->getLeadingWidth();
  1312.  
  1313.        XtVaSetValues(newView->getBaseWidget(),
  1314.                 XmNtopAttachment, XmATTACH_WIDGET,
  1315.                 XmNtopWidget, curView->getBaseWidget(),
  1316.                 0);
  1317.  
  1318.  
  1319.        if (!m_hasRightLabel)
  1320.        {
  1321.         curView->adjustLeadingWidth(lwidth);
  1322.              m_hasRightLabel = True;
  1323.        }
  1324.         newView->setLabelWidth(lwidth);
  1325.   }
  1326.   else
  1327.   {
  1328.    Dimension lbl_width;
  1329.    XtVaGetValues(m_rules.searchLabel, XmNwidth, &lbl_width, 0);
  1330.    newView->setLabelWidth(lbl_width);
  1331.  
  1332.    XtVaSetValues(newView->getBaseWidget(),
  1333.                 XmNtopAttachment, XmATTACH_WIDGET,
  1334.         XmNtopWidget, m_header, 0);
  1335.    }
  1336.    XtVaSetValues(newView->getBaseWidget(),
  1337.                 XmNbottomAttachment, XmATTACH_NONE,
  1338.                 XmNleftAttachment, XmATTACH_FORM,
  1339.                 XmNrightAttachment, XmATTACH_WIDGET, 
  1340.             XmNrightWidget, m_rules.searchCommand, 0);
  1341.  
  1342.    XtVaSetValues(m_rules.commandGroup, 
  1343.         XmNtopAttachment, XmATTACH_WIDGET,
  1344.         XmNtopWidget, newView->getBaseWidget(),
  1345.                  XmNbottomAttachment, XmATTACH_FORM,
  1346.                  0);
  1347.  
  1348.   XtVaSetValues (m_content,XmNwidth, width, 0);
  1349.  
  1350.   XtVaSetValues (m_content, XmNresizePolicy, XmRESIZE_NONE,
  1351.         XmNheight, height+delta, 0);
  1352.  
  1353.   XtVaSetValues (getBaseWidget(), XmNwidth, width, 
  1354.         XmNheight, dheight + delta, 
  1355.         XmNresizePolicy, XmRESIZE_ANY, 0); 
  1356.  
  1357.   XtVaSetValues (getToplevel()->getBaseWidget(), XmNwidth, width, 
  1358.         XmNheight, dheight + delta, 
  1359.         XmNresizePolicy, XmRESIZE_ANY, 0); 
  1360.   newView->show();
  1361.   XtManageChild(m_rules.less_btn);
  1362.  
  1363.   // To prevent more rules to show up after 5th rules
  1364.   // Same as windows
  1365.  
  1366.   if ( m_numsubviews >= MAX_RULES_ALLOWED )
  1367.   {
  1368.     XtSetSensitive(m_rules.more_btn, False);
  1369.   }
  1370.  
  1371.   // Make sure the label ("and" vs. "or") is the same as the rest:
  1372.   setOneBoolean(m_numsubviews-1);
  1373. }
  1374.  
  1375. //fe_search_less_rule_cb(Widget w, XtPointer clientData, XtPointer callData)
  1376. void
  1377. XFE_MNSearchView::lessCallback( Widget, XtPointer clientData, XtPointer)
  1378. {
  1379.    XFE_MNSearchView* obj = (XFE_MNSearchView*)clientData;
  1380.    obj->lessRules();
  1381. }
  1382.  
  1383. void
  1384. XFE_MNSearchView::lessRules()
  1385. {
  1386.    XFE_SearchRuleView *newView;
  1387.    XFE_SearchRuleView *curView;
  1388.    //fe_SearchListElement *newlist;
  1389.    //fe_SearchListElement *curlist;
  1390.    Dimension width = 0, height = 0, dwidth, dheight = 0, curHeight = 0;
  1391.    Dimension minHeight = 0;
  1392.    Dimension mh= 0;
  1393.  
  1394.    // When subtract rules, we use the searchCommand to control
  1395.    // the min Height  of the m_content
  1396.    XtVaGetValues(m_rules.searchCommand, XmNheight, &minHeight, 0);
  1397.  
  1398.    XtVaSetValues (m_content, XmNresizePolicy, XmRESIZE_NONE, 0);
  1399.    XtVaGetValues (m_content, XmNmarginHeight, &mh, 
  1400.         XmNheight, &height, XmNwidth, &width, 0);
  1401.    XtVaGetValues (getToplevel()->getBaseWidget(), XmNwidth, &dwidth, 0);
  1402.    XtVaGetValues (getToplevel()->getBaseWidget(), XmNheight, &dheight, 0 );
  1403.  
  1404.    // Min height of the m_content is made of the height of searchCommand
  1405.    // height plus one margin height. The bottom attachment of searchCommand is
  1406.    // NONE. Therefore, we only use one margin height to calculate the height
  1407.  
  1408.    minHeight = minHeight+mh;
  1409.  
  1410.    if ( m_numsubviews> 1 )
  1411.    {
  1412.     
  1413.      curView = (XFE_SearchRuleView*)(m_subviews[m_numsubviews-1]);
  1414.      m_subviews[m_numsubviews-1] = NULL;
  1415.      m_numsubviews--;
  1416.      newView = (XFE_SearchRuleView*)(m_subviews[m_numsubviews-1]);
  1417.      XtVaSetValues(m_rules.commandGroup, 
  1418.         XmNtopAttachment, XmATTACH_WIDGET,
  1419.         XmNtopWidget, newView->getBaseWidget(), 0);
  1420.  
  1421.      curHeight = curView->getHeight();
  1422.      curView->hide();
  1423.      delete curView;
  1424.    }
  1425.  
  1426.    if ( m_numsubviews== 1 )
  1427.    {
  1428.        XtUnmanageChild(m_rules.less_btn);
  1429.  
  1430.     // To maintain at min height for m_content
  1431.         if ( height - curHeight < minHeight)
  1432.           curHeight = height-minHeight;
  1433.    }
  1434.  
  1435.    XtVaSetValues(m_content, XmNwidth, width, 0 ); 
  1436.  
  1437.    XtVaSetValues(m_content, 
  1438.         XmNresizePolicy, XmRESIZE_NONE,
  1439.         XmNheight, height-curHeight, 
  1440.         0 );
  1441.  
  1442.    XtVaSetValues(getBaseWidget(), 
  1443.     XmNwidth, dwidth, 
  1444.     XmNheight, dheight - curHeight, 
  1445.     XmNresizePolicy, XmRESIZE_ANY, 
  1446.     0 );
  1447.  
  1448.    XtVaSetValues(getToplevel()->getBaseWidget(), 
  1449.     XmNwidth, dwidth, 
  1450.     XmNheight, dheight - curHeight, 
  1451.     XmNresizePolicy, XmRESIZE_ANY, 
  1452.     0 );
  1453.  
  1454.   // To prevent more rules to show up after 5th rules
  1455.   // Same as windows
  1456.  
  1457.   if ( m_numsubviews < MAX_RULES_ALLOWED )
  1458.   {
  1459.     XtSetSensitive(m_rules.more_btn, True);
  1460.   }
  1461. }
  1462.  
  1463.  
  1464. // The Outlinable interface.
  1465. void *
  1466. XFE_MNSearchView::ConvFromIndex(int /*index*/) 
  1467. {
  1468.     return NULL;
  1469. }
  1470.  
  1471. int
  1472. XFE_MNSearchView::ConvToIndex(void */*item*/)
  1473. {
  1474.     return 0;
  1475. }
  1476.  
  1477.  
  1478. char *
  1479. XFE_MNSearchView::getColumnName(int column)
  1480. {
  1481.     switch (column)
  1482.         {
  1483.         case MAILSEARCH_OUTLINER_COLUMN_LOCATION:
  1484.             return XP_GetString(XFE_SEARCH_LOCATION); // XXX i18n
  1485.         case MAILSEARCH_OUTLINER_COLUMN_SUBJECT:
  1486.             return XP_GetString(XFE_SEARCH_SUBJECT); // XXX i18n
  1487.         case MAILSEARCH_OUTLINER_COLUMN_SENDER:
  1488.             return XP_GetString(XFE_SEARCH_SENDER); // XXX i18n
  1489.         case MAILSEARCH_OUTLINER_COLUMN_DATE:
  1490.             return XP_GetString(XFE_SEARCH_DATE); // XXX i18n
  1491.         case MAILSEARCH_OUTLINER_COLUMN_PRIORITY:
  1492.             return XP_GetString(XFE_PRI_PRIORITY); // XXX i18n
  1493.         default:
  1494.             XP_ASSERT(0);
  1495.             return 0;
  1496.         }
  1497. }
  1498.  
  1499. char *
  1500. XFE_MNSearchView::getColumnHeaderText(int column) 
  1501. {
  1502.     switch (column)
  1503.         {
  1504.         case MAILSEARCH_OUTLINER_COLUMN_LOCATION:
  1505.             return XP_GetString(XFE_SEARCH_LOCATION); // XXX i18n
  1506.         case MAILSEARCH_OUTLINER_COLUMN_SUBJECT:
  1507.             return XP_GetString(XFE_SEARCH_SUBJECT); // XXX i18n
  1508.         case MAILSEARCH_OUTLINER_COLUMN_SENDER:
  1509.             return XP_GetString(XFE_SEARCH_SENDER); // XXX i18n
  1510.         case MAILSEARCH_OUTLINER_COLUMN_DATE:
  1511.             return XP_GetString(XFE_SEARCH_DATE); // XXX i18n
  1512.         case MAILSEARCH_OUTLINER_COLUMN_PRIORITY:
  1513.             return XP_GetString(XFE_PRI_PRIORITY); // XXX i18n
  1514.         default:
  1515.             XP_ASSERT(0);
  1516.             return 0;
  1517.     }
  1518. }
  1519.  
  1520.  
  1521. fe_icon *
  1522. XFE_MNSearchView::getColumnHeaderIcon(int) 
  1523. {
  1524.     return NULL;
  1525. }
  1526.  
  1527. EOutlinerTextStyle 
  1528. XFE_MNSearchView::getColumnHeaderStyle(int) 
  1529. {
  1530.     return OUTLINER_Bold;
  1531. }
  1532.  
  1533. void *
  1534. XFE_MNSearchView::acquireLineData(int line) 
  1535. {
  1536.    m_resultLine = NULL;
  1537.    int count = m_outliner->getTotalLines();
  1538.  
  1539.    if (line >= 0 &&
  1540.        line < count) {
  1541.        MSG_GetResultElement(getPane(), line, &m_resultLine);
  1542.    }/* if */
  1543.  
  1544.    return m_resultLine;
  1545. }
  1546.  
  1547.  
  1548. void 
  1549. XFE_MNSearchView::getTreeInfo(XP_Bool */*expandable*/, 
  1550.             XP_Bool */*is_expanded*/, int */*depth*/,
  1551.                         OutlinerAncestorInfo **/*ancestor*/)
  1552. {
  1553.     // Do Nothing
  1554. }
  1555.  
  1556. EOutlinerTextStyle
  1557. XFE_MNSearchView::getColumnStyle(int /*column*/)
  1558. {
  1559.   return OUTLINER_Default;
  1560. }
  1561.  
  1562. char *
  1563. XFE_MNSearchView::getColumnText(int column)
  1564. {
  1565.  MSG_SearchValue *result;
  1566.  char *data = NULL;
  1567.  
  1568.     // Fill in the text for this particular column
  1569.   if (!m_resultLine )  return NULL;
  1570.   switch (column)
  1571.   {
  1572.     case MAILSEARCH_OUTLINER_COLUMN_SUBJECT:
  1573.       MSG_GetResultAttribute(m_resultLine, attribSubject, &result);
  1574.     INTL_DECODE_MIME_PART_II(data, result->u.string, fe_LocaleCharSetID, FALSE);
  1575.     break;
  1576.     case MAILSEARCH_OUTLINER_COLUMN_SENDER:
  1577.       MSG_GetResultAttribute(m_resultLine, attribSender, &result);
  1578.     INTL_DECODE_MIME_PART_II(data, result->u.string, fe_LocaleCharSetID, FALSE);
  1579.     break;
  1580.     case MAILSEARCH_OUTLINER_COLUMN_DATE:
  1581.       MSG_GetResultAttribute(m_resultLine, attribDate, &result);
  1582.     data = XP_STRDUP(MSG_FormatDate(getPane(), result->u.date));
  1583.     break;
  1584.     case MAILSEARCH_OUTLINER_COLUMN_PRIORITY:
  1585.       MSG_GetResultAttribute(m_resultLine, attribPriority, &result);
  1586.     data = priorityToString(result->u.priority);
  1587.     break;
  1588.     case MAILSEARCH_OUTLINER_COLUMN_LOCATION:
  1589.       MSG_GetResultAttribute(m_resultLine, attribLocation, &result);
  1590.     data = XP_STRDUP(result->u.string);
  1591.     break;
  1592.   }
  1593.   MSG_DestroySearchValue(result);
  1594.   return data;
  1595. }
  1596.  
  1597. fe_icon *
  1598. XFE_MNSearchView::getColumnIcon(int column)
  1599. {
  1600.    // Fill in the text for this particular column
  1601.    if ( column == MAILSEARCH_OUTLINER_COLUMN_SUBJECT)
  1602.    {
  1603.     return 0; // Suppose to return mail icon
  1604.    }
  1605.  
  1606.    return 0;
  1607. }
  1608.  
  1609. void
  1610. XFE_MNSearchView::clickHeader(const OutlineButtonFuncData *data)
  1611. {
  1612.   int column = data->column;
  1613.   int invalid = True;
  1614.  
  1615.   switch (column)
  1616.     {
  1617.     case MAILSEARCH_OUTLINER_COLUMN_LOCATION:
  1618.     MSG_SortResultList(getPane(), attribLocation, False);
  1619.     break;
  1620.     case MAILSEARCH_OUTLINER_COLUMN_SUBJECT:
  1621.     MSG_SortResultList(getPane(), attribSubject, False);
  1622.     break;
  1623.     case MAILSEARCH_OUTLINER_COLUMN_SENDER:
  1624.     MSG_SortResultList(getPane(), attribSender, False);
  1625.     break;
  1626.     case MAILSEARCH_OUTLINER_COLUMN_DATE:
  1627.     MSG_SortResultList(getPane(), attribDate, False);
  1628.     break;
  1629.     case MAILSEARCH_OUTLINER_COLUMN_PRIORITY:
  1630.     MSG_SortResultList(getPane(), attribPriority, False);
  1631.     break;
  1632.     default:
  1633.       invalid = False;
  1634.     }/* switch() */
  1635.   if (invalid)
  1636.     m_outliner->invalidate();
  1637. }
  1638.  
  1639. void 
  1640. XFE_MNSearchView::singleClick(const OutlineButtonFuncData *data)
  1641. {
  1642.     m_outliner->selectItemExclusive(data->row);
  1643.     toggleActionButtonState(True);
  1644. }
  1645.  
  1646. void 
  1647. XFE_MNSearchView::doubleClick(const OutlineButtonFuncData *data)
  1648. {
  1649.    MSG_ViewIndex index;
  1650.    MSG_ResultElement *elem = NULL;
  1651.  
  1652.    m_outliner->selectItemExclusive(data->row);
  1653.  
  1654.    toggleActionButtonState(True);
  1655.  
  1656.    index = (MSG_ViewIndex)(data->row);
  1657.    MSG_GetResultElement(getPane(), index, &elem );
  1658.  
  1659.    XP_ASSERT(elem!=NULL);
  1660.  
  1661.  
  1662.    MWContextType cxType = MSG_GetResultElementType(elem);
  1663.  
  1664.    if ( cxType == MWContextMail
  1665.     || cxType == MWContextMailMsg
  1666.     || cxType == MWContextNews
  1667.     || cxType == MWContextNewsMsg )
  1668.    {
  1669.        XP_List *msg_frame_list = 
  1670.         XFE_MozillaApp::theApp()->getFrameList( FRAME_MAILNEWS_MSG );
  1671.     m_msgFrame = NULL;
  1672.         if (!XP_ListIsEmpty(msg_frame_list))
  1673.         {
  1674.           m_msgFrame = (XFE_MsgFrame*)XP_ListTopObject( msg_frame_list );
  1675.         }
  1676.  
  1677.     if (!m_msgFrame)
  1678.     {
  1679.      m_msgFrame = new XFE_MsgFrame(XfeAncestorFindApplicationShell(getToplevel()->getBaseWidget()),
  1680.                                    ViewGlue_getFrame(m_contextData), NULL);
  1681.         }
  1682.         m_searchpane = ((XFE_MsgView*)(m_msgFrame->getView()))->getPane();
  1683.     m_msgFrame->show();
  1684.         MSG_OpenResultElement(elem, m_searchpane);
  1685.  
  1686.         // Tell the message frame to unmanage half its buttons:
  1687.         m_msgFrame->setButtonsByContext(cxType);
  1688.     }
  1689.  
  1690. }
  1691.  
  1692. void 
  1693. XFE_MNSearchView::Buttonfunc(const OutlineButtonFuncData *data)
  1694. {
  1695.     int row = data->row, 
  1696.         clicks = data->clicks;
  1697.  
  1698.     if (row < 0) {
  1699.         clickHeader(data);
  1700.         return;
  1701.     } 
  1702.     else {
  1703.         /* content row 
  1704.          */
  1705.         if (clicks == 2) {
  1706.             m_outliner->selectItemExclusive(data->row);
  1707.             doubleClick(data);
  1708.         }/* clicks == 2 */
  1709.         else if (clicks == 1) {
  1710.             if (data->ctrl)
  1711.                 {
  1712.                     m_outliner->toggleSelected(data->row);
  1713.                 }
  1714.             else if (data->shift) {
  1715.                 // select the range.
  1716.                 const int *selected;
  1717.                 int count;
  1718.                 
  1719.                 m_outliner->getSelection(&selected, &count);
  1720.                 
  1721.                 if (count == 0) { /* there wasn't anything selected yet. */
  1722.                     m_outliner->selectItemExclusive(data->row);
  1723.                 }/* if count == 0 */
  1724.                 else if (count == 1) {
  1725.                     /* there was only one, so we select the range from
  1726.                        that item to the new one. */
  1727.                     m_outliner->selectRangeByIndices(selected[0], data->row);
  1728.                 }/* count == 1 */
  1729.                 else {
  1730.                     /* we had a range of items selected, so let's do something really
  1731.                        nice with them. */
  1732.                     m_outliner->trimOrExpandSelection(data->row);
  1733.                 }/* else */
  1734.             }/* if */
  1735.             else {
  1736.                 m_outliner->selectItemExclusive(data->row);
  1737.             }/* else */
  1738.  
  1739.             Boolean finishSearch = True;
  1740.  
  1741.             /* this "go to btn" should keep consistent state with "more btn" */
  1742.             if ( m_rules.more_btn ) 
  1743.               XtVaGetValues(m_rules.more_btn, XmNsensitive, &finishSearch, 0);
  1744.  
  1745.             if ( finishSearch && m_gotoBtn )  /* if search is done, take care of the gotobtn */
  1746.             {
  1747.             /* Find out how many rows are selected: If only one is selected,
  1748.                we turn on the button m_gotoBtn, otherwise, we don't allow
  1749.                the button m_gotoBtn to be sensitive */
  1750.  
  1751.               int count;
  1752.               const int *selected;
  1753.                 m_outliner->getSelection( &selected, &count);
  1754.  
  1755.               if ((count == 1) &&
  1756.                   MSG_GoToFolderStatus (getPane(), 
  1757.                                         (MSG_ViewIndex *)selected, count))
  1758.               {
  1759.                   XtSetSensitive(m_gotoBtn, True);
  1760.                   XtSetSensitive(m_deleteBtn, True);
  1761.                   m_fileBtn->setSensitive(True);
  1762.               }
  1763.               else if (count > 1)
  1764.               {
  1765.                   XtSetSensitive(m_gotoBtn, False);
  1766.                   XtSetSensitive(m_deleteBtn, True);
  1767.                   m_fileBtn->setSensitive(True);
  1768.               }
  1769.               else
  1770.               {
  1771.                   XtSetSensitive(m_gotoBtn, False);
  1772.                   XtSetSensitive(m_deleteBtn, False);
  1773.                   m_fileBtn->setSensitive(False);
  1774.               }
  1775.  
  1776.             }
  1777.             else if ( finishSearch)
  1778.             {
  1779.               int count;
  1780.               const int *selected;
  1781.                 m_outliner->getSelection( &selected, &count);
  1782.               if ( count >= 1 )
  1783.                  toggleActionButtonState(True);
  1784.               else 
  1785.                  toggleActionButtonState(False);
  1786.  
  1787.             }
  1788.             getToplevel()->notifyInterested(XFE_View::chromeNeedsUpdating);
  1789.         }/* clicks == 1 */
  1790.     }/* else */
  1791. }
  1792.  
  1793. void 
  1794. XFE_MNSearchView::Flippyfunc(const OutlineFlippyFuncData */*data*/)
  1795. {
  1796.     // Do nothing
  1797. }
  1798.  
  1799. void 
  1800. XFE_MNSearchView::releaseLineData() 
  1801. {
  1802.     // Do nothing
  1803. }
  1804. //fe_search_expand_cb(Widget w, XtPointer clientData, XtPointer callData)
  1805. void
  1806. XFE_MNSearchView::expandCallback(Widget, XtPointer clientData, XtPointer)
  1807. {
  1808.   XFE_MNSearchView *obj = (XFE_MNSearchView*)clientData;
  1809.  
  1810.   obj->expand();
  1811. }
  1812.  
  1813. void 
  1814. XFE_MNSearchView::expand()
  1815. {
  1816.   if ( m_result.expand )
  1817.   {
  1818.      doExpand(False);
  1819.   }
  1820.   else
  1821.   {
  1822.      doExpand(True);
  1823.   }
  1824. }
  1825.  
  1826. //fe_search_do_expand(MWContext *context, Boolean doExpand )
  1827. void
  1828. XFE_MNSearchView::doExpand(Boolean doit)
  1829. {
  1830.   Dimension width = 0, height = 0;
  1831.   Dimension cwidth = 0, cheight = 0;
  1832.   Widget shell = getToplevel()->getBaseWidget();
  1833.  
  1834.   if ( doit )
  1835.   {
  1836.         XtVaGetValues(shell, XmNwidth, &width, XmNheight, &height, 0);
  1837.         if ( !m_result.container ) 
  1838.             buildResult();
  1839.         XtVaSetValues(m_result.container, XmNresizePolicy, XmRESIZE_ANY, 0 );
  1840.         XtVaGetValues(m_content, XmNwidth, &cwidth, 0 );
  1841.  
  1842.         XtVaSetValues(m_result.container, XmNwidth, cwidth, 0);
  1843.     XtVaSetValues(shell, XmNwidth, cwidth,  0);
  1844.     XtVaSetValues(getBaseWidget(), XmNwidth, cwidth,  0);
  1845.  
  1846.     if ( !XtIsManaged(m_result.container) )
  1847.      {
  1848.           XtVaGetValues(m_result.container, XmNheight, &cheight, 0);
  1849.           XtManageChild(m_result.container);
  1850.         }
  1851.  
  1852.           XtVaSetValues(m_content, 
  1853.         XmNresizePolicy, XmRESIZE_ANY,
  1854.         0);
  1855.           XtVaSetValues(m_result.container, 
  1856.         XmNresizePolicy, XmRESIZE_ANY,
  1857.         0);
  1858.           XtVaSetValues(getBaseWidget(), 
  1859.         XmNresizePolicy, XmRESIZE_ANY,
  1860.         0);
  1861.           XtVaSetValues(shell, 
  1862.         XmNresizePolicy, XmRESIZE_ANY,
  1863.         0);
  1864.  
  1865.         XtVaSetValues(m_result.container, XmNwidth, cwidth, 0);
  1866.     XtVaSetValues(getBaseWidget(),  XmNheight, cheight + height, 0);
  1867.     XtVaSetValues(shell,  XmNheight, cheight + height, 0);
  1868.         m_result.expand = True;
  1869.    }
  1870.    else
  1871.    {
  1872.      XtVaGetValues(shell, XmNwidth, &width, XmNheight, &height, 0);
  1873.      XtVaSetValues(shell, XmNresizePolicy, XmRESIZE_NONE, 0 );
  1874.      XtVaSetValues(m_content, XmNresizePolicy, XmRESIZE_NONE, 0 );
  1875.      XtVaSetValues(m_content, XmNwidth, width, 0 );
  1876.      XtVaSetValues(shell, XmNwidth, width, 0 );
  1877.      if ( m_result.container && XtIsManaged(m_result.container))
  1878.      {
  1879.         XtVaSetValues(m_result.container, XmNwidth, width, 0);
  1880.         XtVaGetValues(m_result.container, XmNwidth, 
  1881.             &cwidth, XmNheight, &cheight, 0);
  1882.          XtUnmanageChild(m_result.container);
  1883.      XtVaSetValues(m_result.container, XmNwidth, width, 0);
  1884.      }
  1885.      XtVaSetValues(m_content, XmNwidth, width, 0 );
  1886.      XtVaSetValues(shell, XmNwidth, width, 0 );
  1887.  
  1888.      if ( m_result.expand )
  1889.      {
  1890.         XtVaSetValues(shell, XmNheight, height-cheight, 0);
  1891.      }
  1892.      XtVaSetValues(shell, XmNresizePolicy, XmRESIZE_ANY, 0);
  1893.  
  1894.      m_result.expand = False;
  1895.    }
  1896. }
  1897.  
  1898. void
  1899. XFE_MNSearchView::buildResultTable()
  1900. {
  1901.   int num_columns =  5;
  1902.   static int column_widths[] = {20, 10, 9, 10, 10};
  1903.   m_outliner = new XFE_Outliner("addressList",
  1904.                                 this,
  1905.                                 getToplevel(),
  1906.                                 m_result.container,
  1907.                                 False, // constantSize
  1908.                                 True,  // hasHeadings
  1909.                                 num_columns,
  1910.                                 num_columns,
  1911.                                 column_widths,
  1912.                                 OUTLINER_GEOMETRY_PREF);
  1913.  
  1914.   m_outliner->setMultiSelectAllowed(True);
  1915.  
  1916. }
  1917.  
  1918. //fe_search_build_result (MWContext *context)
  1919. void
  1920. XFE_MNSearchView::buildResult()
  1921. {
  1922.   Arg    av[30];
  1923.   Cardinal ac;
  1924.  
  1925.   XtVaSetValues(m_content, XmNbottomAttachment, XmATTACH_NONE, 0 );
  1926.   
  1927.   /* Result */
  1928.   ac = 0;
  1929.   XtSetArg (av [ac], XmNheight, 250); ac++;
  1930.   m_result.container = XmCreateForm(m_displayArea, 
  1931.         "searchResult", av, ac);
  1932.  
  1933.   ac = 0;
  1934.   XtSetArg (av [ac], XmNtopAttachment, XmATTACH_WIDGET); ac++;
  1935.   XtSetArg (av [ac], XmNtopWidget, m_content); ac++;
  1936.   XtSetArg (av [ac], XmNbottomAttachment, XmATTACH_FORM); ac++;
  1937.   XtSetArg (av [ac], XmNleftAttachment, XmATTACH_FORM); ac++;
  1938.   XtSetArg (av [ac], XmNrightAttachment, XmATTACH_FORM); ac++;
  1939.   XtSetArg (av [ac], XmNresizePolicy, XmRESIZE_NONE); ac++;
  1940.   XtSetArg (av [ac], XmNfractionBase, 3); ac++;
  1941.   XtSetValues(m_result.container, av, ac);
  1942.   //XtManageChild(m_result.container);
  1943.  
  1944.  /* Create Result Frame */
  1945.  
  1946.  /* For outliner 
  1947.   */
  1948.  
  1949.   buildResultTable();
  1950.  
  1951.   XtVaSetValues(m_outliner->getBaseWidget(),
  1952.                 XtVaTypedArg, XmNblankBackground, XmRString, "white", 6,
  1953.                 XmNvisibleRows, 15,
  1954.                 NULL);
  1955.   XtVaSetValues(m_outliner->getBaseWidget(),
  1956.                 XmNcellDefaults, True,
  1957.                 XtVaTypedArg, XmNcellBackground, XmRString, "white", 6,
  1958.                 NULL);
  1959.  
  1960.   /* For the "Go to Message Folder"
  1961.   */
  1962.   if ( m_addGotoBtn )
  1963.   {
  1964.   ac = 0;
  1965.   XtSetArg(av[ac], XmNbottomAttachment, XmATTACH_FORM); ++ac;
  1966.   XtSetArg(av[ac], XmNtopAttachment, XmATTACH_NONE); ++ac;
  1967.   XtSetArg(av[ac], XmNleftAttachment, XmATTACH_POSITION); ++ac;
  1968.   XtSetArg(av[ac], XmNleftPosition, 0); ++ac;
  1969.   XtSetArg(av[ac], XmNrightAttachment, XmATTACH_POSITION); ++ac;
  1970.   XtSetArg(av[ac], XmNrightPosition, 1); ++ac;
  1971.   XtSetArg(av[ac], XmNbottomAttachment, XmATTACH_FORM); ++ac;
  1972.   XtSetArg(av[ac], XmNleftOffset, 15); ++ac;
  1973.   XtSetArg(av[ac], XmNrightOffset, 8); ++ac;
  1974.   m_gotoBtn = XmCreatePushButton(m_result.container, "goToMessageFolder", av, ac);
  1975.   XtSetSensitive(m_gotoBtn, False);
  1976.   XtAddCallback(m_gotoBtn, XmNactivateCallback, gotoFolderCallback, this);
  1977.   XtManageChild(m_gotoBtn);
  1978.  
  1979.   // Egregious hack: XFE_Buttons don't appear outdented like PushButtons,
  1980.   // so kludge that by surrounding the XFE_Button with an outdented frame:
  1981.   Widget fileFrame
  1982.        = XtVaCreateManagedWidget("_fileFrame", xmFrameWidgetClass,
  1983.                                    m_result.container,
  1984.                                  XmNshadowType, XmSHADOW_OUT,
  1985.                                  XmNbottomAttachment, XmATTACH_FORM,
  1986.                                  XmNtopAttachment, XmATTACH_NONE,
  1987.                                  XmNleftAttachment, XmATTACH_POSITION,
  1988.                                  XmNleftPosition, 1,
  1989.                                  XmNrightAttachment, XmATTACH_POSITION,
  1990.                                  XmNrightPosition, 2,
  1991.                                  XmNbottomAttachment, XmATTACH_FORM,
  1992.                                  XmNleftOffset, 8,
  1993.                                  XmNrightOffset, 8,
  1994.                                  0);
  1995.   m_fileBtn = new XFE_Button(ViewGlue_getFrame(m_contextData),
  1996.                              fileFrame,
  1997.                              "fileMsg",
  1998.                              XFE_FolderMenu::generate,
  1999.                              (void*)xfeCmdMoveMessage,
  2000.                              0);
  2001.   m_fileBtn->setSensitive(False);
  2002.   m_fileBtn->show();
  2003.   // Also want to set the button's background color to the same as the
  2004.   // background color for m_gotoBtn, but only after they're both realized.
  2005.   
  2006.   ac = 0;
  2007.   XtSetArg(av[ac], XmNbottomAttachment, XmATTACH_FORM); ++ac;
  2008.   XtSetArg(av[ac], XmNtopAttachment, XmATTACH_NONE); ++ac;
  2009.   XtSetArg(av[ac], XmNleftAttachment, XmATTACH_POSITION); ++ac;
  2010.   XtSetArg(av[ac], XmNleftPosition, 2); ++ac;
  2011.   XtSetArg(av[ac], XmNrightAttachment, XmATTACH_POSITION); ++ac;
  2012.   XtSetArg(av[ac], XmNrightPosition, 3); ++ac;
  2013.   XtSetArg(av[ac], XmNbottomAttachment, XmATTACH_FORM); ++ac;
  2014.   XtSetArg(av[ac], XmNleftOffset, 8); ++ac;
  2015.   XtSetArg(av[ac], XmNrightOffset, 15); ++ac;
  2016.   m_deleteBtn = XmCreatePushButton(m_result.container, "deleteMsg", av, ac);
  2017.   XtSetSensitive(m_deleteBtn, False);
  2018.   XtAddCallback(m_deleteBtn, XmNactivateCallback, deleteMsgsCallback, this);
  2019.   XtManageChild(m_deleteBtn);
  2020.   
  2021.  
  2022.      XtVaSetValues(m_outliner->getBaseWidget(),
  2023.  
  2024.           XmNtopAttachment, XmATTACH_FORM,
  2025.                   XmNbottomAttachment, XmATTACH_WIDGET,
  2026.           XmNbottomWidget, m_gotoBtn,
  2027.                   XmNleftAttachment, XmATTACH_FORM,
  2028.                   XmNrightAttachment, XmATTACH_FORM,
  2029.                   0);
  2030.  
  2031.   }
  2032.   else /* No gotoBtn, need to attach to form */
  2033.   {
  2034.      XtVaSetValues(m_outliner->getBaseWidget(),
  2035.           XmNtopAttachment, XmATTACH_FORM,
  2036.                   XmNbottomAttachment, XmATTACH_FORM,
  2037.                   XmNleftAttachment, XmATTACH_FORM,
  2038.                   XmNrightAttachment, XmATTACH_FORM,
  2039.                   0);
  2040.   }
  2041.  
  2042.   // put a realize callback on the outliner so that we can call
  2043.   // hackTranslations() on it to get the popup menus working:
  2044.   XtAddEventHandler(m_outliner->getBaseWidget(), ExposureMask, False,
  2045.                     exposeOutlinerHandler, (XtPointer)this);
  2046.  
  2047.   m_outliner->show();
  2048.  
  2049. XFE_CALLBACK_DEFN(XFE_MNSearchView, searchFinished)(
  2050.         XFE_NotificationCenter */*obj*/,
  2051.                 void */*clientData*/,
  2052.                 void */* callData */)
  2053. {
  2054.   stopSearch();
  2055. }
  2056. void
  2057. XFE_MNSearchView::gotoFolderCallback(Widget w, XtPointer clientData, XtPointer)
  2058. {
  2059.   XFE_MNSearchView *obj = (XFE_MNSearchView*)clientData;
  2060.   obj->gotoFolder(w);
  2061. }
  2062.  
  2063. #define MULTI_ENTRIES 0
  2064. void
  2065. XFE_MNSearchView::gotoFolder(Widget /*w*/)
  2066. {
  2067.    
  2068.   int count, 
  2069.       i = 0;
  2070.   const int *selected;
  2071.   m_outliner->getSelection( &selected, &count);
  2072.   /* support for opening a search result in its thread pane context 
  2073.    */
  2074.   if ((count == 1) &&
  2075.       MSG_GoToFolderStatus (getPane(), (MSG_ViewIndex *)selected, count))
  2076.   {
  2077. #if MULTI_ENTRIES
  2078.       for (i=0; i < count; i++) {
  2079. #endif
  2080.       MSG_ResultElement *elem = NULL;
  2081.       MSG_GetResultElement(getPane(), selected[i], &elem);
  2082.       
  2083.       if ( !elem ) 
  2084. #if MULTI_ENTRIES
  2085.           continue;
  2086. #else
  2087.           return;
  2088. #endif
  2089.       
  2090.       MSG_SearchValue *value;
  2091.       MSG_GetResultAttribute(elem, attribMessageKey, &value);
  2092.       MessageKey key = value->u.key;
  2093.       MSG_GetResultAttribute(elem, attribFolderInfo, &value);
  2094.       MSG_FolderInfo *folderInfo = value->u.folder;
  2095.       
  2096.       fe_showMessages(XfeAncestorFindApplicationShell(getToplevel()->getBaseWidget()),
  2097.                       ViewGlue_getFrame(m_contextData), NULL, folderInfo, 
  2098.                       fe_globalPrefs.reuse_thread_window, FALSE, key);
  2099. #if MULTI_ENTRIES
  2100.       }/* for i */
  2101. #endif
  2102.   }
  2103. }
  2104.  
  2105. void
  2106. XFE_MNSearchView::deleteMsgsCallback(Widget, XtPointer clientData, XtPointer)
  2107. {
  2108.   XFE_MNSearchView *obj = (XFE_MNSearchView*)clientData;
  2109.   obj->deleteMsgs();
  2110. }
  2111.  
  2112. void
  2113. XFE_MNSearchView::deleteMsgs()
  2114. {
  2115.     int count;
  2116.     const int *selected;
  2117.     m_outliner->getSelection(&selected, &count);
  2118.  
  2119.     if (count <= 0)
  2120.         return;
  2121.  
  2122.     MSG_Command(getPane(), MSG_DeleteMessage,
  2123.                 (MSG_ViewIndex *)selected, count);
  2124. }
  2125.  
  2126. // The outliners are created too late to have hackTranslations()
  2127. // called on them, so we install the search translations manually:
  2128. /*static*/ void
  2129. XFE_MNSearchView::exposeOutlinerHandler(Widget w,
  2130.                                         XtPointer, XEvent*, Boolean*)
  2131. {
  2132.     XtOverrideTranslations(w, fe_globalData.mnsearch_global_translations);
  2133. }
  2134.  
  2135. void 
  2136. XFE_MNSearchView::toggleActionButtonState(Boolean)
  2137. {
  2138.   // Do nothing for Mail/News search.. just a place holder for now
  2139. }
  2140.  
  2141.