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 /* $TOG: Main.c /main/11 1998/04/20 12:58:06 mgreess $ */
28 * (c) Copyright 1996 Digital Equipment Corporation.
29 * (c) Copyright 1996 Hewlett-Packard Company.
30 * (c) Copyright 1996 International Business Machines Corp.
31 * (c) Copyright 1996 Sun Microsystems, Inc.
32 * (c) Copyright 1996 Novell, Inc.
33 * (c) Copyright 1996 FUJITSU LIMITED.
34 * (c) Copyright 1996 Hitachi.
38 #include <Xm/ColorObjP.h> /* for Xme Color Obj access API */
39 #include <Dt/dtpdmd.h>
40 #include <Dt/EnvControlP.h>
42 #include "MainWindow.h"
43 #include "PrinterBox.h"
50 typedef struct _PdmShell
53 * application shell widget data
55 XtAppContext app_context;
58 XWindowAttributes parent_attr;
61 * command line parameters
63 String print_display_spec;
64 String print_context_str;
69 * application resources
71 static XrmOptionDescRec PdmOptions[] =
73 { "-window", "parentWindowStr", XrmoptionSepArg, (caddr_t)0 },
74 { "-pdisplay", "printDisplaySpec", XrmoptionSepArg, (caddr_t)NULL },
75 { "-pcontext", "printContextStr", XrmoptionSepArg, (caddr_t)0 }
78 static XtResource PdmResources[] =
80 { "printDisplaySpec", "PrintDisplaySpec", XmRString, sizeof(String),
81 XtOffsetOf(PdmShell, print_display_spec), XmRImmediate, (XtPointer)NULL,
83 { "printContextStr", "PrintContextStr", XmRString, sizeof(String),
84 XtOffsetOf(PdmShell, print_context_str), XmRImmediate, (XtPointer)NULL,
91 static String PdmShellFallbackResources[] =
93 "Dtpdm.title: Print Setup"
97 * static function declarations
99 static PdmShell* PdmShellNew();
100 static int PdmShellCreate(PdmShell*, const String*, int*, String*);
101 static void PdmShellPresent(PdmShell* me);
102 static Boolean PdmStartOkWorkProc(XtPointer client_data);
105 * ------------------------------------------------------------------------
110 * Allocates a new PdmShell data structure.
114 * A pointer to the new PdmShell structure.
120 return (PdmShell*)XtCalloc(1, sizeof(PdmShell));
124 * ------------------------------------------------------------------------
125 * Name: PdmShellCreate
129 * This function creates a top level application shell.
133 * 0 if successful; a PDM_EXIT code if not.
137 PdmShellCreate(PdmShell* me,
138 const String* fallback_resources,
139 int* argc_in_out, String* argv_in_out)
143 XmPixelSet pixelSets[XmCO_NUM_COLORS];
144 XrmClass class_list[3];
146 XrmName name_list[3];
147 XrmRepresentation rep_type;
153 * create the application context and open the video display
155 XtToolkitInitialize();
156 XtSetLanguageProc((XtAppContext)NULL, (XtLanguageProc)NULL,
158 me->app_context = XtCreateApplicationContext();
160 XtAppSetFallbackResources(me->app_context, (String*)fallback_resources);
163 XtOpenDisplay(me->app_context, (String)NULL,
164 (String)NULL, "Dtpdm",
165 PdmOptions, XtNumber(PdmOptions),
166 argc_in_out, argv_in_out);
167 if((Display*)NULL == me->display)
168 return PDM_EXIT_VXAUTH;
169 XtGetApplicationNameAndClass(me->display, &app_name, &app_class);
171 * the fallback resources are only intended for the video display, so
172 * remove them from the application context
174 XtAppSetFallbackResources(me->app_context, (String*)NULL);
176 * get the parent video window id from the display's resource database
178 db = XtDatabase(me->display);
179 name_list[0] = XrmStringToQuark(app_name);
180 name_list[1] = XrmStringToQuark("parentWindowStr");
181 name_list[2] = NULLQUARK;
182 class_list[0] = XrmStringToQuark(app_class);
183 class_list[1] = XrmStringToQuark("ParentWindowStr");
184 class_list[2] = NULLQUARK;
185 XrmQGetResource(db, name_list, class_list, &rep_type, &value);
186 if(!value.addr) return PDM_EXIT_ERROR;
187 me->parent_window = (Window)strtoul((char*)value.addr, (char**)NULL, 0);
189 * obtain the parent video window's attributes
191 if(!XGetWindowAttributes(me->display, me->parent_window, &me->parent_attr))
192 return PDM_EXIT_ERROR;
194 * register interest in the DestroyNotify event for the parent window
196 XSelectInput(me->display, me->parent_window, StructureNotifyMask);
198 * create the application shell
200 decor = MWM_DECOR_ALL | MWM_DECOR_RESIZEH | MWM_DECOR_MINIMIZE
201 | MWM_DECOR_MAXIMIZE;
202 funcs = MWM_FUNC_ALL | MWM_FUNC_RESIZE | MWM_FUNC_MINIMIZE
205 XtVaAppCreateShell(app_name, app_class,
206 applicationShellWidgetClass,
208 XmNdeleteResponse, XmDESTROY,
209 XmNmappedWhenManaged, False,
210 XmNmwmDecorations, decor,
211 XmNmwmFunctions, funcs,
212 XmNmwmInputMode,MWM_INPUT_PRIMARY_APPLICATION_MODAL,
213 XmNscreen, me->parent_attr.screen,
217 * pick up the secondary color set, so that the PDM presents the same
218 * colors as a secondary window. (the XmColorObj is created by the
219 * the XmDisplay object, which is created when the app shell is
222 if(XmeGetColorObjData(XtScreen(me->widget), (int*)NULL,
223 pixelSets, XmCO_NUM_COLORS,
224 (short*)NULL, (short*)NULL, (short*)NULL,
225 &secondary_id, (short*)NULL))
228 * In the Xrm database, reassign primary color resource values
229 * with the corresponding secondary color values. This will cause
230 * subsequently created widgets that utilize colors from the
231 * primary set to actually present secondary colors.
233 db = XtScreenDatabase(XtScreen(me->widget));
234 value.size = sizeof(Pixel);
235 value.addr = (char*)&pixelSets[secondary_id].bg;
236 XrmPutResource (&db, "*background", "Pixel", &value);
237 XrmPutResource (&db, "*frameBackground", "Pixel", &value);
238 value.addr = (char*)&pixelSets[secondary_id].fg;
239 XrmPutResource (&db, "*foreground", "Pixel", &value);
240 XrmPutResource (&db, "*backPageForeground", "Pixel", &value);
241 value.addr = (char*)&pixelSets[secondary_id].bs;
242 XrmPutResource (&db, "*bottomShadowColor", "Pixel", &value);
243 value.addr = (char*)&pixelSets[secondary_id].ts;
244 XrmPutResource (&db, "*topShadowColor", "Pixel", &value);
247 * get the application resources
249 XtGetApplicationResources(me->widget, me,
250 PdmResources, XtNumber(PdmResources),
259 * ------------------------------------------------------------------------
260 * Name: PdmShellPresent
264 * Displays the application shell as a transient for the window
265 * passed via the -window command line parameter.
270 * True if successful.
274 PdmShellPresent(PdmShell* me)
276 int parent_abs_x, parent_abs_y;
278 XtArgVal width0, height0;
279 Dimension width, height;
282 * get the absolute screen coordinates of the parent window
284 XTranslateCoordinates(me->display, me->parent_window,
285 me->parent_attr.root,
291 * get the dimensions of the PDM window
293 XtRealizeWidget(me->widget);
294 XtVaGetValues(me->widget, XmNwidth, &width0, XmNheight, &height0, NULL);
295 width = (Dimension)width0;
296 height = (Dimension)height0;
298 * determine the origin of the PDM popup such that it is
299 * centered w.r.t. the parent window
301 x = parent_abs_x + me->parent_attr.width/2 - width/2;
302 y = parent_abs_y + me->parent_attr.height/2 - height/2;
304 * update the app shell position
306 XtVaSetValues(me->widget, XmNx, x, XmNy, y, NULL);
308 * present the PDM as transient for the passed video window
310 * Note: this only works if the passed video window is a
311 * top-level window; i.e. one that the window manager
314 XSetTransientForHint(me->display, XtWindow(me->widget),
319 XtMapWidget(me->widget);
323 * ------------------------------------------------------------------------
324 * Name: PdmStartOkWorkProc
328 * Send the PDM_START_OK message to the dtpdmd on stderr. This
329 * routine is an Xt work proc that is intended to be invoked by Xt
330 * following the dispatch of all events generated during
331 * startup. This function is only called once during the life of the
336 * True, which causes Xt to remove this work proc.
340 PdmStartOkWorkProc(XtPointer client_data)
342 fprintf(stderr, "PDM_START_OK");
348 * ------------------------------------------------------------------------
353 * main function for the DtPrint Dialog Manager.
357 * This function never returns.
360 int main(int argc, char* argv[])
363 PdmMainWin* pdm_main_window;
364 String* fallback_resources;
369 * Initialize environment so we can find message catalog.
371 _DtEnvControl(DT_ENV_SET);
374 * ensure we can convert Xp attributes for this locale
376 if(!XSupportsLocale())
378 fprintf(stderr, "%s\n", PDM_MSG_ERR_X_LOCALE);
379 exit(PDM_EXIT_ERROR);
382 * create the PDM objects for the app shell, the main window, and the
385 pdm_shell = PdmShellNew();
386 pdm_main_window = PdmMainWinNew();
387 PdmMainWinAddSetupBox(pdm_main_window, PdmPrinterBoxNew());
388 PdmMainWinAddSetupBox(pdm_main_window, PdmJobBoxNew());
390 * create the application shell widget
393 PdmMainWinMergeFallbacks(pdm_main_window,
394 PdmShellFallbackResources,
395 XtNumber(PdmShellFallbackResources));
396 status = PdmShellCreate(pdm_shell, fallback_resources, &argc, argv);
399 PdmMainWinDelete(pdm_main_window);
402 XtFree((char*)fallback_resources);
404 * create the main PDM window widget hierarchy
406 PdmMainWinCreate(pdm_main_window,
408 pdm_shell->print_display_spec,
409 pdm_shell->print_context_str);
413 PdmShellPresent(pdm_shell);
415 * signal the PDM is up following startup event processing
417 XtAppAddWorkProc(pdm_shell->app_context,
418 PdmStartOkWorkProc, (XtPointer)NULL);
427 XtAppNextEvent(pdm_shell->app_context, &event);
429 * check to see if the parent video window has been destroyed
431 if(event.xany.display == pdm_shell->display
433 event.xany.window == pdm_shell->parent_window
435 event.xany.type == DestroyNotify)
437 PdmMainWinDelete(pdm_main_window);
438 exit(PDM_EXIT_CANCEL);
441 XtDispatchEvent(&event);