Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtmail / dtmail / PropUi.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: PropUi.C /main/6 1998/02/17 15:18:54 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 "RoamApp.h"
43 #include <DtMail/DtVirtArray.hh>
44 #include <DtMail/PropUi.hh>
45 #include <DtMail/PropSource.hh>
46 #include <string.h>
47
48 // PropUiItem::PropUiItem 
49 // PropUiItem ctor
50 ////////////////////////////////////////////////////////////////
51 PropUiItem::PropUiItem( Widget          w,
52                         int             source,
53                         char            *search_key,
54                         PropUiCallback  validator,
55                         void            *validator_data)
56 {
57   // init variables
58   prop_widget = w;
59   dirty_bit = FALSE;
60   source = source;
61   key = strdup(search_key);
62   _uiValueValidator = validator;
63   _uiValueValidatorData = validator_data;
64   DtMailEnv error;
65   DtMail::Session * d_session = NULL;
66   DtMail::MailRc * m_rc = NULL;
67
68   switch (source)
69   {
70     case _FROM_MAILRC:
71       d_session = theRoamApp.session()->session();
72       m_rc = d_session->mailRc(error);
73       prop_source = (PropSource *) new MailRcSource(m_rc, key );
74       break;
75       
76     default:
77       prop_source = NULL;
78       fprintf(stderr, "Error in PropUiItem ctor\n");
79       break; 
80   };
81 }
82
83 // PropUiItem::~PropUiItem
84 // PropUiItem dtor
85 ////////////////////////////////////////////////////////////////
86 PropUiItem::~PropUiItem()
87 {
88   // release memory alloced by the class
89   free(key);
90   delete prop_source;
91 }
92
93 //
94 // Returns NULL if the PropUiItem has a valid value; NLS error message if not.
95 ////////////////////////////////////////////////////////////////
96 char * PropUiItem::uiValueIsValid()
97 {
98     if (NULL == _uiValueValidator) return NULL;
99     return _uiValueValidator(this, _uiValueValidatorData);
100 }