home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / AdvSearchDialog.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  6.1 KB  |  188 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.    AdvSearchDialog.cpp -- dialog for specifying options to message search
  20.    Created: Akkana Peck <akkana@netscape.com>, 21-Oct-97.
  21.  */
  22.  
  23.  
  24.  
  25. #include "AdvSearchDialog.h"
  26.  
  27. #include <Xm/Form.h>
  28. #include <Xm/Frame.h>
  29. #include <Xm/RowColumn.h>
  30. #include <Xm/LabelG.h>
  31. #include <Xm/ToggleBG.h>
  32.  
  33. #include "prefapi.h"
  34.  
  35. // we will need this in the post() method.
  36. extern "C" void fe_EventLoop();
  37.  
  38. XFE_AdvSearchDialog::XFE_AdvSearchDialog(Widget parent, char *name,
  39.                                          XFE_Frame *frame)
  40.     : XFE_Dialog(parent, 
  41.                  name, 
  42.                  TRUE, // ok
  43.                  TRUE, // cancel
  44.                  FALSE, // help
  45.                  FALSE, // apply
  46.                  TRUE, // separator
  47.                  TRUE // modal
  48.         )
  49. {
  50.     m_frame = frame;
  51.  
  52.     Widget form = XtCreateManagedWidget("form",
  53.                                         xmFormWidgetClass,
  54.                                         m_chrome,
  55.                                         NULL, 0);
  56.  
  57.     m_subfolderToggle = XtVaCreateManagedWidget("subfolderToggle",
  58.                                                 xmToggleButtonGadgetClass,
  59.                                                 form,
  60.                                                 XmNleftAttachment,
  61.                                                   XmATTACH_FORM,
  62.                                                 XmNtopAttachment,
  63.                                                   XmATTACH_FORM,
  64.                                                 0);
  65.     XtAddCallback(m_subfolderToggle, XmNvalueChangedCallback, toggle_cb, this);
  66.  
  67.     Widget framew = XtVaCreateManagedWidget("frame",
  68.                                            xmFrameWidgetClass,
  69.                                            form,
  70.                                            XmNleftAttachment, XmATTACH_FORM,
  71.                                            XmNrightAttachment, XmATTACH_FORM,
  72.                                            XmNtopAttachment, XmATTACH_WIDGET,
  73.                                            XmNtopWidget, m_subfolderToggle,
  74.                                            0);
  75.     XtVaCreateManagedWidget("whenOnlineSearch",
  76.                             xmLabelGadgetClass,
  77.                             framew,
  78.                             XmNchildType, XmFRAME_TITLE_CHILD,
  79.                             0);
  80.     Arg av[3];
  81.     int ac=0;
  82.     XtSetArg(av[ac], XmNchildType, XmFRAME_WORKAREA_CHILD); ++ac;
  83.     XtSetArg(av[ac], XmNorientation, XmVERTICAL); ++ac;
  84.     Widget rc = XmCreateRadioBox(framew, "radiobox", av, ac);
  85.  
  86.     m_searchLocalToggle = XtVaCreateManagedWidget("searchLocalToggle",
  87.                                                   xmToggleButtonGadgetClass,
  88.                                                   rc,
  89.                                                   0);
  90.     m_searchServerToggle = XtVaCreateManagedWidget("searchServerToggle",
  91.                                                    xmToggleButtonGadgetClass,
  92.                                                    rc,
  93.                                                    0);
  94.     XtManageChild(rc);
  95.  
  96.     XtAddCallback(m_chrome, XmNokCallback, ok_cb, this);
  97.     XtAddCallback(m_chrome, XmNcancelCallback, cancel_cb, this);
  98. }
  99.  
  100. XFE_AdvSearchDialog::~XFE_AdvSearchDialog()
  101. {
  102.     // nothing needed (that I'm aware of) yet.
  103. }
  104.  
  105. XP_Bool
  106. XFE_AdvSearchDialog::post()
  107. {
  108.     // Set the toggle button states:
  109.     // Note that we're assuming here that XP_Bool is the same as Boolean!
  110.     XP_Bool searchSubfolders, searchServer;
  111.     PREF_GetBoolPref("mailnews.searchSubFolders", &searchSubfolders);
  112.     XmToggleButtonGadgetSetState(m_subfolderToggle, searchSubfolders, FALSE);
  113.     PREF_GetBoolPref("mailnews.searchServer", &searchServer);
  114.     if (searchServer)
  115.         XmToggleButtonGadgetSetState(m_searchServerToggle, TRUE, TRUE);
  116.     else
  117.         XmToggleButtonGadgetSetState(m_searchLocalToggle, TRUE, TRUE);
  118.  
  119.     m_doneWithLoop = False;
  120.   
  121.     XtVaSetValues(m_chrome,
  122.                   XmNdeleteResponse, XmUNMAP,
  123.                   NULL);
  124.  
  125.     show();
  126.  
  127.     while(!m_doneWithLoop)
  128.         fe_EventLoop();
  129.  
  130.     return m_retVal;
  131. }
  132.  
  133. void
  134. XFE_AdvSearchDialog::ok()
  135. {
  136.     m_doneWithLoop = True;
  137.     m_retVal = True;
  138.  
  139.     Boolean searchSubfolders = XmToggleButtonGadgetGetState(m_subfolderToggle);
  140.     Boolean searchServer = XmToggleButtonGadgetGetState(m_searchServerToggle);
  141.  
  142.     // Note that we're assuming here that XP_Bool is the same as Boolean!
  143.     PREF_SetBoolPref("mailnews.searchSubFolders", searchSubfolders);
  144.     PREF_SetBoolPref("mailnews.searchServer", searchServer);
  145.             
  146.     hide();
  147. }
  148.  
  149. void
  150. XFE_AdvSearchDialog::cancel()
  151. {
  152.     m_doneWithLoop = True;
  153.     m_retVal = False;
  154.  
  155.     hide();
  156. }
  157.  
  158. void
  159. XFE_AdvSearchDialog::toggle()
  160. {
  161.     // do something with value of m_subfolderToggle here
  162. }
  163.  
  164. void
  165. XFE_AdvSearchDialog::toggle_cb(Widget, XtPointer clientData, XtPointer)
  166. {
  167.     XFE_AdvSearchDialog *obj = (XFE_AdvSearchDialog*)clientData;
  168.  
  169.     obj->toggle();
  170. }
  171.  
  172. void 
  173. XFE_AdvSearchDialog::ok_cb(Widget, XtPointer clientData, XtPointer)
  174. {
  175.     XFE_AdvSearchDialog *obj = (XFE_AdvSearchDialog*)clientData;
  176.  
  177.     obj->ok();
  178. }
  179.  
  180. void
  181. XFE_AdvSearchDialog::cancel_cb(Widget, XtPointer clientData, XtPointer)
  182. {
  183.     XFE_AdvSearchDialog *obj = (XFE_AdvSearchDialog*)clientData;
  184.  
  185.     obj->cancel();
  186. }
  187.  
  188.