Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / programs / dtmail / dtmail / CheckForMailUiItem.C
1 /* $TOG: CheckForMailUiItem.C /main/1 1998/02/17 15:19:56 mgreess $ */
2 /*
3  *+SNOTICE
4  *
5  *      RESTRICTED CONFIDENTIAL INFORMATION:
6  *      
7  *      The information in this document is subject to special
8  *      restrictions in a confidential disclosure agreement bertween
9  *      HP, IBM, Sun, USL, SCO and Univel.  Do not distribute this
10  *      document outside HP, IBM, Sun, USL, SCO, or Univel wihtout
11  *      Sun's specific written approval.  This documment and all copies
12  *      and derivative works thereof must be returned or destroyed at
13  *      Sun's request.
14  *
15  *      Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
16  *
17  *+ENOTICE
18  */
19
20 #include <X11/Intrinsic.h>
21 #include <Xm/XmAll.h>
22 #include <DtMail/options_util.h>
23 #include <DtMail/PropUi.hh>
24 #include <DtMail/CheckForMailUiItem.hh>
25 #include <DtMail/SpinBoxUiItem.hh>
26
27 int                               CheckForMailUiItem::_initialized = 0;
28 DtVirtArray<CheckForMailUiItem*> *CheckForMailUiItem::_checkformail_ui = NULL;
29
30 CheckForMailUiItem::CheckForMailUiItem(Widget w, int source, char *search_key):
31 SpinBoxUiItem(w, source, search_key)
32 {
33     Widget textfield;
34
35     if (! _initialized)
36     {
37         _initialized = 1;
38         _checkformail_ui = new DtVirtArray<CheckForMailUiItem*> (3);
39     }
40
41     options_spinbox_init(w, &(this->dirty_bit));
42     XtVaGetValues(w, XmNtextField, &textfield, NULL);
43     XtAddCallback(
44                 textfield,
45                 XmNvalueChangedCallback,
46                 CheckForMailUiItem::valueChangedCB,
47                 this);
48
49     _checkformail_ui->append(this);
50 }
51
52 //
53 // Takes values in the UI and puts them into the source DB
54 ///////////////////////////////////////////////////////////////////
55 void CheckForMailUiItem::valueChangedCB(Widget w, XtPointer client, XtPointer)
56 {
57     CheckForMailUiItem *cui = (CheckForMailUiItem*) client;
58     cui->_valueChanged = TRUE;
59 }
60
61 //
62 // Takes values in the UI and puts them into the source DB
63 ///////////////////////////////////////////////////////////////////
64 void CheckForMailUiItem::writeFromUiToSource()
65 {
66     int spinbox_value;
67     Widget w = this->getWidget();
68     char val_str[64];
69
70     if (!_valueChanged) return;
71
72     spinbox_value = options_spinbox_get_value(w);
73     sprintf(val_str, "%d", spinbox_value);
74     prop_source->setValue(val_str);
75
76     for (int i = 0; i < _checkformail_ui->length(); i++)
77     {
78         CheckForMailUiItem *cui = (*_checkformail_ui)[i];
79         if (cui != this) cui->writeFromSourceToUi();
80     }
81     _valueChanged = FALSE;
82 }
83
84 //
85 // Takes values in the UI and puts them into the source DB
86 ///////////////////////////////////////////////////////////////////
87 void CheckForMailUiItem::writeFromSourceToUi()
88 {
89     const char *value;
90     Widget w = this->getWidget();
91
92     value = prop_source->getValue();
93     options_spinbox_set_value(w, atoi(value), this->dirty_bit);
94     _valueChanged = FALSE;
95
96     if (NULL != value) free((void*) value);
97 }