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 Dimension width, height;
281 * get the absolute screen coordinates of the parent window
283 XTranslateCoordinates(me->display, me->parent_window,
284 me->parent_attr.root,
290 * get the dimensions of the PDM window
292 XtRealizeWidget(me->widget);
293 XtVaGetValues(me->widget, XmNwidth, &width, XmNheight, &height, NULL);
295 * determine the origin of the PDM popup such that it is
296 * centered w.r.t. the parent window
298 x = parent_abs_x + me->parent_attr.width/2 - width/2;
299 y = parent_abs_y + me->parent_attr.height/2 - height/2;
301 * update the app shell position
303 XtVaSetValues(me->widget, XmNx, x, XmNy, y, NULL);
305 * present the PDM as transient for the passed video window
307 * Note: this only works if the passed video window is a
308 * top-level window; i.e. one that the window manager
311 XSetTransientForHint(me->display, XtWindow(me->widget),
316 XtMapWidget(me->widget);
320 * ------------------------------------------------------------------------
321 * Name: PdmStartOkWorkProc
325 * Send the PDM_START_OK message to the dtpdmd on stderr. This
326 * routine is an Xt work proc that is intended to be invoked by Xt
327 * following the dispatch of all events generated during
328 * startup. This function is only called once during the life of the
333 * True, which causes Xt to remove this work proc.
337 PdmStartOkWorkProc(XtPointer client_data)
339 fprintf(stderr, "PDM_START_OK");
345 * ------------------------------------------------------------------------
350 * main function for the DtPrint Dialog Manager.
354 * This function never returns.
357 int main(int argc, char* argv[])
360 PdmMainWin* pdm_main_window;
361 String* fallback_resources;
366 * Initialize environment so we can find message catalog.
368 _DtEnvControl(DT_ENV_SET);
371 * ensure we can convert Xp attributes for this locale
373 if(!XSupportsLocale())
375 fprintf(stderr, "%s\n", PDM_MSG_ERR_X_LOCALE);
376 exit(PDM_EXIT_ERROR);
379 * create the PDM objects for the app shell, the main window, and the
382 pdm_shell = PdmShellNew();
383 pdm_main_window = PdmMainWinNew();
384 PdmMainWinAddSetupBox(pdm_main_window, PdmPrinterBoxNew());
385 PdmMainWinAddSetupBox(pdm_main_window, PdmJobBoxNew());
387 * create the application shell widget
390 PdmMainWinMergeFallbacks(pdm_main_window,
391 PdmShellFallbackResources,
392 XtNumber(PdmShellFallbackResources));
393 status = PdmShellCreate(pdm_shell, fallback_resources, &argc, argv);
396 PdmMainWinDelete(pdm_main_window);
399 XtFree((char*)fallback_resources);
401 * create the main PDM window widget hierarchy
403 PdmMainWinCreate(pdm_main_window,
405 pdm_shell->print_display_spec,
406 pdm_shell->print_context_str);
410 PdmShellPresent(pdm_shell);
412 * signal the PDM is up following startup event processing
414 XtAppAddWorkProc(pdm_shell->app_context,
415 PdmStartOkWorkProc, (XtPointer)NULL);
424 XtAppNextEvent(pdm_shell->app_context, &event);
426 * check to see if the parent video window has been destroyed
428 if(event.xany.display == pdm_shell->display
430 event.xany.window == pdm_shell->parent_window
432 event.xany.type == DestroyNotify)
434 PdmMainWinDelete(pdm_main_window);
435 exit(PDM_EXIT_CANCEL);
438 XtDispatchEvent(&event);