~ubuntu-branches/debian/sid/x11-apps/sid

« back to all changes in this revision

Viewing changes to xedit/printdialog.c

  • Committer: Bazaar Package Importer
  • Author(s): Julien Cristau
  • Date: 2011-02-09 18:15:58 UTC
  • mfrom: (9.1.3 experimental)
  • Revision ID: james.westby@ubuntu.com-20110209181558-4wta1q27k11xrtae
Tags: 7.6+4
* debian/rules::get-tarballs: pass "--destdir ." to uscan
* xbiff 1.0.3.
* Remove Brice Goglin and David Nusinow from Uploaders.  Thanks for your
  work!
* Drop Pre-Depends on x11-common.
* Bump Standards-Version to 3.9.1.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * $Xorg: printdialog.c,v 1.1 2004/05/12 02:05:54 gisburn Exp $
3
 
 *
4
 
Copyright 2004 Roland Mainz <roland.mainz@nrubsig.org>
5
 
 
6
 
Permission to use, copy, modify, distribute, and sell this software and its
7
 
documentation for any purpose is hereby granted without fee, provided that
8
 
the above copyright notice appear in all copies and that both that
9
 
copyright notice and this permission notice appear in supporting
10
 
documentation.
11
 
 
12
 
The above copyright notice and this permission notice shall be included in
13
 
all copies or substantial portions of the Software.
14
 
 
15
 
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
18
 
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19
 
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
 
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
 
 
22
 
Except as contained in this notice, the name of The Open Group shall not be
23
 
used in advertising or otherwise to promote the sale, use or other dealings
24
 
in this Software without prior written authorization from The Open Group.
25
 
 *
26
 
 */
27
 
 
28
 
/* Force ANSI C prototypes from X11 headers */
29
 
#ifndef FUNCPROTO 
30
 
#define FUNCPROTO 15
31
 
#endif /* !FUNCPROTO */
32
 
 
33
 
#include <X11/StringDefs.h> 
34
 
#include <X11/Intrinsic.h> 
35
 
#include <X11/Shell.h>
36
 
#include <X11/Xaw/Form.h>
37
 
#include <X11/Xaw/Toggle.h>
38
 
#include <X11/Xaw/List.h>
39
 
#include <X11/Xaw/Command.h>
40
 
#include <X11/Xaw/AsciiText.h>
41
 
#include <X11/Xaw/Dialog.h>
42
 
 
43
 
#ifdef XKB
44
 
#include <X11/extensions/XKBbells.h>
45
 
#endif /* XKB */
46
 
 
47
 
#ifdef XEDIT
48
 
#include "xedit.h"
49
 
#endif /* XEDIT */
50
 
#include "printdialog.h"
51
 
#include "printdialogprivates.h"
52
 
#include "print.h"
53
 
 
54
 
#include <stdlib.h>
55
 
#include <ctype.h>
56
 
#include <stdio.h>
57
 
 
58
 
/* Turn a NULL pointer string into an empty string */
59
 
#define NULLSTR(x) (((x)!=NULL)?(x):(""))
60
 
 
61
 
#define Error(x) { printf x ; exit(EXIT_FAILURE); }
62
 
#define Assertion(expr, msg) { if (!(expr)) { Error msg } }
63
 
#ifdef DEBUG
64
 
#  define Log(x)   { if(True)  printf x; }
65
 
#else
66
 
#  define Log(x)   { if(False) printf x; }
67
 
#endif /* DEBUG */
68
 
 
69
 
/* Local prototypes */
70
 
static void     do_beep(PrintDialogWidget pdw);
71
 
static void     center_popup(Widget parent, Widget popup);
72
 
static void     updateWidgetStates(PrintDialogWidget pdw);
73
 
static void     printSetupClose(PrintDialogWidget pdw);
74
 
static void     printSetupOKXtProc(Widget w, XtPointer client_data, XtPointer callData);
75
 
static void     printSetupCancelXtProc(Widget w, XtPointer client_data, XtPointer callData);
76
 
static void     printSetupJobCopiesXtProc(Widget w, XtPointer client_data, XtPointer callData);
77
 
static void     printDialogDestXtProc(Widget w, XtPointer client_data, XtPointer callData);
78
 
static void     printSelectFileXtProc(Widget w, XtPointer client_data, XtPointer callData);
79
 
static void     printOKXtProc(Widget w, XtPointer client_data, XtPointer callData);
80
 
static void     printSetupXtProc(Widget w, XtPointer client_data, XtPointer callData);
81
 
static void     printFileSelectedXtProc(Widget w, XtPointer client_data, XtPointer callData);
82
 
static void     buildFileDialog(PrintDialogWidget pdw);
83
 
static void     closePrinterConnection(PrintDialogWidget  pdw, Bool closeDisplay);
84
 
static Bool     openPrinterConnection(PrintDialogWidget  pdw);
85
 
static void     destroyPrintSetupDialog(PrintDialogWidget pdw);
86
 
static Widget   buildPrintSetupDialog(PrintDialogWidget pdw);
87
 
static String  *xpprinterlist_to_widget_printerlist(XPPrinterList printerlist, int num_printers);
88
 
static String  *xppaperlist_to_widget_paperlist(XpuMediumSourceSizeList paperlist, int num_papers);
89
 
static String  *xpresolutionlist_to_widget_resolutionlist(XpuResolutionList reslist, int num_resolutions);
90
 
static String  *xporientationlist_to_widget_orientationlist(XpuOrientationList orientationlist, int num_orientations);
91
 
static String  *xpplexlist_to_widget_plexlist(XpuPlexList plexlist, int num_plex);
92
 
static String  *xpcolorspacelist_to_widget_colorspacelist(XpuColorspaceList colorspacelist, int num_colorspaces);
93
 
static void     printerSelectionPrinterSelectedXtProc(Widget w, XtPointer client_data, XtPointer callData);
94
 
static void     printSelectPrinterXtProc(Widget w, XtPointer client_data, XtPointer callData);
95
 
static void     printerSelectionClose(PrintDialogWidget  pdw);
96
 
static void     printerSelectionOKXtProc(Widget w, XtPointer client_data, XtPointer callData);
97
 
static void     printerSelectionCancelXtProc(Widget w, XtPointer client_data, XtPointer callData);
98
 
static Bool     buildPrinterSelectionDialog(PrintDialogWidget  pdw);
99
 
static void     destroyPrinterSelectionDialog(PrintDialogWidget pdw);
100
 
static void     createprintdialogchildren(Widget w);
101
 
 
102
 
static
103
 
void do_beep(PrintDialogWidget pdw)
104
 
{
105
 
    Log(("*** Beep!\n"));
106
 
#ifdef XKB
107
 
    XkbStdBell(XtDisplay((Widget)pdw), XtWindow((Widget)pdw), 0, XkbBI_MinorError);
108
 
#else
109
 
    XBell(XtDisplay((Widget)pdw), 0);
110
 
#endif /* XKB */
111
 
}
112
 
 
113
 
/* Center popup (on parent, not on screen - which would be a bad idea
114
 
 * in the Xinerama case) */
115
 
static
116
 
void center_popup(Widget parent, Widget popup)
117
 
{
118
 
    Dimension width,
119
 
              height;
120
 
    Position  x,
121
 
              y;
122
 
 
123
 
    XtVaGetValues(parent,
124
 
        XtNx,  &x,
125
 
        XtNy,  &y,
126
 
        NULL);
127
 
    XtVaGetValues(popup,
128
 
        XtNwidth,  &width,
129
 
        XtNheight, &height,
130
 
        NULL);
131
 
 
132
 
    x += (Position)width  / 2;
133
 
    y += (Position)height / 3;
134
 
 
135
 
    XtVaSetValues(popup,
136
 
        XtNx, x,
137
 
        XtNy, y,
138
 
        NULL);
139
 
}
140
 
 
141
 
static
142
 
void updateWidgetStates(PrintDialogWidget pdw)
143
 
