2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
23 /* $XConsortium: Main.c /main/6 1996/06/07 12:04:30 daniel $ */
24 #include "PrintDemo.h"
27 * VideoShell structure definition
29 typedef struct _VideoShell
37 * application-level resources
39 static XrmOptionDescRec XrmOptions[] =
41 {"-print", "printOnly", XrmoptionNoArg, (caddr_t)"True"},
42 {"-fileName", "fileName", XrmoptionSepArg, (caddr_t)NULL},
44 static XtResource VideoResources[] =
46 {"printOnly", "PrintOnly", XmRBoolean, sizeof (Boolean),
47 XtOffsetOf (VideoShell, print_only), XmRImmediate, (XtPointer)False,
49 {"fileName", "FileName", XmRString, sizeof (char *),
50 XtOffsetOf (VideoShell, file_name), XmRImmediate, (XtPointer)NULL,
55 * static function declarations
57 static VideoShell* VideoShell_new(Display* display);
60 * ------------------------------------------------------------------------
61 * Name: VideoShell_new
65 * Allocates a new VideoShell data structure.
67 * This function creates a top level application shell on the passed
72 * A pointer to the new VideoShell structure.
75 VideoShell_new(Display* display)
77 VideoShell* me = (VideoShell*)XtCalloc(1, sizeof(VideoShell));
79 me->widget = XtVaAppCreateShell(NULL, APP_CLASS,
80 applicationShellWidgetClass,
82 XmNtitle, "DtPrint Demo",
84 XtGetApplicationResources(me->widget, me,
85 VideoResources, XtNumber(VideoResources),
91 * ------------------------------------------------------------------------
92 * Name: CloseProgramCB
105 XtPointer client_data,
108 AppPrintData * p = (AppPrintData *) client_data ;
109 /* we want to wait for the current job to complete before exiting */
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
114 if (p->printed_lines) {
115 /* put up a dialog saying it's waiting for the job
117 XtAddCallback(p->print_shell, XmNendJobCallback, CloseProgramCB, p);
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",
135 * ------------------------------------------------------------------------
140 * "main" function for the DtPrint demo program.
144 int main(int argc, char* argv[])
146 XtAppContext app_context;
147 VideoShell* video_shell;
148 MainWindow* main_window;
149 Display* video_display;
152 * attempt to open the X video display
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),
160 XtAppSetFallbackResources(app_context, fallbacks);
161 if(video_display == (Display*)NULL)
164 * parse command line and determine if "GUI-less" printing is
171 fprintf(stderr, "unable to open display\n");
175 * Create the top level video shell
177 video_shell = VideoShell_new(video_display);
179 * one AppPrintData object per app
181 p = AppPrintData_new();
182 p->print_only = video_shell->print_only;
184 * check to see if we're running the app, or just printing (e.g. from
185 * within a print action)
187 if(video_shell->print_only)
190 * create the application-specific object, and add it to the
191 * AppPrintData structure.
193 p->app_object = AppObject_new((Widget)NULL, video_shell->file_name);
195 * create the print setup box as the child of the top level shell
197 CreatePrintSetup(video_shell->widget, p);
199 * set the cancel button to exit the program
201 XtAddCallback(p->print_dialog, DtNcancelCallback, CloseProgramCB, p);
203 * manage the print setup box
205 XtManageChild(p->print_dialog);
210 * create the main window
212 main_window = MainWindow_new(video_shell->widget);
214 * add callbacks to the main window
216 XtAddCallback(main_window->print_menu_button, XmNactivateCallback,
218 p->pr_button = main_window->print_menu_button;
220 XtAddCallback(main_window->quick_print_button, XmNactivateCallback,
222 XtAddCallback(main_window->exit_button, XmNactivateCallback,
225 * create the application-specific object, and add it to the
226 * AppPrintData structure.
229 AppObject_new(main_window->widget, video_shell->file_name);
231 * manage the main window
233 XtManageChild(main_window->widget);
238 XtRealizeWidget(video_shell->widget);
239 XtAppMainLoop(app_context);
241 * we never get here, but this makes the compiler happy