-fpermissive to allow GCC to compile old C++
[oweals/cde.git] / cde / programs / dtmail / dtmail / CheckForMailUiItem.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $TOG: CheckForMailUiItem.C /main/1 1998/02/17 15:19:56 mgreess $ */
24 /*
25  *+SNOTICE
26  *
27  *      RESTRICTED CONFIDENTIAL INFORMATION:
28  *      
29  *      The information in this document is subject to special
30  *      restrictions in a confidential disclosure agreement bertween
31  *      HP, IBM, Sun, USL, SCO and Univel.  Do not distribute this
32  *      document outside HP, IBM, Sun, USL, SCO, or Univel wihtout
33  *      Sun's specific written approval.  This documment and all copies
34  *      and derivative works thereof must be returned or destroyed at
35  *      Sun's request.
36  *
37  *      Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
38  *
39  *+ENOTICE
40  */
41
42 #include <X11/Intrinsic.h>
43 #include <Xm/XmAll.h>
44 #include <DtMail/options_util.h>
45 #include <DtMail/PropUi.hh>
46 #include <DtMail/CheckForMailUiItem.hh>
47 #include <DtMail/SpinBoxUiItem.hh>
48
49 int                               CheckForMailUiItem::_initialized = 0;
50 DtVirtArray<CheckForMailUiItem*> *CheckForMailUiItem::_checkformail_ui = NULL;
51
52 CheckForMailUiItem::CheckForMailUiItem(Widget w, int source, char *search_key):
53 SpinBoxUiItem(w, source, search_key)
54 {
55     Widget textfield;
56
57     if (! _initialized)
58     {
59         _initialized = 1;
60         _checkformail_ui = new DtVirtArray<CheckForMailUiItem*> (3);
61     }
62
63     options_spinbox_init(w, &(this->dirty_bit));
64     XtVaGetValues(w, XmNtextField, &textfield, NULL);
65     XtAddCallback(
66                 textfield,
67                 XmNvalueChangedCallback,
68                 CheckForMailUiItem::valueChangedCB,
69                 this);
70
71     _checkformail_ui->append(this);
72 }
73
74 //
75 // Takes values in the UI and puts them into the source DB
76 ///////////////////////////////////////////////////////////////////
77 void CheckForMailUiItem::valueChangedCB(Widget w, XtPointer client, XtPointer)
78 {
79     CheckForMailUiItem *cui = (CheckForMailUiItem*) client;
80     cui->_valueChanged = TRUE;
81 }
82
83 //
84 // Takes values in the UI and puts them into the source DB
85 ///////////////////////////////////////////////////////////////////
86 void CheckForMailUiItem::writeFromUiToSource()
87 {
88     int spinbox_value;
89     Widget w = this->getWidget();
90     char val_str[64];
91
92     if (!_valueChanged) return;
93
94     spinbox_value = options_spinbox_get_value(w);
95     sprintf(val_str, "%d", spinbox_value);
96     prop_source->setValue(val_str);
97
98     for (int i = 0; i < _checkformail_ui->length(); i++)
99     {
100         CheckForMailUiItem *cui = (*_checkformail_ui)[i];
101         if (cui != this) cui->writeFromSourceToUi();
102     }
103     _valueChanged = FALSE;
104 }
105
106 //
107 // Takes values in the UI and puts them into the source DB
108 ///////////////////////////////////////////////////////////////////
109 void CheckForMailUiItem::writeFromSourceToUi()
110 {
111     const char *value;
112     Widget w = this->getWidget();
113
114     value = prop_source->getValue();
115     options_spinbox_set_value(w, atoi(value), this->dirty_bit);
116     _valueChanged = FALSE;
117
118     if (NULL != value) free((void*) value);
119 }