{
144
 
    PrintDialogPart *pdp = &pdw->printdialog;
145
 
    
146
 
    /* Do not update anything if we will be destroyed */
147
 
    if (pdw->core.being_destroyed)
148
 
        return;
149
 
 
150
 
    if (pdp->printToFile == False) {  
151
 
        XtVaSetValues(pdp->main.printtoprinter, XtNstate,     True,  NULL);
152
 
        XtVaSetValues(pdp->main.printtofile,    XtNstate,     False, NULL);
153
 
        /* Disable the widgets which depend on print-to-file */
154
 
        XtVaSetValues(pdp->main.filenamelabel,  XtNsensitive, False, NULL);
155
 
        XtVaSetValues(pdp->main.filename,       XtNsensitive, False, NULL);
156
 
        XtVaSetValues(pdp->main.selectfile,     XtNsensitive, False, NULL);
157
 
    }
158
 
    else
159
 
    {
160
 
        XtVaSetValues(pdp->main.printtoprinter, XtNstate, False, NULL);
161
 
        XtVaSetValues(pdp->main.printtofile,    XtNstate, True,  NULL);
162
 
        /* Enable the widgets which depend on print-to-file */
163
 
        XtVaSetValues(pdp->main.filenamelabel,  XtNsensitive, True, NULL);
164
 
        XtVaSetValues(pdp->main.filename,       XtNsensitive, True, NULL);
165
 
        XtVaSetValues(pdp->main.selectfile,     XtNsensitive, True, NULL);
166
 
    }
167
 
 
168
 
    /* Update file name */
169
 
    XtVaSetValues(pdp->main.filename, XtNlabel, pdp->filename?pdp->filename:"-", NULL);
170
 
    
171
 
    /* General check whether we can print... */
172
 
    pdp->canPrint = True;
173
 
    if (pdp->printer_name == NULL) {
174
 
        pdp->canPrint = False;
175
 
    }
176
 
    else if (strlen(pdp->printer_name) == 0) {
177
 
        pdp->canPrint = False;
178
 
    }
179
 
 
180
 
    pdp->canReallyPrint = pdp->canPrint;
181
 
 
182
 
    /* Some extra checks for print-to-file */
183
 
    if (pdp->printToFile) {
184
 
        if (pdp->filename == NULL) {
185
 
            pdp->canReallyPrint = False;
186
 
        }
187
 
        else if (strlen(pdp->filename) == 0) {
188
 
            pdp->canReallyPrint = False;
189
 
        }
190
 
    }
191
 
 
192
 
    XtVaSetValues(pdp->main.ok,    XtNsensitive, pdp->canReallyPrint, NULL);
193
 
    XtVaSetValues(pdp->main.setup, XtNsensitive, pdp->canPrint,       NULL);
194
 
}
195
 
 
196
 
static void
197
 
printSetupClose(PrintDialogWidget pdw)
198
 
199
 
    PrintDialogPart *pdp = &pdw->printdialog;
200
 
    if (pdp->setup.popup) {
201
 
        XtPopdown(pdp->setup.popup);
202
 
    }
203
 
}
204
 
 
205
 
static void
206
 
printSetupOKXtProc(Widget w, XtPointer client_data, XtPointer callData)
207
 
{
208
 
    PrintDialogWidget    pdw = (PrintDialogWidget)client_data;
209
 
    PrintDialogPart     *pdp = &pdw->printdialog;
210
 
    char                *s;
211
 
    XawListReturnStruct *lrs;    
212
 
    Log(("## printSetupOK: closing print setup!\n"));
213
 
    
214
 
    /* Set copy count (if the value is invalid beep and return to the user ) */
215
 
    XtVaGetValues(pdp->setup.jobcopies, XtNstring, &s, NULL);
216
 
    if (s) {
217
 
        int c = atoi(s);
218
 
        if (c < 1 || c > 999) {
219
 
            do_beep(pdw);
220
 
            XtVaSetValues(pdp->setup.jobcopies, XtNstring, "1", NULL);
221
 
            Log(("## printSetupOKXtProc: not a valid copy count value\n"));
222
 
            return;
223
 
        }
224
 
        
225
 
        /* Fix me: We should set the number of _job_ copies here, not _doc_ copies */
226
 
        XpuSetDocumentCopies(pdp->pdpy, pdp->pcontext, c);
227
 
    }
228
 
    
229
 
    /* Set paper size */
230
 
    lrs = XawListShowCurrent(pdp->setup.paperlist);
231
 
    if (lrs->list_index != XAW_LIST_NONE) {
232
 
        Log(("selected paper is '%s'/'%d'\n", lrs->string, lrs->list_index));
233
 
        Assertion(lrs->list_index < pdp->num_papers, (("Error: lrs->list_index < pdp->num_papers\n")));
234
 
        XpuSetDocMediumSourceSize(pdp->pdpy, pdp->pcontext, &pdp->paperlist[lrs->list_index]);
235
 
    }
236
 
    XtFree((char *)lrs);
237
 
 
238
 
    /* Set resolution */
239
 
    lrs = XawListShowCurrent(pdp->setup.resolutionlist);
240
 
    if (lrs->list_index != XAW_LIST_NONE) {
241
 
        Log(("selected resolution is '%s'/'%d'\n", lrs->string, lrs->list_index));
242
 
        Assertion(lrs->list_index < pdp->num_resolutions, (("Error: lrs->list_index < pdp->num_resolutions\n")));
243
 
        XpuSetDocResolution(pdp->pdpy, pdp->pcontext, &pdp->resolutionlist[lrs->list_index]);
244
 
    }
245
 
    XtFree((char *)lrs);
246
 
 
247
 
    /* Set orientation */
248
 
    lrs = XawListShowCurrent(pdp->setup.orientationlist);
249
 
    if (lrs->list_index != XAW_LIST_NONE) {
250
 
        Log(("selected orientation is '%s'/'%d'\n", lrs->string, lrs->list_index));
251
 
        Assertion(lrs->list_index < pdp->num_orientations, (("Error: lrs->list_index < pdp->num_orientations\n")));
252
 
        XpuSetDocOrientation(pdp->pdpy, pdp->pcontext, &pdp->orientationlist[lrs->list_index]);
253
 
    }
254
 
    XtFree((char *)lrs);
255
 
 
256
 
    /* Set plex mode */
257
 
    lrs = XawListShowCurrent(pdp->setup.plexlist);
258
 
    if (lrs->list_index != XAW_LIST_NONE) {
259
 
        Log(("selected plex is '%s'/'%d'\n", lrs->string, lrs->list_index));
260
 
        Assertion(lrs->list_index < pdp->num_plex, (("Error: lrs->list_index < pdp->num_plex\n")));
261
 
        XpuSetDocPlex(pdp->pdpy, pdp->pcontext, &pdp->plexlist[lrs->list_index]);
262
 
    }
263
 
    XtFree((char *)lrs);
264
 
 
265
 
    /* Set colorspace */
266
 
    lrs = XawListShowCurrent(pdp->setup.colorspacelist);
267
 
    if (lrs->list_index != XAW_LIST_NONE) {
268
 
        Log(("selected colorspace is '%s'/'%d'\n", lrs->string, lrs->list_index));
269
 
        Assertion(lrs->list_index < pdp->num_colorspaces, (("Error: lrs->list_index < pdp->num_colorspaces\n")));
270
 
        pdp->selected_colorspace = &pdp->colorspacelist[lrs->list_index];
271
 
    }
272
 
    XtFree((char *)lrs);
273
 
    
274
 
    printSetupClose(pdw);
275
 
}
276
 
 
277
 
static void
278
 
printSetupCancelXtProc(Widget w, XtPointer client_data, XtPointer callData)
279
 
{
280
 
    PrintDialogWidget  pdw = (PrintDialogWidget)client_data;
281
 
    Log(("## printSetupCancel: closing print setup!\n"));
282
 
 
283
 
    printSetupClose(pdw);
284
 
}
285
 
 
286
 
static void
287
 
printSetupJobCopiesXtProc(Widget w, XtPointer client_data, XtPointer callData)
288
 
{
289
 
    PrintDialogWidget pdw    = (PrintDialogWidget)client_data;
290
 
    PrintDialogPart  *pdp    = &pdw->printdialog;
291
 
    char             *string = NULL;
292
 
    
293
 
    Log(("## printSetupJobCopiesXtProc!\n"));
294
 
 
295
 
    /* Check whether the input is a valid number - and in the case of invalid input reset the value */    
296
 
    XtVaGetValues(pdp->setup.jobcopies, XtNstring, &string, NULL);
297
 
    if (string) {
298
 
        char *s;
299
 
        int   i;
300
 
        Bool  isValidNumber = True;
301
 
 
302
 
        /* First check for invalid characters... */
303
 
        for( s = string ; *s != '\0' ; s++ ) {
304
 
            if (!isdigit(*s)) {
305
 
                isValidNumber = False;
306
 
                break;
307
 
            }
308
 
        }
309
 
        
310
 
        /* .. and the do a range check... */
311
 
        i = atoi(string);
312
 
        if (i < 1 || i > 999) {
313
 
            isValidNumber = False;
314
 
        }
315
 
        
316
 
        if (!isValidNumber) {
317
 
            do_beep(pdw);
318
 
            XtVaSetValues(pdp->setup.jobcopies, XtNstring, "1", NULL);
319
 
            Log(("## printSetupJobCopiesXtProc: not a valid number\n"));
320
 
        }
321
 
    }
322
 
}
323
 
 
324
 
static void
325
 
printCancelXtProc(Widget w, XtPointer client_data, XtPointer callData)
326
 
{
327
 
    PrintDialogWidget pdw = (PrintDialogWidget)client_data;
328
 
    PrintDialogPart  *pdp = &pdw->printdialog;
329
 
 
330
 
    printSetupClose(pdw);
331
 
 
332
 
    if (pdp->cancel_callback) {
333
 
        Log(("printCancelXtProc: calling callback\n"));
334
 
        XtCallCallbackList((Widget)pdw, pdp->cancel_callback, NULL);
335
 
    }
336
 
}
337
 
 
338
 
static void
339
 
printDialogDestXtProc(Widget w, XtPointer client_data, XtPointer callData)
340
 
