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