home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / src / ViewDialog.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  4.3 KB  |  206 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 -- implementation for Dialogs that can contain views.
  20.    Created: Chris Toshok <toshok@netscape.com>, 16-Oct-96.
  21.  */
  22.  
  23.  
  24.  
  25. #include "ViewDialog.h"
  26. #include "xpassert.h"
  27. #include "structs.h"
  28. #include "xfe.h"
  29.  
  30. XFE_ViewDialog::XFE_ViewDialog(XFE_View *view, Widget parent,
  31.                                char *name, 
  32.                                MWContext *context,
  33.                                Boolean ok, Boolean cancel,
  34.                                Boolean help, Boolean apply,
  35.                                Boolean separator, Boolean modal,
  36.                                Widget chrome_widget)
  37.   : XFE_Dialog(parent, name, ok, cancel, help, apply, separator, modal, chrome_widget),
  38.   m_okToDestroy(TRUE)
  39. {
  40.   m_view = view;
  41.   m_context = context;
  42.  
  43.   if (m_view)
  44.     m_view->show();
  45.  
  46.   if (cancel)
  47.     XtAddCallback(m_chrome, XmNcancelCallback, cancel_cb, this);
  48.  
  49.   if (ok)
  50.     XtAddCallback(m_chrome, XmNokCallback, ok_cb, this);
  51.  
  52.   if (help)
  53.     XtAddCallback(m_chrome, XmNhelpCallback, help_cb, this);
  54.  
  55.   if (apply)
  56.     XtAddCallback(m_chrome, XmNapplyCallback, apply_cb, this);
  57. }
  58.  
  59. XFE_ViewDialog::~XFE_ViewDialog()
  60. {
  61.   if (m_view)
  62.     delete m_view;
  63. }
  64.  
  65. void
  66. XFE_ViewDialog::setView(XFE_View *view)
  67. {
  68.   m_view = view;
  69.   if (m_view)
  70.     m_view->show();
  71. }
  72.  
  73. void
  74. XFE_ViewDialog::cancel()
  75. {
  76.   CommandType cancel_cmd = xfeCmdDialogCancel;
  77.   XP_ASSERT(m_view);
  78.  
  79.   if (!m_view->handlesCommand(cancel_cmd))
  80.     {
  81.       XBell(XtDisplay(m_widget), 100);
  82.       return;
  83.     }
  84.  
  85.   if (m_view->isCommandEnabled(cancel_cmd))
  86.     {
  87.       m_view->doCommand(cancel_cmd);
  88.     }
  89. }
  90.  
  91. void
  92. XFE_ViewDialog::help()
  93. {
  94.   CommandType help_cmd = xfeCmdDialogHelp;
  95.   XP_ASSERT(m_view);
  96.  
  97.   if (!m_view->handlesCommand(help_cmd))
  98.     {
  99.       XBell(XtDisplay(m_widget), 100);
  100.       return;
  101.     }
  102.  
  103.   if (m_view->isCommandEnabled(help_cmd))
  104.     {
  105.       m_view->doCommand(help_cmd);
  106.     }
  107. }
  108.  
  109. void
  110. XFE_ViewDialog::apply()
  111. {
  112.   CommandType apply_cmd = xfeCmdDialogApply;
  113.   XP_ASSERT(m_view);
  114.  
  115.   if (!m_view->handlesCommand(apply_cmd))
  116.     {
  117.       XBell(XtDisplay(m_widget), 100);
  118.       return;
  119.     }
  120.  
  121.   if (m_view->isCommandEnabled(apply_cmd))
  122.     {
  123.       m_view->doCommand(apply_cmd);
  124.     }
  125. }
  126.  
  127. void
  128. XFE_ViewDialog::ok()
  129. {
  130.   CommandType ok_cmd = xfeCmdDialogOk;
  131.  
  132.   XP_ASSERT(m_view);
  133.  
  134.   if (!m_view->handlesCommand(ok_cmd))
  135.     {
  136.       XBell(XtDisplay(m_widget), 100);
  137.       return;
  138.     }
  139.  
  140.   if (m_view->isCommandEnabled(ok_cmd))
  141.     {
  142.       m_view->doCommand(ok_cmd);
  143.     }
  144. }
  145.  
  146. void
  147. XFE_ViewDialog::cancel_cb(Widget, XtPointer clientData, XtPointer)
  148. {
  149.   XFE_ViewDialog *obj = (XFE_ViewDialog*)clientData;
  150.  
  151.   obj->cancel();
  152.  
  153.   XtDestroyWidget(obj->getBaseWidget());
  154. }
  155.  
  156. void
  157. XFE_ViewDialog::help_cb(Widget, XtPointer clientData, XtPointer)
  158. {
  159.   XFE_ViewDialog *obj = (XFE_ViewDialog*)clientData;
  160.  
  161.   obj->help();
  162. }
  163.  
  164. void
  165. XFE_ViewDialog::apply_cb(Widget, XtPointer clientData, XtPointer)
  166. {
  167.   XFE_ViewDialog *obj = (XFE_ViewDialog*)clientData;
  168.  
  169.   obj->apply();
  170. }
  171.  
  172. void
  173. XFE_ViewDialog::ok_cb(Widget, XtPointer clientData, XtPointer)
  174. {
  175.   XFE_ViewDialog *obj = (XFE_ViewDialog*)clientData;
  176.  
  177.   obj->ok();
  178.  
  179.   if (obj->m_okToDestroy)
  180.       XtDestroyWidget(obj->getBaseWidget());
  181. }
  182.  
  183. Pixel
  184. XFE_ViewDialog::getFGPixel()
  185. {
  186.   return CONTEXT_DATA(m_context)->fg_pixel;
  187. }
  188.  
  189. Pixel
  190. XFE_ViewDialog::getBGPixel()
  191. {
  192.   return CONTEXT_DATA(m_context)->default_bg_pixel;
  193. }
  194.  
  195. Pixel
  196. XFE_ViewDialog::getTopShadowPixel()
  197. {
  198.   return CONTEXT_DATA(m_context)->top_shadow_pixel;
  199. }
  200.  
  201. Pixel
  202. XFE_ViewDialog::getBottomShadowPixel()
  203. {
  204.   return CONTEXT_DATA(m_context)->bottom_shadow_pixel;
  205. }
  206.