{
341
 
    PrintDialogWidget  pdw = (PrintDialogWidget)client_data;
342
 
    PrintDialogPart   *pdp = &pdw->printdialog;
343
 
 
344
 
    if (w == pdp->main.printtoprinter) {  
345
 
        pdp->printToFile = False;
346
 
    }
347
 
    else if (w == pdp->main.printtofile) {
348
 
        pdp->printToFile = True;
349
 
    }
350
 
    else
351
 
    {
352
 
        Log(("printDialogDestXtProc: ERROR: Unknown widget.\n"));
353
 
    }
354
 
 
355
 
    updateWidgetStates(pdw);
356
 
}
357
 
 
358
 
static void
359
 
printSelectFileXtProc(Widget w, XtPointer client_data, XtPointer callData)
360
 
{
361
 
    PrintDialogWidget   pdw = (PrintDialogWidget)client_data;
362
 
    PrintDialogPart    *pdp = &pdw->printdialog;
363
 
 
364
 
    Log(("## printSelectFileXtProc!\n"));
365
 
 
366
 
    if (!pdp->selectFile.shell) {
367
 
        buildFileDialog(pdw);
368
 
    }
369
 
    
370
 
    center_popup((Widget)pdw, pdp->selectFile.shell);
371
 
 
372
 
    XtPopup(pdp->selectFile.shell, XtGrabExclusive);
373
 
}
374
 
 
375
 
static void
376
 
printOKXtProc(Widget w, XtPointer client_data, XtPointer callData)
377
 
{
378
 
    PrintDialogWidget  pdw = (PrintDialogWidget)client_data;
379
 
    PrintDialogPart   *pdp = &pdw->printdialog;
380
 
    Log(("## printing!\n"));
381
 
    
382
 
    if (!pdp->pdpy) {
383
 
        Log(("printOKXtProc: no printer connection, opening one....\n"));
384
 
        openPrinterConnection(pdw);
385
 
 
386
 
        if (!pdp->pdpy) {
387
 
            Log(("printOKXtProc: still no printer connection - BAD (this should never happen).\n"));
388
 
            do_beep(pdw);
389
 
            return;
390
 
        }
391
 
    }    
392
 
 
393
 
    if (pdp->ok_callback) {
394
 
        XawPrintDialogCallbackStruct pdcs;
395
 
 
396
 
        Log(("printOKXtProc: calling callbacks...\n"));
397
 
        memset(&pdcs, 0, sizeof(pdcs));
398
 
        pdcs.pdpy            = pdp->pdpy;
399
 
        pdcs.pcontext        = pdp->pcontext;
400
 
        pdcs.printToFile     = pdp->printToFile;
401
 
        pdcs.printToFileName = (const char *)pdp->filename;
402
 
        pdcs.colorspace      = pdp->selected_colorspace;
403
 
        XtCallCallbackList((Widget)pdw, pdp->ok_callback, &pdcs);
404
 
    }
405
 
 
406
 
    printSetupClose(pdw);
407
 
}
408
 
 
409
 
static void
410
 
printSetupXtProc(Widget w, XtPointer client_data, XtPointer callData)
411
 
{
412
 
    PrintDialogWidget   pdw = (PrintDialogWidget)client_data;
413
 
    PrintDialogPart    *pdp = &pdw->printdialog;
414
 
 
415
 
    Log(("## setup!\n"));
416
 
 
417
 
    if (!pdp->setup.popup) {
418
 
        if (buildPrintSetupDialog(pdw) == NULL) {
419
 
            Log(("printSetupXtProc: buildPrintSetupDialog failure.\n"));
420
 
            return;
421
 
        }
422
 
    }
423
 
 
424
 
    center_popup((Widget)pdw, pdp->setup.popup);
425
 
 
426
 
    XtPopup(pdp->setup.popup, XtGrabExclusive);
427
 
}
428
 
 
429
 
static void
430
 
printFileSelectedXtProc(Widget w, XtPointer client_data, XtPointer callData)
431
 
{
432
 
    PrintDialogWidget  pdw = (PrintDialogWidget)client_data;
433
 
    PrintDialogPart   *pdp = &pdw->printdialog;
434
 
    const char        *filename;
435
 
    
436
 
    Log(("printFileSelectedXtProc: User selected file.\n"));
437
 
    filename = XawDialogGetValueString(pdp->selectFile.dialog);
438
 
    
439
 
    if (pdp->filename)
440
 
        free(pdp->filename);
441
 
    pdp->filename = strdup(filename);
442
 
    
443
 
    XtPopdown(pdp->selectFile.shell);
444
 
    
445
 
    updateWidgetStates(pdw);
446
 
}
447
 
 
448
 
static
449
 
void buildFileDialog(PrintDialogWidget pdw)
450
 
{
451
 
    PrintDialogPart *pdp = &pdw->printdialog;
452
 
    int              n;
453
 
    Arg              args[20];
454
 
 
455
 
    pdp->selectFile.shell = XtCreatePopupShell("selectfile",
456
 
                                               transientShellWidgetClass,
457
 
                                               (Widget)pdw, NULL, 0);
458
 
    n = 0;
459
 
    XtSetArg(args[n], XtNvalue, pdp->filename?pdp->filename:""); n++;  
460
 
    pdp->selectFile.dialog = XtCreateManagedWidget("dialog", dialogWidgetClass,
461
 
                                                   pdp->selectFile.shell, args, n);
462
 
    XawDialogAddButton(pdp->selectFile.dialog, "Accept", printFileSelectedXtProc, pdw);
463
 
 
464
 
    XtRealizeWidget(pdp->selectFile.shell);
465
 
}
466
 
 
467
 
static
468
 
void closePrinterConnection(PrintDialogWidget pdw, Bool closeDisplay)
469
 
470
 
    PrintDialogPart *pdp = &pdw->printdialog;
471
 
    
472
 
    Log(("# closePrinterConnection\n"));
473
 
 
474
 
    destroyPrintSetupDialog(pdw);
475
 
 
476
 
    if (pdp->paperlist) {
477
 
        XpuFreeMediumSourceSizeList(pdp->paperlist);
478
 
        pdp->paperlist = NULL;
479
 
    }
480
 
 
481
 
    if (pdp->widget_paperlist) {
482
 
        free(pdp->widget_paperlist);
483
 
        pdp->widget_paperlist = NULL;
484
 
    }
485
 
 
486
 
    if (pdp->resolutionlist) {
487
 
        XpuFreeResolutionList(pdp->resolutionlist);
488
 
        pdp->resolutionlist = NULL;
489
 
    }
490
 
 
491
 
    if (pdp->widget_resolutionlist) {
492
 
        free(pdp->widget_resolutionlist);
493
 
        pdp->widget_resolutionlist = NULL;
494
 
    }
495
 
 
496
 
 
497
 
    if (pdp->orientationlist) {
498
 
        XpuFreeOrientationList(pdp->orientationlist);
499
 
        pdp->orientationlist = NULL;
500
 
    }  
501
 
 
502
 
    if (pdp->widget_orientationlist) {
503
 
        free(pdp->widget_orientationlist);
504
 
        pdp->widget_orientationlist = NULL;
505
 
    }
506
 
 
507
 
    if (pdp->plexlist) {
508
 
        XpuFreePlexList(pdp->plexlist);
509
 
        pdp->plexlist = NULL;
510
 
    }  
511
 
 
512
 
    if (pdp->widget_plexlist) {
513
 
        free(pdp->widget_plexlist);
514
 
        pdp->widget_plexlist = NULL;
515
 
    }
516
 
 
517
 
    if (pdp->colorspacelist) {
518
 
        XpuFreeColorspaceList(pdp->colorspacelist);
519
 
        pdp->colorspacelist = NULL;
520
 
    }  
521
 
 
522
 
    if (pdp->widget_colorspacelist) {
523
 
        free(pdp->widget_colorspacelist);
524
 
        pdp->widget_colorspacelist = NULL;
525
 
    }
526
 
    pdp->selected_colorspace = NULL;
527
 
 
528
 
    if (pdp->pdpy) {
529
 
        if (closeDisplay) {
530
 
            XpuClosePrinterDisplay(pdp->pdpy, pdp->pcontext);
531
 
        }
532
 
        pdp->pdpy     = NULL;
533
 
        pdp->pcontext = None;
534
 
    }
535
 
 
536
 
    updateWidgetStates(pdw);
537
 
}
538
 
 
539
 
static
540
 
Bool openPrinterConnection(PrintDialogWidget pdw)
541
 
