41c763051d114bbd50e5767360f2eab981fb9883
[oweals/cde.git] / cde / programs / dtinfo / dtinfo / src / Agents / PrintPanelAgentMotif.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 libraries 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 /*
24  *  $TOG: PrintPanelAgentMotif.C /main/35 1997/08/01 15:17:10 samborn $
25  *
26  * (c) Copyright 1996 Digital Equipment Corporation.
27  * (c) Copyright 1996 Hewlett-Packard Company.
28  * (c) Copyright 1996 International Business Machines Corp.
29  * (c) Copyright 1996 Sun Microsystems, Inc.
30  * (c) Copyright 1996 Novell, Inc. 
31  * (c) Copyright 1996 FUJITSU LIMITED.
32  * (c) Copyright 1996 Hitachi.
33  *
34  * Copyright (c) 1992 HAL Computer Systems International, Ltd.
35  * All rights reserved.  Unpublished -- rights reserved under
36  * the Copyright Laws of the United States.  USE OF A COPYRIGHT
37  * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
38  * OR DISCLOSURE.
39  * 
40  * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
41  * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.  USE,
42  * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
43  * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
44  * INTERNATIONAL, LTD. 
45  * 
46  *                         RESTRICTED RIGHTS LEGEND
47  * Use, duplication, or disclosure by the Government is subject
48  * to the restrictions as set forth in subparagraph (c)(l)(ii)
49  * of the Rights in Technical Data and Computer Software clause
50  * at DFARS 252.227-7013.
51  *
52  *          HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
53
54  *                  1315 Dell Avenue
55  *                  Campbell, CA  95008
56  * 
57  */
58
59 //------------- Includes -----------------------------------
60
61 #define C_xList
62 #define L_Support
63
64 #define C_TOC_Element
65 #define C_NodeViewInfo
66 #define L_Basic
67
68 #define C_Printgr
69 #define C_PrintMgr
70 #define C_PrefMgr
71 #define C_MessageMgr
72 #define L_Managers
73
74 #define C_PrintPanelAgent
75 #define C_HelpAgent
76 #define L_Agents
77
78 #include <X11/IntrinsicP.h>
79 #include <X11/CoreP.h>
80
81 #include <Xm/MessageB.h>
82 #include <Xm/PushB.h>
83 #include <Xm/Scale.h>
84
85 #include <DtI/DisplayAreaP.h>
86 #include <DtI/DisplayAreaI.h>
87
88 #include <Prelude.h>
89
90 #include "Other/XmStringLocalized.hh"
91 #include "Managers/CatMgr.hh"
92
93 #include "Registration.hh"
94
95 #include <WWL/WXmDialogShell.h>
96 #include <WWL/WXmForm.h>
97 #include <WWL/WXmFrame.h>
98 #include <WWL/WXmPushButton.h>
99 #include <WWL/WXmSeparator.h>
100 #include <sstream>
101 using namespace std;
102
103 #define CLASS PrintPanelAgent
104
105 #include "create_macros.hh"
106
107 #include <sys/types.h>
108 #include <sys/stat.h>
109 #include <unistd.h>
110 #include <fcntl.h>
111 #include <errno.h>
112
113
114 #define AM WAutoManage
115 #define WXmToggleBtn WXmToggleButton
116 #define WXmPushBtn WXmPushButton
117
118 #if 0
119 #  define RCS_DEBUG(statement) cerr << statement << endl
120 #else
121 #  define RCS_DEBUG(statement)
122 #endif
123
124 //-------- External References ---------------------------------
125
126 extern Widget footer_book_name;
127 extern Widget footer_page_no;
128 extern DtHelpDispAreaStruct *gHelpDisplayArea;
129
130 //------------ Global Variables -----------------------------
131
132 Widget f_print_shell = NULL;
133 Widget f_scrollbar = NULL;
134 Widget f_dialog = NULL;
135 const char *f_printOrientation = NULL;
136 Boolean print_server_error = False;
137
138 //------------ Private Variables -----------------------------
139
140 //  Prefixed with an l to distinguish from f_AppPrintData in 
141 //  AppPrintData class.  
142 AppPrintData *  l_AppPrintData; 
143
144 static  WXmForm                 f_print_panel;
145 static  WXmLabel                f_selected_field;
146 static  WXmLabel                f_to_print_field;
147 static  WXmToggleButton         f_print_nodes;
148 static  WXmToggleButton         f_print_hierarchy;
149
150 static Boolean print_hierarchy;  // keep track of hierarchy vs section
151
152 #if 0 && defined(PRINTING_SUPPORTED)
153 static void PrintEverything(AppPrintData *p);
154 #endif  /* PRINTING_SUPPORTED */
155
156 static void PrintOneUASCommon(UAS_Pointer<UAS_Common> &doc, Widget pshell, int *cur_pageP);
157
158 PrintPanelAgent::PrintPanelAgent()
159 {
160     RCS_DEBUG("PrintPanelAgent constructor entered.\n");
161
162     l_AppPrintData = new AppPrintData();
163     cout << "overloaded PrintPanelAgenct constructor called.\n";   
164
165     RCS_DEBUG("PrintPanelAgent constructor exiting.\n");   
166 }
167
168 PrintPanelAgent::PrintPanelAgent(AppPrintData *p)
169 {
170     l_AppPrintData = p;
171     cout << "overloaded PrintPanelAgenct constructor called.\n";   
172 }
173
174 PrintPanelAgent::~PrintPanelAgent()
175 {
176     cout << "PrintPanelAgenct destructor called.\n";
177 }
178
179 /*
180  * ------------------------------------------------------------------------
181  * Name:  reset_ui
182  *
183  * Description:
184  *     Resets the number of nodes and what to print buttons.
185  *
186  * Return value:
187  *     None.
188  *
189  */
190 void
191 reset_ui(AppPrintData *p)
192 {
193    RCS_DEBUG("reset_ui called.\n");   
194
195     xList<UAS_Pointer<UAS_Common> > &print_list = *(p->f_print_list);
196     Xassert (print_list.length() > 0);
197     
198     // Set up the "Number of Nodes" labels. 
199     static char buffer[24];
200
201     snprintf (buffer, sizeof(buffer), "%d", print_list.length());
202     f_selected_field.LabelString (WXmString (buffer));
203     f_to_print_field.LabelString (WXmString (buffer));
204     
205     // Set up "What to print" buttons based on command line 
206     // value set in Window System 
207
208     print_hierarchy = window_system().videoShell()->hierarchy;
209
210     f_print_hierarchy.Set(print_hierarchy);
211     f_print_nodes.Set(!print_hierarchy);
212     
213     Boolean hierarchy_sensitive = False;
214     
215     List_Iterator<UAS_Pointer<UAS_Common> > l (print_list);
216
217     // NOTE: Could fail if toc() is NULL. 
218     UAS_List<UAS_Common> kids = l.item()->children();
219     if ((!strncmp(l.item()->locator(), "mmdb:", 5)) && print_list.length() == 1 && kids.length() > 0) {
220         hierarchy_sensitive = True;
221     }
222     
223     // If one is insensitive, the other one must be as well. 
224     f_print_nodes.SetSensitive (hierarchy_sensitive);
225     f_print_hierarchy.SetSensitive (hierarchy_sensitive);
226
227 }
228
229
230 /*
231  * ------------------------------------------------------------------------
232  * Name: customizePrintSetupBox
233  *
234  * Description:
235  *     Adds application specific items to the passed print setup box.
236  *
237  * Return value:
238  *
239  *     None.
240  *
241  */
242 void
243 customizePrintSetupBox(AppPrintData *p)
244 {
245     XmString label;
246
247     Widget print_dialog = p->f_print_dialog;
248     RCS_DEBUG("customizePrintSetupBox called.\n");   
249
250     Widget how_many_frame, how_many_form, selected_label, print_panel;
251     Widget what_frame, what_form, selected_field, to_print_field;
252     Widget print_nodes;
253
254     //  Create the app-specific top work area
255
256     f_print_panel = print_panel = XtVaCreateManagedWidget("workarea",
257                                             xmFormWidgetClass,
258                                             print_dialog,
259                                             XmNorientation, XmHORIZONTAL,
260                                             NULL);
261
262     // How many?
263     
264     how_many_frame = XtVaCreateManagedWidget("how_many_frame",
265                                              xmFrameWidgetClass,
266                                              print_panel, 
267                                              XmNleftAttachment, XmATTACH_FORM,
268                                              XmNrightAttachment, XmATTACH_POSITION,
269                                              XmNtopAttachment, XmATTACH_FORM,
270                                              XmNrightPosition, 49,
271                                              XmNtopOffset, 2,
272                                              XmNleftOffset, 5,
273                                              XmNmarginHeight, 2,
274                                              NULL);
275
276     label = XmStringGenerate(CATGETS(Set_AgentLabel, 205, "Number of Sections"), 
277                              NULL, XmCHARSET_TEXT, NULL);
278
279     XtVaCreateManagedWidget("how_many_title",
280                                              xmLabelWidgetClass,
281                                              how_many_frame,
282                                              XmNchildType, XmFRAME_TITLE_CHILD,
283                                              XmNlabelString, label,
284                                              NULL);
285
286     XmStringFree(label);
287
288     how_many_form = XtVaCreateManagedWidget("how_many_frame",
289                                             xmFormWidgetClass,
290                                             how_many_frame,
291                                             NULL);
292
293     label = XmStringGenerate(CATGETS(Set_AgentLabel, 206, "Selected:"),
294                              NULL, XmCHARSET_TEXT, NULL);
295
296     selected_label = XtVaCreateManagedWidget("selected_label", 
297                                              xmLabelWidgetClass, 
298                                              how_many_form, 
299                                              XmNlabelString, label,
300                                              XmNtopAttachment, XmATTACH_FORM,
301                                              XmNleftAttachment, XmATTACH_FORM,
302                                              XmNleftOffset, 4,
303                                              XmNtopOffset, 2,
304                                              NULL);
305     XmStringFree(label);
306
307     f_selected_field = selected_field = XtVaCreateManagedWidget("selected_field",
308                                                xmLabelWidgetClass, 
309                                                how_many_form, 
310                                                XmNlabelString, label,
311                                                XmNalignment, XmALIGNMENT_END,
312                                                XmNrightAttachment, XmATTACH_FORM,
313                                                XmNrightOffset, 2,
314                                                XmNtopAttachment, XmATTACH_FORM,
315                                                XmNtopOffset, 2,
316                                                NULL);
317
318     label = XmStringGenerate(CATGETS(Set_AgentLabel, 207, "To Be Printed:"),
319                              NULL, XmCHARSET_TEXT, NULL);
320     
321     XtVaCreateManagedWidget("to_print_label",
322                                              xmLabelWidgetClass,
323                                              how_many_form, 
324                                              XmNlabelString, label,
325                                              XmNtopAttachment, XmATTACH_WIDGET,
326                                              XmNtopWidget, selected_label,
327                                              XmNleftAttachment, XmATTACH_FORM,
328                                              XmNbottomAttachment, XmATTACH_FORM,
329                                              XmNleftOffset, 4,
330                                              XmNbottomOffset, 5,
331                                              XmNtopOffset, 8, 
332                                              NULL);
333     XmStringFree(label);
334
335     f_to_print_field = to_print_field = XtVaCreateManagedWidget("to_print_field",
336                                                xmLabelWidgetClass,
337                                                how_many_form, 
338                                                XmNalignment, XmALIGNMENT_END,
339                                                XmNtopAttachment, XmATTACH_WIDGET,
340                                                XmNtopWidget, selected_field,
341                                                XmNtopOffset, 8,
342                                                XmNrightAttachment, XmATTACH_FORM,
343                                                XmNrightOffset, 2,
344                                                XmNbottomAttachment, XmATTACH_FORM,
345                                                XmNbottomOffset, 5,
346                                                NULL);
347
348     // What?
349
350     what_frame = XtVaCreateManagedWidget("what_frame",
351                                          xmFrameWidgetClass,
352                                          print_panel,
353                                          XmNleftAttachment, XmATTACH_POSITION,
354                                          XmNleftPosition, 51,
355                                          XmNrightAttachment, XmATTACH_FORM,
356                                          XmNtopAttachment, XmATTACH_FORM,
357                                          XmNtopOffset, 2,
358                                          XmNrightOffset, 5,
359                                          NULL);
360
361     label = XmStringGenerate(CATGETS(Set_AgentLabel, 209, "What to Print"),
362                              NULL, XmCHARSET_TEXT, NULL);
363
364     XtVaCreateManagedWidget("what_title",
365                                          xmLabelWidgetClass,
366                                          what_frame,
367                                          XmNlabelString, label,
368                                          XmNchildType, XmFRAME_TITLE_CHILD,
369                                          NULL);
370     XmStringFree(label);
371     
372     what_form = XtVaCreateManagedWidget("what_form",
373                                         xmFormWidgetClass,
374                                         what_frame,
375                                         NULL);
376
377     label = XmStringGenerate(CATGETS(Set_AgentLabel, 210, "Sections"),
378                              NULL, XmCHARSET_TEXT, NULL);
379
380     f_print_nodes = print_nodes = XtVaCreateManagedWidget("print_nodes",
381                                             xmToggleButtonWidgetClass,
382                                             what_form,
383                                             XmNlabelString, label,
384                                             XmNset, TRUE,
385                                             XmNalignment, XmALIGNMENT_BEGINNING,
386                                             XmNindicatorType, XmONE_OF_MANY,
387                                             XmNleftAttachment, XmATTACH_FORM,
388                                             XmNrightAttachment, XmATTACH_FORM,
389                                             XmNtopAttachment, XmATTACH_FORM,
390                                             XmNleftOffset, 4,
391                                             XmNrightOffset, 4,
392                                             NULL);
393
394     XmStringFree(label);
395     XtAddCallback(print_nodes, XmNvalueChangedCallback, ToggleWhatCB, p);
396
397     label = XmStringGenerate(CATGETS(Set_AgentLabel, 211, "Hierarchy"),
398                              NULL, XmCHARSET_TEXT, NULL);
399         
400     f_print_hierarchy = XtVaCreateManagedWidget("print_hierarchy",
401                                                 xmToggleButtonWidgetClass,
402                                                 what_form,
403                                                 XmNlabelString, label,
404                                                 XmNalignment, XmALIGNMENT_BEGINNING,
405                                                 XmNindicatorType, XmONE_OF_MANY,
406                                                 XmNtopAttachment, XmATTACH_WIDGET,
407                                                 XmNtopWidget, print_nodes,
408                                                 XmNbottomAttachment, XmATTACH_FORM,
409                                                 XmNbottomOffset, 3,
410                                                 XmNleftAttachment, XmATTACH_FORM,
411                                                 XmNrightAttachment, XmATTACH_FORM,
412                                                 XmNleftOffset, 4,
413                                                 XmNrightOffset, 4,
414                                                 NULL);
415
416     XtAddCallback(f_print_hierarchy, XmNvalueChangedCallback, ToggleWhatCB, p);
417
418     XmStringFree(label);
419
420     RCS_DEBUG("customizePrintSetupBox exiting.\n");   
421
422 }
423
424 /*
425  * ------------------------------------------------------------------------
426  * Name: PdmNotifyCB
427  *
428  * Description:
429  *
430  *     Called when the PDM is up, or down.
431  *
432  */
433 void 
434 PdmNotifyCB(Widget pr_shell, XtPointer client_data, XtPointer call_data)
435 {
436     RCS_DEBUG("PdmNotifyCB called.\n");   
437
438 #if 0 && defined(PRINTING_SUPPORTED)
439     char *msg;
440
441     XmPrintShellCallbackStruct* pr_cbs = 
442         (XmPrintShellCallbackStruct*) call_data;
443     
444     if ((pr_cbs->reason == XmCR_PDM_NONE) ||
445         (pr_cbs->reason == XmCR_PDM_START_ERROR) ||
446         (pr_cbs->reason == XmCR_PDM_START_VXAUTH) ||
447         (pr_cbs->reason == XmCR_PDM_START_PXAUTH))
448     {
449         msg = CATGETS(Set_PrintPanelAgent, 12, "Print Dialog Manager error - setup failed.");
450         message_mgr().error_dialog(msg);
451     }
452  
453     RCS_DEBUG("PdmNotifyCB exiting.\n");   
454 #endif  /* PRINTING_SUPPORTED */
455 }
456
457 /*
458  * ------------------------------------------------------------------------
459  * Name: CreatePrintShell
460  *
461  * Description:
462  *
463  *     Called when the user selects the "Print" or the "Setup..." button
464  *       in the setupbox.
465  *
466  */
467 void 
468 CreatePrintShell(Widget widget, AppPrintData* p)
469 {
470     RCS_DEBUG("CreatePrintShell called.\n");   
471
472 #if 0 && defined(PRINTING_SUPPORTED)
473     char buf[BUFSIZ];
474
475     /*
476      * create a print_shell if none available.  the print dialog callback
477      * always provides valid printer context and print display initialized: 
478      * XpInitContext called, attributes set.
479      */
480     if (!p->f_print_shell) {
481         
482         p->f_print_shell = XmPrintSetup(widget, 
483                                         XpGetScreenOfContext(p->f_print_data->print_display,
484                                                              p->f_print_data->print_context),
485                                         (char*)"PrintShell", NULL, 0);
486
487
488         //  set the global variable to this value so that the create_ui function in 
489         //  NodePrintAgent will know what to parent it's form to
490         f_print_shell = p->f_print_shell;
491
492         //  set the print display in the window manager so the fontcache can connect
493         //  to the correct display
494         window_system().setPrintDisplay(f_print_shell);
495         
496         // XtAddCallback(p->f_print_shell, XmNpageSetupCallback, PageSetupCB, (XtPointer)p);
497         XtAddCallback(p->f_print_shell, XmNpdmNotificationCallback, PdmNotifyCB, (XtPointer)p);
498         
499         // set default print medium if specified on command line
500         
501         if (window_system().videoShell()->paper_size != NULL) {
502             snprintf(buf, sizeof(buf), "*default-medium: %s\n",
503                         window_system().videoShell()->paper_size);
504             XpSetAttributes(
505                 p->f_print_data->print_display, 
506                 p->f_print_data->print_context, 
507                 XPDocAttr, 
508                 buf, 
509                 XPAttrMerge);
510         }
511
512     }
513 #endif  /* PRINTING_SUPPORTED */
514     RCS_DEBUG("CreatePrintShell exiting.\n");   
515
516 }
517
518 /*
519  * ------------------------------------------------------------------------
520  * Name: PrintSetupCB
521  *
522  * Description:
523  *
524  *     Called when the user presses the setup box "Setup..." button.
525  *
526  */
527 void 
528 PrintSetupCB(Widget print_dialog, XtPointer client_data, XtPointer call_data)
529 {
530     RCS_DEBUG("PrintSetupCB called.\n");   
531
532 #if 0 && defined(PRINTING_SUPPORTED)
533     char *msg;
534
535     AppPrintData *p = (AppPrintData*)client_data;
536     DtPrintSetupCallbackStruct *pbs = (DtPrintSetupCallbackStruct*)call_data;
537
538     // copy the setup data into our space 
539
540     if (p->f_print_data->print_display != NULL)
541         DtPrintFreeSetupData(p->f_print_data);
542     DtPrintCopySetupData(p->f_print_data, pbs->print_data);
543
544     // create a print shell if not already done 
545
546     CreatePrintShell(print_dialog, p);
547
548     // pop up the PDM 
549     if (XmPrintPopupPDM(p->f_print_shell, print_dialog) 
550         != XmPDM_NOTIFY_SUCCESS) {
551         /* post a message error dialog */
552         msg = CATGETS(Set_PrintPanelAgent, 6, "Unable to display the Print Dialog Manager");
553         message_mgr().error_dialog(msg);
554         RCS_DEBUG("XmPrintPopupPDM failed\n");
555     }   
556
557     // Free the setup data - use fresh data when Print button pressed.
558     DtPrintFreeSetupData(p->f_print_data);
559
560 #endif  /* PRINTING_SUPPORTED */
561     RCS_DEBUG("PrintSetupCB exiting.\n");   
562 }
563
564 /*
565  * ------------------------------------------------------------------------
566  * Name: CancelCB
567  *
568  * Description:
569  *
570  *     Called when the user cancels out of the Print Setup dialog.
571  *     If gui-less printing, causes the program to exit.
572  *
573  */
574 static void 
575 CancelCB(Widget print_dialog, XtPointer client_data, XtPointer call_data)
576 {
577         
578     // if gui-less command line printing, exit now that job is canceled
579     
580     if (window_system().videoShell()->print_only) {
581         _exit(1);
582     }
583
584 }
585
586 /*
587  * ------------------------------------------------------------------------
588  * Name: CreatePrintSetup
589  *
590  * Description:
591  *
592  *     Creates a DtPrintSetupBox dialog.
593  *
594  */
595 void
596 CreatePrintSetup(Widget parent, AppPrintData* p)
597 {
598     RCS_DEBUG("CreatePrintSetup called.\n");   
599
600     //  Only create one PrintSetupBox 
601
602     if (p->f_print_dialog == NULL)
603     {
604         Cardinal n = 0;
605         Arg args[10];
606
607         // resources common to silent and noisy printing cases
608
609         XtSetArg(args[n], (char*)DtNcopies, window_system().videoShell()->copies); n++;
610         
611         // set print to file if file name given 
612         if ((char *)window_system().videoShell()->file_name != NULL) {
613             XtSetArg(args[n], (char*)DtNfileName, (char *)window_system().videoShell()->file_name); n++;
614             XtSetArg(args[n], (char*)DtNprintDestination, DtPRINT_TO_FILE); n++;
615         }
616
617         // printer name
618         if ((char *)window_system().videoShell()->printer != NULL) {
619             XtSetArg(args[n], (char*)DtNprinterName, (char *)window_system().videoShell()->printer); n++;
620         }
621
622         // if silent printing we won't need a dialog
623
624         if (window_system().videoShell()->silent) {
625
626             // if parent widget is an application shell, use it, otherwise use
627             // the grandparent
628
629             if (XtIsApplicationShell(parent)) {
630                 p->f_print_dialog =
631                     DtCreatePrintSetupBox(parent, (char*)"PrintSetup", args, n);
632             }
633             else {      
634                 p->f_print_dialog =
635                     DtCreatePrintSetupBox(XtParent(parent), (char*)"PrintSetup", args, n);
636             }
637         }    
638
639         //  not silent printing so we will need a dialog
640
641         else
642         {
643             // additional dialog resources
644
645             XmString title = XmStringCreateLocalized(
646                 CATGETS(Set_PrintPanelAgent, 1, "Dtinfo: Print"));
647
648             XtSetArg(args[n], XmNdialogTitle, title); n++;
649             XtSetArg(args[n], (char*)DtNworkAreaLocation, DtWORK_AREA_BOTTOM); n++;
650  
651             // if parent widget is an application shell, use it, otherwise use
652             // the grandparent
653
654             if (XtIsApplicationShell(parent)) {
655                 p->f_print_dialog =
656                     DtCreatePrintSetupDialog(parent, (char*)"PrintSetup", args, n);
657             }
658             else {
659                 p->f_print_dialog =
660                     DtCreatePrintSetupDialog(XtParent(parent), (char*)"PrintSetup", args, n);
661             }
662 //          XmStringFree(title);
663         }
664
665         // customize the print setup box
666
667         customizePrintSetupBox(p);
668         
669         // add  callbacks
670
671         XtAddCallback(p->f_print_dialog, DtNclosePrintDisplayCallback, PrintCloseDisplayCB, 
672                       (XtPointer)p);
673
674         XtAddCallback(p->f_print_dialog, DtNsetupCallback,
675                       PrintSetupCB, 
676                       (XtPointer)p);
677
678         XtAddCallback(p->f_print_dialog, DtNprintCallback, PrintCB, (XtPointer)p);
679         XtAddCallback(p->f_print_dialog, DtNcancelCallback, CancelCB, (XtPointer)p);
680
681         // add context help for dialog
682
683         help_agent().add_activate_help(p->f_print_dialog, (char*)"print_panel_help");
684     }
685
686     //  update message area
687     reset_ui(p);
688
689     RCS_DEBUG("CreatePrintSetup exiting.\n");   
690
691 }
692
693 /*
694  * ------------------------------------------------------------------------
695  * Name: PrintCB
696  *
697  * Description:
698  *
699  *     Called when the user presses the setup box "Print" button.
700  *
701  */
702 void 
703 PrintCB(Widget print_dialog, XtPointer client_data, XtPointer call_data)
704 {
705     RCS_DEBUG("PrintCB called.\n");   
706
707     AppPrintData *p = (AppPrintData*)client_data;
708     DtPrintSetupCallbackStruct *pbs = (DtPrintSetupCallbackStruct*)call_data;
709
710     /*
711      * get the new printer data from the DtPrintSetupBox, and copy it
712      * into our AppPrint data
713      */
714     if (p->f_print_data->print_display != NULL)
715          DtPrintFreeSetupData(p->f_print_data);
716     DtPrintCopySetupData(p->f_print_data, pbs->print_data);
717    
718     DoPrint(print_dialog, p);
719
720     RCS_DEBUG("PrintCB exiting.\n");   
721 }
722
723 /*
724  * ------------------------------------------------------------------------
725  * Name: QuickPrintCB
726  *
727  * Description:
728  *
729  *     Called when the user hits "Print" quick button.
730  *     not sure of this functions role in the "new order" ???? rCs
731  */
732 void 
733 QuickPrintCB(Widget pr_button, XtPointer client_data, XtPointer call_data)
734 {
735     RCS_DEBUG("QuickPrintCB called.\n");   
736
737     AppPrintData *p = (AppPrintData*)client_data;
738
739     CreatePrintSetup(pr_button, p);
740
741
742     // check if the DtPrintSetupBox ("Print...") has been called yet 
743
744     if(p->f_print_data->print_display == (Display*)NULL)
745     {
746         
747         // first time thru print setup, so get default data 
748         
749         if (DtPrintFillSetupData(p->f_print_dialog, p->f_print_data)
750             != DtPRINT_SUCCESS) {
751             // NOTE: DtPrintFillSetupData() already posts an error
752             // dialog on failure - no need to post our own.
753             RCS_DEBUG("DtPrintFillSetupData failed\n");
754             return ;
755         }
756     }
757  
758     DoPrint(pr_button, p) ;
759
760     RCS_DEBUG("QuickPrintCB exiting.\n");   
761
762 }
763
764 /*
765  * ------------------------------------------------------------------------
766  * Name: FinishPrintToFile
767  *
768  * Description:
769  *
770  *     App-specific print data holder allocate function.
771  *
772  */
773 #if 0 && defined(PRINTING_SUPPORTED)
774 void 
775 FinishPrintToFile(Display *display,
776                   XPGetDocStatus status,
777                   XPointer client_data)
778 {
779     char *msg;
780
781     RCS_DEBUG("FinishPrintToFile called.\n");   
782
783
784     if (status != XPGetDocFinished) {
785
786         msg = CATGETS(Set_PrintPanelAgent, 8, "Error printing to file");
787         message_mgr().error_dialog(msg);
788
789         RCS_DEBUG("Something went wrong with XmPrintToFile...\n");
790     }
791     else {
792
793         msg = CATGETS(Set_PrintPanelAgent, 9, "Print to file completed.");
794         message_mgr().info_dialog(msg);
795
796         RCS_DEBUG("XmPrintToFile completed OK\n");
797     }
798     RCS_DEBUG("FinishPrintToFile exiting.\n");   
799
800     return;
801
802 }
803 #endif /* PRINTING_SUPPORTED */
804
805 /*
806  * ------------------------------------------------------------------------
807  * Name: DoPrint
808  *
809  * Description:
810  *     
811  *     Routine used from the "Print" button and from the OK button of the
812  *     "Print..." dialog.  
813  *
814  */
815 void 
816 DoPrint(Widget widget, AppPrintData * p) 
817 {
818 #if 0 && defined(PRINTING_SUPPORTED)
819     int save_data = XPSpool;
820     char *msg;
821
822     xList<UAS_Pointer<UAS_Common> > &print_list = *(p->f_print_list);
823     Xassert (print_list.length() > 0);    
824
825 #endif  /* PRINTING_SUPPORTED */
826
827     RCS_DEBUG("DoPrint called.\n");   
828
829 #if 0 && defined(PRINTING_SUPPORTED)
830     // create print shell, if not done yet 
831     CreatePrintShell(widget, p);
832
833     if (p->f_print_data->destination == DtPRINT_TO_FILE)
834     {
835         save_data = XPGetData;
836     }
837
838     // start job must precede XpGetDocumentData in XmPrintToFile 
839
840     XpStartJob(XtDisplay(p->f_print_shell), save_data);  
841
842     // maintain the sequence
843     // between startjob and getdocument 
844
845     XFlush(XtDisplay(p->f_print_shell));  
846
847     // setup print to file 
848
849     if (p->f_print_data->destination == DtPRINT_TO_FILE)
850     {
851         if (!XmPrintToFile(XtDisplay(p->f_print_shell), 
852                            p->f_print_data->dest_info, 
853                            (XPFinishProc)FinishPrintToFile, 
854                            NULL))
855         {
856             // Add real error message here.
857             // printf("XmPrintToFile: Unable to print to file %s\n",
858             //        p->print_data->dest_info);
859             
860             XpCancelJob(XtDisplay(p->f_print_shell), False);
861             
862             // we can go back to the event loop as if we had never printed
863             return;
864         }
865     }
866     
867     if (!(window_system().videoShell()->silent)) {
868
869         XtRealizeWidget(p->f_print_shell);
870         XtPopup(p->f_print_shell, XtGrabNone);
871     }
872
873     PrintEverything(p);
874
875     XpEndJob(XtDisplay(p->f_print_shell));
876
877     // synch the print display (i am hoping this will get
878     // the xlib error handler called, if need be
879
880     XSync(XtDisplay(p->f_print_shell), False);
881
882     // if a print server error occurred then notify the user
883
884     if (print_server_error) {
885
886         print_server_error = False; // reset for next time
887
888         // Post an error dialog 
889
890         msg = CATGETS(Set_PrintPanelAgent, 
891                       11, 
892                       "Print Job Failed.\n\nThe X Print Server is Temporarily Out of Resources.");
893         message_mgr().error_dialog(msg);
894         
895     }
896
897     if (!(window_system().videoShell()->silent)) {
898         XtPopdown(p->f_print_shell);
899     }
900
901     // if we are in print only mode flush the output
902     // buffer to force the print and then exit
903
904     if (window_system().videoShell()->print_only) {
905
906         XSync(XtDisplay(p->f_print_shell), False);
907
908         // call this function to avoid invoking destructors
909         _exit(0);
910     }
911
912     //  have the print manager destroy the print agent
913     //  used to print this job
914
915     print_mgr().destroy_agent();
916
917     // destroy print shell as well
918     
919     if (p->f_print_shell)
920     {
921         XtDestroyWidget(p->f_print_shell);
922         p->f_print_shell = (Widget)NULL ;
923         f_print_shell = (Widget)NULL ;
924
925     }
926
927 #endif  /* PRINTING_SUPPORTED */
928     RCS_DEBUG("DoPrint exiting.\n");   
929
930 }
931
932 #if 0 && defined(PRINTING_SUPPORTED)
933 /*
934  * ------------------------------------------------------------------------
935  * Name: PrintEverything
936  *
937  * Description:
938  *
939  *     Called when the print shell receives the XP events. Contains the 
940  *     logic for printing all topics.
941  *
942  */
943 static void 
944 PrintEverything(AppPrintData *p)
945 {
946     int cur_page = 0;
947     
948     RCS_DEBUG("PrintEverything called.\n");
949
950     xList<UAS_Pointer<UAS_Common> > &print_list = *(p->f_print_list);
951     Xassert (print_list.length() > 0);
952
953     l_AppPrintData = p;
954     Widget pshell = p->f_print_shell;
955
956     List_Iterator<UAS_Pointer<UAS_Common> > l (print_list);
957
958     while (l)
959     {
960         PrintOneUASCommon(l.item(), pshell, &cur_page);
961         l++;
962     }
963
964     RCS_DEBUG("PrintEverything exiting.\n");
965 }
966 #endif  /* PRINTING_SUPPORTED */
967
968 static void
969 PrintOneUASCommon(UAS_Pointer<UAS_Common> &doc, Widget pshell, int *cur_pageP)
970 {
971     Arg args[15];
972     int n;
973     XmString label;
974     char buf[BUFSIZ];
975
976     // Retrieve the topic from the doc
977     // The retrieve function will send a UAS_DocumentRetrievedMsg to the
978     // print manager which will render the canvas with the appropriate topic
979
980     doc->retrieve((void *)1);
981
982     // set print orientation to either landscape or portrait (if set)
983
984 #if 0 && defined(PRINTING_SUPPORTED)
985     if (f_printOrientation != NULL) {
986         snprintf(buf, sizeof(buf),
987                         "*content-orientation: %s\n", f_printOrientation);
988         XpSetAttributes(XtDisplay(pshell), XpGetContext(XtDisplay(pshell)),
989                         XPPageAttr, buf, XPAttrMerge);
990     }
991 #endif /* PRINTING_SUPPORTED */
992     
993     for (gHelpDisplayArea->firstVisible = gHelpDisplayArea->nextNonVisible = 0;
994          gHelpDisplayArea->nextNonVisible >= 0;
995          gHelpDisplayArea->firstVisible = gHelpDisplayArea->nextNonVisible + 1)
996     {
997         (*cur_pageP)++;
998
999 #if 0 && defined(PRINTING_SUPPORTED)
1000         XpStartPage(XtDisplay(pshell), XtWindow(pshell));
1001 #endif /* PRINTING_SUPPORTED */
1002
1003         snprintf(buf, sizeof(buf), "%d", *cur_pageP);
1004         label = XmStringCreateLocalized(buf);
1005
1006         n = 0;
1007         XtSetArg(args[n], XmNlabelString, label); n++;
1008         XtSetValues(footer_page_no, args, n);
1009         XmStringFree(label);
1010
1011         // Process exposures so label is updated.
1012         XmUpdateDisplay(footer_page_no);
1013
1014         // _DtHelpCleanAndDrawWholeCanvas((XtPointer)gHelpDisplayArea);
1015
1016 #if 0 && defined(PRINTING_SUPPORTED)
1017         XpEndPage(XtDisplay(pshell));
1018 #endif /* PRINTING_SUPPORTED */
1019     }
1020
1021     // Print chidren if appropriate
1022     if (print_hierarchy)
1023     {
1024         unsigned int i;
1025         UAS_List<UAS_Common> kids = doc->children();
1026
1027         for (i = 0; i < kids.length(); i++)
1028         {
1029             PrintOneUASCommon(kids[i], pshell, cur_pageP);
1030         }
1031     }
1032 }
1033
1034 /*
1035  * ------------------------------------------------------------------------
1036  * Name: PrintCloseDisplayCB
1037  *
1038  * Description:
1039  *
1040  *     Called when the print setup box is about to close the print
1041  *     display (in response to a new printer on a different display, or
1042  *     when the setup box is destroyed).
1043  */
1044 void
1045 PrintCloseDisplayCB(
1046     Widget widget,
1047     XtPointer client_data,
1048     XtPointer call_data)
1049 {
1050     RCS_DEBUG("PrintCloseDisplayCB called.\n");   
1051
1052     AppPrintData *p = (AppPrintData*)client_data;
1053
1054     if (p->f_print_shell)
1055     {
1056         XtDestroyWidget(p->f_print_shell);
1057         p->f_print_shell = (Widget)NULL ;
1058         f_print_shell = (Widget)NULL ;
1059
1060     }
1061
1062     DtPrintFreeSetupData(p->f_print_data);
1063
1064     // reset gHelpDisplayArea so that it will be recreated.
1065     // ??? should i also destroy the canvas here?
1066     gHelpDisplayArea = 0;
1067     
1068     RCS_DEBUG("PrintCloseDisplayCB exiting.\n");   
1069
1070 }
1071
1072
1073 // /////////////////////////////////////////////////////////////////
1074 // ToggleWhatCB
1075 // /////////////////////////////////////////////////////////////////
1076
1077 void
1078 ToggleWhatCB(
1079     Widget widget,
1080     XtPointer client_data,
1081     XtPointer call_data)
1082 {
1083     RCS_DEBUG("ToggleWhatCB called.\n");   
1084
1085     AppPrintData * p = (AppPrintData *)client_data;
1086     
1087     xList<UAS_Pointer<UAS_Common> > &print_list = *(p->f_print_list);
1088     
1089     static char buffer[24];
1090     WXmToggleButton other (NULL), active(widget);
1091     
1092     ON_DEBUG (printf ("PrintPanel::ToggleWhatCB (%p)\n", widget));
1093     
1094     Xassert ( (widget == (Widget)f_print_nodes) || (widget == (Widget)f_print_hierarchy));
1095     
1096     // Figure out which one is the other one (ie: not clicked on). 
1097     if (active == f_print_nodes) 
1098     {
1099         other = f_print_hierarchy;
1100     }
1101     else 
1102     {
1103         other = f_print_nodes;
1104     }
1105     
1106     active.Set (True);
1107     other.Set (False);
1108     
1109     if (active == f_print_nodes)
1110     {
1111         snprintf (buffer, sizeof(buffer), "%d", print_list.length());
1112         print_hierarchy = False;
1113     }
1114     else // active == f_print_hierarchy 
1115     {
1116         List_Iterator<UAS_Pointer<UAS_Common> > l (print_list);
1117         int subtree_size = l.item()->subtree_size ();
1118
1119         if (subtree_size != 0)
1120         {
1121             snprintf (buffer, sizeof(buffer), "%d", subtree_size);
1122         }
1123         else
1124         {
1125             *((char *) memcpy(buffer, "?", 1) + 1) = '\0';
1126         }
1127         print_hierarchy = True;
1128     }
1129     
1130     if (*buffer == '0') 
1131     {
1132         *buffer = '?';
1133     }
1134     f_to_print_field.LabelString (WXmString (buffer));
1135
1136     RCS_DEBUG("ToggleWhatCBB exiting.\n");   
1137
1138 }