1 /***********************************************************************/
2 /* Open Visualization Data Explorer */
3 /* (C) Copyright IBM Corp. 1989,1999 */
4 /* ALL RIGHTS RESERVED */
5 /* This code licensed under the */
6 /* "IBM PUBLIC LICENSE - Open Visualization Data Explorer" */
7 /***********************************************************************/
8
9 #include <dxconfig.h>
10 #include <defines.h>
11
12 #include <Xm/Xm.h>
13 #include <Xm/MainW.h>
14
15 #include "CommandInterface.h"
16 #include "Command.h"
17 #include "Application.h"
18
19
CommandInterface_ExecuteCommandCB(Widget,XtPointer clientData,XtPointer)20 extern "C" void CommandInterface_ExecuteCommandCB(Widget,
21 XtPointer clientData,
22 XtPointer)
23 {
24 ASSERT(clientData);
25 CommandInterface* DXinterface = (CommandInterface*)clientData;
26
27 DXinterface->executeCommand();
28 }
29
30
31
CommandInterface(char * name,Command * command)32 CommandInterface::CommandInterface(char* name,
33 Command* command): UIComponent(name)
34 {
35 ASSERT(command);
36
37 this->command = command;
38
39 if (command != NUL(Command*))
40 {
41 command->registerClient(this);
42 }
43 }
44
45
~CommandInterface()46 CommandInterface::~CommandInterface()
47 {
48 command->unregisterClient(this);
49 }
50
51
setCommand(Command * command)52 inline void CommandInterface::setCommand(Command* command)
53 {
54 this->command = command;
55 }
56
57
notify(const Symbol message,const void * data,const char * msg)58 void CommandInterface::notify(const Symbol message, const void *data, const char *msg)
59 {
60 if (message == Command::MsgActivate)
61 {
62 this->activate();
63 }
64 else if (message == Command::MsgDeactivate)
65 {
66 this->deactivate(msg);
67 }
68 else if (message == Command::MsgDisassociate)
69 {
70 this->command = NUL(Command*);
71 }
72 }
73
74
getDialogParent()75 Widget CommandInterface::getDialogParent()
76 {
77 Widget w = this->getRootWidget();
78
79 while (w && !XmIsMainWindow(w))
80 w = XtParent(w);
81
82 if (!w)
83 w = theApplication->getRootWidget();
84
85 return w;
86 }
87
executeCommand()88 void CommandInterface::executeCommand()
89 {
90 if (this->command != NUL(Command*))
91 {
92 theApplication->startCommandInterfaceExecution();
93 this->command->execute(this);
94 theApplication->endCommandInterfaceExecution();
95 }
96 }
97