{
542
 
    PrintDialogPart   *pdp = &pdw->printdialog;
543
 
 
544
 
    Log(("# openPrinterConnection\n"));
545
 
 
546
 
    /* Close any outstanding connection first... */
547
 
    closePrinterConnection(pdw, True);
548
 
 
549
 
    if (!pdp->printer_name) {
550
 
        Log(("# error: openPrinterConnection: No printer name.\n"));
551
 
        return False;
552
 
    }
553
 
 
554
 
    if (XpuGetPrinter(pdp->printer_name, &pdp->pdpy, &pdp->pcontext) == False) {
555
 
        Log(("openPrinterConnection: could not open printer.\n"));
556
 
        return False;
557
 
    }
558
 
 
559
 
    pdp->paperlist       = XpuGetMediumSourceSizeList(pdp->pdpy, pdp->pcontext, &pdp->num_papers);
560
 
    pdp->resolutionlist  =       XpuGetResolutionList(pdp->pdpy, pdp->pcontext, &pdp->num_resolutions);
561
 
    pdp->orientationlist =      XpuGetOrientationList(pdp->pdpy, pdp->pcontext, &pdp->num_orientations);
562
 
    pdp->plexlist        =             XpuGetPlexList(pdp->pdpy, pdp->pcontext, &pdp->num_plex);  
563
 
    pdp->colorspacelist  =       XpuGetColorspaceList(pdp->pdpy, pdp->pcontext, &pdp->num_colorspaces);  
564
 
 
565
 
    pdp->widget_paperlist       = xppaperlist_to_widget_paperlist(pdp->paperlist, pdp->num_papers);
566
 
    pdp->widget_resolutionlist  = xpresolutionlist_to_widget_resolutionlist(pdp->resolutionlist, pdp->num_resolutions);
567
 
    pdp->widget_orientationlist = xporientationlist_to_widget_orientationlist(pdp->orientationlist, pdp->num_orientations);
568
 
    pdp->widget_plexlist        = xpplexlist_to_widget_plexlist(pdp->plexlist, pdp->num_plex);
569
 
    pdp->widget_colorspacelist  = xpcolorspacelist_to_widget_colorspacelist(pdp->colorspacelist, pdp->num_colorspaces);
570
 
 
571
 
    updateWidgetStates(pdw);
572
 
 
573
 
    return True;
574
 
}
575
 
 
576
 
#undef DEFAULT_WIDTH
577
 
#define DEFAULT_WIDTH 120
578
 
#undef DEFAULT_INFOLABEL_WIDTH
579
 
#define DEFAULT_INFOLABEL_WIDTH 250
580
 
 
581
 
static
582
 
void destroyPrintSetupDialog(PrintDialogWidget pdw)
583
 
{
584
 
    PrintDialogPart *pdp = &pdw->printdialog;
585
 
 
586
 
    if (pdp->setup.popup) {
587
 
        XtDestroyWidget(pdp->setup.popup);
588
 
    }
589
 
 
590
 
    /* |XtDestroyWidget(pdp->setup.popup);| above will recursively destroy
591
 
     * all children so we only have to reset the pointers here... */
592
 
    pdp->setup.popup            = NULL;
593
 
    pdp->setup.form             = NULL;
594
 
    pdp->setup.paperlist        = NULL;
595
 
    pdp->setup.resolutionlist   = NULL;
596
 
    pdp->setup.orientationlist  = NULL;
597
 
    pdp->setup.plexlist         = NULL;
598
 
    pdp->setup.colorspacelist   = NULL;
599
 
    pdp->setup.ok               = NULL;
600
 
    pdp->setup.cancel           = NULL;
601
 
}
602
 
 
603
 
static
604
 
Widget buildPrintSetupDialog(PrintDialogWidget pdw)
605
 
{
606
 
    PrintDialogPart  *pdp = &pdw->printdialog;
607
 
    int               n;
608
 
    Arg               args[20];
609
 
    Widget            listform;
610
 
    XpuSupportedFlags jobflags,
611
 
                      docflags;
612
 
    Bool              canChangeJobCopies,
613
 
                      canChangePaperSize,
614
 
                      canChangeResolution,
615
 
                      canChangeOrientation,
616
 
                      canChangePlex;
617
 
 
618
 
    if (!pdp->pdpy) {
619
 
        Log(("buildPrintSetupDialog: no printer connection, opening one....\n"));
620
 
        openPrinterConnection(pdw);
621
 
 
622
 
        if (!pdp->pdpy) {
623
 
            Log(("buildPrintSetupDialog: still no printer connection - BAD.\n"));
624
 
            do_beep(pdw);
625
 
            return NULL;
626
 
        }
627
 
    }
628
 
 
629
 
    /* Get flags which types of attributes can be modified */
630
 
    jobflags = XpuGetSupportedDocAttributes(pdp->pdpy, pdp->pcontext);
631
 
    docflags = XpuGetSupportedDocAttributes(pdp->pdpy, pdp->pcontext);
632
 
    canChangeJobCopies   = (jobflags & XPUATTRIBUTESUPPORTED_COPY_COUNT) == XPUATTRIBUTESUPPORTED_COPY_COUNT;
633
 
    canChangePaperSize   = (docflags & XPUATTRIBUTESUPPORTED_DEFAULT_MEDIUM) == XPUATTRIBUTESUPPORTED_DEFAULT_MEDIUM;
634
 
    canChangeResolution  = (docflags & XPUATTRIBUTESUPPORTED_DEFAULT_PRINTER_RESOLUTION) == XPUATTRIBUTESUPPORTED_DEFAULT_PRINTER_RESOLUTION;
635
 
    canChangeOrientation = (docflags & XPUATTRIBUTESUPPORTED_CONTENT_ORIENTATION) == XPUATTRIBUTESUPPORTED_CONTENT_ORIENTATION;
636
 
    canChangePlex        = (docflags & XPUATTRIBUTESUPPORTED_PLEX) == XPUATTRIBUTESUPPORTED_PLEX;
637
 
 
638
 
    n = 0;
639
 
    XtSetArg(args[n], XtNallowShellResize, True); n++;
640
 
    pdp->setup.popup = XtCreatePopupShell("setup", transientShellWidgetClass, (Widget)pdw, args, n);
641
 
 
642
 
    n = 0;
643
 
    pdp->setup.form = XtCreateManagedWidget("form", formWidgetClass, pdp->setup.popup, args, n);
644
 
 
645
 
    n = 0;
646
 
    listform = XtCreateManagedWidget("list", formWidgetClass, pdp->setup.form, args, n);
647
 
 
648
 
    n = 0;
649
 
    XtSetArg(args[n], XtNresizable,           True);                        n++;
650
 
    XtSetArg(args[n], XtNforceColumns,        True);                        n++;
651
 
    XtSetArg(args[n], XtNdefaultColumns,      1);                           n++;
652
 
    XtSetArg(args[n], XtNsensitive,           canChangePaperSize);          n++;
653
 
    XtSetArg(args[n], XtNlist,                pdp->widget_paperlist);       n++;
654
 
    XtSetArg(args[n], XtNwidth,               DEFAULT_WIDTH);               n++;
655
 
    pdp->setup.paperlist = XtCreateManagedWidget("paperlist", listWidgetClass, listform, args, n);
656
 
 
657
 
    n = 0;
658
 
    XtSetArg(args[n], XtNresizable,           True);                        n++;
659
 
    XtSetArg(args[n], XtNforceColumns,        True);                        n++;
660
 
    XtSetArg(args[n], XtNdefaultColumns,      1);                           n++;
661
 
    XtSetArg(args[n], XtNsensitive,           canChangeResolution);         n++;
662
 
    XtSetArg(args[n], XtNlist,                pdp->widget_resolutionlist);  n++;
663
 
    XtSetArg(args[n], XtNwidth,               DEFAULT_WIDTH);               n++;
664
 
    pdp->setup.resolutionlist = XtCreateManagedWidget("resolutionlist", listWidgetClass, listform, args, n);
665
 
    
666
 
    n = 0;
667
 
    XtSetArg(args[n], XtNresizable,           True);                        n++;
668
 
    XtSetArg(args[n], XtNforceColumns,        True);                        n++;
669
 
    XtSetArg(args[n], XtNdefaultColumns,      1);                           n++;
670
 
    XtSetArg(args[n], XtNsensitive,           canChangeOrientation);        n++;
671
 
    XtSetArg(args[n], XtNlist,                pdp->widget_orientationlist); n++;
672
 
    XtSetArg(args[n], XtNwidth,               DEFAULT_WIDTH);               n++;
673
 
    pdp->setup.orientationlist = XtCreateManagedWidget("orientationlist", listWidgetClass, listform, args, n);
674
 
 
675
 
    n = 0;
676
 
    XtSetArg(args[n], XtNresizable,           True);                        n++;
677
 
    XtSetArg(args[n], XtNforceColumns,        True);                        n++;
678
 
    XtSetArg(args[n], XtNdefaultColumns,      1);                           n++;
679
 
    XtSetArg(args[n], XtNsensitive,           canChangePlex);               n++;
680
 
    XtSetArg(args[n], XtNlist,                pdp->widget_plexlist);        n++;
681
 
    XtSetArg(args[n], XtNwidth,               DEFAULT_WIDTH);               n++;
682
 
    pdp->setup.plexlist = XtCreateManagedWidget("plexlist", listWidgetClass, listform, args, n);
683
 
 
684
 
    n = 0;
685
 
    XtSetArg(args[n], XtNresizable,           True);                        n++;
686
 
    XtSetArg(args[n], XtNforceColumns,        True);                        n++;
687
 
    XtSetArg(args[n], XtNdefaultColumns,      1);                           n++;
688
 
    XtSetArg(args[n], XtNsensitive,           True);                        n++;
689
 
    XtSetArg(args[n], XtNlist,                pdp->widget_colorspacelist);  n++;
690
 
    XtSetArg(args[n], XtNwidth,               DEFAULT_WIDTH);               n++;
691
 
    pdp->setup.colorspacelist = XtCreateManagedWidget("colorspacelist", listWidgetClass, listform, args, n);
692
 
    
693
 
    n = 0;
694
 
    XtSetArg(args[n], XtNborderWidth,         0);                           n++;
695
 
    XtSetArg(args[n], XtNresizable,           False);                       n++;
696
 
    XtSetArg(args[n], XtNjustify,             XtJustifyRight);              n++;
697
 
    XtSetArg(args[n], XtNwidth,               DEFAULT_WIDTH);               n++;
698
 
    XtSetArg(args[n], XtNsensitive,           canChangeJobCopies);          n++;
699
 
    pdp->setup.jobcopieslabel = XtCreateManagedWidget("jobcopieslabel", labelWidgetClass, listform, args, n);
700
 
 
701
 
    n = 0;
702
 
    XtSetArg(args[n], XtNstring,              "1");                         n++;
703
 
    XtSetArg(args[n], XtNresizable,           True);                        n++;
704
 
    XtSetArg(args[n], XtNeditType,            XawtextEdit);                 n++;
705
 
    XtSetArg(args[n], XtNsensitive,           canChangeJobCopies);          n++;
706
 
    pdp->setup.jobcopies = XtCreateManagedWidget("jobcopies", asciiTextWidgetClass, listform, args, n);
707
 
    XtAddCallback(pdp->setup.jobcopies, XtNpositionCallback, printSetupJobCopiesXtProc, pdw);
708
 
 
709
 
    n = 0;
710
 
    pdp->setup.ok = XtCreateManagedWidget("ok", commandWidgetClass, pdp->setup.form, args, n);
711
 
    XtAddCallback(pdp->setup.ok, XtNcallback, printSetupOKXtProc, pdw);
712
 
 
713
 
    n = 0;
714
 
    pdp->setup.cancel = XtCreateManagedWidget("cancel", commandWidgetClass, pdp->setup.form, args, n);
715
 
    XtAddCallback(pdp->setup.cancel, XtNcallback, printSetupCancelXtProc, pdw);
716
 
 
717
 
    XtRealizeWidget(pdp->setup.popup); 
718
 
 
719
 
    return pdp->setup.popup;
720
 
}
721
 
 
722
 
