xref: /aoo41x/main/padmin/source/prtsetup.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "prtsetup.hxx"
29 #include "helper.hxx" // for PaResId
30 #include "rtsetup.hrc"
31 #include "cmddlg.hxx"
32 
33 #include "vcl/fontmanager.hxx"
34 
35 #include "osl/thread.h"
36 
37 #define LSCAPE_STRING String( RTL_CONSTASCII_USTRINGPARAM( "Landscape" ) )
38 #define PORTRAIT_STRING String( RTL_CONSTASCII_USTRINGPARAM( "Portrait" ) )
39 
40 using namespace rtl;
41 using namespace psp;
42 using namespace padmin;
43 
44 void RTSDialog::insertAllPPDValues( ListBox& rBox, const PPDParser* pParser, const PPDKey* pKey )
45 {
46 	if( ! pKey || ! pParser )
47 		return;
48 
49 	const PPDValue* pValue = NULL;
50 	sal_uInt16 nPos = 0;
51 	String aOptionText;
52 
53 	for( int i = 0; i < pKey->countValues(); i++ )
54 	{
55 		pValue = pKey->getValue( i );
56 		aOptionText = pParser->translateOption( pKey->getKey(), pValue->m_aOption) ;
57 
58 		if( m_aJobData.m_aContext.checkConstraints( pKey, pValue ) )
59 		{
60 			if( rBox.GetEntryPos( (void*)pValue ) == LISTBOX_ENTRY_NOTFOUND )
61 			{
62 				nPos = rBox.InsertEntry( aOptionText, LISTBOX_APPEND );
63 					rBox.SetEntryData( nPos, (void*)pValue );
64 			}
65 		}
66 		else
67 		{
68 			if( ( nPos = rBox.GetEntryPos( (void*)pValue ) ) != LISTBOX_ENTRY_NOTFOUND )
69 				rBox.RemoveEntry( nPos );
70 		}
71 	}
72 	pValue = m_aJobData.m_aContext.getValue( pKey );
73 	if( pValue )
74 	{
75 		if( ( nPos = rBox.GetEntryPos( (void*)pValue ) ) != LISTBOX_ENTRY_NOTFOUND )
76 			rBox.SelectEntryPos( nPos );
77 	}
78 	else
79 		rBox.SelectEntry( m_aInvalidString );
80 }
81 
82 // --------------------------------------------------------------------------
83 
84 /*
85  * RTSDialog
86  */
87 
88 RTSDialog::RTSDialog( const PrinterInfo& rJobData, const String& rPrinter, bool bAllPages, Window* pParent ) :
89 		TabDialog(  pParent, PaResId( RID_RTS_RTSDIALOG ) ),
90         m_aJobData( rJobData ),
91 		m_aPrinter( rPrinter ),
92         m_aTabControl( this, PaResId( RID_RTS_RTSDIALOG_TABCONTROL ) ),
93 		m_aOKButton( this ),
94 		m_aCancelButton( this ),
95         m_pPaperPage( NULL ),
96 		m_pDevicePage( NULL ),
97 		m_pOtherPage( NULL ),
98 		m_pFontSubstPage( NULL ),
99 		m_pCommandPage( NULL ),
100         m_aInvalidString( PaResId( RID_RTS_RTSDIALOG_INVALID_TXT ) ),
101 		m_aFromDriverString( PaResId( RID_RTS_RTSDIALOG_FROMDRIVER_TXT ) )
102 {
103 	FreeResource();
104 
105 	String aTitle( GetText() );
106 	aTitle.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "%s" ) ), m_aJobData.m_aPrinterName );
107 	SetText( aTitle );
108 
109 	if( ! bAllPages )
110 	{
111 		m_aTabControl.RemovePage( RID_RTS_OTHERPAGE );
112 		m_aTabControl.RemovePage( RID_RTS_FONTSUBSTPAGE );
113 		m_aTabControl.RemovePage( RID_RTS_COMMANDPAGE );
114 	}
115     else if( m_aJobData.m_aDriverName.compareToAscii( "CUPS:", 5 ) == 0 && ! PrinterInfoManager::get().isCUPSDisabled() )
116     {
117         // command page makes no sense for CUPS printers
118 		m_aTabControl.RemovePage( RID_RTS_COMMANDPAGE );
119     }
120 
121 	m_aTabControl.SetActivatePageHdl( LINK( this, RTSDialog, ActivatePage ) );
122 	m_aOKButton.SetClickHdl( LINK( this, RTSDialog, ClickButton ) );
123 	m_aCancelButton.SetClickHdl( LINK( this, RTSDialog, ClickButton ) );
124 	ActivatePage( &m_aTabControl );
125 
126 	m_aOKButton.Show();
127 	m_aCancelButton.Show();
128 }
129 
130 // --------------------------------------------------------------------------
131 
132 RTSDialog::~RTSDialog()
133 {
134 	if( m_pPaperPage )
135 		delete m_pPaperPage;
136 	if( m_pDevicePage )
137 		delete m_pDevicePage;
138 	if( m_pOtherPage )
139 		delete m_pOtherPage;
140 	if( m_pFontSubstPage )
141 		delete m_pFontSubstPage;
142 	if( m_pCommandPage )
143 		delete m_pCommandPage;
144 }
145 
146 // --------------------------------------------------------------------------
147 
148 IMPL_LINK( RTSDialog, ActivatePage, TabControl*, pTabCtrl )
149 {
150 	if( pTabCtrl != &m_aTabControl )
151 		return 0;
152 
153 	sal_uInt16 nId = m_aTabControl.GetCurPageId();
154 
155 	if ( ! m_aTabControl.GetTabPage( nId ) )
156 	{
157 		TabPage *pPage = NULL;
158 		if( nId == RID_RTS_PAPERPAGE )
159 			pPage = m_pPaperPage = new RTSPaperPage( this );
160 		else if( nId == RID_RTS_DEVICEPAGE )
161 			pPage = m_pDevicePage = new RTSDevicePage( this );
162 		else if( nId == RID_RTS_OTHERPAGE )
163 			pPage = m_pOtherPage = new RTSOtherPage( this );
164 		else if( nId == RID_RTS_FONTSUBSTPAGE )
165 			pPage = m_pFontSubstPage = new RTSFontSubstPage( this );
166 		else if( nId == RID_RTS_COMMANDPAGE )
167 			pPage = m_pCommandPage = new RTSCommandPage( this );
168 		if( pPage )
169 			m_aTabControl.SetTabPage( nId, pPage );
170 	}
171 	else
172 	{
173 		switch( nId )
174 		{
175 			case RID_RTS_PAPERPAGE:		m_pPaperPage->update();break;
176 			case RID_RTS_DEVICEPAGE:	m_pDevicePage->update();break;
177 			default: break;
178 		}
179 	}
180 
181 	return 0;
182 }
183 
184 // --------------------------------------------------------------------------
185 
186 IMPL_LINK( RTSDialog, ClickButton, Button*, pButton )
187 {
188 	if( pButton == &m_aOKButton )
189 	{
190 		// refresh the changed values
191 		if( m_pPaperPage )
192 		{
193 			// orientation
194 			m_aJobData.m_eOrientation = m_pPaperPage->getOrientation().Equals( LSCAPE_STRING ) ? orientation::Landscape : orientation::Portrait;
195 		}
196 		if( m_pDevicePage )
197 		{
198 			m_aJobData.m_nColorDepth	= m_pDevicePage->getDepth();
199 			m_aJobData.m_nColorDevice	= m_pDevicePage->getColorDevice();
200 			m_aJobData.m_nPSLevel		= m_pDevicePage->getLevel();
201 			m_aJobData.m_nPDFDevice     = m_pDevicePage->getPDFDevice();
202 		}
203 		if( m_pOtherPage )
204 			// write other settings
205 			m_pOtherPage->save();
206 		if( m_pCommandPage )
207 			// write command settings
208 			m_pCommandPage->save();
209 
210 		EndDialog( 1 );
211 	}
212 	else if( pButton == &m_aCancelButton )
213 		EndDialog( 0 );
214 
215 	return 0;
216 }
217 
218 // --------------------------------------------------------------------------
219 
220 /*
221  * RTSPaperPage
222  */
223 
224 RTSPaperPage::RTSPaperPage( RTSDialog* pParent ) :
225 		TabPage( & pParent->m_aTabControl, PaResId( RID_RTS_PAPERPAGE ) ),
226 
227 		m_pParent( pParent ),
228 
229 		m_aPaperText( this, PaResId( RID_RTS_PAPER_PAPER_TXT ) ),
230 		m_aPaperBox( this, PaResId( RID_RTS_PAPER_PAPER_BOX ) ),
231 		m_aOrientText( this, PaResId( RID_RTS_PAPER_ORIENTATION_TXT ) ),
232 		m_aOrientBox( this, PaResId( RID_RTS_PAPER_ORIENTATION_BOX ) ),
233 		m_aDuplexText( this, PaResId( RID_RTS_PAPER_DUPLEX_TXT ) ),
234 		m_aDuplexBox( this, PaResId( RID_RTS_PAPER_DUPLEX_BOX ) ),
235 		m_aSlotText( this, PaResId( RID_RTS_PAPER_SLOT_TXT ) ),
236 		m_aSlotBox( this, PaResId( RID_RTS_PAPER_SLOT_BOX ) )
237 {
238 	m_aPaperBox.SetSelectHdl( LINK( this, RTSPaperPage, SelectHdl ) );
239 	m_aOrientBox.SetSelectHdl( LINK( this, RTSPaperPage, SelectHdl ) );
240 	m_aDuplexBox.SetSelectHdl( LINK( this, RTSPaperPage, SelectHdl ) );
241 	m_aSlotBox.SetSelectHdl( LINK( this, RTSPaperPage, SelectHdl ) );
242 
243 	FreeResource();
244 
245 	sal_uInt16 nPos = 0;
246 
247 	m_aOrientBox.InsertEntry( PORTRAIT_STRING );
248 	m_aOrientBox.InsertEntry( LSCAPE_STRING );
249 	// duplex
250 	nPos = m_aDuplexBox.InsertEntry( m_pParent->m_aInvalidString );
251 	m_aDuplexBox.SetEntryData( nPos, NULL );
252 
253 	// paper does not have an invalid entry
254 
255 	// input slots
256 	nPos = m_aSlotBox.InsertEntry( m_pParent->m_aInvalidString );
257 	m_aSlotBox.SetEntryData( nPos, NULL );
258 
259 	update();
260 }
261 
262 // --------------------------------------------------------------------------
263 
264 RTSPaperPage::~RTSPaperPage()
265 {
266 }
267 
268 // --------------------------------------------------------------------------
269 
270 void RTSPaperPage::update()
271 {
272 	const PPDKey* pKey		= NULL;
273 
274 	// orientation
275 	m_aOrientBox.SelectEntry(
276 		m_pParent->m_aJobData.m_eOrientation == orientation::Landscape
277 		? LSCAPE_STRING : PORTRAIT_STRING );
278 
279 	// duplex
280 	if( m_pParent->m_aJobData.m_pParser &&
281         (pKey = m_pParent->m_aJobData.m_pParser->getKey( String( RTL_CONSTASCII_USTRINGPARAM( "Duplex" ) ) )) )
282     {
283 		m_pParent->insertAllPPDValues( m_aDuplexBox, m_pParent->m_aJobData.m_pParser, pKey );
284     }
285 	else
286     {
287         m_aDuplexText.Enable( sal_False );
288 		m_aDuplexBox.Enable( sal_False );
289     }
290 
291 	// paper
292 	if( m_pParent->m_aJobData.m_pParser &&
293         (pKey = m_pParent->m_aJobData.m_pParser->getKey( String( RTL_CONSTASCII_USTRINGPARAM( "PageSize" ) ) )) )
294     {
295 		m_pParent->insertAllPPDValues( m_aPaperBox, m_pParent->m_aJobData.m_pParser, pKey );
296     }
297 	else
298     {
299         m_aPaperText.Enable( sal_False );
300 		m_aPaperBox.Enable( sal_False );
301     }
302 
303 	// input slots
304 	if( m_pParent->m_aJobData.m_pParser &&
305         (pKey = m_pParent->m_aJobData.m_pParser->getKey( String::CreateFromAscii( "InputSlot" ) )) )
306     {
307 		m_pParent->insertAllPPDValues( m_aSlotBox, m_pParent->m_aJobData.m_pParser, pKey );
308     }
309 	else
310     {
311         m_aSlotText.Enable( sal_False );
312 		m_aSlotBox.Enable( sal_False );
313     }
314 }
315 
316 // --------------------------------------------------------------------------
317 
318 IMPL_LINK( RTSPaperPage, SelectHdl, ListBox*, pBox )
319 {
320 	const PPDKey* pKey = NULL;
321 	if( pBox == &m_aPaperBox )
322     {
323         if( m_pParent->m_aJobData.m_pParser )
324             pKey = m_pParent->m_aJobData.m_pParser->getKey( String( RTL_CONSTASCII_USTRINGPARAM( "PageSize" ) ) );
325     }
326 	else if( pBox == &m_aDuplexBox )
327     {
328         if( m_pParent->m_aJobData.m_pParser )
329             pKey = m_pParent->m_aJobData.m_pParser->getKey( String( RTL_CONSTASCII_USTRINGPARAM( "Duplex" ) ) );
330     }
331 	else if( pBox == &m_aSlotBox )
332     {
333         if( m_pParent->m_aJobData.m_pParser )
334             pKey = m_pParent->m_aJobData.m_pParser->getKey( String( RTL_CONSTASCII_USTRINGPARAM( "InputSlot" ) ) );
335     }
336 	else if( pBox == &m_aOrientBox )
337 	{
338 		m_pParent->m_aJobData.m_eOrientation = m_aOrientBox.GetSelectEntry().Equals( LSCAPE_STRING ) ? orientation::Landscape : orientation::Portrait;
339 	}
340 	if( pKey )
341 	{
342 		PPDValue* pValue =
343 			(PPDValue*)pBox->GetEntryData( pBox->GetSelectEntryPos() );
344 		m_pParent->m_aJobData.m_aContext.setValue( pKey, pValue );
345 		update();
346 	}
347 	return 0;
348 }
349 
350 // --------------------------------------------------------------------------
351 
352 /*
353  * RTSDevicePage
354  */
355 
356 RTSDevicePage::RTSDevicePage( RTSDialog* pParent ) :
357 		TabPage( & pParent->m_aTabControl, PaResId( RID_RTS_DEVICEPAGE ) ),
358 
359 		m_pParent( pParent ),
360 
361 		m_aSpaceColor( PaResId( RID_RTS_DEVICE_COLOR_TXT ) ),
362 		m_aSpaceGray( PaResId( RID_RTS_DEVICE_GRAY_TXT ) ),
363 		m_aPPDKeyText( this, PaResId( RID_RTS_DEVICE_PPDKEY_TXT ) ),
364 		m_aPPDKeyBox( this, PaResId( RID_RTS_DEVICE_PPDKEY_BOX ) ),
365 		m_aPPDValueText( this, PaResId( RID_RTS_DEVICE_PPDVALUE_TXT ) ),
366 		m_aPPDValueBox( this, PaResId( RID_RTS_DEVICE_PPDVALUE_BOX ) ),
367 		m_aLevelText( this, PaResId( RID_RTS_DEVICE_PRINTLANG_TXT ) ),
368 		m_aLevelBox( this, PaResId( RID_RTS_DEVICE_PRINTLANG_BOX ) ),
369 		m_aSpaceText( this, PaResId( RID_RTS_DEVICE_SPACE_TXT ) ),
370 		m_aSpaceBox( this, PaResId( RID_RTS_DEVICE_SPACE_BOX ) ),
371 		m_aDepthText( this, PaResId( RID_RTS_DEVICE_DEPTH_TXT ) ),
372 		m_aDepthBox( this, PaResId( RID_RTS_DEVICE_DEPTH_BOX ) )
373 {
374 	FreeResource();
375 
376 	m_aPPDKeyBox.SetSelectHdl( LINK( this, RTSDevicePage, SelectHdl ) );
377 	m_aPPDValueBox.SetSelectHdl( LINK( this, RTSDevicePage, SelectHdl ) );
378 
379 	m_aSpaceBox.InsertEntry( m_pParent->m_aFromDriverString );
380 	m_aSpaceBox.InsertEntry( m_aSpaceColor );
381 	m_aSpaceBox.InsertEntry( m_aSpaceGray );
382 	switch( m_pParent->m_aJobData.m_nColorDevice )
383 	{
384 		case -1: m_aSpaceBox.SelectEntry( m_aSpaceGray );break;
385 		case  0: m_aSpaceBox.SelectEntry( m_pParent->m_aFromDriverString );break;
386 		case  1: m_aSpaceBox.SelectEntry( m_aSpaceColor );break;
387 	}
388 
389 	sal_uLong nLevelEntryData = 0;
390 	if( m_pParent->m_aJobData.m_nPDFDevice > 0 )
391 	    nLevelEntryData = 10;
392 	else
393 	    nLevelEntryData = m_pParent->m_aJobData.m_nPSLevel+1;
394 	for( sal_uInt16 i = 0; i < m_aLevelBox.GetEntryCount(); i++ )
395 	{
396 	    if( (sal_uLong)m_aLevelBox.GetEntryData( i ) == nLevelEntryData )
397 	    {
398 	        m_aLevelBox.SelectEntryPos( i );
399 	        break;
400 	    }
401 	}
402 
403 	m_aDepthBox.SelectEntry( String::CreateFromInt32( m_pParent->m_aJobData.m_nColorDepth ).AppendAscii( " Bit" ) );
404 
405 	// fill ppd boxes
406     if( m_pParent->m_aJobData.m_pParser )
407     {
408         for( int i = 0; i < m_pParent->m_aJobData.m_pParser->getKeys(); i++ )
409         {
410             const PPDKey* pKey = m_pParent->m_aJobData.m_pParser->getKey( i );
411             if( pKey->isUIKey()									&&
412                 ! pKey->getKey().EqualsAscii( "PageSize" )		&&
413                 ! pKey->getKey().EqualsAscii( "InputSlot" )		&&
414                 ! pKey->getKey().EqualsAscii( "PageRegion" )	&&
415                 ! pKey->getKey().EqualsAscii( "Duplex" )
416                 )
417             {
418                 String aEntry( m_pParent->m_aJobData.m_pParser->translateKey( pKey->getKey() ) );
419                 sal_uInt16 nPos = m_aPPDKeyBox.InsertEntry( aEntry );
420                 m_aPPDKeyBox.SetEntryData( nPos, (void*)pKey );
421             }
422         }
423     }
424 }
425 
426 // --------------------------------------------------------------------------
427 
428 RTSDevicePage::~RTSDevicePage()
429 {
430 }
431 
432 // --------------------------------------------------------------------------
433 
434 void RTSDevicePage::update()
435 {
436 }
437 
438 // ------------------------------------------------------------------
439 
440 sal_uLong RTSDevicePage::getLevel()
441 {
442     sal_uLong nLevel = (sal_uLong)m_aLevelBox.GetEntryData( m_aLevelBox.GetSelectEntryPos() );
443     return nLevel < 10 ? nLevel-1 : 0;
444 }
445 
446 // ------------------------------------------------------------------
447 
448 sal_uLong RTSDevicePage::getPDFDevice()
449 {
450     sal_uLong nLevel = (sal_uLong)m_aLevelBox.GetEntryData( m_aLevelBox.GetSelectEntryPos() );
451     return nLevel > 9 ? 1 : 0;
452 }
453 
454 // ------------------------------------------------------------------
455 
456 IMPL_LINK( RTSDevicePage, SelectHdl, ListBox*, pBox )
457 {
458 	if( pBox == &m_aPPDKeyBox )
459 	{
460 		const PPDKey* pKey = (PPDKey*)m_aPPDKeyBox.GetEntryData( m_aPPDKeyBox.GetSelectEntryPos() );
461 		FillValueBox( pKey );
462 	}
463 	else if( pBox == &m_aPPDValueBox )
464 	{
465 		const PPDKey* pKey = (PPDKey*)m_aPPDKeyBox.GetEntryData( m_aPPDKeyBox.GetSelectEntryPos() );
466 		const PPDValue* pValue = (PPDValue*)m_aPPDValueBox.GetEntryData( m_aPPDValueBox.GetSelectEntryPos() );
467 		if( pKey && pValue )
468 		{
469 			m_pParent->m_aJobData.m_aContext.setValue( pKey, pValue );
470 			FillValueBox( pKey );
471 		}
472 	}
473 	return 0;
474 }
475 
476 // ------------------------------------------------------------------
477 
478 void RTSDevicePage::FillValueBox( const PPDKey* pKey )
479 {
480 	m_aPPDValueBox.Clear();
481 
482 	if( ! pKey )
483 		return;
484 
485 	const PPDValue* pValue = NULL;
486 	for( int i = 0; i < pKey->countValues(); i++ )
487 	{
488 		pValue = pKey->getValue( i );
489 		if( m_pParent->m_aJobData.m_aContext.checkConstraints( pKey, pValue ) &&
490             m_pParent->m_aJobData.m_pParser )
491 		{
492             String aEntry( m_pParent->m_aJobData.m_pParser->translateOption( pKey->getKey(), pValue->m_aOption ) );
493 			sal_uInt16 nPos = m_aPPDValueBox.InsertEntry( aEntry );
494 			m_aPPDValueBox.SetEntryData( nPos, (void*)pValue );
495 		}
496 	}
497 	pValue = m_pParent->m_aJobData.m_aContext.getValue( pKey );
498 	m_aPPDValueBox.SelectEntryPos( m_aPPDValueBox.GetEntryPos( (void*)pValue ) );
499 }
500 
501 // --------------------------------------------------------------------------
502 
503 /*
504  * RTSOtherPage
505  */
506 
507 RTSOtherPage::RTSOtherPage( RTSDialog* pParent ) :
508 		TabPage( &pParent->m_aTabControl, PaResId( RID_RTS_OTHERPAGE ) ),
509 		m_pParent( pParent ),
510 		m_aLeftTxt( this, PaResId( RID_RTS_OTHER_LEFTMARGIN_TXT ) ),
511 		m_aLeftLB( this, PaResId( RID_RTS_OTHER_LEFTMARGIN_BOX ) ),
512 		m_aTopTxt( this, PaResId( RID_RTS_OTHER_TOPMARGIN_TXT ) ),
513 		m_aTopLB( this, PaResId( RID_RTS_OTHER_TOPMARGIN_BOX ) ),
514 		m_aRightTxt( this, PaResId( RID_RTS_OTHER_RIGHTMARGIN_TXT ) ),
515 		m_aRightLB( this, PaResId( RID_RTS_OTHER_RIGHTMARGIN_BOX ) ),
516 		m_aBottomTxt( this, PaResId( RID_RTS_OTHER_BOTTOMMARGIN_TXT ) ),
517 		m_aBottomLB( this, PaResId( RID_RTS_OTHER_BOTTOMMARGIN_BOX ) ),
518 		m_aCommentTxt( this, PaResId( RID_RTS_OTHER_COMMENT_TXT ) ),
519 		m_aCommentEdt( this, PaResId( RID_RTS_OTHER_COMMENT_EDT ) ),
520 		m_aDefaultBtn( this, PaResId( RID_RTS_OTHER_DEFAULT_BTN ) )
521 {
522 	FreeResource();
523 
524 	m_aTopLB.EnableEmptyFieldValue( sal_True );
525 	m_aBottomLB.EnableEmptyFieldValue( sal_True );
526 	m_aLeftLB.EnableEmptyFieldValue( sal_True );
527 	m_aRightLB.EnableEmptyFieldValue( sal_True );
528 
529 	m_aDefaultBtn.SetClickHdl( LINK( this, RTSOtherPage, ClickBtnHdl ) );
530 
531 	initValues();
532 }
533 
534 // ------------------------------------------------------------------
535 
536 RTSOtherPage::~RTSOtherPage()
537 {
538 }
539 
540 // ------------------------------------------------------------------
541 
542 void RTSOtherPage::initValues()
543 {
544 	int nMarginLeft = 0;
545 	int nMarginTop = 0;
546 	int nMarginRight = 0;
547 	int nMarginBottom = 0;
548 
549     if( m_pParent->m_aJobData.m_pParser )
550     {
551         m_pParent->m_aJobData.m_pParser->
552             getMargins( m_pParent->m_aJobData.m_pParser->getDefaultPaperDimension(),
553                         nMarginLeft,
554                         nMarginRight,
555                         nMarginTop,
556                         nMarginBottom );
557     }
558 
559 	nMarginLeft		+= m_pParent->m_aJobData.m_nLeftMarginAdjust;
560 	nMarginRight	+= m_pParent->m_aJobData.m_nRightMarginAdjust;
561 	nMarginTop		+= m_pParent->m_aJobData.m_nTopMarginAdjust;
562 	nMarginBottom	+= m_pParent->m_aJobData.m_nBottomMarginAdjust;
563 
564 	m_aLeftLB.SetValue( nMarginLeft, FUNIT_POINT );
565 	m_aRightLB.SetValue( nMarginRight, FUNIT_POINT );
566 	m_aTopLB.SetValue( nMarginTop, FUNIT_POINT );
567 	m_aBottomLB.SetValue( nMarginBottom, FUNIT_POINT );
568 	m_aCommentEdt.SetText( m_pParent->m_aJobData.m_aComment );
569 }
570 
571 // ------------------------------------------------------------------
572 
573 void RTSOtherPage::save()
574 {
575 	int nMarginLeft = 0;
576 	int nMarginTop = 0;
577 	int nMarginRight = 0;
578 	int nMarginBottom = 0;
579 
580     if( m_pParent->m_aJobData.m_pParser )
581     {
582         m_pParent->m_aJobData.m_pParser->
583             getMargins( m_pParent->m_aJobData.m_pParser->getDefaultPaperDimension(),
584                         nMarginLeft,
585                         nMarginRight,
586                         nMarginTop,
587                         nMarginBottom );
588     }
589 
590 	m_pParent->m_aJobData.m_nLeftMarginAdjust	= m_aLeftLB.GetValue( FUNIT_POINT ) - nMarginLeft;
591 	m_pParent->m_aJobData.m_nRightMarginAdjust	= m_aRightLB.GetValue( FUNIT_POINT ) - nMarginRight;
592 	m_pParent->m_aJobData.m_nTopMarginAdjust	= m_aTopLB.GetValue( FUNIT_POINT ) - nMarginTop;
593 	m_pParent->m_aJobData.m_nBottomMarginAdjust	= m_aBottomLB.GetValue( FUNIT_POINT ) - nMarginBottom;
594 	m_pParent->m_aJobData.m_aComment = m_aCommentEdt.GetText();
595 }
596 
597 // ------------------------------------------------------------------
598 
599 IMPL_LINK( RTSOtherPage, ClickBtnHdl, Button*, pButton )
600 {
601 	if( pButton == &m_aDefaultBtn )
602 	{
603 		m_pParent->m_aJobData.m_nLeftMarginAdjust =
604 			m_pParent->m_aJobData.m_nRightMarginAdjust =
605 			m_pParent->m_aJobData.m_nTopMarginAdjust =
606 			m_pParent->m_aJobData.m_nBottomMarginAdjust = 0;
607 
608 		initValues();
609 	}
610 	return 0;
611 }
612 
613 // ------------------------------------------------------------------
614 
615 /*
616  *	RTSFontSubstPage
617  */
618 
619 RTSFontSubstPage::RTSFontSubstPage( RTSDialog* pParent ) :
620 		TabPage( &pParent->m_aTabControl, PaResId( RID_RTS_FONTSUBSTPAGE ) ),
621 		m_pParent( pParent ),
622 		m_aSubstitutionsText( this, PaResId( RID_RTS_FS_SUBST_TXT ) ),
623 		m_aSubstitutionsBox( this, PaResId( RID_RTS_FS_SUBST_BOX ) ),
624 		m_aFromFontText( this, PaResId( RID_RTS_FS_FROM_TXT ) ),
625 		m_aFromFontBox( this, PaResId( RID_RTS_FS_FROM_BOX ) ),
626 		m_aToFontText( this, PaResId( RID_RTS_FS_TO_TXT ) ),
627 		m_aToFontBox( this, PaResId( RID_RTS_FS_TO_BOX ) ),
628 		m_aAddButton( this, PaResId( RID_RTS_FS_ADD_BTN ) ),
629 		m_aRemoveButton( this, PaResId( RID_RTS_FS_REMOVE_BTN ) ),
630 		m_aEnableBox( this, PaResId( RID_RTS_FS_ENABLE_BTN ) )
631 {
632 	FreeResource();
633 
634 	// fill to box
635 	PrintFontManager& rFontManager = PrintFontManager::get();
636 	::std::list< FastPrintFontInfo > aFonts;
637 	rFontManager.getFontListWithFastInfo( aFonts, m_pParent->m_aJobData.m_pParser, false );
638 	::std::list< FastPrintFontInfo >::const_iterator it;
639 	::std::hash_map< OUString, int, OUStringHash > aToMap, aFromMap;
640 	for( it = aFonts.begin(); it != aFonts.end(); ++it )
641 	{
642 		if( it->m_eType == fonttype::Builtin )
643 		{
644 			if( aToMap.find( it->m_aFamilyName ) == aToMap.end() )
645 			{
646 				m_aToFontBox.InsertEntry( it->m_aFamilyName );
647 				aToMap[ it->m_aFamilyName ] = 1;
648 			}
649 		}
650 		else
651 		{
652 			if( aFromMap.find( it->m_aFamilyName ) == aFromMap.end() )
653 			{
654 				m_aFromFontBox.InsertEntry( it->m_aFamilyName );
655 				aFromMap[ it->m_aFamilyName ] = 1;
656 			}
657 		}
658 	}
659 
660 	m_aEnableBox.Check( m_pParent->m_aJobData.m_bPerformFontSubstitution );
661 	m_aRemoveButton.Enable( sal_False );
662 	if( ! m_pParent->m_aJobData.m_bPerformFontSubstitution )
663 	{
664 		m_aSubstitutionsBox.Enable( sal_False );
665 		m_aSubstitutionsText.Enable( sal_False );
666 		m_aAddButton.Enable( sal_False );
667 		m_aToFontBox.Enable( sal_False );
668 		m_aToFontText.Enable( sal_False );
669 		m_aFromFontBox.Enable( sal_False );
670 		m_aFromFontText.Enable( sal_False );
671 	}
672 
673 	update();
674 
675 	m_aAddButton.SetClickHdl( LINK( this, RTSFontSubstPage, ClickBtnHdl ) );
676 	m_aRemoveButton.SetClickHdl( LINK( this, RTSFontSubstPage, ClickBtnHdl ) );
677 	m_aEnableBox.SetClickHdl( LINK( this, RTSFontSubstPage, ClickBtnHdl ) );
678 	m_aSubstitutionsBox.SetSelectHdl( LINK( this, RTSFontSubstPage, SelectHdl ) );
679 	m_aSubstitutionsBox.setDelPressedLink( LINK( this, RTSFontSubstPage, DelPressedHdl ) );
680 }
681 
682 RTSFontSubstPage::~RTSFontSubstPage()
683 {
684 }
685 
686 void RTSFontSubstPage::update()
687 {
688 	m_aSubstitutionsBox.Clear();
689 	m_aRemoveButton.Enable( sal_False );
690 	// fill substitutions box
691 	::std::hash_map< OUString, OUString, OUStringHash >::const_iterator it;
692 	for( it = m_pParent->m_aJobData.m_aFontSubstitutes.begin();
693 		 it != m_pParent->m_aJobData.m_aFontSubstitutes.end(); ++it )
694 	{
695 		String aEntry( it->first );
696 		aEntry.AppendAscii( " -> " );
697 		aEntry.Append( String( it->second ) );
698 		m_aSubstitutionsBox.InsertEntry( aEntry );
699 	}
700 }
701 
702 IMPL_LINK( RTSFontSubstPage, DelPressedHdl, ListBox*, pBox )
703 {
704 	if( pBox == &m_aSubstitutionsBox &&
705 		m_aRemoveButton.IsEnabled() )
706 		ClickBtnHdl( &m_aRemoveButton );
707 	return 0;
708 }
709 
710 IMPL_LINK( RTSFontSubstPage, SelectHdl, ListBox*, pBox )
711 {
712 	if( pBox == &m_aSubstitutionsBox )
713 	{
714 		m_aRemoveButton.Enable( m_aSubstitutionsBox.GetSelectEntryCount() && m_pParent->m_aJobData.m_bPerformFontSubstitution );
715 	}
716 	return 0;
717 }
718 
719 IMPL_LINK( RTSFontSubstPage, ClickBtnHdl, Button*, pButton )
720 {
721 	if( pButton == &m_aAddButton )
722 	{
723 		m_pParent->m_aJobData.m_aFontSubstitutes[ m_aFromFontBox.GetText() ] = m_aToFontBox.GetSelectEntry();
724 		update();
725 	}
726 	else if( pButton == &m_aRemoveButton )
727 	{
728 		for( int i = 0; i < m_aSubstitutionsBox.GetSelectEntryCount(); i++ )
729 		{
730 			String aEntry( m_aSubstitutionsBox.GetSelectEntry( i ) );
731 			sal_uInt16 nPos = aEntry.SearchAscii( " -> " );
732 			aEntry.Erase( nPos );
733 			m_pParent->m_aJobData.m_aFontSubstitutes.erase( aEntry );
734 		}
735 		update();
736 	}
737 	else if( pButton == &m_aEnableBox )
738 	{
739 		m_pParent->m_aJobData.m_bPerformFontSubstitution = m_aEnableBox.IsChecked() ? true : false;
740 		m_aSubstitutionsBox.Enable( m_pParent->m_aJobData.m_bPerformFontSubstitution );
741 		m_aSubstitutionsText.Enable( m_pParent->m_aJobData.m_bPerformFontSubstitution );
742 		m_aAddButton.Enable( m_pParent->m_aJobData.m_bPerformFontSubstitution );
743 		m_aRemoveButton.Enable( m_aSubstitutionsBox.GetSelectEntryCount() && m_pParent->m_aJobData.m_bPerformFontSubstitution );
744 		m_aToFontBox.Enable( m_pParent->m_aJobData.m_bPerformFontSubstitution );
745 		m_aToFontText.Enable( m_pParent->m_aJobData.m_bPerformFontSubstitution );
746 		m_aFromFontBox.Enable( m_pParent->m_aJobData.m_bPerformFontSubstitution );
747 		m_aFromFontText.Enable( m_pParent->m_aJobData.m_bPerformFontSubstitution );
748 	}
749 	return 0;
750 }
751 
752 
753 class RTSPWDialog : public ModalDialog
754 {
755     FixedText		m_aText;
756     FixedText		m_aUserText;
757     Edit			m_aUserEdit;
758     FixedText		m_aPassText;
759     Edit			m_aPassEdit;
760 
761     OKButton		m_aOKButton;
762     CancelButton	m_aCancelButton;
763 public:
764     RTSPWDialog( const OString& rServer, const OString& rUserName, Window* pParent );
765     ~RTSPWDialog();
766 
767     OString getUserName() const;
768     OString getPassword() const;
769 };
770 
771 RTSPWDialog::RTSPWDialog( const OString& rServer, const OString& rUserName, Window* pParent )
772         :
773         ModalDialog( pParent, PaResId( RID_RTS_PWDIALOG ) ),
774         m_aText( this, PaResId( RID_RTS_PWDIALOG_TXT ) ),
775         m_aUserText( this, PaResId( RID_RTS_PWDIALOG_USER_TXT ) ),
776         m_aUserEdit( this, PaResId( RID_RTS_PWDIALOG_USER_EDT ) ),
777         m_aPassText( this, PaResId( RID_RTS_PWDIALOG_PASS_TXT ) ),
778         m_aPassEdit( this, PaResId( RID_RTS_PWDIALOG_PASS_EDT ) ),
779         m_aOKButton( this, PaResId( RID_RTS_PWDIALOG_OK_BTN ) ),
780         m_aCancelButton( this, PaResId( RID_RTS_PWDIALOG_CANCEL_BTN ) )
781 {
782     FreeResource();
783     String aText( m_aText.GetText() );
784     aText.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "%s" ) ), OStringToOUString( rServer, osl_getThreadTextEncoding() ) );
785     m_aText.SetText( aText );
786     m_aUserEdit.SetText( OStringToOUString( rUserName, osl_getThreadTextEncoding() ) );
787 }
788 
789 RTSPWDialog::~RTSPWDialog()
790 {
791 }
792 
793 OString RTSPWDialog::getUserName() const
794 {
795     return rtl::OUStringToOString( m_aUserEdit.GetText(), osl_getThreadTextEncoding() );
796 }
797 
798 OString RTSPWDialog::getPassword() const
799 {
800     return rtl::OUStringToOString( m_aPassEdit.GetText(), osl_getThreadTextEncoding() );
801 }
802 
803 extern "C" {
804 
805 	int SPA_DLLPUBLIC Sal_SetupPrinterDriver( ::psp::PrinterInfo& rJobData )
806 	{
807 		int nRet = 0;
808 		RTSDialog aDialog( rJobData, rJobData.m_aPrinterName, false );
809 
810 		if( aDialog.Execute() )
811 		{
812 			rJobData = aDialog.getSetup();
813 			nRet = 1;
814 		}
815 
816 		return nRet;
817 	}
818 
819 	int SPA_DLLPUBLIC Sal_queryFaxNumber( String& rNumber )
820 	{
821         String aTmpString( PaResId( RID_TXT_QUERYFAXNUMBER ) );
822 		QueryString aQuery( NULL, aTmpString, rNumber );
823 		return aQuery.Execute();
824 	}
825 
826     bool SPA_DLLPUBLIC Sal_authenticateQuery( const OString& rServer, OString& rUserName, OString& rPassword )
827     {
828         bool bRet = false;
829 
830         RTSPWDialog aDialog( rServer, rUserName, NULL );
831         if( aDialog.Execute() )
832         {
833             rUserName = aDialog.getUserName();
834             rPassword = aDialog.getPassword();
835             bRet = true;
836         }
837         return bRet;
838     }
839 
840 } // extern "C"
841