ksh: fix up shipin for more modern systems WRT test and wc
[oweals/cde.git] / cde / examples / dtprint / Main.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 /* $XConsortium: Main.c /main/6 1996/06/07 12:04:30 daniel $ */
24 #include "PrintDemo.h"
25
26 /*
27  * VideoShell structure definition
28  */
29 typedef struct _VideoShell
30 {
31     Widget widget;
32     Boolean print_only;
33     String file_name;
34 } VideoShell;
35
36 /*
37  * application-level resources
38  */
39 static XrmOptionDescRec XrmOptions[] =
40 {
41    {"-print", "printOnly", XrmoptionNoArg, (caddr_t)"True"},
42    {"-fileName", "fileName", XrmoptionSepArg, (caddr_t)NULL},
43 };
44 static XtResource VideoResources[] =
45 {
46   {"printOnly", "PrintOnly", XmRBoolean, sizeof (Boolean),
47         XtOffsetOf (VideoShell, print_only), XmRImmediate, (XtPointer)False,
48   },
49   {"fileName", "FileName", XmRString, sizeof (char *),
50         XtOffsetOf (VideoShell, file_name), XmRImmediate, (XtPointer)NULL,
51   },
52 };
53
54 /*
55  * static function declarations
56  */
57 static VideoShell* VideoShell_new(Display* display);
58
59 /*
60  * ------------------------------------------------------------------------
61  * Name: VideoShell_new
62  *
63  * Description:
64  *
65  *     Allocates a new VideoShell data structure.
66  *
67  *     This function creates a top level application shell on the passed
68  *     video display.
69  *
70  * Return value:
71  *
72  *     A pointer to the new VideoShell structure.
73  */
74 static VideoShell*
75 VideoShell_new(Display* display)
76 {
77     VideoShell* me = (VideoShell*)XtCalloc(1, sizeof(VideoShell));
78
79     me->widget = XtVaAppCreateShell(NULL, APP_CLASS,
80                                     applicationShellWidgetClass,
81                                     display,
82                                     XmNtitle, "DtPrint Demo",
83                                     NULL);
84     XtGetApplicationResources(me->widget, me,
85                               VideoResources, XtNumber(VideoResources),
86                               NULL, 0);
87     return me;
88 }
89
90 /*
91  * ------------------------------------------------------------------------
92  * Name: CloseProgramCB
93  *
94  * Description:
95  *
96  *     Exit the program.
97  *
98  * Return value:
99  *
100  *     None.
101  */
102 void
103 CloseProgramCB(
104                 Widget w,
105                 XtPointer client_data,
106                 XtPointer call_data)
107 {
108     AppPrintData * p = (AppPrintData *) client_data ;
109     /* we want to wait for the current job to complete before exiting */
110
111     /* if a job is running, just unmap the windows and install itself
112        as endjob callback, which will be called when printed_lines is
113        back to zero */
114     if (p->printed_lines) {
115         /* put up a dialog saying it's waiting for the job
116            to complete */
117         XtAddCallback(p->print_shell, XmNendJobCallback, CloseProgramCB, p);
118     } else {
119         exit(0);
120     }
121 }
122
123 static String fallbacks[] = {
124 "Dtprint.Print*background:white",
125 "Dtprint.Print*renderTable:-dt-application-bold-r-normal-serif-0-0-0-0-p-0-iso8859-1",
126 "Dtprint.Print*shadowThickness:0",
127 "Dtprint.Print*highlightThickness:0",
128 "Dtprint.Print*pform.marginHeight: 1in",
129 "Dtprint.Print*pform.marginWidth: 1in",
130 "Dtprint.Print*ptext.Attachment:attach_form",
131 NULL
132 };
133
134 /*
135  * ------------------------------------------------------------------------
136  * Name: main
137  *
138  * Description:
139  *
140  *     "main" function for the DtPrint demo program.
141  *
142  *
143  */
144 int main(int argc, char* argv[])
145 {
146     XtAppContext app_context;
147     VideoShell* video_shell;
148     MainWindow* main_window;
149     Display* video_display;
150     AppPrintData* p;
151     /*
152      * attempt to open the X video display
153      */
154     XtSetLanguageProc(NULL, (XtLanguageProc)NULL, NULL);
155     XtToolkitInitialize();
156     app_context = XtCreateApplicationContext();
157     video_display = XtOpenDisplay(app_context, NULL, NULL, APP_CLASS,
158                                   XrmOptions, XtNumber(XrmOptions),
159                                   &argc, argv);
160     XtAppSetFallbackResources(app_context, fallbacks);
161     if(video_display == (Display*)NULL)
162     {
163         /*
164          * parse command line and determine if "GUI-less" printing is
165          * desired
166          */
167
168         /*
169          * XXX  exit for now
170          */
171         fprintf(stderr, "unable to open display\n");
172         return 1;
173     }
174     /*
175      * Create the top level video shell
176      */
177     video_shell = VideoShell_new(video_display);
178     /*
179      * one AppPrintData object per app
180      */
181     p = AppPrintData_new();
182     p->print_only = video_shell->print_only;
183     /*
184      * check to see if we're running the app, or just printing (e.g. from
185      * within a print action)
186      */
187     if(video_shell->print_only)
188     {
189         /*
190          * create the application-specific object, and add it to the
191          * AppPrintData structure.
192          */
193         p->app_object = AppObject_new((Widget)NULL, video_shell->file_name);
194         /*
195          * create the print setup box as the child of the top level shell
196          */
197         CreatePrintSetup(video_shell->widget, p);
198         /*
199          * set the cancel button to exit the program
200          */
201         XtAddCallback(p->print_dialog, DtNcancelCallback, CloseProgramCB, p);
202         /*
203          * manage the print setup box
204          */
205         XtManageChild(p->print_dialog);
206     }
207     else
208     {
209         /*
210          * create the main window
211          */
212         main_window = MainWindow_new(video_shell->widget);
213         /*
214          * add callbacks to the main window
215          */
216         XtAddCallback(main_window->print_menu_button, XmNactivateCallback,
217                       PrintMenuCB, p);
218         p->pr_button = main_window->print_menu_button;
219
220         XtAddCallback(main_window->quick_print_button, XmNactivateCallback,
221                       QuickPrintCB, p);
222         XtAddCallback(main_window->exit_button, XmNactivateCallback,
223                       CloseProgramCB, p);
224         /*
225          * create the application-specific object, and add it to the
226          * AppPrintData structure.
227          */
228         p->app_object =
229             AppObject_new(main_window->widget, video_shell->file_name);
230         /*
231          * manage the main window
232          */
233         XtManageChild(main_window->widget);
234     }
235     /*
236      * main loop
237      */
238     XtRealizeWidget(video_shell->widget);
239     XtAppMainLoop(app_context);
240     /*
241      * we never get here, but this makes the compiler happy
242      */
243     return 0;
244 }