#undef DEFAULT_WIDTH
723
 
#define DEFAULT_WIDTH 150
724
 
 
725
 
static
726
 
String *xpprinterlist_to_widget_printerlist(XPPrinterList printerlist, int num_printers)
727
 
{
728
 
    int     i;
729
 
    String *names;
730
 
 
731
 
    names = malloc(sizeof(String *) * (num_printers+1));
732
 
    if(!names)
733
 
      return NULL;
734
 
 
735
 
    for(i = 0 ; i < num_printers ; i++)
736
 
        names[i] = printerlist[i].name;
737
 
 
738
 
    names[i] = NULL; /* Terminate the list */
739
 
 
740
 
    return names;
741
 
}
742
 
 
743
 
static
744
 
String *xppaperlist_to_widget_paperlist(XpuMediumSourceSizeList paperlist, int num_papers)
745
 
{
746
 
    int     i;
747
 
    String *names;
748
 
 
749
 
    names = malloc(sizeof(String *) * (num_papers+1));
750
 
    if (!names)
751
 
      return NULL;
752
 
 
753
 
    for(i = 0 ; i < num_papers ; i++)
754
 
        names[i] = (char *)paperlist[i].medium_name; /* FixMe: tray selection missing */
755
 
 
756
 
    names[i] = NULL; /* Terminate the list */
757
 
 
758
 
    return names;
759
 
}
760
 
 
761
 
static
762
 
String *xpresolutionlist_to_widget_resolutionlist(XpuResolutionList reslist, int num_resolutions)
763
 
{
764
 
    int     i;
765
 
    String *names;
766
 
 
767
 
    names = malloc(sizeof(String *) * (num_resolutions+1));
768
 
    if (!names)
769
 
        return NULL;
770
 
 
771
 
    for(i = 0 ; i < num_resolutions ; i++)
772
 
        names[i] = (char *)reslist[i].name;
773
 
 
774
 
    names[i] = NULL; /* Terminate the list */
775
 
 
776
 
    return names;
777
 
}
778
 
 
779
 
static
780
 
String *xporientationlist_to_widget_orientationlist(XpuOrientationList orientationlist, int num_orientations)
781
 
{
782
 
    int     i;
783
 
    String *names;
784
 
 
785
 
    names = malloc(sizeof(String *) * (num_orientations+1));
786
 
    if (!names)
787
 
        return NULL;
788
 
 
789
 
    for(i = 0 ; i < num_orientations ; i++)
790
 
        names[i] = (char *)orientationlist[i].orientation;
791
 
 
792
 
    names[i] = NULL; /* Terminate the list */
793
 
 
794
 
    return names;
795
 
}
796
 
 
797
 
static
798
 
String *xpplexlist_to_widget_plexlist(XpuPlexList plexlist, int num_plex)
799
 
{
800
 
    int     i;
801
 
    String *names;
802
 
 
803
 
    names = malloc(sizeof(String *) * (num_plex+1));
804
 
    if(!names)
805
 
      return NULL;
806
 
 
807
 
    for(i = 0 ; i < num_plex ; i++)
808
 
      names[i] = (char *)plexlist[i].plex;
809
 
 
810
 
    names[i] = NULL; /* Terminate the list */
811
 
 
812
 
    return names;
813
 
}
814
 
 
815
 
static
816
 
String *xpcolorspacelist_to_widget_colorspacelist(XpuColorspaceList colorspacelist, int num_colorspaces)
817
 
{
818
 
    int     i;
819
 
    String *names;
820
 
 
821
 
    names = malloc(sizeof(String *) * (num_colorspaces+1));
822
 
    if(!names)
823
 
      return NULL;
824
 
 
825
 
    for(i = 0 ; i < num_colorspaces ; i++)
826
 
      names[i] = (char *)colorspacelist[i].name;
827
 
 
828
 
    names[i] = NULL; /* Terminate the list */
829
 
 
830
 
    return names;
831
 
}
832
 
 
833
 
static void
834
 
printerSelectionPrinterSelectedXtProc(Widget w, XtPointer client_data, XtPointer callData)
835
 
{
836
 
    PrintDialogWidget    pdw = (PrintDialogWidget)client_data;
837
 
    PrintDialogPart     *pdp = &pdw->printdialog;
838
 
    XawListReturnStruct *lrs = (XawListReturnStruct *)callData;
839
 
    int                  list_index;
840
 
 
841
 
    Log(("## user selected a printer\n"));
842
 
 
843
 
    list_index = lrs->list_index;
844
 
    if (list_index == XAW_LIST_NONE) {
845
 
        Log(("printerSelectionPrinterSelectedXtProc: Nothing selected.\n"));
846
 
        return;
847
 
    }
848
 
    
849
 
    Log(("selected printer is '%d'/'%s'/'%s'\n", 
850
 
        list_index, lrs->string, NULLSTR(pdp->printerlist[list_index].name)));
851
 
 
852
 
    /* Enable OK button */
853
 
    XtVaSetValues(pdp->selectPrinter.ok, XtNsensitive, True, NULL);
854
 
}
855
 
 
856
 
static void
857
 
printSelectPrinterXtProc(Widget w, XtPointer client_data, XtPointer callData)
858
 
{
859
 
    PrintDialogWidget   pdw = (PrintDialogWidget)client_data;
860
 
    PrintDialogPart    *pdp = &pdw->printdialog;
861
 
 
862
 
    Log(("## select printer!\n"));
863
 
 
864
 
    if (!pdp->selectPrinter.popup) {
865
 
        if (!buildPrinterSelectionDialog(pdw)) {
866
 
            Log(("printSelectPrinterXtProc: buildPrinterSelectionDialog failure.\n"));
867
 
            return;
868
 
        }
869
 
    }
870
 
 
871
 
    center_popup((Widget)pdw, pdp->selectPrinter.popup);
872
 
 
873
 
    XtPopup(pdp->selectPrinter.popup, XtGrabExclusive);
874
 
}
875
 
 
876
 
static void
877
 
printerSelectionClose(PrintDialogWidget  pdw)
878
 
879
 
    PrintDialogPart *pdp = &pdw->printdialog;
880
 
 
881
 
    if (pdp->selectPrinter.popup) {
882
 
        XtPopdown(pdp->selectPrinter.popup);
883
 
    }
884
 
}
885
 
 
886
 
static void
887
 
printerSelectionOKXtProc(Widget w, XtPointer client_data, XtPointer callData)
888
 
