Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtappbuilder / src / libABobjXm / objxm_conn.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
24 /*
25  *      $XConsortium: objxm_conn.c /main/4 1995/11/06 18:45:37 rswiston $
26  *
27  *      @(#)objxm_conn.c        1.23 04 May 1995        cde_app_builder/src/libABobjXm
28  *
29  *      RESTRICTED CONFIDENTIAL INFORMATION:
30  *      
31  *      The information in this document is subject to special
32  *      restrictions in a confidential disclosure agreement between
33  *      HP, IBM, Sun, USL, SCO and Univel.  Do not distribute this
34  *      document outside HP, IBM, Sun, USL, SCO, or Univel without
35  *      Sun's specific written approval.  This document and all copies
36  *      and derivative works thereof must be returned or destroyed at
37  *      Sun's request.
38  *
39  *      Copyright 1993 Sun Microsystems, Inc.  All rights reserved.
40  *
41  */
42
43
44 /*
45  *  objxm_conn.c - handles connections stuff
46  *
47  */
48 #include <assert.h>
49 #include <ab_private/objxm.h>
50 #include <Dt/SpinBox.h>
51 #include <Dt/ComboBox.h>
52
53 /*************************************************************************
54 **                                                                      **
55 **       Private Function Declarations                                  **
56 **                                                                      **
57 **************************************************************************/
58 static STRING   get_resource_for_set_value(ABObj compObj, ABObj obj);
59 static STRING   get_resource_for_set_text(ABObj compObj, ABObj obj);
60 static STRING   get_resource_for_set_label(ABObj compObj, ABObj obj);
61
62
63 /*************************************************************************
64 **                                                                      **
65 **       Data                                                           **
66 **                                                                      **
67 **************************************************************************/
68
69 /*************************************************************************
70 **                                                                      **
71 **       Function Definitions                                           **
72 **                                                                      **
73 **************************************************************************/
74
75 #define ObjWClassIs(obj, class_name) \
76                 (util_streq(obj_get_class_name(obj), class_name))
77
78 #define ObjWClassIsApplicationShell(obj) \
79                 (ObjWClassIs((obj), _applicationShell))
80
81 #define ObjWClassIsArrowButton(obj) \
82                 (ObjWClassIs((obj), _xmArrowButton))
83
84 #define ObjWClassIsBulletinBoard(obj) \
85                 (ObjWClassIs((obj), _xmBulletinBoard))
86
87 #define ObjWClassIsCascadeButton(obj) \
88                 (ObjWClassIs((obj), _xmCascadeButton))
89
90 #define ObjWClassIsDialogShell(obj) \
91                 (ObjWClassIs((obj), _xmDialogShell))
92
93 #define ObjWClassIsDrawingArea(obj) \
94                 (ObjWClassIs((obj), _xmDrawingArea))
95
96 #define ObjWClassIsDrawnButton(obj) \
97                 (ObjWClassIs((obj), _xmDrawnButton))
98
99 #define ObjWClassIsFileChooserShell(obj) \
100                 (ObjWClassIs((obj), _xmFileSelectionBox))
101
102 #define ObjWClassIsForm(obj) \
103                 (ObjWClassIs((obj), _xmForm))
104
105 #define ObjWClassIsLabel(obj) \
106                 (ObjWClassIs((obj), _xmLabel))
107
108 #define ObjWClassIsList(obj) \
109                 (ObjWClassIs((obj), _xmList))
110
111 #define ObjWClassIsMainWindow(obj) \
112                 (ObjWClassIs((obj), _xmMainWindow))
113
114 #define ObjWClassIsMenuButton(obj) \
115                 (ObjWClassIs((obj), _dtMenuButton))
116
117 #define ObjWClassIsMenuShell(obj) \
118                 (ObjWClassIs((obj), _xmMenuShell))
119
120 #define ObjWClassIsPanedWindow(obj) \
121                 (ObjWClassIs((obj), _xmPanedWindow))
122
123 #define ObjWClassIsPrimitive(obj) \
124                 (ObjWClassIs((obj), _xmPrimitive))
125
126 #define ObjWClassIsPushButton(obj) \
127                 (ObjWClassIs((obj), _xmPushButton))
128
129 #define ObjWClassIsRowColumn(obj) \
130                 (ObjWClassIs((obj), _xmRowColumn))
131
132 #define ObjWClassIsScrolledWindow(obj) \
133                 (ObjWClassIs((obj), _xmScrolledWindow))
134
135 #define ObjWClassIsTextField(obj) \
136                 (ObjWClassIs((obj), _xmTextField))
137
138 #define ObjWClassIsText(obj) \
139                 (ObjWClassIs((obj), _xmText))
140
141 #define ObjWClassIsToggleButton(obj) \
142                 (ObjWClassIs((obj), _xmToggleButton))
143
144 #define ObjWClassIsBaseWinShell(obj) \
145                 (ObjWClassIsApplicationShell(obj))
146
147 #define ObjWClassIsScale(obj) \
148                 (ObjWClassIs((obj), _xmScale))
149
150 #define ObjWClassIsSpinBox(obj) \
151                 (ObjWClassIs((obj), _dtSpinBox))
152
153 /*
154  * Complex checks
155  */
156 #define ObjWClassIsShell(obj) \
157         (   (ObjWClassIsBaseWinShell(obj)) \
158          || (ObjWClassIsDialogShell(obj)) \
159          || (ObjWClassIsFileChooserShell(obj)) \
160          || (ObjWClassIsMenuShell(obj)) \
161          )
162
163
164 STRING
165 objxm_get_resource_for_when(
166     ABObj       obj, 
167     AB_WHEN     when
168 )
169 {
170     STRING    res= NULL;
171
172     /********** GET "DEFAULT" RESOURCE NAME *********/
173
174     switch (when)
175     {
176         case AB_WHEN_DESTROYED: res= XmNdestroyCallback;
177         break;
178     }
179
180
181     /********** GET TYPE-SPECIFIC RESOURCE NAME *********/
182
183     switch (obj_get_type(obj))
184     {
185     case AB_TYPE_BASE_WINDOW:
186         switch (when)
187         {
188             case AB_WHEN_HIDDEN: res= XmNpopdownCallback;
189             break;
190             case AB_WHEN_SHOWN: res= XmNpopupCallback;
191             break;
192         }
193     break;
194
195     case AB_TYPE_BUTTON:
196         switch (when)
197         {
198             case AB_WHEN_ACTIVATED: res= XmNactivateCallback; 
199             break;
200         }
201     break;
202
203     case AB_TYPE_CHOICE:
204     break;
205
206     case AB_TYPE_COMBO_BOX:
207         if (when == AB_WHEN_ITEM_SELECTED)
208             res = DtNselectionCallback;
209     break;
210
211     case AB_TYPE_CONTAINER:
212     break;
213
214     case AB_TYPE_DIALOG:
215         switch (when)
216         {
217             case AB_WHEN_HIDDEN: res= XmNpopdownCallback;
218             break;
219             case AB_WHEN_SHOWN: res= XmNpopupCallback;
220             break;
221         }
222     break;
223
224     case AB_TYPE_DRAWING_AREA:
225         switch (when)
226         {
227             case AB_WHEN_REPAINT_NEEDED: res= XmNexposeCallback;
228             break;
229             case AB_WHEN_AFTER_RESIZED: res= XmNresizeCallback;
230             break;
231         }
232     break;
233
234     case AB_TYPE_FILE_CHOOSER:
235         switch (when)
236         {
237             case AB_WHEN_OK: res = XmNokCallback;
238                 break;
239             case AB_WHEN_CANCEL: res = XmNcancelCallback;
240                 break;
241             case AB_WHEN_HIDDEN: res= XmNpopdownCallback;
242                 break;
243             case AB_WHEN_SHOWN: res= XmNpopupCallback;
244                 break;
245         }
246     break;
247
248     case AB_TYPE_ITEM:
249         switch (obj_get_item_type(obj))
250         {
251             case AB_ITEM_FOR_CHOICE:
252                 switch (when)
253                 {
254                     /* For optionmenu items */
255                     case AB_WHEN_ACTIVATED:
256                         if (ObjWClassIsPushButton(obj))
257                         {
258                             res = XmNactivateCallback;
259                         }
260                         break;
261
262                     /* For checkbox/radiobox items */
263                     case AB_WHEN_TOGGLED:
264                             res = XmNvalueChangedCallback;
265                         break;
266                 }
267             break;
268             case AB_ITEM_FOR_LIST:
269             break;
270             case AB_ITEM_FOR_MENUBAR:
271 /*
272                 switch (when)
273                 {
274                     case AB_WHEN_BEFORE_POST_MENU: 
275                         res = XmNcascadingCallback;
276                     break;
277                 }
278 */
279             break;
280             case AB_ITEM_FOR_MENU:
281                 switch (when)
282                 {
283                     case AB_WHEN_ACTIVATED: 
284                         res = XmNactivateCallback;
285                     break;
286                 }
287             break;
288         }
289     break;
290
291     case AB_TYPE_LABEL:
292     break;
293
294     case AB_TYPE_LAYERS:
295     break;
296
297     case AB_TYPE_LIST:
298         switch (when)
299         {
300             case AB_WHEN_ITEM_SELECTED:
301                 switch (obj_get_selection_mode(obj))
302                 {
303                     case AB_SELECT_SINGLE:
304                         res = XmNsingleSelectionCallback;
305                         break;
306                     case AB_SELECT_BROWSE:
307                         res = XmNbrowseSelectionCallback;
308                         break;
309                     case AB_SELECT_MULTIPLE:
310                         res = XmNmultipleSelectionCallback;
311                         break;
312                     case AB_SELECT_BROWSE_MULTIPLE:
313                         res = XmNextendedSelectionCallback;
314                         break;
315                 }
316                 break;
317         
318             case AB_WHEN_DOUBLE_CLICKED_ON:
319                 res = XmNdefaultActionCallback;
320                 break;
321         }
322     break;
323
324     case AB_TYPE_MENU:
325         switch (when)
326         {
327             case AB_WHEN_POPPED_UP: res= XmNpopupCallback;
328             break;
329             case AB_WHEN_POPPED_DOWN: res= XmNpopdownCallback;
330             break;
331         }
332     break;
333
334     case AB_TYPE_SEPARATOR:
335     break;
336
337     case AB_TYPE_SPIN_BOX:
338         if (when == AB_WHEN_VALUE_CHANGED)
339             res = XmNvalueChangedCallback;
340     break;
341
342     case AB_TYPE_SCALE:
343         switch (when)
344         {
345             case AB_WHEN_VALUE_CHANGED: res= XmNvalueChangedCallback;
346             break;
347         
348             case AB_WHEN_DRAGGED: res = XmNdragCallback;
349             break;
350         }
351     break;
352
353     case AB_TYPE_TERM_PANE:
354     break;
355
356     case AB_TYPE_TEXT_FIELD:
357     case AB_TYPE_TEXT_PANE:
358         switch (when)
359         {
360             case AB_WHEN_BEFORE_TEXT_CHANGED: 
361                 res= XmNmodifyVerifyCallback;
362             break;
363
364             case AB_WHEN_TEXT_CHANGED: 
365                 res= XmNvalueChangedCallback;
366             break;
367         }
368     break;
369     } /* switch obj_get_type() */
370
371     return res;
372 }
373
374
375 /*
376  * The parameter 'obj' is the actual subobject (probably from
377  * objxm_comp_get_target_for_builtin_action()) that the resource
378  * will be set on.
379  * 
380  */
381 STRING
382 objxm_get_resource_for_builtin_action(
383     ABObj               obj, 
384     AB_BUILTIN_ACTION   builtin_action
385 )
386 {
387     ABObj       compObj = obj_get_root(obj);
388     STRING      resource = NULL;
389
390     switch (builtin_action)
391     {
392     case AB_STDACT_DISABLE:
393     case AB_STDACT_ENABLE:
394         resource = XmNsensitive;
395     break;
396
397     case AB_STDACT_HIDE:
398     case AB_STDACT_SHOW:
399         /* This is not handled through a resource directly, but through
400          *  a convenience function. So, this case isn't really necessary, but
401          *  is here for completeness. 
402          */
403         resource = XmNmappedWhenManaged;
404     break;
405
406     case AB_STDACT_SET_LABEL:
407         resource = get_resource_for_set_label(compObj, obj);
408     break;
409
410     case AB_STDACT_SET_TEXT:
411         resource = get_resource_for_set_text(compObj, obj);
412     break;
413
414     case AB_STDACT_SET_VALUE:
415         resource = get_resource_for_set_value(compObj, obj);
416     break;
417     }
418
419     return resource;
420 }
421
422
423 ABObj
424 objxm_comp_get_source_for_when(ABObj subObj, AB_WHEN when)
425 {
426     ABObj       source = NULL;
427     ABObj       compObj = obj_get_root(subObj);
428
429     switch (when)
430     {
431         case AB_WHEN_POPPED_UP:
432         case AB_WHEN_POPPED_DOWN:
433             /* If this object is an optionmenu or a menu 
434              * we need to get a handle for the pulldown 
435              * menu, so that we can add a callback to 
436              * its menuShell.
437              */
438 /*
439             if (obj_is_option_menu(compObj))
440             {
441                 source = objxm_comp_get_subobj(compObj, AB_CFG_PARENT_OBJ);
442             }
443             else if (obj_is_menu_ref(subObj))
444             {
445                 source = subObj;
446             }
447 */
448             if (obj_is_menu_ref(subObj))
449             {
450                 source = subObj;
451             }
452             break;
453                 
454         default:
455             source = objxm_comp_get_subobj(compObj, AB_CFG_OBJECT_OBJ);
456     }
457
458     return source;
459 }
460
461
462 ABObj
463 objxm_comp_get_target_for_builtin_action(ABObj subObj, AB_BUILTIN_ACTION action)
464 {
465     ABObj       compObj = obj_get_root(subObj);
466     ABObj       actualTarget = NULL;
467     BOOL        useObjectObj = FALSE;
468
469     /*
470      * Adjust the actual "to" object
471      */
472     switch (action)
473     {
474     case AB_STDACT_ENABLE:
475     case AB_STDACT_DISABLE:
476         actualTarget = compObj;
477     break;
478
479     case AB_STDACT_HIDE:
480     case AB_STDACT_SHOW:
481         if (obj_is_popup_win(compObj))
482         {
483             actualTarget = objxm_comp_get_subobj(compObj, AB_CFG_WINDOW_BB_OBJ);
484         }
485         else if (obj_is_base_win(compObj))
486         {
487             actualTarget = objxm_comp_get_subobj(compObj, AB_CFG_OBJECT_OBJ);
488         }
489         else if (obj_is_file_chooser(compObj))
490         {
491             actualTarget = objxm_comp_get_subobj(compObj, AB_CFG_OBJECT_OBJ);
492         }
493         else
494         {
495             actualTarget = compObj;
496         }
497         break;
498
499     case AB_STDACT_SET_LABEL:
500         actualTarget = objxm_comp_get_subobj(compObj, AB_CFG_LABEL_OBJ);
501     break;
502
503     default:
504         useObjectObj = TRUE;
505     break;
506     }
507
508     if (actualTarget == NULL)
509     {
510         if (useObjectObj)
511         {
512             actualTarget = objxm_comp_get_subobj(compObj, AB_CFG_OBJECT_OBJ);
513         }
514     }
515
516     return actualTarget;
517 }
518
519
520 /*
521  * the set-label connections we support:
522  *
523  *      button
524  *      choice
525  *      combobox
526  *      label
527  *      scale
528  *      spinbox
529  *      textfield
530  *      item (choice, menu, menubar)
531  */
532 static STRING
533 get_resource_for_set_label(ABObj compObj, ABObj obj)
534 {
535     STRING      resource = NULL;
536
537         assert(!ObjWClassIsArrowButton(obj));   /* not supported */
538         if (ObjWClassIsShell(obj))
539         {
540             resource = XmNtitleString;
541         }
542         else if (   ObjWClassIsCascadeButton(obj)
543                  || ObjWClassIsDrawnButton(obj)
544                  || ObjWClassIsMenuButton(obj)
545                  || ObjWClassIsPushButton(obj)
546                  || ObjWClassIsToggleButton(obj)
547                  || ObjWClassIsLabel(obj) )
548         {
549             if (obj_get_label_type(compObj) == AB_LABEL_GLYPH)
550             {
551                 resource = XmNlabelPixmap;
552             }
553             else
554             {
555                 resource = XmNlabelString;
556             }
557         }
558     return resource;
559 }
560
561
562 static STRING
563 get_resource_for_set_text(ABObj compObj, ABObj obj)
564 {
565     STRING      resource = NULL;
566     compObj = compObj;  /* avoid warning */
567
568         if (ObjWClassIsSpinBox(obj))
569         {
570             resource = DtNposition;
571         }
572         else
573         {
574             resource = XmNvalue;
575         }
576
577     return resource;
578 }
579
580
581 static STRING
582 get_resource_for_set_value(ABObj compObj, ABObj obj)
583 {
584     STRING      resource = NULL;
585     compObj = compObj;  /* avoid warning */
586
587         if (ObjWClassIsScale(obj))
588             resource = XmNvalue;
589         else if (ObjWClassIsSpinBox(obj))
590             resource = DtNposition;
591
592     return resource;
593 }
594