Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / programs / dtmail / MotifApp / ToggleButtonInterface.C
1 /* $TOG: ToggleButtonInterface.C /main/6 1998/09/21 18:50:08 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 // ToggleButtonInterface.C: A toggle button interface to a Cmd object
21 ///////////////////////////////////////////////////////////////
22 #include <stdlib.h>
23 #include <ctype.h>
24 #include "Cmd.h"
25 #include "MotifCmds.h"
26 #include "ToggleButtonInterface.h"
27 #include <Xm/ToggleB.h>
28 #include "Help.hh"
29
30 ToggleButtonInterface::ToggleButtonInterface ( 
31     Widget parent, 
32     Cmd *cmd 
33 ) : CmdInterface ( cmd )
34 {
35
36     // We need to generate a button name that doesn't have illegal characters.
37     //
38     char *w_name = new char[200];
39     strcpy(w_name, _name);
40     for (char * cur = w_name; *cur; cur++) {
41         if (isspace(*cur) || *cur == ',') {
42             *cur = '_';
43             continue;
44         }
45
46         if (*cur == '.') {
47             *cur = 0;
48             break;
49         }
50     }
51
52     XmString label = XmStringCreateLocalized(cmd->getLabel());
53
54     if (0 ==  strcmp(cmd->className(),"ToggleButtonCmd"))
55     {
56         ToggleButtonCmd *tbc = (ToggleButtonCmd*) cmd;
57         Boolean         visible_when_off = tbc->visibleWhenOff();
58         unsigned char   indicator_type = tbc->indicatorType();
59
60         _w = XtVaCreateWidget (w_name, 
61                 xmToggleButtonWidgetClass,
62                 parent,
63                 XmNlabelString, label,
64                 XmNvisibleWhenOff, visible_when_off,
65                 XmNindicatorType, indicator_type,
66                 NULL);
67     }
68     else
69         _w = XtVaCreateWidget (w_name, 
70                 xmToggleButtonWidgetClass,
71                 parent,
72                 XmNlabelString, label,
73                 XmNvisibleWhenOff, TRUE,
74                 NULL);
75
76     XmStringFree(label);
77
78     printHelpId("_w", _w);
79
80     // XtAddCallback(_w, XmNhelpCallback, HelpCB, helpId);
81     // free(helpId);
82
83     installDestroyHandler();
84     
85     // The _active member is set when each instance is registered
86     // with an associated Cmd object. Now that a widget exists,
87     // set the widget's sensitivity according to its active state.
88     
89     if ( _active )
90         activate();     
91     else
92         deactivate();   
93
94 #ifdef GNU_CC  // No idea what the right ifdef is for automatically recognizing g++
95     
96     // G++ reportedly doesn't like the form expected by cfront. I'm
97     // told this will work, but I haven't tested it myself.
98     
99     XtAddCallback ( _w,  
100                    XmNvalueChangedCallback, 
101                    executeCmdCallback,
102                    (XtPointer) this );  
103 #else
104
105     XtAddCallback ( _w,  
106                    XmNvalueChangedCallback,
107                    &CmdInterface::executeCmdCallback,
108                    (XtPointer) this );  
109 #endif
110     delete [] w_name;
111 }
112
113 #ifndef CAN_INLINE_VIRTUALS
114 ToggleButtonInterface::~ToggleButtonInterface (void)
115 {
116 }
117 #endif /* ! CAN_INLINE_VIRTUALS */