{
889
 
    PrintDialogWidget    pdw = (PrintDialogWidget)client_data;
890
 
    PrintDialogPart     *pdp = &pdw->printdialog;
891
 
    XawListReturnStruct *lrs;
892
 
    int                  list_index;
893
 
 
894
 
    Log(("## printerSelectionOKXtProc: closing printer selection!\n"));
895
 
 
896
 
    /* Copy current selection in printer list widget and open a printer connection */
897
 
    lrs = XawListShowCurrent(pdp->selectPrinter.list);
898
 
    if (!lrs) {
899
 
        Log(("printerSelectionOKXtProc: |lrs|==NULL\n"));
900
 
        return;
901
 
    }
902
 
 
903
 
    list_index = lrs->list_index;
904
 
    if (lrs->list_index == XAW_LIST_NONE) {
905
 
        Log(("printerSelectionOKXtProc: rs->list_index == XAW_LIST_NONE\n"));
906
 
        XtFree((char *)lrs);
907
 
        return;
908
 
    }
909
 
 
910
 
    /* Set printer name and description in main dialog */
911
 
    XtVaSetValues(pdp->main.name, XtNlabel, NULLSTR(pdp->printerlist[list_index].name), NULL);
912
 
    XtVaSetValues(pdp->main.desc, XtNlabel, NULLSTR(pdp->printerlist[list_index].desc), NULL);
913
 
 
914
 
    if (pdp->printer_name)
915
 
        free(pdp->printer_name);
916
 
    pdp->printer_name = strdup(lrs->string);
917
 
 
918
 
    /* Close any outstanding printer connection since user has selected
919
 
     * a different printer */
920
 
    closePrinterConnection(pdw, True);
921
 
 
922
 
    printerSelectionClose(pdw);
923
 
    
924
 
    XtFree((char *)lrs);
925
 
}
926
 
 
927
 
static void
928
 
printerSelectionCancelXtProc(Widget w, XtPointer client_data, XtPointer callData)
929
 
{
930
 
    PrintDialogWidget  pdw = (PrintDialogWidget)client_data;
931
 
    Log(("## printerSelectionCancelXtProc: closing printer selection!\n"));
932
 
 
933
 
    printerSelectionClose(pdw);
934
 
}
935
 
 
936
 
static
937
 
Bool buildPrinterSelectionDialog(PrintDialogWidget  pdw)
938
 
{
939
 
    PrintDialogPart   *pdp = &pdw->printdialog;
940
 
 
941
 
    int  n;
942
 
    Arg  args[20];
943
 
 
944
 
    n = 0;
945
 
    XtSetArg(args[n], XtNallowShellResize, True);                    n++;
946
 
    pdp->selectPrinter.popup = XtCreatePopupShell("printerselection", transientShellWidgetClass, (Widget)pdw, args, n);
947
 
 
948
 
    n = 0;
949
 
    pdp->selectPrinter.form = XtCreateManagedWidget("form", formWidgetClass, pdp->selectPrinter.popup, args, n);
950
 
 
951
 
    n = 0;
952
 
    XtSetArg(args[n], XtNresizable,        True);                    n++;
953
 
    XtSetArg(args[n], XtNforceColumns,     True);                    n++;
954
 
    XtSetArg(args[n], XtNdefaultColumns,   1);                       n++;
955
 
    XtSetArg(args[n], XtNlist,             pdp->widget_printerlist); n++;
956
 
    XtSetArg(args[n], XtNwidth,            DEFAULT_WIDTH);           n++;
957
 
    pdp->selectPrinter.list = XtCreateManagedWidget("list", listWidgetClass, pdp->selectPrinter.form, args, n);
958
 
    XtAddCallback(pdp->selectPrinter.list, XtNcallback, printerSelectionPrinterSelectedXtProc, pdw);
959
 
 
960
 
    n = 0;
961
 
    XtSetArg(args[n], XtNsensitive,        False);                   n++;
962
 
    pdp->selectPrinter.ok = XtCreateManagedWidget("ok", commandWidgetClass, pdp->selectPrinter.form, args, n);
963
 
    XtAddCallback(pdp->selectPrinter.ok, XtNcallback, printerSelectionOKXtProc, pdw);
964
 
 
965
 
    n = 0;
966
 
    pdp->selectPrinter.cancel = XtCreateManagedWidget("cancel", commandWidgetClass, pdp->selectPrinter.form, args, n);
967
 
    XtAddCallback(pdp->selectPrinter.cancel, XtNcallback, printerSelectionCancelXtProc, pdw);
968
 
 
969
 
    XtRealizeWidget(pdp->selectPrinter.popup);
970
 
 
971
 
    return True;
972
 
}
973
 
 
974
 
static
975
 
void destroyPrinterSelectionDialog(PrintDialogWidget pdw)
976
 
{
977
 
    PrintDialogPart *pdp = &pdw->printdialog;
978
 
 
979
 
    if (pdp->selectPrinter.popup) {
980
 
        XtDestroyWidget(pdp->selectPrinter.popup);
981
 
    }
982
 
 
983
 
    /* |XtDestroyWidget(pdp->setup.popup);| above will recursively destroy
984
 
     * all children so we only have to reset the pointers here... */
985
 
    pdp->selectPrinter.popup   = NULL;
986
 
    pdp->selectPrinter.form    = NULL;
987
 
    pdp->selectPrinter.list    = NULL;
988
 
    pdp->selectPrinter.popup   = NULL;
989
 
    pdp->selectPrinter.cancel  = NULL;
990
 
}
991
 
 
992
 
/*
993
 
 * Function:
994
 
 *      createprintdialogchildren
995
 
 *
996
 
 * Parameters:
997
 
 *      w - print dialog widget
998
 
 *
999
 
 * Description:
1000
 
 *      Creates the print dialog widgets.
1001
 
 *
1002
 
 * Note
1003
 
 *      -
1004
 
 */
1005
 
static void
1006
 
createprintdialogchildren(Widget w)
1007
 
