home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / Dialog.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  4.8 KB  |  180 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.    Dialog.cpp -- class for toplevel XFE dialogs.
  20.    Created: Linda Wei <lwei@netscape.com>, 16-Sep-96.
  21.  */
  22.  
  23.  
  24.  
  25. #include "Dialog.h"
  26. #include "xpassert.h"
  27. #include "xfe2_extern.h"
  28.  
  29. #include <Xm/SelectioB.h>
  30.  
  31. // ==================== Public Member Functions ====================
  32.  
  33. // Member:       XFE_Dialog
  34. // Description:  Constructor
  35. // Inputs:
  36. // Side effects: Creates a prompt dialog
  37.  
  38. XFE_Dialog::XFE_Dialog(Widget   parent,      // dialog parent
  39.                        char    *name,        // dialog name
  40.                        Boolean  ok,          // show OK button?
  41.                        Boolean  cancel,      // show cancel button?
  42.                        Boolean  help,        // show help button?
  43.                        Boolean  apply,       // show apply button?
  44.                        Boolean  separator,   // show separator?
  45.                        Boolean  modal,       // modal dialog?
  46.                        Widget chrome_widget)
  47.     : XFE_Component()
  48. {
  49.     m_wParent = parent;
  50.  
  51.     // Create the chrome
  52.  
  53.     if (chrome_widget == NULL)
  54.       m_chrome = createDialogChromeWidget(parent, name, ok, cancel,
  55.                                           help, apply, separator, modal);
  56.     else
  57.       m_chrome = chrome_widget;
  58.  
  59.     // Register base widget and parent widget
  60.  
  61.     setBaseWidget(XtParent(m_chrome));
  62.     installDestroyHandler();
  63. }
  64.  
  65. // Member:       ~XFE_Dialog
  66. // Description:  Destructor
  67. // Inputs:
  68. // Side effects: 
  69.  
  70. XFE_Dialog::~XFE_Dialog()
  71. {
  72. }
  73.  
  74. // Member:       show
  75. // Description:  
  76. // Inputs:
  77. // Side effects:
  78.  
  79. void XFE_Dialog::show()
  80. {
  81.     XP_ASSERT(m_chrome);
  82.     fe_NukeBackingStore(m_chrome);
  83.     XtManageChild(m_chrome);
  84. }
  85.  
  86. // Member:       hide
  87. // Description:  
  88. // Inputs:
  89. // Side effects:
  90.  
  91. void XFE_Dialog::hide()
  92. {
  93.     XP_ASSERT(m_chrome);
  94.     XtUnmanageChild(m_chrome);
  95. }
  96.  
  97. // ==================== Protected Member Functions ====================
  98.  
  99. // ==================== Private Member Functions ====================
  100.  
  101. Widget
  102. XFE_Dialog::createDialogChromeWidget(Widget   parent,    
  103.                                      char    *name,
  104.                                      Boolean  ok,
  105.                                      Boolean  cancel,
  106.                                      Boolean  help,
  107.                                      Boolean  apply,
  108.                                      Boolean  separator,
  109.                                      Boolean  modal)
  110. {
  111.     Visual   *v = 0;
  112.     Colormap  cmap = 0;
  113.     Cardinal  depth = 0;
  114.     Arg       av[20];
  115.     int       ac;
  116.     Widget chrome;
  117.  
  118.     XtVaGetValues (parent, 
  119.                    XtNvisual, &v, 
  120.                    XtNcolormap, &cmap,
  121.                    XtNdepth, &depth,
  122.                    0);
  123.  
  124.     ac = 0;
  125.     XtSetArg (av[ac], XmNvisual, v); ac++;
  126.     XtSetArg (av[ac], XmNdepth, depth); ac++;
  127.     XtSetArg (av[ac], XmNcolormap, cmap); ac++;
  128.     XtSetArg (av[ac], XmNallowShellResize, TRUE); ac++;
  129.     XtSetArg (av[ac], XmNtransientFor, parent); ac++;
  130.     if (modal) {
  131.         XtSetArg (av[ac], XmNdialogStyle, XmDIALOG_PRIMARY_APPLICATION_MODAL); ac++;
  132.     }
  133.     XtSetArg (av[ac], XmNdialogType, XmDIALOG_QUESTION); ac++;
  134.     XtSetArg (av[ac], XmNdeleteResponse, XmDESTROY); ac++;
  135.     XtSetArg (av[ac], XmNautoUnmanage, False); ac++;
  136.     XtSetArg (av[ac], XmNnoResize, True); ac++;
  137.  
  138.     chrome = XmCreatePromptDialog (parent, name, av, ac);
  139.  
  140.     if (!separator)
  141.         fe_UnmanageChild_safe(XmSelectionBoxGetChild(chrome,
  142.                                                      XmDIALOG_SEPARATOR));
  143.  
  144.     fe_UnmanageChild_safe (XmSelectionBoxGetChild (chrome, 
  145.                                                    XmDIALOG_TEXT));
  146.  
  147.     fe_UnmanageChild_safe (XmSelectionBoxGetChild (chrome,
  148.                                                    XmDIALOG_SELECTION_LABEL));
  149.  
  150.     if (!ok)
  151.         fe_UnmanageChild_safe (XmSelectionBoxGetChild (chrome, 
  152.                                                        XmDIALOG_OK_BUTTON));
  153.     else
  154.         m_okButton = XmSelectionBoxGetChild(chrome, XmDIALOG_OK_BUTTON);
  155.  
  156.     if (!cancel)
  157.         fe_UnmanageChild_safe (XmSelectionBoxGetChild (chrome,
  158.                                                        XmDIALOG_CANCEL_BUTTON));
  159.     else
  160.         m_cancelButton = XmSelectionBoxGetChild(chrome, XmDIALOG_CANCEL_BUTTON);
  161.  
  162.     fe_UnmanageChild_safe (XmSelectionBoxGetChild (chrome, XmDIALOG_HELP_BUTTON));
  163.  
  164.     if (help) {
  165.         // TODO: Enable help later
  166.         fe_UnmanageChild_safe (XmSelectionBoxGetChild (chrome, XmDIALOG_HELP_BUTTON));
  167.         // m_helpButton = XmSelectionBoxGetChild(chrome, XmDIALOG_HELP_BUTTON);
  168.     }
  169.     else
  170.         fe_UnmanageChild_safe (XmSelectionBoxGetChild (chrome, XmDIALOG_HELP_BUTTON));
  171.  
  172.     if (apply) {
  173.         m_applyButton = XmSelectionBoxGetChild(chrome, XmDIALOG_APPLY_BUTTON);
  174.         XtManageChild(m_applyButton);
  175.     }
  176.  
  177.     return chrome;
  178. }
  179.  
  180.