Debian Codegraph @

src/af/xap/xp/xap_Dlg_Print.cpp

raw
1 /* AbiSource Application Framework
2 * Copyright (C) 1998 AbiSource, Inc.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301 USA.
18 */
19
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <string.h>
23 #include "ut_go_file.h"
24 #include "ut_assert.h"
25 #include "ut_string.h"
26 #include "ut_debugmsg.h"
27 #include "xap_Dialog_Id.h"
28 #include "xap_Dlg_Print.h"
29 #include "xap_Frame.h"
30 #include "xap_DialogFactory.h"
31 #include "xap_Dlg_FileOpenSaveAs.h"
32
33
34 /******************************************************************/
35
36 XAP_Dialog_Print::XAP_Dialog_Print(XAP_DialogFactory * pDlgFactory, XAP_Dialog_Id id)
37 : XAP_Dialog_AppPersistent(pDlgFactory,id, "interface/dialogprint")
38 {
39 m_bPersistValid = false;
40 m_persistNrCopies = 1;
41 m_persistCollate = true;
42 m_persistColorSpace = GR_Graphics::GR_COLORSPACE_COLOR; /* full color is default */
43 m_persistPrintToFile = false;
44
45 m_szDocumentTitle = NULL;
46 m_szDocumentPathname = NULL;
47 m_szPrintToFilePathname = NULL;
48 m_szPrintCommand = NULL;
49 m_bBypassActualDialog = false;
50 m_bEnablePageRange = false;
51 m_bEnablePrintSelection = false;
52 m_bEnablePrintToFile = false;
53 m_nFirstPage = 0;
54 m_nLastPage = 0;
55
56 m_pageSize = 0;
57 m_answer = a_VOID;
58 }
59
60 XAP_Dialog_Print::~XAP_Dialog_Print(void)
61 {
62 UT_ASSERT_HARMLESS(!m_bInUse);
63 }
64
65 void XAP_Dialog_Print::useStart(void)
66 {
67 XAP_Dialog_AppPersistent::useStart();
68
69 FREEP(m_szDocumentTitle);
70 FREEP(m_szDocumentPathname);
71 FREEP(m_szPrintToFilePathname);
72
73 m_bBypassActualDialog = false;
74 m_bEnablePageRange = false;
75 m_bEnablePrintSelection = false;
76 m_bEnablePrintToFile = false;
77 m_nFirstPage = 0;
78 m_nLastPage = 0;
79
80 m_nCopies = ((m_bPersistValid) ? m_persistNrCopies : 1);
81 m_bCollate = ((m_bPersistValid) ? m_persistCollate : true);
82 m_cColorSpace = ((m_bPersistValid) ? m_persistColorSpace : GR_Graphics::GR_COLORSPACE_COLOR);
83 m_bDoPrintToFile = ((m_bPersistValid) ? m_persistPrintToFile : false);
84
85 m_answer = a_VOID;
86 }
87
88 void XAP_Dialog_Print::useEnd(void)
89 {
90 XAP_Dialog_AppPersistent::useEnd();
91
92 FREEP(m_szDocumentTitle);
93 FREEP(m_szDocumentPathname);
94 FREEP(m_szPrintToFilePathname);
95 FREEP(m_pageSize);
96
97 if (m_answer == a_OK)
98 {
99 m_bPersistValid = true;
100 m_persistNrCopies = m_nCopies;
101 m_persistCollate = m_bCollate;
102 m_persistColorSpace = m_cColorSpace;
103 m_persistPrintToFile = m_bDoPrintToFile;
104 }
105
106 // the platform sub-classes should store all persistent fields
107 // if (m_answer == a_OK) in their implementations.
108 }
109
110 XAP_Dialog_Print::tAnswer XAP_Dialog_Print::getAnswer(void) const
111 {
112 // let our caller know if user hit ok or cancel.
113
114 return m_answer;
115 }
116
117 void XAP_Dialog_Print::setPaperSize(const char * szPageSize)
118 {
119 FREEP(m_pageSize);
120 if (szPageSize && *szPageSize)
121 m_pageSize = g_strdup(szPageSize);
122 }
123
124 void XAP_Dialog_Print::setDocumentTitle(const char * szDocTitle)
125 {
126 FREEP(m_szDocumentTitle);
127 if (szDocTitle && *szDocTitle)
128 m_szDocumentTitle = g_strdup(szDocTitle);
129 }
130
131 void XAP_Dialog_Print::setDocumentPathname(const char * szDocPath)
132 {
133 FREEP(m_szDocumentPathname);
134 if (szDocPath && *szDocPath) {
135 if (UT_go_path_is_uri(szDocPath)) {
136 char *filename = UT_go_filename_from_uri(szDocPath);
137 m_szDocumentPathname = filename;
138 } else
139 m_szDocumentPathname = g_strdup(szDocPath);
140 }
141 }
142
143 void XAP_Dialog_Print::setEnablePageRangeButton(bool bEnable,
144 UT_uint32 nFirst,
145 UT_uint32 nLast)
146 {
147 m_bEnablePageRange = bEnable;
148 m_nFirstPage = ((bEnable) ? nFirst : 0);
149 m_nLastPage = ((bEnable) ? nLast : 0);
150 }
151
152 void XAP_Dialog_Print::setEnablePrintSelection(bool bEnable)
153 {
154 m_bEnablePrintSelection = bEnable;
155 }
156
157 void XAP_Dialog_Print::setEnablePrintToFile(bool bEnable)
158 {
159 m_bEnablePrintToFile = bEnable;
160 }
161
162 void XAP_Dialog_Print::setTryToBypassActualDialog(bool bEnable)
163 {
164 // allow the caller to bypass the actual dialog (useful for the
165 // print button on the toolbar (which should try to reuse as much
166 // state from the previous use as possible)). we only let this
167 // happen if they ask for it and we have valid persistence data.
168
169 m_bBypassActualDialog = (bEnable && m_bPersistValid);
170 }
171
172 bool XAP_Dialog_Print::getDoPrintRange(UT_sint32 * pnFirst, UT_sint32 * pnLast) const
173 {
174 UT_ASSERT(m_answer == a_OK);
175
176 // we set the page ranges whether they checked the print-to-file button or not.
177
178 if (pnFirst)
179 *pnFirst = m_nFirstPage;
180 if (pnLast)
181 *pnLast = m_nLastPage;
182
183 return m_bDoPrintRange;
184 }
185
186 bool XAP_Dialog_Print::getDoPrintSelection(void) const
187 {
188 UT_ASSERT(m_answer == a_OK);
189
190 return m_bDoPrintSelection;
191 }
192
193 bool XAP_Dialog_Print::getDoPrintToFile(const char *) const
194 {
195 UT_ASSERT(m_answer == a_OK);
196
197 return m_bDoPrintToFile;
198 }
199
200 UT_uint32 XAP_Dialog_Print::getNrCopies(void) const
201 {
202 UT_ASSERT(m_answer == a_OK);
203
204 return m_nCopies;
205 }
206
207 bool XAP_Dialog_Print::getCollate(void) const
208 {
209 UT_ASSERT(m_answer == a_OK);
210
211 return m_persistCollate;
212 }
213
214 GR_Graphics::ColorSpace XAP_Dialog_Print::getColorSpace(void) const
215 {
216 UT_ASSERT(m_answer == a_OK);
217
218 return m_persistColorSpace;
219 }
220
221 bool XAP_Dialog_Print::_getPrintToFilePathname(XAP_Frame * pFrame,
222 const char * szSuggestedName)
223 {
224 UT_return_val_if_fail(pFrame,false);
225 UT_ASSERT(szSuggestedName && *szSuggestedName);
226
227 XAP_Dialog_Id id = XAP_DIALOG_ID_PRINTTOFILE;
228
229 XAP_DialogFactory * pDialogFactory
230 = (XAP_DialogFactory *)(pFrame->getDialogFactory());
231
232 XAP_Dialog_FileOpenSaveAs * pDialog
233 = (XAP_Dialog_FileOpenSaveAs *)(pDialogFactory->requestDialog(id));
234 UT_return_val_if_fail(pDialog,false);
235
236 pDialog->setCurrentPathname(szSuggestedName);
237 pDialog->setSuggestFilename(true);
238
239 const char ** szDescList = NULL;
240 const char ** szSuffixList = NULL;
241 UT_sint32 * nTypeList = NULL;
242 {
243 // TODO : FIX THIS! Make this pull dynamic types from the export
244 // TODO : filter list (creat that while you're at it).
245
246 // TODO : Right now we can just feed the dialog some static filters
247 // TODO : that will be ignored by Windows but will be required
248 // TODO : by Unix.
249
250 UT_uint32 filterCount = 1;
251
252 szDescList = (const char **) UT_calloc(filterCount + 1,
253 sizeof(char *));
254 szSuffixList = (const char **) UT_calloc(filterCount + 1,
255 sizeof(char *));
256 // HACK : this should be IEFileType
257 nTypeList = (UT_sint32 *) UT_calloc(filterCount + 1,
258 sizeof(UT_sint32));
259
260 szDescList[0] = "PostScript 2.0";
261 szSuffixList[0] = "ps";
262 nTypeList[0] = 0;
263
264 pDialog->setFileTypeList(szDescList, szSuffixList, (const UT_sint32 *) nTypeList);
265 }
266
267 pDialog->runModal(pFrame);
268
269 XAP_Dialog_FileOpenSaveAs::tAnswer ans = pDialog->getAnswer();
270 bool bOK = (ans == XAP_Dialog_FileOpenSaveAs::a_OK);
271
272 if (bOK)
273 m_szPrintToFilePathname = g_strdup(pDialog->getPathname());
274
275 FREEP(szDescList);
276 FREEP(szSuffixList);
277 FREEP(nTypeList);
278
279 pDialogFactory->releaseDialog(pDialog);
280
281 return bOK;
282 }