{
1008
 
    int                n;
1009
 
    Arg                args[20];
1010
 
    PrintDialogWidget  pdw = (PrintDialogWidget)w;
1011
 
    PrintDialogPart   *pdp = &pdw->printdialog;
1012
 
    const char        *default_printername = NULL,
1013
 
                      *default_printerdesc = NULL;
1014
 
    Bool               has_default_printer = False;
1015
 
 
1016
 
    pdp->printerlist = XpuGetPrinterList(NULL, &pdp->num_printers);
1017
 
    pdp->widget_printerlist = xpprinterlist_to_widget_printerlist(pdp->printerlist, pdp->num_printers);
1018
 
 
1019
 
    if (pdp->num_printers > 0) {
1020
 
        if (pdp->printerlist[0].name && strlen(pdp->printerlist[0].name)) {
1021
 
            /* XprintUtils moves the default printer to the top */
1022
 
            default_printername = pdp->printerlist[0].name;
1023
 
            default_printerdesc = pdp->printerlist[0].desc;
1024
 
            pdp->printer_name   = strdup(pdp->printerlist[0].name);
1025
 
            has_default_printer = True;
1026
 
        }
1027
 
    }
1028
 
    else
1029
 
    {
1030
 
      PrintMsg(("No Xprint servers could be found.\n"
1031
 
                "Check whether the XPSERVERLIST environment variable contains any valid Xprint server(s).\n"));
1032
 
    }
1033
 
    
1034
 
    n = 0;
1035
 
    XtSetArg(args[n], XtNborderWidth,     0);                        n++;
1036
 
    pdp->main.form = XtCreateManagedWidget("main", formWidgetClass, (Widget)pdw, args, n);
1037
 
 
1038
 
    n = 0;
1039
 
    pdp->main.innerform = XtCreateManagedWidget("innerform", formWidgetClass, pdp->main.form, args, n);
1040
 
 
1041
 
    n = 0;
1042
 
    XtSetArg(args[n], XtNborderWidth,     0);                        n++;
1043
 
    XtSetArg(args[n], XtNresizable,       False);                    n++;
1044
 
    XtSetArg(args[n], XtNjustify,         XtJustifyRight);           n++;
1045
 
    XtSetArg(args[n], XtNwidth,           DEFAULT_WIDTH);            n++;
1046
 
    pdp->main.desclabel = XtCreateManagedWidget("desclabel", labelWidgetClass, pdp->main.innerform, args, n);
1047
 
 
1048
 
    n = 0;
1049
 
    XtSetArg(args[n], XtNborderWidth,     0);                        n++;
1050
 
    XtSetArg(args[n], XtNresizable,       False);                    n++;
1051
 
    XtSetArg(args[n], XtNjustify,         XtJustifyLeft);            n++;
1052
 
    XtSetArg(args[n], XtNwidth,           DEFAULT_INFOLABEL_WIDTH);  n++;
1053
 
    XtSetArg(args[n], XtNlabel,           default_printerdesc?default_printerdesc:"-"); n++;
1054
 
    pdp->main.desc = XtCreateManagedWidget("desc", labelWidgetClass, pdp->main.innerform, args, n);
1055
 
 
1056
 
    n = 0;
1057
 
    XtSetArg(args[n], XtNsensitive,       has_default_printer);      n++;
1058
 
    pdp->main.info = XtCreateManagedWidget("info", commandWidgetClass, pdp->main.innerform, args, n);
1059
 
  /*
1060
 
    XtAddCallback(pdp->main.info, XtNcallback, printerInfoXtProc, pdw);
1061
 
  */
1062
 
    n = 0;
1063
 
    XtSetArg(args[n], XtNborderWidth,     0);                        n++;
1064
 
    XtSetArg(args[n], XtNresizable,       False);                    n++;
1065
 
    XtSetArg(args[n], XtNjustify,         XtJustifyRight);           n++;
1066
 
    XtSetArg(args[n], XtNwidth,           DEFAULT_WIDTH);            n++;
1067
 
    pdp->main.namelabel = XtCreateManagedWidget("namelabel", labelWidgetClass, pdp->main.innerform, args, n);
1068
 
 
1069
 
    n = 0;
1070
 
    XtSetArg(args[n], XtNborderWidth,     0);                        n++;
1071
 
    XtSetArg(args[n], XtNresizable,       False);                    n++;
1072
 
    XtSetArg(args[n], XtNjustify,         XtJustifyLeft);            n++;
1073
 
    XtSetArg(args[n], XtNlabel,           default_printername?default_printername:"-"); n++;
1074
 
    XtSetArg(args[n], XtNwidth,           DEFAULT_INFOLABEL_WIDTH);  n++;
1075
 
    pdp->main.name = XtCreateManagedWidget("name", labelWidgetClass, pdp->main.innerform, args, n);
1076
 
 
1077
 
    n = 0;
1078
 
    pdp->main.selectprinter = XtCreateManagedWidget("selectprinter", commandWidgetClass, pdp->main.innerform, args, n);
1079
 
    XtAddCallback(pdp->main.selectprinter, XtNcallback, printSelectPrinterXtProc, pdw);
1080
 
 
1081
 
    /* Line: "File selection" */
1082
 
 
1083
 
    n = 0;
1084
 
    XtSetArg(args[n], XtNborderWidth,     0);                        n++;
1085
 
    XtSetArg(args[n], XtNresizable,       False);                    n++;
1086
 
    XtSetArg(args[n], XtNjustify,         XtJustifyRight);           n++;
1087
 
    XtSetArg(args[n], XtNwidth,           DEFAULT_WIDTH);            n++;
1088
 
    XtSetArg(args[n], XtNsensitive,       False);                    n++;
1089
 
    pdp->main.filenamelabel = XtCreateManagedWidget("filenamelabel", labelWidgetClass, pdp->main.innerform, args, n);
1090
 
 
1091
 
    n = 0;
1092
 
    XtSetArg(args[n], XtNborderWidth,     0);                        n++;
1093
 
    XtSetArg(args[n], XtNresizable,       False);                    n++;
1094
 
    XtSetArg(args[n], XtNjustify,         XtJustifyLeft);            n++;
1095
 
    XtSetArg(args[n], XtNlabel,           "-");                      n++;
1096
 
    XtSetArg(args[n], XtNwidth,           DEFAULT_INFOLABEL_WIDTH);  n++;
1097
 
    XtSetArg(args[n], XtNsensitive,       False);                    n++;
1098
 
    pdp->main.filename = XtCreateManagedWidget("filename", labelWidgetClass, pdp->main.innerform, args, n);
1099
 
 
1100
 
    n = 0;
1101
 
    XtSetArg(args[n], XtNsensitive,       False);                    n++;
1102
 
    pdp->main.selectfile = XtCreateManagedWidget("selectfile", commandWidgetClass, pdp->main.innerform, args, n);
1103
 
    XtAddCallback(pdp->main.selectfile, XtNcallback, printSelectFileXtProc, pdw);
1104
 
 
1105
 
    /* Line: Misc (Print destination toggles, copy-count etc.)*/
1106
 
    n = 0;
1107
 
    XtSetArg(args[n], XtNstate,           True);                     n++;
1108
 
    pdp->main.printtoprinter = XtCreateManagedWidget("printtoprinter", toggleWidgetClass, pdp->main.innerform, args, n);
1109
 
    XtAddCallback(pdp->main.printtoprinter, XtNcallback, printDialogDestXtProc, pdw);
1110
 
 
1111
 
    n = 0;
1112
 
    XtSetArg(args[n], XtNstate,           False);                    n++;
1113
 
    pdp->main.printtofile = XtCreateManagedWidget("printtofile", toggleWidgetClass, pdp->main.innerform, args, n);
1114
 
    XtAddCallback(pdp->main.printtofile, XtNcallback, printDialogDestXtProc, pdw);
1115
 
 
1116
 
    /* End-of-Inner-Form-Content */
1117
 
 
1118
 
    n = 0;
1119
 
    XtSetArg(args[n], XtNsensitive,       has_default_printer);       n++;
1120
 
    pdp->main.ok = XtCreateManagedWidget("ok", commandWidgetClass, pdp->main.form, args, n);
1121
 
    XtAddCallback(pdp->main.ok, XtNcallback, printOKXtProc, pdw);
1122
 
 
1123
 
    n = 0;
1124
 
    XtSetArg(args[n], XtNsensitive,       has_default_printer);       n++;
1125
 
    pdp->main.setup = XtCreateManagedWidget("setup", commandWidgetClass, pdp->main.form, args, n);
1126
 
    XtAddCallback(pdp->main.setup, XtNcallback, printSetupXtProc, pdw);
1127
 
 
1128
 
    n = 0;
1129
 
    pdp->main.cancel = XtCreateManagedWidget("cancel", commandWidgetClass, pdp->main.form, args, n);
1130
 
    XtAddCallback(pdp->main.cancel, XtNcallback, printCancelXtProc, pdw);
1131
 
}
1132
 
 
1133
 
/*
1134
 
 * Class Methods
1135
 
 */
1136
 
static void    XawPrintDialogConstraintInitialize(Widget, Widget, ArgList, Cardinal *);
1137
 
static void    XawPrintDialogGetValuesHook(Widget, ArgList, Cardinal*);
1138
 
static void    XawPrintDialogInitialize(Widget, Widget, ArgList, Cardinal*);
1139
 
static void    XawPrintDialogDestroy(Widget);
1140
 
static Boolean XawPrintDialogSetValues(Widget, Widget, Widget, ArgList, Cardinal *);
1141
 
 
1142
 
/*
1143
 
 * Initialization
1144
 
 */
1145
 
static XtResource resources[] = {
1146
 
  {
1147
 
    XtNicon,
1148
 
    XtCIcon,
1149
 
    XtRBitmap,
1150
 
    sizeof(Pixmap),
1151
 
    XtOffsetOf(PrintDialogRec, printdialog.icon),
1152
 
    XtRImmediate,
1153
 
    0
1154
 
  },
1155
 
  {
1156
 
    XawNOkCallback, XtCCallback, XtRCallback,
1157
 
    sizeof(XtCallbackList), XtOffsetOf(PrintDialogRec, printdialog.ok_callback),
1158
 
    XtRImmediate, (XtPointer)NULL
1159
 
  },
1160
 
  {
1161
 
    XawNCancelCallback, XtCCallback, XtRCallback,
1162
 
    sizeof(XtCallbackList), XtOffsetOf(PrintDialogRec, printdialog.cancel_callback),
1163
 
    XtRImmediate, (XtPointer)NULL
1164
 
  },
1165
 
};
1166
 
 
1167
 
PrintDialogClassRec printdialogClassRec = {
1168
 
  /* core */
1169
 
  {
1170
 
    (WidgetClass)&formClassRec,         /* superclass */
1171
 
    "PrintDialog",                      /* class_name */
1172
 
    sizeof(PrintDialogRec),             /* widget_size */
1173
 
    XawInitializeWidgetSet,             /* class_initialize */
1174
 
    NULL,                               /* class_part init */
1175
 
    False,                              /* class_inited */
1176
 
    XawPrintDialogInitialize,           /* initialize */
1177
 
    NULL,                               /* initialize_hook */
1178
 
    XtInheritRealize,                   /* realize */
1179
 
    NULL,                               /* actions */
1180
 
    0,                                  /* num_actions */
1181
 
    resources,                          /* resources */
1182
 
    XtNumber(resources),                /* num_resources */
1183
 
    NULLQUARK,                          /* xrm_class */
1184
 
    True,                               /* compress_motion */
1185
 
    True,                               /* compress_exposure */
1186
 
    True,                               /* compress_enterleave */
1187
 
    False,                              /* visible_interest */
1188
 
    XawPrintDialogDestroy,              /* destroy */
1189
 
    XtInheritResize,                    /* resize */
1190
 
    XtInheritExpose,                    /* expose */
1191
 
    XawPrintDialogSetValues,            /* set_values */
1192
 
    NULL,                               /* set_values_hook */
1193
 
    XtInheritSetValuesAlmost,           /* set_values_almost */
1194
 
    XawPrintDialogGetValuesHook,        /* get_values_hook */
1195
 
    NULL,                               /* accept_focus */
1196
 
    XtVersion,                          /* version */
1197
 
    NULL,                               /* callback_private */
1198
 
    NULL,                               /* tm_table */
1199
 
    XtInheritQueryGeometry,             /* query_geometry */
1200
 
    XtInheritDisplayAccelerator,        /* display_accelerator */
1201
 
    NULL,                               /* extension */
1202
 
  },
1203
 
  /* composite */
1204
 
  {
1205
 
    XtInheritGeometryManager,           /* geometry_manager */
1206
 
    XtInheritChangeManaged,             /* change_managed */
1207
 
    XtInheritInsertChild,               /* insert_child */
1208
 
    XtInheritDeleteChild,               /* delete_child */
1209
 
    NULL,                               /* extension */
1210
 
  },
1211
 
  /* constraint */
1212
 
  {
1213
 
    NULL,                               /* subresourses */
1214
 
    0,                                  /* subresource_count */
1215
 
    sizeof(PrintDialogConstraintsRec),  /* constraint_size */
1216
 
    XawPrintDialogConstraintInitialize, /* initialize */
1217
 
    NULL,                               /* destroy */
1218
 
    NULL,                               /* set_values */
1219
 
    NULL,                               /* extension */
1220
 
  },
1221
 
  /* form */
1222
 
  {
1223
 
    XtInheritLayout,                    /* layout */
1224
 
  },
1225
 
  /* printdialog */
1226
 
  {
1227
 
    NULL,                               /* extension */
1228
 
  }
1229
 
};
1230
 
 
1231
 
