Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / programs / dtwm / Print.c
1 /* $XConsortium: Print.c /main/4 1995/11/01 11:29:33 rswiston $ */
2 /*****************************************************************************
3  *
4  *   File:         Print.c
5  *
6  *   Project:       DT
7  *
8  *   Description:  This file contains the function which prints out the
9  *                 front panel contents.  It is used as a client for this
10  *                 purpose.
11  *
12  * (c) Copyright 1993, 1994 Hewlett-Packard Company
13  * (c) Copyright 1993, 1994 International Business Machines Corp.
14  * (c) Copyright 1993, 1994 Sun Microsystems, Inc.
15  * (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of Novell, Inc.
16  *
17  ****************************************************************************/
18
19 #include <Dt/DtP.h>                /* required for DtDirPaths type */
20 #include <Dt/DbReader.h>            /* required for DtDbPathId type */
21 #include <Dt/WsmM.h>
22 #include <Dt/IconFile.h>
23 #include "DataBaseLoad.h"
24 #include "Parse.h"
25
26 #ifdef __STDC__
27 const char *szWM_TOOL_CLASS = DtWM_TOOL_CLASS;
28 #else
29 char *szWM_TOOL_CLASS = DtWM_TOOL_CLASS;
30 #endif /* __STDC__ */
31
32
33
34 String unpost_arrow_image;
35 String unpost_monitor_arrow_image;
36
37 /************************************************************************
38  *
39  *  CheckOtherMonitorsOn
40  *      Due to a dependancy, CheckOtherMonitorsOn must be defined.  This
41  *      is a stubbed procedure that ensures that the procedure is defined.
42  *
43  ************************************************************************/
44 Boolean
45 CheckOtherMonitorsOn(SubpanelData * subpanel_data)
46 {
47    return False;
48 }
49
50
51 /************************************************************************
52  *
53  *  ToggleDefaultControl
54  *      Due to a dependancy, ToggleDefaultControl must be defined.  This
55  *      is a stubbed procedure that ensures that the procedure is defined.
56  *
57  ************************************************************************/
58
59
60 void
61 ToggleDefaultControl (ControlData  * main_control_data,
62                       SubpanelData * subpanel_data,
63                       ControlData  * control_data)
64
65
66 {
67 }
68
69
70
71
72 /************************************************************************
73  *
74  *  GetIconName
75  *      Get the file name for an icon by extracting the panel resolution
76  *      and then looking up the image name.
77  *
78  ************************************************************************/
79
80
81 String
82 GetIconName (String       image_name, 
83              unsigned int icon_size)
84
85
86 {
87    String       return_name;
88    Screen     * screen = XtScreen (panel.shell);
89
90    /*  Get name.  */
91
92    return_name = _DtGetIconFileName (screen, image_name, NULL, NULL, icon_size);
93
94    if (return_name == NULL)
95        return_name = _DtGetIconFileName (screen, image_name, NULL, NULL,
96                                          DtUNSPECIFIED);
97    if (return_name == NULL)
98        return_name = XtNewString (image_name);
99
100
101    /*  Return value to be freed by caller.  */
102
103    return (return_name);
104 }
105
106
107
108
109 /************************************************************************
110  *
111  *  PrintFrontPanelContents
112  *      Using the information from the loading of the database
113  *      print out the contents of the database.
114  *
115  ************************************************************************/
116
117 void
118
119 PrintFrontPanelContents(void)
120
121 {
122    BoxData * box_data;
123    SwitchData * switch_data;
124    ControlData * control_data, * switch_control_data;
125    SubpanelData * subpanel_data;
126    int switch_position = POSITION_FIRST;
127    int i,j, k;
128
129
130    /*  print out the component tree  */
131    
132    printf ("PANEL       %s\n", (char *) panel.element_values[0].parsed_value);
133
134    for (i = 0; i < panel.box_data_count; i++)
135    {
136       box_data = panel.box_data[i];
137
138       if (box_data->switch_data != NULL)
139       {
140          switch_data = box_data->switch_data;
141          switch_position = (int) box_data->switch_data->element_values[SWITCH_POSITION_HINTS].parsed_value;
142       }
143       else
144          switch_data = NULL;
145
146
147       printf ("   BOX   %s\n", 
148               (char *) box_data->element_values[0].parsed_value);
149
150       for (j = 0; j < box_data->control_data_count; j++)
151       {
152          control_data = box_data->control_data[j];
153
154          if (switch_data != NULL &&
155              switch_position < (int) (control_data->element_values[CONTROL_POSITION_HINTS].parsed_value))
156          {
157             printf ("      SWITCH       %s\n",
158                  (char *) switch_data->element_values[0].parsed_value);
159
160             switch_position = POSITION_LAST;
161
162             for (k = 0; k < switch_data->control_data_count; k++)
163             {
164                 switch_control_data = switch_data->control_data[k];
165
166                 printf ("         CONTROL       %s\n", (char *)
167                         switch_control_data->element_values[0].parsed_value);
168
169             }
170          }
171
172          printf ("      CONTROL %s\n",
173                  (char *) control_data->element_values[0].parsed_value);
174
175          if (control_data->subpanel_data != NULL)
176          {
177             subpanel_data = control_data->subpanel_data;
178
179             printf("         SUBPANEL   %s\n", (char *)
180                     subpanel_data->element_values[0].parsed_value);
181       
182             for (k = 0; k < subpanel_data->control_data_count; k++)
183             {
184                 control_data = subpanel_data->control_data[k];
185
186                 printf ("               CONTROL %s\n", (char *)
187                         control_data->element_values[0].parsed_value);
188             }
189          }
190       }
191    }
192 }
193
194
195
196
197 /************************************************************************
198  *
199  *  The main program for the fron panel print function.
200  *
201  ************************************************************************/
202
203 void
204 main (int argc,
205       char         **argv)
206
207
208 {
209     XtAppContext    appContext;
210     Widget              widget;
211
212    /* This call is required to have values to pass to DtAppInitialize */
213     widget = XtAppInitialize( &appContext, "Dtfplist",
214                               NULL, 0, &argc, argv, NULL, NULL, 0);
215
216    /* This is required initialization so that FrontPanelReadDatabases()
217     * procedure complete successfully.
218     */
219     DtAppInitialize( appContext, XtDisplay(widget), widget,
220                      argv[0], (char *)szWM_TOOL_CLASS);
221
222     
223    /* Load the database for use in printing. If it is able to load print
224     * contents of front panel.
225     */
226     DtDbLoad();
227
228     panel.app_name = strdup(argv[0]);
229     if (FrontPanelReadDatabases ())
230     {
231       /* Print out the contents of the .fp database */
232        PrintFrontPanelContents ();
233     }
234     else
235     {
236       /* NEEDS TO BE LOCALIZED */
237        printf ("PANEL not found. Error in reading database.\n");
238     }
239
240 }