dtinfo subtree dtinfo
[oweals/cde.git] / cde / programs / dtinfo / dtinfo / src / Managers / PrintMgr.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 librararies 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  * $XConsortium: PrintMgr.C /main/15 1996/12/06 14:41:31 rcs $
25  *
26  * Copyright (c) 1993 HAL Computer Systems International, Ltd.
27  * All  $(MISC_LIB)rights reserved.  Unpublished -- rights reserved under
28  * the Copyright Laws of the United States.  USE OF A COPYRIGHT
29  * NOTICE IS PRECAUTIONARY ONLY AND DOES NOT IMPLY PUBLICATION
30  * OR DISCLOSURE.
31  * 
32  * THIS SOFTWARE CONTAINS CONFIDENTIAL INFORMATION AND TRADE
33  * SECRETS OF HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.  USE,
34  * DISCLOSURE, OR REPRODUCTION IS PROHIBITED WITHOUT THE
35  * PRIOR EXPRESS WRITTEN PERMISSION OF HAL COMPUTER SYSTEMS
36  * INTERNATIONAL, LTD.
37  * 
38  *                         RESTRICTED RIGHTS LEGEND
39  * Use, duplication, or disclosure by the Government is subject
40  * to the restrictions as set forth in subparagraph (c)(l)(ii)
41  * of the Rights in Technical Data and Computer Software clause
42  * at DFARS 252.227-7013.
43  *
44  *          HAL COMPUTER SYSTEMS INTERNATIONAL, LTD.
45  *                  1315 Dell Avenue
46  *                  Campbell, CA  95008
47  * 
48  */
49
50 #include <X11/Xlib.h>
51
52 #define C_xList
53 #define C_Support
54
55 #define C_TOC_Element
56 #define C_NodeViewInfo
57 #define L_Basic
58
59 #define C_PrintPanelAgent
60 #define C_NodePrintAgent
61 #define L_Agents
62
63 #define C_PrintMgr
64 #define C_PrefMgr
65 #define C_NodeMgr
66 #define C_NodeWindowMgr
67 #define C_StyleSheetMgr
68 #define C_LibraryMgr
69 #define C_GraphicsMgr
70 #define L_Managers
71
72 #include "Prelude.h"
73
74 #include "Managers/CatMgr.hh"
75 #include "Registration.hh"
76
77 #include "DocParser.h"
78 #include "Resolver.h" 
79 #include "StyleSheet.h"
80 #include "StyleSheetExceptions.h"
81 #include "../OnlineRender/CanvasRenderer.hh"
82
83 #if 0
84 #  define RCS_DEBUG(statement) cerr << statement << endl
85 #else
86 #  define RCS_DEBUG(statement) 
87 #endif
88
89 extern "C" { const char *unique_id(void); }
90
91 LONG_LIVED_CC(PrintMgr,print_mgr);
92
93 class PrintNode : public UAS_Receiver<UAS_DocumentRetrievedMsg>
94 {
95 public:
96     PrintNode()
97     { 
98         UAS_Common::request ((UAS_Receiver<UAS_DocumentRetrievedMsg> *) this); 
99     }
100 private:
101     void receive(UAS_DocumentRetrievedMsg &message, void *client_data);
102 };
103
104 void
105 PrintNode::receive (UAS_DocumentRetrievedMsg &message, void *client_data)
106 {
107     RCS_DEBUG("PrintNode::receive called.");
108
109     size_t cd = (size_t)client_data;
110
111     //  1 == print request
112     if (cd == 1) {
113         print_mgr().print(message.fDoc);
114     }
115     else {
116         RCS_DEBUG("PrintNode::receive exiting -- not a print request.");
117         return;
118     }
119     
120     RCS_DEBUG("PrintNode::receive exiting.");
121     return;
122 }
123
124 static PrintNode node_printer;
125
126 // /////////////////////////////////////////////////////////////////
127 // class constructor
128 // /////////////////////////////////////////////////////////////////
129
130 PrintMgr::PrintMgr()
131     : f_print_panel(NULL), f_npa(NULL), f_font_scale(0)
132 {
133     RCS_DEBUG("PrintMgr::PrintMgr called.");
134     set_font_scale(pref_mgr().get_int(PrefMgr::FontScale));
135     RCS_DEBUG("PrintMgr::PrintMgr exiting.");
136 }
137
138 // /////////////////////////////////////////////////////////////////
139 // print - Just do it.
140 // /////////////////////////////////////////////////////////////////
141
142
143 void
144 PrintMgr::print(UAS_Pointer<UAS_Common> &node_ptr)
145 {
146     Wait_Cursor bob;
147     f_last_printed = node_ptr;
148     
149     RCS_DEBUG("PrintMgr::print called.");
150
151     if (f_npa == NULL) {
152         f_npa = new NodePrintAgent();
153     }
154
155     f_npa->display(node_ptr);
156
157     RCS_DEBUG("PrintMgr::print exiting.");
158 }
159
160
161 /*
162  * ------------------------------------------------------------------------
163  * Name: PrintMgr::destroy_agent
164  *
165  * Description:
166  *
167  *     Deletes the print agent so that the next print doesn't hang.
168  *
169  */
170 void
171 PrintMgr::destroy_agent()
172 {
173     RCS_DEBUG("PrintMgr::destroy_agent called.");
174
175     delete f_npa;
176     f_npa = NULL;    
177
178     RCS_DEBUG("PrintMgr::destroy_agent exiting.");
179 }
180
181 void
182 PrintMgr::set_font_scale(int value)
183 {
184     int real_value = value * 2 ;
185     if (real_value < - MIN_DOWNSCALE) {
186         real_value = - MIN_DOWNSCALE ;
187     }
188     
189     int change_amount = real_value - f_font_scale ;
190     if (change_amount == 0) {
191         return ;
192     }
193     
194     // save the new font scale
195     f_font_scale = real_value ;
196     
197 }
198
199
200
201 NodeViewInfo *
202 PrintMgr::load(UAS_Pointer<UAS_Common> &node_ptr)
203 {
204   static int first = 0;
205
206   extern int styleparse();
207   extern void stylerestart(FILE *);
208   extern NodeViewInfo *gNodeViewInfo;
209
210   mtry
211     {
212       style_sheet_mgr().initPrintStyleSheet(node_ptr);
213     }
214   mcatch_noarg (StyleSheetSyntaxError)
215     {
216       message_mgr().error_dialog(
217           (char*)UAS_String(CATGETS(Set_Messages, 39, 
218     "There is an error in the Style Sheet for this Section.\nDefault features have been applied.")
219               ));
220     }
221   end_try ;
222
223   istringstream input((char *) node_ptr->data());
224
225   mtry
226     {
227       window_system().setPrinting(True);
228       // assign node_ptr to global variable that TmlRenderer can pick up 
229       gNodeViewInfo = new NodeViewInfo(node_ptr);
230       CanvasRenderer renderer (pref_mgr().get_int(PrefMgr::FontScale)) ;
231       Resolver resolver(*gPathTab, renderer);
232       DocParser docparser(resolver);
233       docparser.parse(input);
234       window_system().setPrinting(False);
235     }
236   mcatch_any()
237     {
238       ON_DEBUG(cerr << "PrintMgr::load...exception thrown" << endl);
239       delete gNodeViewInfo ;
240       gNodeViewInfo = 0;
241       rethrow;
242     }
243   end_try;
244
245   // TmlRenderer set this up for us 
246   return gNodeViewInfo ;
247 }
248