WidgetClass printDialogWidgetClass = (WidgetClass)&printdialogClassRec;
1232
 
 
1233
 
/*
1234
 
 * Implementation
1235
 
 */
1236
 
/*ARGSUSED*/
1237
 
static void
1238
 
XawPrintDialogInitialize(Widget request, Widget cnew, ArgList args, Cardinal *num_args)
1239
 
{
1240
 
    PrintDialogWidget dw = (PrintDialogWidget)cnew;
1241
 
    Arg               arglist[9];
1242
 
    Cardinal          arg_cnt = 0;
1243
 
 
1244
 
    XtSetArg(arglist[arg_cnt], XtNborderWidth, 0);     arg_cnt++;
1245
 
    XtSetArg(arglist[arg_cnt], XtNleft, XtChainLeft);  arg_cnt++;
1246
 
 
1247
 
    if (dw->printdialog.icon != (Pixmap)0) {
1248
 
        XtSetArg(arglist[arg_cnt], XtNbitmap, dw->printdialog.icon);     arg_cnt++;
1249
 
        XtSetArg(arglist[arg_cnt], XtNright, XtChainLeft);               arg_cnt++;
1250
 
        dw->printdialog.iconW = XtCreateManagedWidget("icon", labelWidgetClass,
1251
 
                                                      cnew, arglist, arg_cnt);
1252
 
        arg_cnt = 2;
1253
 
        XtSetArg(arglist[arg_cnt], XtNfromHoriz, dw->printdialog.iconW); arg_cnt++;
1254
 
    }
1255
 
    else {
1256
 
        dw->printdialog.iconW = NULL;
1257
 
    }
1258
 
    
1259
 
    createprintdialogchildren((Widget)dw);
1260
 
}
1261
 
 
1262
 
/*ARGSUSED*/
1263
 
static void
1264
 
XawPrintDialogConstraintInitialize(Widget request, Widget cnew,
1265
 
                                   ArgList args, Cardinal *num_args)
1266
 
{
1267
 
    PrintDialogWidget dw = (PrintDialogWidget)cnew->core.parent;
1268
 
    PrintDialogConstraints constraint = (PrintDialogConstraints)cnew->core.constraints;
1269
 
 
1270
 
    if (!XtIsSubclass(cnew, commandWidgetClass)) /* if not a button */
1271
 
        return;                                  /* then just use defaults */
1272
 
 
1273
 
    constraint->form.left = constraint->form.right = XtChainLeft;
1274
 
    constraint->form.vert_base = dw->printdialog.main.form;
1275
 
 
1276
 
    if (dw->composite.num_children > 1) {
1277
 
        WidgetList  children = dw->composite.children;
1278
 
        Widget     *childP;
1279
 
 
1280
 
        for (childP = children + dw->composite.num_children - 1;
1281
 
           childP >= children; childP-- ) {
1282
 
            if (*childP == dw->printdialog.main.form)
1283
 
                break;
1284
 
            if (XtIsManaged(*childP) &&
1285
 
                XtIsSubclass(*childP, commandWidgetClass)) {
1286
 
                constraint->form.horiz_base = *childP;
1287
 
                break;
1288
 
            }
1289
 
        }
1290
 
    }
1291
 
}
1292
 
 
1293
 
#define ICON       0
1294
 
#define NUM_CHECKS 1
1295
 
/*ARGSUSED*/
1296
 
static Boolean
1297
 
XawPrintDialogSetValues(Widget current, Widget request, Widget cnew,
1298
 
                        ArgList in_args, Cardinal *in_num_args)
1299
 
{
1300
 
    PrintDialogWidget w   = (PrintDialogWidget)cnew;
1301
 
    PrintDialogWidget old = (PrintDialogWidget)current;
1302
 
    Arg               args[5];
1303
 
    unsigned int      i;
1304
 
    Bool              checks[NUM_CHECKS];
1305
 
 
1306
 
    for (i = 0; i < NUM_CHECKS; i++)
1307
 
        checks[i] = False;
1308
 
 
1309
 
    for (i = 0; i < *in_num_args; i++) {
1310
 
        if (!strcmp(XtNicon, in_args[i].name))
1311
 
            checks[ICON]  = True;
1312
 
    }
1313
 
 
1314
 
    if (checks[ICON]) {
1315
 
        if (w->printdialog.icon != 0) {
1316
 
            XtSetArg(args[0], XtNbitmap, w->printdialog.icon);
1317
 
            if (old->printdialog.iconW != NULL) {
1318
 
                XtSetValues(old->printdialog.iconW, args, 1);
1319
 
            }
1320
 
            else {
1321
 
                XtSetArg(args[1], XtNborderWidth, 0);
1322
 
                XtSetArg(args[2], XtNleft,        XtChainLeft);
1323
 
                XtSetArg(args[3], XtNright,       XtChainLeft);
1324
 
                w->printdialog.iconW = XtCreateWidget("icon", labelWidgetClass,
1325
 
                                                      cnew, args, 4);
1326
 
                XtManageChild(w->printdialog.iconW);
1327
 
            }
1328
 
        }
1329
 
        else if (old->printdialog.icon != 0) {
1330
 
            XtDestroyWidget(old->printdialog.iconW);
1331
 
            w->printdialog.iconW = NULL;
1332
 
        }
1333
 
    }
1334
 
 
1335
 
    return True;
1336
 
}
1337
 
 
1338
 
/*
1339
 
 * Function:
1340
 
 *      XawPrintDialogGetValuesHook
1341
 
 *
1342
 
 * Parameters:
1343
 
 *      w        - Print Dialog Widget
1344
 
 *      args     - argument list
1345
 
 *      num_args - number of args
1346
 
 *
1347
 
 * Description:
1348
 
 *      This is a get values hook routine that gets the values in the dialog.
1349
 
 */
1350
 
static void
1351
 
XawPrintDialogGetValuesHook(Widget w, ArgList args, Cardinal *num_args)
1352
 
{
1353
 
    /* NO-OP for now */
1354
 
}
1355
 
 
1356
 
static void 
1357
 
XawPrintDialogDestroy(Widget w)
1358
 
{
1359
 
    PrintDialogWidget pdw = (PrintDialogWidget)w;
1360
 
    Log(("# XawPrintDialogDestroy: start.\n"));
1361
 
 
1362
 
    destroyPrintSetupDialog(pdw);
1363
 
    destroyPrinterSelectionDialog(pdw);
1364
 
    closePrinterConnection(pdw, True);
1365
 
    
1366
 
    Log(("# XawPrintDialogDestroy: done.\n"));
1367
 
}
1368
 
 
1369
 
/*
1370
 
 * Function:
1371
 
 *      XawPrintDialogClosePrinterConnection
1372
 
 *
1373
 
 * Parameters:
1374
 
 *      w            - Print Dialog Widget
1375
 
 *      closeDisplay - Boolean which decides whether |Display *|
1376
 
 *                     and |XPContext| should be disposed, too.
1377
 
 *
1378
 
 * Description:
1379
 
 *      The print display connection is owned by the print dialog
1380
 
 *      by default.
1381
 
 *      If the application wishes to close the display connection
1382
 
 *      to the print server, either to close it itself or force
1383
 
 *      a disconnection for other reasons this function can be used.
1384
 
 *
1385
 
 * Notes
1386
 
 *      1. PUBLIC API
1387
 
 *      2. After this function returns all resources returned by the
1388
 
 *         print dialog which are related to the status of the printer
1389
 
 *         connection are stale.
1390
 
 */
1391
 
void
1392
 
XawPrintDialogClosePrinterConnection(Widget w, Bool closeDisplay)
1393
 
{
1394
 
    closePrinterConnection((PrintDialogWidget)w, closeDisplay);
1395
 
}
1396