Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / programs / dtmail / MotifApp / AskFirstCmd.C
1 /* $TOG: AskFirstCmd.C /main/5 1997/03/31 15:59:09 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 //////////////////////////////////////////////////////////////////////////////
21 //         This example code is from the book:
22 //
23 //           Object-Oriented Programming with C++ and OSF/Motif
24 //         by
25 //           Douglas Young
26 //           Prentice Hall, 1992
27 //           ISBN 0-13-630252-1 
28 //
29 //         Copyright 1991 by Prentice Hall
30 //         All Rights Reserved
31 //
32 //  Permission to use, copy, modify, and distribute this software for 
33 //  any purpose except publication and without fee is hereby granted, provided 
34 //  that the above copyright notice appear in all copies of the software.
35 ///////////////////////////////////////////////////////////////////////////////
36 //////////////////////////////////////////////////////////////////////////////
37
38
39 //////////////////////////////////////////////////////////
40 // AskFirstCmd.C
41 //////////////////////////////////////////////////////////
42 #include "AskFirstCmd.h"
43 #include "QuestionDialogManager.h"
44
45 #include <stdlib.h>
46 #include <nl_types.h>
47 extern nl_catd catd;
48
49 #include "NLS.hh"
50
51 AskFirstCmd::AskFirstCmd ( char *name, 
52                            char *label, 
53                            int active ) : Cmd ( name, label, active )
54 {
55     _dialog = NULL;
56     _question = NULL;
57     _dialogParentWidget = NULL;
58     setQuestion ( GETMSG(catd, 1, 1,
59            "Do you really want to execute this command?"));
60 }
61
62 void AskFirstCmd::setQuestion ( char *str )
63 {
64     if (_question)
65         free(_question);
66     _question = strdup ( str );
67 }
68
69 void AskFirstCmd::execute()
70 {
71     char *name_str;
72     char *label_str;
73     
74     name_str = (char *) name();
75     label_str = (char *) getLabel();
76
77
78     if (!_dialogParentWidget) return;
79
80     if (!_dialog) {
81         _dialog = new QuestionDialogManager(name_str);
82     }
83     
84     _dialog->post(
85                 label_str,
86                 _question,
87                 _dialogParentWidget,
88                 (void *) this,
89                 &AskFirstCmd::yesCallback,
90                 &AskFirstCmd::cancelCallback);
91 }       
92
93 void AskFirstCmd::yesCallback ( void *clientData )
94 {
95     AskFirstCmd *obj = (AskFirstCmd *) clientData;
96     
97     obj->doYesCallback();
98  
99 }
100
101 void 
102 AskFirstCmd::cancelCallback ( void *)
103 {
104
105 }
106
107 void
108 AskFirstCmd::doYesCallback()
109 {
110
111     // unmanage the dialog right away
112    _dialog->unmanage();
113
114
115    // Call the base class execute()
116    // member function to do all the
117    // usual processing of the command
118
119    this->Cmd::execute();  
120
121 }