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