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 "../base/defines.h"
11 
12 
13 #ifndef _StandIn_h
14 #define _StandIn_h
15 
16 
17 #include "UIComponent.h"
18 #include "List.h"
19 #include "DXDragSource.h"
20 #include "Tab.h"
21 
22 
23 //
24 // Class name definition:
25 //
26 #define ClassStandIn	"StandIn"
27 
28 //
29 // XtCallbackProc (*CB), XtEventHandler (*EH) and XtActionProc (*AP)
30 // DialogCallback (*DCB), XtInputCallbackProc (*ICP), XtWorkProc (*WP)
31 // functions for this and derived classes
32 //
33 extern "C" void StandIn_TrackArkEH(Widget, XtPointer, XEvent*, Boolean*);
34 extern "C" void StandIn_Button2PressEH(Widget, XtPointer, XEvent*, Boolean*);
35 extern "C" void StandIn_Button2ReleaseEH(Widget, XtPointer, XEvent*, Boolean*);
36 extern "C" void StandIn_TabKeyNavEH(Widget, XtPointer, XEvent*, Boolean*);
37 extern "C" void StandIn_DisarmTabCB(Widget, XtPointer, XtPointer);
38 extern "C" void StandIn_ArmOutputCB(Widget, XtPointer, XtPointer);
39 extern "C" void StandIn_ArmInputCB(Widget, XtPointer, XtPointer);
40 extern "C" void StandIn_SelectNodeCB(Widget, XtPointer, XtPointer);
41 extern "C" Boolean StandIn_DragDropWP(XtPointer);
42 
43 class Tab;
44 class Ark;
45 class Node;
46 class EditorWindow;
47 class WorkSpace;
48 
49 typedef long NodeParameterStatusChange;	// Also defined in Node.h
50 
51 //
52 // StandIn class definition:
53 //
54 class StandIn : public UIComponent, public DXDragSource
55 {
56 
57 //friend class Node;
58 //friend class Network;
59 
60 
61   private:
62 
63     static Boolean ClassInitialized;
64     static Widget DragIcon;
65     static Dictionary *DragTypeDictionary;
66 
67     int selected;
68     WorkSpace *workSpace;
69 
70     List  inputTabList;
71     List  outputTabList;
72 
73 
74     /*
75      * module label (button):
76      */
77     Widget 	buttonWidget;
78     Dimension	buttonHeight;
79     Dimension   requiredButtonWidth;
80 
81 
82     friend void StandIn_SelectNodeCB(Widget widget,
83                 XtPointer clientData,
84                 XtPointer cdata);
85 
86     friend void StandIn_ArmInputCB(Widget widget,
87                 XtPointer clientData,
88                 XtPointer cdata);
89     void armInput(Widget widget, XtPointer cdata);
90 
91     friend void StandIn_ArmOutputCB(Widget widget,
92                 XtPointer clientData,
93                 XtPointer cdata);
94     void armOutput(Widget widget, XtPointer cdata);
95 
96 
97     friend void StandIn_DisarmTabCB(Widget widget,
98                 XtPointer clientData,
99                 XtPointer cdata);
100     void disarmTab(Widget widget, XtPointer cdata);
101 
102 
103     friend void StandIn_Button2PressEH(Widget widget,
104                 XtPointer ,
105                 XEvent* event,
106 		Boolean *keep_going);
107     friend void StandIn_Button2ReleaseEH(Widget widget,
108                 XtPointer ,
109                 XEvent* event,
110 		Boolean *keep_going);
111 
112     friend void StandIn_TrackArkEH(Widget widget,
113                 XtPointer clientData,
114                 XEvent* event,
115 		Boolean *cont);
116     friend void StandIn_TabKeyNavEH(Widget widget,
117                 XtPointer ,
118                 XEvent* event,
119 		Boolean *keep_going);
120     friend Boolean StandIn_DragDropWP(XtPointer);
121 
122     void trackArk(Widget widget, XEvent *event);
123 
124     boolean  setMinimumWidth(int &width);
125     int  getVisibleInputCount();
126     int  getVisibleOutputCount();
127     void adjustParameterLocations(int width);
128 
129     Tab *createInputTab(Widget parent, int index, int width);
130     Tab *createOutputTab(Widget parent, int index, int width);
131 
132     void indicateSelection(boolean select);
133 
134     void setVisibility(int index, boolean outputTab);
135     XmString   createButtonLabel();
136 
137     //
138     // Supply the type dictionary which stores the types we can supply for a dnd
139     //
getDragDictionary()140     virtual Dictionary *getDragDictionary() { return StandIn::DragTypeDictionary; }
141 
142     // Define the data type for the drag operation.  These replace the use of
143     // function pointers.  They're passed to addSupportedType and decoded in
144     // decodeDragType
145     enum {
146 	Modules,
147 	Interactors,
148 	Trash
149     };
150 
151     //
152     // Dragging a StandIn onto the tool selector means deleting the
153     // standin.  The new Motif doesn't permit deleting an object involved
154     // in a drag drop during the operation.  We used delete it in the
155     // dropFinishCallback.  Now we create a work proc so that the Nodes
156     // will be deleted right away but not until the Drag-n-Drop is over
157     //
158     int drag_drop_wpid;
159 
160 
161     //
162     // In order to allow keyboard events to percolate up to the workspace,
163     // I'm breaking out low level window munging code from :createStandIn()
164     // into a separate method because the code needs to be applied to the
165     // io tabs as well.
166     //
167     static void ModifyButtonWindowAttributes(Widget button, int mask);
168 
169   protected:
170     //
171     // Protected member data:
172     //
173     static String  DefaultResources[];
174 
175     Node* node;
176     virtual void  initialize();
177 
178     void       setButtonLabel();
179     virtual    const char *getButtonLabel();
180     virtual    void handleSelectionChange(boolean select);
181 
182     //
183     // Drag and Drop related stuff
184     //
185     virtual int decideToDrag(XEvent *);
186     virtual void dropFinish(long, int, unsigned char);
187     virtual boolean decodeDragType (int, char *, XtPointer*, unsigned long*, long);
188 
189     virtual const char *getButtonLabelFont();
190 
191     //
192     // Constructor:
193     //
194     StandIn(WorkSpace *w, Node *node);
195 
196     //
197     // Set XmNuserData on the root widget so that we can track movement
198     // in the workspace for the purpose of implementing undo
199     //
200     virtual void setRootWidget(Widget root, boolean standardDestroy = TRUE);
201 
202   public:
203 
204 
205     //
206     // Allocator that is installed in theSIAllocatorDictionary
207     //
208     static StandIn *AllocateStandIn(WorkSpace *w, Node *n);
209 
210     //
211     // Destructor:
212     //
213     ~StandIn();
214 
215     void createStandIn();
216     void addInput(int index);
217     void removeLastInput();
218 
219     void addOutput(int index);
220     void removeLastOutput();
221 
222     virtual void setLabelColor(Pixel color);
223     virtual Pixel getLabelColor();
224 
225     void deleteArk(Ark *a);
226     void drawArks(Node *dst_node);
227     void drawTab(int paramIndex, boolean outputTab);
228 
229     void ioStatusChange(int index, boolean outputTab,
230 					NodeParameterStatusChange status);
231 
232     static void ToggleHotSpots(EditorWindow* editor,
233                                Node*    destnode,
234                                boolean     on);
235 
236     void displayTabLabel(int index, boolean outputTab);
237     void clearTabLabel();
238     Tab *getInputParameterTab(int i);
239     Tab *getOutputParameterTab(int i);
240 
getParameterTab(int i,int input)241     Tab *getParameterTab(int i, int input)
242         { return (input ? getInputParameterTab(i):
243                           getOutputParameterTab(i)); }
244 
245     Widget getInputParameterLine(int i);
246     Widget getOutputParameterLine(int i);
getParameterLine(int i,int input)247     Widget getParameterLine(int i, int input)
248         { return (input ? getInputParameterLine(i):
249                           getOutputParameterLine(i)); }
250 
251     void setInputParameterLine(int i, Widget w);
252     void setOutputParameterLine(int i, Widget w);
setParameterLine(int i,Widget w,int input)253     void setParameterLine(int i, Widget w, int input)
254         { input ? setInputParameterLine(i,w) :
255                   setOutputParameterLine(i,w); }
256 
257     int getIOWidth();
258     int getIOHeight();
259 
260     int getInputParameterTabX(int i);
261     int getInputParameterTabY(int i);
262 
263     int getOutputParameterTabX(int i);
264     int getOutputParameterTabY(int i);
265 
getParameterTabY(int i,int input)266     int getParameterTabY(int i,int input)
267         { return (input ? getInputParameterTabY(i):getOutputParameterTabY(i));}
268 
getParameterTabX(int i,int input)269     int getParameterTabX(int i,int input)
270         { return (input ? getInputParameterTabX(i):getOutputParameterTabX(i));}
271 
272 
273 
274     void setSelected(boolean s);
isSelected()275     int isSelected()        { return this->selected; }
276 
277     void addArk(EditorWindow* editor, Ark *a);
278 
279     //
280     // Print a representation of the stand in on a PostScript device.  We
281     // assume that the device is in the same coordinate space as the parent
282     // of this uicomponent (i.e. we send the current geometry to the
283     // PostScript output file).  We do not print the ArkStandIns, but do
284     // print the Tabs.
285     //
286     boolean printPostScriptPage(FILE *f, boolean label_parameters = TRUE);
287     static boolean PrintPostScriptSetup(FILE *f);
288     virtual const char *getPostScriptLabelFont();
289 
290 
291     //
292     // This function can be called to notify a standin that its label
293     // has changed.  By default, this standin just calls setButtonLabel()
294     // to reset the label.
295     virtual void notifyLabelChange();
296 
297     //
298     // Now that StandIns can live in any WorkSpace, we need to query this.
299     //
getWorkSpace()300     WorkSpace *getWorkSpace() { return this->workSpace; }
301 
302     //
303     // In addition to superclass work, also recreate an XmWorkspaceLine because
304     // the start/end locations of the lines are fixed when they're created.
305     // We need to do this on behalf of the new function that rearranges the
306     // contents of the vpe based on connectivity.
307     //
308     virtual void setXYPosition (int x, int y);
309 
310     //
311     // Returns a pointer to the class name.
312     //
getClassName()313     const char* getClassName()
314     {
315 	return ClassStandIn;
316     }
317 };
318 
319 extern Pixel standInGetDefaultForeground();
320 
321 #endif // _StandIn_h
322