1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sanedlg.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
36 #include <tools/config.hxx>
38 #include <vcl/msgbox.hxx>
39 #include <sanedlg.hxx>
40 #include <sanedlg.hrc>
44 #define USE_SAVE_STATE
45 #undef SAVE_ALL_STATES
47 ResId
SaneResId( sal_uInt32 nID
)
49 static ResMgr
* pResMgr
= ResMgr::CreateResMgr( "san" );
50 return ResId( nID
, *pResMgr
);
53 SaneDlg::SaneDlg( Window
* pParent
, Sane
& rSane
) :
54 ModalDialog( pParent
, SaneResId( RID_SANE_DIALOG
) ),
56 mbIsDragging( FALSE
),
58 maMapMode( MAP_APPFONT
),
59 maOKButton( this, SaneResId( RID_SCAN_OK
) ),
60 maCancelButton( this, SaneResId( RID_SCAN_CANCEL
) ),
61 maDeviceInfoButton( this, SaneResId( RID_DEVICEINFO_BTN
) ),
62 maPreviewButton( this, SaneResId( RID_PREVIEW_BTN
) ),
63 maButtonOption( this, SaneResId( RID_SCAN_BUTTON_OPTION_BTN
) ),
64 maOptionsTxt( this, SaneResId( RID_SCAN_OPTION_TXT
) ),
65 maOptionTitle( this, SaneResId( RID_SCAN_OPTIONTITLE_TXT
) ),
66 maOptionDescTxt( this, SaneResId( RID_SCAN_OPTION_DESC_TXT
) ),
67 maVectorTxt( this, SaneResId( RID_SCAN_NUMERIC_VECTOR_TXT
) ),
68 maScanLeftTxt( this, SaneResId( RID_SCAN_LEFT_TXT
) ),
69 maLeftField( this, SaneResId( RID_SCAN_LEFT_BOX
) ),
70 maScanTopTxt( this, SaneResId( RID_SCAN_TOP_TXT
) ),
71 maTopField( this, SaneResId( RID_SCAN_TOP_BOX
) ),
72 maRightTxt( this, SaneResId( RID_SCAN_RIGHT_TXT
) ),
73 maRightField( this, SaneResId( RID_SCAN_RIGHT_BOX
) ),
74 maBottomTxt( this, SaneResId( RID_SCAN_BOTTOM_TXT
) ),
75 maBottomField( this, SaneResId( RID_SCAN_BOTTOM_BOX
) ),
76 maDeviceBoxTxt( this, SaneResId( RID_DEVICE_BOX_TXT
) ),
77 maDeviceBox( this, SaneResId( RID_DEVICE_BOX
) ),
78 maReslTxt( this, SaneResId( RID_SCAN_RESOLUTION_TXT
) ),
79 maReslBox( this, SaneResId( RID_SCAN_RESOLUTION_BOX
) ),
80 maAdvancedTxt( this, SaneResId( RID_SCAN_ADVANCED_TXT
) ),
81 maAdvancedBox( this, SaneResId( RID_SCAN_ADVANCED_BOX
) ),
82 maVectorBox( this, SaneResId( RID_SCAN_NUMERIC_VECTOR_BOX
) ),
83 maQuantumRangeBox( this, SaneResId( RID_SCAN_QUANTUM_RANGE_BOX
) ),
84 maStringRangeBox( this, SaneResId( RID_SCAN_STRING_RANGE_BOX
) ),
85 maPreviewBox( this, SaneResId( RID_PREVIEW_BOX
) ),
86 maAreaBox( this, SaneResId( RID_SCANAREA_BOX
) ),
87 maBoolCheckBox( this, SaneResId( RID_SCAN_BOOL_OPTION_BOX
) ),
88 maStringEdit( this, SaneResId( RID_SCAN_STRING_OPTION_EDT
) ),
89 maNumericEdit( this, SaneResId( RID_SCAN_NUMERIC_OPTION_EDT
) ),
90 maOptionBox( this, SaneResId( RID_SCAN_OPTION_BOX
) ),
95 InitDevices(); // opens first sane device
100 maDeviceInfoButton
.SetClickHdl( LINK( this, SaneDlg
, ClickBtnHdl
) );
101 maPreviewButton
.SetClickHdl( LINK( this, SaneDlg
, ClickBtnHdl
) );
102 maButtonOption
.SetClickHdl( LINK( this, SaneDlg
, ClickBtnHdl
) );
103 maDeviceBox
.SetSelectHdl( LINK( this, SaneDlg
, SelectHdl
) );
104 maOptionBox
.SetSelectHdl( LINK( this, SaneDlg
, OptionsBoxSelectHdl
) );
105 maOKButton
.SetClickHdl( LINK( this, SaneDlg
, ClickBtnHdl
) );
106 maCancelButton
.SetClickHdl( LINK( this, SaneDlg
, ClickBtnHdl
) );
107 maBoolCheckBox
.SetClickHdl( LINK( this, SaneDlg
, ClickBtnHdl
) );
108 maStringEdit
.SetModifyHdl( LINK( this, SaneDlg
, ModifyHdl
) );
109 maNumericEdit
.SetModifyHdl( LINK( this, SaneDlg
, ModifyHdl
) );
110 maVectorBox
.SetModifyHdl( LINK( this, SaneDlg
, ModifyHdl
) );
111 maReslBox
.SetModifyHdl( LINK( this, SaneDlg
, ModifyHdl
) );
112 maStringRangeBox
.SetSelectHdl( LINK( this, SaneDlg
, SelectHdl
) );
113 maQuantumRangeBox
.SetSelectHdl( LINK( this, SaneDlg
, SelectHdl
) );
114 maLeftField
.SetModifyHdl( LINK( this, SaneDlg
, ModifyHdl
) );
115 maRightField
.SetModifyHdl( LINK( this, SaneDlg
, ModifyHdl
) );
116 maTopField
.SetModifyHdl( LINK( this, SaneDlg
, ModifyHdl
) );
117 maBottomField
.SetModifyHdl( LINK( this, SaneDlg
, ModifyHdl
) );
118 maAdvancedBox
.SetClickHdl( LINK( this, SaneDlg
, ClickBtnHdl
) );
120 maOldLink
= mrSane
.SetReloadOptionsHdl( LINK( this, SaneDlg
, ReloadSaneOptionsHdl
) );
122 maOptionBox
.SetNodeBitmaps(
123 Bitmap( SaneResId( RID_SCAN_BITMAP_PLUS
) ),
124 Bitmap( SaneResId( RID_SCAN_BITMAP_MINUS
) )
126 maOptionBox
.SetWindowBits( WB_HASLINES
|
128 WB_NOINITIALSELECTION
|
129 WB_HASBUTTONSATROOT
|
139 short SaneDlg::Execute()
141 if( ! Sane::IsSane() )
143 ErrorBox
aErrorBox( NULL
, WB_OK
| WB_DEF_OK
,
144 String( SaneResId( RID_SANE_NOSANELIB_TXT
) ) );
149 return ModalDialog::Execute();
152 void SaneDlg::InitDevices()
154 if( ! Sane::IsSane() )
157 if( mrSane
.IsOpen() )
159 mrSane
.ReloadDevices();
161 for( int i
= 0; i
< Sane::CountDevices(); i
++ )
162 maDeviceBox
.InsertEntry( Sane::GetName( i
) );
163 if( Sane::CountDevices() )
166 maDeviceBox
.SelectEntry( Sane::GetName( 0 ) );
171 void SaneDlg::InitFields()
173 if( ! Sane::IsSane() )
176 int nOption
, i
, nValue
;
178 BOOL bSuccess
= FALSE
;
179 const char *ppSpecialOptions
[] = {
190 maMinTopLeft
= Point( 0, 0 );
191 maMaxBottomRight
= Point( PREVIEW_WIDTH
, PREVIEW_HEIGHT
);
193 if( ! mrSane
.IsOpen() )
197 nOption
= mrSane
.GetOptionByName( "resolution" );
202 bSuccess
= mrSane
.GetOptionValue( nOption
, fRes
);
205 maReslBox
.Enable( TRUE
);
207 maReslBox
.SetValue( (long)fRes
);
208 double *pDouble
= NULL
;
209 nValue
= mrSane
.GetRange( nOption
, pDouble
);
214 maReslBox
.SetMin( (long)pDouble
[0] );
215 maReslBox
.SetMax( (long)pDouble
[ nValue
-1 ] );
216 for( i
=0; i
<nValue
; i
++ )
218 if( i
== 0 || i
== nValue
-1 || ! ( ((int)pDouble
[i
]) % 20) )
219 maReslBox
.InsertValue( (long)pDouble
[i
] );
224 maReslBox
.SetMin( (long)pDouble
[0] );
225 maReslBox
.SetMax( (long)pDouble
[1] );
226 maReslBox
.InsertValue( (long)pDouble
[0] );
227 // mh@openoffice.org: issue 68557: Can only select 75 and 2400 dpi in Scanner dialogue
228 // scanner allows random setting of dpi resolution, a slider might be useful
230 // workaround: offer at least some more standard dpi resolution between
233 for ( int nRes
= (long) pDouble
[0] * 2; nRes
< (long) pDouble
[1]; nRes
= nRes
* 2 )
235 if ( !bGot300
&& nRes
> 300 ) {
236 nRes
= 300; bGot300
= 1;
238 maReslBox
.InsertValue(nRes
);
240 maReslBox
.InsertValue( (long)pDouble
[1] );
246 maReslBox
.Enable( FALSE
);
250 maReslBox
.Enable( FALSE
);
253 for( i
= 0; i
< 4; i
++ )
255 char const *pOptionName
= NULL
;
256 MetricField
* pField
= NULL
;
260 pOptionName
= "tl-x";
261 pField
= &maLeftField
;
264 pOptionName
= "tl-y";
265 pField
= &maTopField
;
268 pOptionName
= "br-x";
269 pField
= &maRightField
;
272 pOptionName
= "br-y";
273 pField
= &maBottomField
;
275 nOption
= pOptionName
? mrSane
.GetOptionByName( pOptionName
) : -1;
279 bSuccess
= mrSane
.GetOptionValue( nOption
, fValue
, 0 );
282 if( mrSane
.GetOptionUnit( nOption
) == SANE_UNIT_MM
)
284 pField
->SetUnit( FUNIT_MM
);
285 pField
->SetValue( (int)fValue
, FUNIT_MM
);
287 else // SANE_UNIT_PIXEL
289 pField
->SetValue( (int)fValue
, FUNIT_CUSTOM
);
290 pField
->SetCustomUnitText( String::CreateFromAscii( "Pixel" ) );
293 case 0: maTopLeft
.X() = (int)fValue
;break;
294 case 1: maTopLeft
.Y() = (int)fValue
;break;
295 case 2: maBottomRight
.X() = (int)fValue
;break;
296 case 3: maBottomRight
.Y() = (int)fValue
;break;
299 double *pDouble
= NULL
;
300 nValue
= mrSane
.GetRange( nOption
, pDouble
);
305 pField
->SetMin( (long)pDouble
[0] );
307 pField
->SetMax( (long)pDouble
[ nValue
-1 ] );
309 pField
->SetMax( (long)pDouble
[ 1 ] );
313 case 0: maMinTopLeft
.X() = pField
->GetMin();break;
314 case 1: maMinTopLeft
.Y() = pField
->GetMin();break;
315 case 2: maMaxBottomRight
.X() = pField
->GetMax();break;
316 case 3: maMaxBottomRight
.Y() = pField
->GetMax();break;
322 case 0: maMinTopLeft
.X() = (int)fValue
;break;
323 case 1: maMinTopLeft
.Y() = (int)fValue
;break;
324 case 2: maMaxBottomRight
.X() = (int)fValue
;break;
325 case 3: maMaxBottomRight
.Y() = (int)fValue
;break;
328 pField
->Enable( TRUE
);
332 mbDragEnable
= FALSE
;
336 maMinTopLeft
.X() = 0;
338 pField
->SetMax( PREVIEW_WIDTH
);
339 pField
->SetValue( 0 );
342 maMinTopLeft
.Y() = 0;
344 pField
->SetMax( PREVIEW_HEIGHT
);
345 pField
->SetValue( 0 );
348 maMaxBottomRight
.X() = PREVIEW_WIDTH
;
349 maBottomRight
.X() = PREVIEW_WIDTH
;
350 pField
->SetMax( PREVIEW_WIDTH
);
351 pField
->SetValue( PREVIEW_WIDTH
);
354 maMaxBottomRight
.Y() = PREVIEW_HEIGHT
;
355 maBottomRight
.Y() = PREVIEW_HEIGHT
;
356 pField
->SetMax( PREVIEW_HEIGHT
);
357 pField
->SetValue( PREVIEW_HEIGHT
);
360 pField
->Enable( FALSE
);
363 maTopLeft
= GetPixelPos( maTopLeft
);
364 maBottomRight
= GetPixelPos( maBottomRight
);
365 maPreviewRect
= Rectangle( maTopLeft
,
366 Size( maBottomRight
.X() - maTopLeft
.X(),
367 maBottomRight
.Y() - maTopLeft
.Y() )
371 SvLBoxEntry
* pParentEntry
= 0;
372 BOOL bGroupRejected
= FALSE
;
373 for( i
= 1; i
< mrSane
.CountOptions(); i
++ )
375 String aOption
=mrSane
.GetOptionName( i
);
376 BOOL bInsertAdvanced
=
377 mrSane
.GetOptionCap( i
) & SANE_CAP_ADVANCED
&&
378 ! maAdvancedBox
.IsChecked() ? FALSE
: TRUE
;
379 if( mrSane
.GetOptionType( i
) == SANE_TYPE_GROUP
)
381 if( bInsertAdvanced
)
383 aOption
= mrSane
.GetOptionTitle( i
);
384 pParentEntry
= maOptionBox
.InsertEntry( aOption
);
385 bGroupRejected
= FALSE
;
388 bGroupRejected
= TRUE
;
390 else if( aOption
.Len() &&
391 ! ( mrSane
.GetOptionCap( i
) &
393 SANE_CAP_HARD_SELECT
|
396 bInsertAdvanced
&& ! bGroupRejected
)
398 BOOL bIsSpecial
= FALSE
;
399 for( size_t n
= 0; !bIsSpecial
&&
400 n
< sizeof(ppSpecialOptions
)/sizeof(ppSpecialOptions
[0]); n
++ )
402 if( aOption
.EqualsAscii( ppSpecialOptions
[n
] ) )
408 maOptionBox
.InsertEntry( aOption
, pParentEntry
);
410 maOptionBox
.InsertEntry( aOption
);
416 IMPL_LINK( SaneDlg
, ClickBtnHdl
, Button
*, pButton
)
418 if( mrSane
.IsOpen() )
420 if( pButton
== &maDeviceInfoButton
)
422 String
aString( SaneResId( RID_SANE_DEVICEINFO_TXT
) );
423 String
aSR( RTL_CONSTASCII_USTRINGPARAM( "%s" ) );
424 aString
.SearchAndReplace( aSR
, Sane::GetName( mrSane
.GetDeviceNumber() ) );
425 aString
.SearchAndReplace( aSR
, Sane::GetVendor( mrSane
.GetDeviceNumber() ) );
426 aString
.SearchAndReplace( aSR
, Sane::GetModel( mrSane
.GetDeviceNumber() ) );
427 aString
.SearchAndReplace( aSR
, Sane::GetType( mrSane
.GetDeviceNumber() ) );
428 InfoBox
aInfoBox( this, aString
);
431 else if( pButton
== &maPreviewButton
)
433 else if( pButton
== &maBoolCheckBox
)
435 mrSane
.SetOptionValue( mnCurrentOption
,
436 maBoolCheckBox
.IsChecked() ?
437 (BOOL
)TRUE
: (BOOL
)FALSE
);
439 else if( pButton
== &maButtonOption
)
442 SANE_Value_Type nType
= mrSane
.GetOptionType( mnCurrentOption
);
445 case SANE_TYPE_BUTTON
:
446 mrSane
.ActivateButtonOption( mnCurrentOption
);
448 case SANE_TYPE_FIXED
:
451 int nElements
= mrSane
.GetOptionElements( mnCurrentOption
);
452 double* x
= new double[ nElements
];
453 double* y
= new double[ nElements
];
454 for( int i
= 0; i
< nElements
; i
++ )
456 mrSane
.GetOptionValue( mnCurrentOption
, y
);
458 GridWindow
aGrid( x
, y
, nElements
, this );
459 aGrid
.SetText( mrSane
.GetOptionName( mnCurrentOption
) );
460 aGrid
.setBoundings( 0, mfMin
, nElements
, mfMax
);
461 if( aGrid
.Execute() && aGrid
.getNewYValues() )
462 mrSane
.SetOptionValue( mnCurrentOption
, aGrid
.getNewYValues() );
469 case SANE_TYPE_STRING
:
470 case SANE_TYPE_GROUP
:
474 else if( pButton
== &maAdvancedBox
)
476 ReloadSaneOptionsHdl( NULL
);
479 if( pButton
== &maOKButton
)
481 double fRes
= (double)maReslBox
.GetValue();
482 SetAdjustedNumericalValue( "resolution", fRes
);
483 mrSane
.SetReloadOptionsHdl( maOldLink
);
484 UpdateScanArea( TRUE
);
486 EndDialog( mrSane
.IsOpen() ? 1 : 0 );
488 else if( pButton
== &maCancelButton
)
490 mrSane
.SetReloadOptionsHdl( maOldLink
);
497 IMPL_LINK( SaneDlg
, SelectHdl
, ListBox
*, pListBox
)
499 if( pListBox
== &maDeviceBox
&& Sane::IsSane() && Sane::CountDevices() )
501 String aNewDevice
= maDeviceBox
.GetSelectEntry();
503 if( aNewDevice
.Equals( Sane::GetName( nNumber
= mrSane
.GetDeviceNumber() ) ) )
506 mrSane
.Open( nNumber
);
510 if( mrSane
.IsOpen() )
512 if( pListBox
== &maQuantumRangeBox
)
514 ByteString
aValue( maQuantumRangeBox
.GetSelectEntry(), osl_getThreadTextEncoding() );
515 double fValue
= atof( aValue
.GetBuffer() );
516 mrSane
.SetOptionValue( mnCurrentOption
, fValue
, mnCurrentElement
);
518 else if( pListBox
== &maStringRangeBox
)
520 mrSane
.SetOptionValue( mnCurrentOption
, maStringRangeBox
.GetSelectEntry() );
526 IMPL_LINK( SaneDlg
, OptionsBoxSelectHdl
, SvTreeListBox
*, pBox
)
528 if( pBox
== &maOptionBox
&& Sane::IsSane() )
531 maOptionBox
.GetEntryText( maOptionBox
.FirstSelected() );
532 int nOption
= mrSane
.GetOptionByName( ByteString( aOption
, osl_getThreadTextEncoding() ).GetBuffer() );
533 if( nOption
!= -1 && nOption
!= mnCurrentOption
)
536 mnCurrentOption
= nOption
;
537 maOptionTitle
.SetText( mrSane
.GetOptionTitle( mnCurrentOption
) );
538 SANE_Value_Type nType
= mrSane
.GetOptionType( mnCurrentOption
);
539 SANE_Constraint_Type nConstraint
;
542 case SANE_TYPE_BOOL
: EstablishBoolOption();break;
543 case SANE_TYPE_STRING
:
544 nConstraint
= mrSane
.GetOptionConstraintType( mnCurrentOption
);
545 if( nConstraint
== SANE_CONSTRAINT_STRING_LIST
)
546 EstablishStringRange();
548 EstablishStringOption();
550 case SANE_TYPE_FIXED
:
553 nConstraint
= mrSane
.GetOptionConstraintType( mnCurrentOption
);
554 int nElements
= mrSane
.GetOptionElements( mnCurrentOption
);
555 mnCurrentElement
= 0;
556 if( nConstraint
== SANE_CONSTRAINT_RANGE
||
557 nConstraint
== SANE_CONSTRAINT_WORD_LIST
)
558 EstablishQuantumRange();
562 EstablishNumericOption();
566 if( nElements
<= 10 )
568 maVectorBox
.SetValue( 1 );
569 maVectorBox
.SetMin( 1 );
571 mrSane
.GetOptionElements( mnCurrentOption
) );
572 maVectorBox
.Show( TRUE
);
573 maVectorTxt
.Show( TRUE
);
578 // bring up dialog only on button click
579 EstablishButtonOption();
584 case SANE_TYPE_BUTTON
:
585 EstablishButtonOption();
594 IMPL_LINK( SaneDlg
, ModifyHdl
, Edit
*, pEdit
)
596 if( mrSane
.IsOpen() )
598 if( pEdit
== &maStringEdit
)
600 mrSane
.SetOptionValue( mnCurrentOption
, maStringEdit
.GetText() );
602 else if( pEdit
== &maReslBox
)
604 double fRes
= (double)maReslBox
.GetValue();
605 int nOption
= mrSane
.GetOptionByName( "resolution" );
608 double* pDouble
= NULL
;
609 int nValues
= mrSane
.GetRange( nOption
, pDouble
);
613 for( i
= 0; i
< nValues
; i
++ )
615 if( fRes
== pDouble
[i
] )
621 else if( nValues
== 0 )
623 if( fRes
< pDouble
[ 0 ] )
625 if( fRes
> pDouble
[ 1 ] )
628 maReslBox
.SetValue( (ULONG
)fRes
);
631 else if( pEdit
== &maNumericEdit
)
635 ByteString
aContents( maNumericEdit
.GetText(), osl_getThreadTextEncoding() );
636 fValue
= atof( aContents
.GetBuffer() );
637 if( mfMin
!= mfMax
&& ( fValue
< mfMin
|| fValue
> mfMax
) )
641 else if( fValue
> mfMax
)
643 sprintf( pBuf
, "%g", fValue
);
644 maNumericEdit
.SetText( String( pBuf
, osl_getThreadTextEncoding() ) );
646 mrSane
.SetOptionValue( mnCurrentOption
, fValue
, mnCurrentElement
);
648 else if( pEdit
== &maVectorBox
)
651 mnCurrentElement
= maVectorBox
.GetValue()-1;
653 mrSane
.GetOptionValue( mnCurrentOption
, fValue
, mnCurrentElement
);
654 sprintf( pBuf
, "%g", fValue
);
655 String
aValue( pBuf
, osl_getThreadTextEncoding() );
656 maNumericEdit
.SetText( aValue
);
657 maQuantumRangeBox
.SelectEntry( aValue
);
659 else if( pEdit
== &maTopField
)
661 Point
aPoint( 0, maTopField
.GetValue() );
662 aPoint
= GetPixelPos( aPoint
);
663 maTopLeft
.Y() = aPoint
.Y();
666 else if( pEdit
== &maLeftField
)
668 Point
aPoint( maLeftField
.GetValue(), 0 );
669 aPoint
= GetPixelPos( aPoint
);
670 maTopLeft
.X() = aPoint
.X();
673 else if( pEdit
== &maBottomField
)
675 Point
aPoint( 0, maBottomField
.GetValue() );
676 aPoint
= GetPixelPos( aPoint
);
677 maBottomRight
.Y() = aPoint
.Y();
680 else if( pEdit
== &maRightField
)
682 Point
aPoint( maRightField
.GetValue(), 0 );
683 aPoint
= GetPixelPos( aPoint
);
684 maBottomRight
.X() = aPoint
.X();
691 IMPL_LINK( SaneDlg
, ReloadSaneOptionsHdl
, Sane
*, /*pSane*/ )
693 mnCurrentOption
= -1;
694 mnCurrentElement
= 0;
696 // #92024# preserve preview rect, should only be set
697 // initially or in AcquirePreview
698 Rectangle aPreviewRect
= maPreviewRect
;
700 maPreviewRect
= aPreviewRect
;
701 Rectangle
aDummyRect( Point( 0, 0 ), GetSizePixel() );
706 void SaneDlg::AcquirePreview()
708 if( ! mrSane
.IsOpen() )
711 UpdateScanArea( TRUE
);
712 // set small resolution for preview
713 double fResl
= (double)maReslBox
.GetValue();
714 SetAdjustedNumericalValue( "resolution", 30.0 );
716 int nOption
= mrSane
.GetOptionByName( "preview" );
719 String
aString( SaneResId( RID_SANE_NORESOLUTIONOPTION_TXT
) );
720 WarningBox
aBox( this, WB_OK_CANCEL
| WB_DEF_OK
, aString
);
721 if( aBox
.Execute() == RET_CANCEL
)
725 mrSane
.SetOptionValue( nOption
, (BOOL
)TRUE
);
727 BitmapTransporter aTransporter
;
728 if( ! mrSane
.Start( aTransporter
) )
730 ErrorBox
aErrorBox( this, WB_OK
| WB_DEF_OK
,
731 String( SaneResId( RID_SANE_SCANERROR_TXT
) ) );
736 #if OSL_DEBUG_LEVEL > 1
737 aTransporter
.getStream().Seek( STREAM_SEEK_TO_END
);
738 fprintf( stderr
, "Previewbitmapstream contains %d bytes\n", (int)aTransporter
.getStream().Tell() );
740 aTransporter
.getStream().Seek( STREAM_SEEK_TO_BEGIN
);
741 maPreviewBitmap
.Read( aTransporter
.getStream(), TRUE
);
744 SetAdjustedNumericalValue( "resolution", fResl
);
745 maReslBox
.SetValue( (ULONG
)fResl
);
748 maPreviewRect
= Rectangle( maTopLeft
,
749 Size( maBottomRight
.X() - maTopLeft
.X(),
750 maBottomRight
.Y() - maTopLeft
.Y() )
754 Size
aBMSize( maPreviewBitmap
.GetSizePixel() );
755 if( aBMSize
.Width() > aBMSize
.Height() )
757 int nVHeight
= (maBottomRight
.X() - maTopLeft
.X()) * aBMSize
.Height() / aBMSize
.Width();
758 maPreviewRect
= Rectangle( Point( maTopLeft
.X(), ( maTopLeft
.Y() + maBottomRight
.Y() )/2 - nVHeight
/2 ),
759 Size( maBottomRight
.X() - maTopLeft
.X(),
764 int nVWidth
= (maBottomRight
.Y() - maTopLeft
.Y()) * aBMSize
.Width() / aBMSize
.Height();
765 maPreviewRect
= Rectangle( Point( ( maTopLeft
.X() + maBottomRight
.X() )/2 - nVWidth
/2, maTopLeft
.Y() ),
767 maBottomRight
.Y() - maTopLeft
.Y() ) );
771 Paint( Rectangle( Point( 0, 0 ), GetSizePixel() ) );
774 void SaneDlg::Paint( const Rectangle
& rRect
)
776 SetMapMode( maMapMode
);
777 SetFillColor( Color( COL_WHITE
) );
778 SetLineColor( Color( COL_WHITE
) );
779 DrawRect( Rectangle( Point( PREVIEW_UPPER_LEFT
, PREVIEW_UPPER_TOP
),
780 Size( PREVIEW_WIDTH
, PREVIEW_HEIGHT
) ) );
781 SetMapMode( MapMode( MAP_PIXEL
) );
782 // check for sane values
783 DrawBitmap( maPreviewRect
.TopLeft(), maPreviewRect
.GetSize(),
789 ModalDialog::Paint( rRect
);
792 void SaneDlg::DisableOption()
794 maBoolCheckBox
.Show( FALSE
);
795 maStringEdit
.Show( FALSE
);
796 maNumericEdit
.Show( FALSE
);
797 maQuantumRangeBox
.Show( FALSE
);
798 maStringRangeBox
.Show( FALSE
);
799 maButtonOption
.Show( FALSE
);
800 maVectorBox
.Show( FALSE
);
801 maVectorTxt
.Show( FALSE
);
802 maOptionDescTxt
.Show( FALSE
);
805 void SaneDlg::EstablishBoolOption()
807 BOOL bSuccess
, bValue
;
809 bSuccess
= mrSane
.GetOptionValue( mnCurrentOption
, bValue
);
812 maOptionDescTxt
.SetText( mrSane
.GetOptionName( mnCurrentOption
) );
813 maOptionDescTxt
.Show( TRUE
);
814 maBoolCheckBox
.Check( bValue
);
815 maBoolCheckBox
.Show( TRUE
);
819 void SaneDlg::EstablishStringOption()
824 bSuccess
= mrSane
.GetOptionValue( mnCurrentOption
, aValue
);
827 maOptionDescTxt
.SetText( mrSane
.GetOptionName( mnCurrentOption
) );
828 maOptionDescTxt
.Show( TRUE
);
829 maStringEdit
.SetText( String( aValue
, osl_getThreadTextEncoding() ) );
830 maStringEdit
.Show( TRUE
);
834 void SaneDlg::EstablishStringRange()
836 const char** ppStrings
= mrSane
.GetStringConstraint( mnCurrentOption
);
837 maStringRangeBox
.Clear();
838 for( int i
= 0; ppStrings
[i
] != 0; i
++ )
839 maStringRangeBox
.InsertEntry( String( ppStrings
[i
], osl_getThreadTextEncoding() ) );
841 mrSane
.GetOptionValue( mnCurrentOption
, aValue
);
842 maStringRangeBox
.SelectEntry( String( aValue
, osl_getThreadTextEncoding() ) );
843 maStringRangeBox
.Show( TRUE
);
844 maOptionDescTxt
.SetText( mrSane
.GetOptionName( mnCurrentOption
) );
845 maOptionDescTxt
.Show( TRUE
);
848 void SaneDlg::EstablishQuantumRange()
855 int nValues
= mrSane
.GetRange( mnCurrentOption
, mpRange
);
858 mfMin
= mpRange
[ 0 ];
859 mfMax
= mpRange
[ 1 ];
862 EstablishNumericOption();
864 else if( nValues
> 0 )
867 maQuantumRangeBox
.Clear();
868 mfMin
= mpRange
[ 0 ];
869 mfMax
= mpRange
[ nValues
-1 ];
870 for( int i
= 0; i
< nValues
; i
++ )
872 sprintf( pBuf
, "%g", mpRange
[ i
] );
873 maQuantumRangeBox
.InsertEntry( String( pBuf
, osl_getThreadTextEncoding() ) );
876 if( mrSane
.GetOptionValue( mnCurrentOption
, fValue
, mnCurrentElement
) )
878 sprintf( pBuf
, "%g", fValue
);
879 maQuantumRangeBox
.SelectEntry( String( pBuf
, osl_getThreadTextEncoding() ) );
881 maQuantumRangeBox
.Show( TRUE
);
882 String
aText( mrSane
.GetOptionName( mnCurrentOption
) );
884 aText
+= mrSane
.GetOptionUnitName( mnCurrentOption
);
885 maOptionDescTxt
.SetText( aText
);
886 maOptionDescTxt
.Show( TRUE
);
890 void SaneDlg::EstablishNumericOption()
895 bSuccess
= mrSane
.GetOptionValue( mnCurrentOption
, fValue
);
900 String
aText( mrSane
.GetOptionName( mnCurrentOption
) );
902 aText
+= mrSane
.GetOptionUnitName( mnCurrentOption
);
905 sprintf( pBuf
, " < %g ; %g >", mfMin
, mfMax
);
906 aText
+= String( pBuf
, osl_getThreadTextEncoding() );
908 maOptionDescTxt
.SetText( aText
);
909 maOptionDescTxt
.Show( TRUE
);
910 sprintf( pBuf
, "%g", fValue
);
911 maNumericEdit
.SetText( String( pBuf
, osl_getThreadTextEncoding() ) );
912 maNumericEdit
.Show( TRUE
);
915 void SaneDlg::EstablishButtonOption()
917 maOptionDescTxt
.SetText( mrSane
.GetOptionName( mnCurrentOption
) );
918 maOptionDescTxt
.Show( TRUE
);
919 maButtonOption
.Show( TRUE
);
922 #define RECT_SIZE_PIX 7
924 void SaneDlg::MouseMove( const MouseEvent
& rMEvt
)
928 Point aMousePos
= rMEvt
.GetPosPixel();
929 // move into valid area
930 Point aLogicPos
= GetLogicPos( aMousePos
);
931 aMousePos
= GetPixelPos( aLogicPos
);
932 switch( meDragDirection
)
934 case TopLeft
: maTopLeft
= aMousePos
; break;
935 case Top
: maTopLeft
.Y() = aMousePos
.Y(); break;
937 maTopLeft
.Y() = aMousePos
.Y();
938 maBottomRight
.X() = aMousePos
.X();
940 case Right
: maBottomRight
.X() = aMousePos
.X(); break;
941 case BottomRight
: maBottomRight
= aMousePos
; break;
942 case Bottom
: maBottomRight
.Y() = aMousePos
.Y(); break;
944 maTopLeft
.X() = aMousePos
.X();
945 maBottomRight
.Y() = aMousePos
.Y();
947 case Left
: maTopLeft
.X() = aMousePos
.X(); break;
951 if( maTopLeft
.X() > maBottomRight
.X() )
953 nSwap
= maTopLeft
.X();
954 maTopLeft
.X() = maBottomRight
.X();
955 maBottomRight
.X() = nSwap
;
957 if( maTopLeft
.Y() > maBottomRight
.Y() )
959 nSwap
= maTopLeft
.Y();
960 maTopLeft
.Y() = maBottomRight
.Y();
961 maBottomRight
.Y() = nSwap
;
964 UpdateScanArea( FALSE
);
966 ModalDialog::MouseMove( rMEvt
);
969 void SaneDlg::MouseButtonDown( const MouseEvent
& rMEvt
)
971 Point aMousePixel
= rMEvt
.GetPosPixel();
973 if( ! mbIsDragging
&& mbDragEnable
)
975 int nMiddleX
= ( maBottomRight
.X() - maTopLeft
.X() ) / 2 - RECT_SIZE_PIX
/2 + maTopLeft
.X();
976 int nMiddleY
= ( maBottomRight
.Y() - maTopLeft
.Y() ) / 2 - RECT_SIZE_PIX
/2 + maTopLeft
.Y();
977 if( aMousePixel
.Y() >= maTopLeft
.Y() &&
978 aMousePixel
.Y() < maTopLeft
.Y() + RECT_SIZE_PIX
)
980 if( aMousePixel
.X() >= maTopLeft
.X() &&
981 aMousePixel
.X() < maTopLeft
.X() + RECT_SIZE_PIX
)
983 meDragDirection
= TopLeft
;
984 aMousePixel
= maTopLeft
;
987 else if( aMousePixel
.X() >= nMiddleX
&&
988 aMousePixel
.X() < nMiddleX
+ RECT_SIZE_PIX
)
990 meDragDirection
= Top
;
991 aMousePixel
.Y() = maTopLeft
.Y();
994 else if( aMousePixel
.X() > maBottomRight
.X() - RECT_SIZE_PIX
&&
995 aMousePixel
.X() <= maBottomRight
.X() )
997 meDragDirection
= TopRight
;
998 aMousePixel
= Point( maBottomRight
.X(), maTopLeft
.Y() );
1002 else if( aMousePixel
.Y() >= nMiddleY
&&
1003 aMousePixel
.Y() < nMiddleY
+ RECT_SIZE_PIX
)
1005 if( aMousePixel
.X() >= maTopLeft
.X() &&
1006 aMousePixel
.X() < maTopLeft
.X() + RECT_SIZE_PIX
)
1008 meDragDirection
= Left
;
1009 aMousePixel
.X() = maTopLeft
.X();
1010 mbIsDragging
= TRUE
;
1012 else if( aMousePixel
.X() > maBottomRight
.X() - RECT_SIZE_PIX
&&
1013 aMousePixel
.X() <= maBottomRight
.X() )
1015 meDragDirection
= Right
;
1016 aMousePixel
.X() = maBottomRight
.X();
1017 mbIsDragging
= TRUE
;
1020 else if( aMousePixel
.Y() <= maBottomRight
.Y() &&
1021 aMousePixel
.Y() > maBottomRight
.Y() - RECT_SIZE_PIX
)
1023 if( aMousePixel
.X() >= maTopLeft
.X() &&
1024 aMousePixel
.X() < maTopLeft
.X() + RECT_SIZE_PIX
)
1026 meDragDirection
= BottomLeft
;
1027 aMousePixel
= Point( maTopLeft
.X(), maBottomRight
.Y() );
1028 mbIsDragging
= TRUE
;
1030 else if( aMousePixel
.X() >= nMiddleX
&&
1031 aMousePixel
.X() < nMiddleX
+ RECT_SIZE_PIX
)
1033 meDragDirection
= Bottom
;
1034 aMousePixel
.Y() = maBottomRight
.Y();
1035 mbIsDragging
= TRUE
;
1037 else if( aMousePixel
.X() > maBottomRight
.X() - RECT_SIZE_PIX
&&
1038 aMousePixel
.X() <= maBottomRight
.X() )
1040 meDragDirection
= BottomRight
;
1041 aMousePixel
= maBottomRight
;
1042 mbIsDragging
= TRUE
;
1048 SetPointerPosPixel( aMousePixel
);
1051 ModalDialog::MouseButtonDown( rMEvt
);
1054 void SaneDlg::MouseButtonUp( const MouseEvent
& rMEvt
)
1058 UpdateScanArea( TRUE
);
1060 mbIsDragging
= FALSE
;
1062 ModalDialog::MouseButtonUp( rMEvt
);
1065 void SaneDlg::DrawRectangles( Point
& rUL
, Point
& rBR
)
1067 int nMiddleX
, nMiddleY
;
1070 aUR
= Point( rBR
.X(), rUL
.Y() );
1071 aBL
= Point( rUL
.X(), rBR
.Y() );
1072 nMiddleX
= ( rBR
.X() - rUL
.X() ) / 2 + rUL
.X();
1073 nMiddleY
= ( rBR
.Y() - rUL
.Y() ) / 2 + rUL
.Y();
1075 DrawLine( rUL
, aBL
);
1076 DrawLine( aBL
, rBR
);
1077 DrawLine( rBR
, aUR
);
1078 DrawLine( aUR
, rUL
);
1079 DrawRect( Rectangle( rUL
, Size( RECT_SIZE_PIX
,RECT_SIZE_PIX
) ) );
1080 DrawRect( Rectangle( aBL
, Size( RECT_SIZE_PIX
, -RECT_SIZE_PIX
) ) );
1081 DrawRect( Rectangle( rBR
, Size( -RECT_SIZE_PIX
, -RECT_SIZE_PIX
) ) );
1082 DrawRect( Rectangle( aUR
, Size( -RECT_SIZE_PIX
, RECT_SIZE_PIX
) ) );
1083 DrawRect( Rectangle( Point( nMiddleX
- RECT_SIZE_PIX
/2, rUL
.Y() ), Size( RECT_SIZE_PIX
, RECT_SIZE_PIX
) ) );
1084 DrawRect( Rectangle( Point( nMiddleX
- RECT_SIZE_PIX
/2, rBR
.Y() ), Size( RECT_SIZE_PIX
, -RECT_SIZE_PIX
) ) );
1085 DrawRect( Rectangle( Point( rUL
.X(), nMiddleY
- RECT_SIZE_PIX
/2 ), Size( RECT_SIZE_PIX
, RECT_SIZE_PIX
) ) );
1086 DrawRect( Rectangle( Point( rBR
.X(), nMiddleY
- RECT_SIZE_PIX
/2 ), Size( -RECT_SIZE_PIX
, RECT_SIZE_PIX
) ) );
1089 void SaneDlg::DrawDrag()
1091 static Point aLastUL
, aLastBR
;
1093 if( ! mbDragEnable
)
1096 RasterOp eROP
= GetRasterOp();
1097 SetRasterOp( ROP_INVERT
);
1098 SetMapMode( MapMode( MAP_PIXEL
) );
1101 DrawRectangles( aLastUL
, aLastBR
);
1103 aLastUL
= maTopLeft
;
1104 aLastBR
= maBottomRight
;
1105 DrawRectangles( maTopLeft
, maBottomRight
);
1108 SetRasterOp( eROP
);
1109 SetMapMode( maMapMode
);
1112 Point
SaneDlg::GetPixelPos( const Point
& rIn
)
1115 ( ( rIn
.X() * PREVIEW_WIDTH
) /
1116 ( maMaxBottomRight
.X() - maMinTopLeft
.X() ) )
1117 + PREVIEW_UPPER_LEFT
,
1118 ( ( rIn
.Y() * PREVIEW_HEIGHT
)
1119 / ( maMaxBottomRight
.Y() - maMinTopLeft
.Y() ) )
1120 + PREVIEW_UPPER_TOP
);
1122 return LogicToPixel( aConvert
, maMapMode
);
1125 Point
SaneDlg::GetLogicPos( const Point
& rIn
)
1127 Point aConvert
= PixelToLogic( rIn
, maMapMode
);
1128 aConvert
.X() -= PREVIEW_UPPER_LEFT
;
1129 aConvert
.Y() -= PREVIEW_UPPER_TOP
;
1130 if( aConvert
.X() < 0 )
1132 if( aConvert
.X() >= PREVIEW_WIDTH
)
1133 aConvert
.X() = PREVIEW_WIDTH
-1;
1134 if( aConvert
.Y() < 0 )
1136 if( aConvert
.Y() >= PREVIEW_HEIGHT
)
1137 aConvert
.Y() = PREVIEW_HEIGHT
-1;
1139 aConvert
.X() *= ( maMaxBottomRight
.X() - maMinTopLeft
.X() );
1140 aConvert
.X() /= PREVIEW_WIDTH
;
1141 aConvert
.Y() *= ( maMaxBottomRight
.Y() - maMinTopLeft
.Y() );
1142 aConvert
.Y() /= PREVIEW_HEIGHT
;
1146 void SaneDlg::UpdateScanArea( BOOL bSend
)
1148 if( ! mbDragEnable
)
1151 Point aUL
= GetLogicPos( maTopLeft
);
1152 Point aBR
= GetLogicPos( maBottomRight
);
1154 maLeftField
.SetValue( aUL
.X() );
1155 maTopField
.SetValue( aUL
.Y() );
1156 maRightField
.SetValue( aBR
.X() );
1157 maBottomField
.SetValue( aBR
.Y() );
1162 if( mrSane
.IsOpen() )
1164 SetAdjustedNumericalValue( "tl-x", (double)aUL
.X() );
1165 SetAdjustedNumericalValue( "tl-y", (double)aUL
.Y() );
1166 SetAdjustedNumericalValue( "br-x", (double)aBR
.X() );
1167 SetAdjustedNumericalValue( "br-y", (double)aBR
.Y() );
1171 BOOL
SaneDlg::LoadState()
1173 #ifdef USE_SAVE_STATE
1176 if( ! Sane::IsSane() )
1179 const char* pEnv
= getenv("HOME");
1180 String
aFileName( pEnv
? pEnv
: "", osl_getThreadTextEncoding() );
1181 aFileName
+= String( RTL_CONSTASCII_USTRINGPARAM( "/.so_sane_state" ) );
1182 Config
aConfig( aFileName
);
1183 if( ! aConfig
.HasGroup( "SANE" ) )
1186 aConfig
.SetGroup( "SANE" );
1187 ByteString aString
= aConfig
.ReadKey( "SO_LastSaneDevice" );
1188 for( i
= 0; i
< Sane::CountDevices() && ! aString
.Equals( ByteString( Sane::GetName( i
), osl_getThreadTextEncoding() ) ); i
++ ) ;
1189 if( i
== Sane::CountDevices() )
1193 mrSane
.Open( aString
.GetBuffer() );
1198 if( mrSane
.IsOpen() )
1200 int iMax
= aConfig
.GetKeyCount();
1201 for( i
= 0; i
< iMax
; i
++ )
1203 aString
= aConfig
.GetKeyName( i
);
1204 ByteString aValue
= aConfig
.ReadKey( i
);
1205 int nOption
= mrSane
.GetOptionByName( aString
.GetBuffer() );
1208 if( aValue
.CompareTo( "BOOL=", 5 ) == COMPARE_EQUAL
)
1210 aValue
.Erase( 0, 5 );
1211 BOOL aBOOL
= (BOOL
)aValue
.ToInt32();
1212 mrSane
.SetOptionValue( nOption
, aBOOL
);
1214 else if( aValue
.CompareTo( "STRING=", 7 ) == COMPARE_EQUAL
)
1216 aValue
.Erase( 0, 7 );
1217 mrSane
.SetOptionValue( nOption
, String( aValue
, osl_getThreadTextEncoding() ) );
1219 else if( aValue
.CompareTo( "NUMERIC=", 8 ) == COMPARE_EQUAL
)
1221 aValue
.Erase( 0, 8 );
1222 int nMax
= aValue
.GetTokenCount( ':' );
1224 for( int n
= 0; n
< nMax
; n
++ )
1226 ByteString aSub
= aValue
.GetToken( n
, ':' );
1227 sscanf( aSub
.GetBuffer(), "%lg", &fValue
);
1228 SetAdjustedNumericalValue( aString
.GetBuffer(), fValue
, n
);
1244 void SaneDlg::SaveState()
1246 #ifdef USE_SAVE_STATE
1247 if( ! Sane::IsSane() )
1250 const char* pEnv
= getenv( "HOME" );
1251 String
aFileName( pEnv
? pEnv
: "", osl_getThreadTextEncoding() );
1252 aFileName
.AppendAscii( "/.so_sane_state" );
1254 Config
aConfig( aFileName
);
1255 aConfig
.DeleteGroup( "SANE" );
1256 aConfig
.SetGroup( "SANE" );
1257 aConfig
.WriteKey( "SO_LastSANEDevice", ByteString( maDeviceBox
.GetSelectEntry(), RTL_TEXTENCODING_UTF8
) );
1259 #ifdef SAVE_ALL_STATES
1260 for( int i
= 1; i
< mrSane
.CountOptions(); i
++ )
1262 String aOption
=mrSane
.GetOptionName( i
);
1263 SANE_Value_Type nType
= mrSane
.GetOptionType( i
);
1266 case SANE_TYPE_BOOL
:
1269 if( mrSane
.GetOptionValue( i
, bValue
) )
1271 ByteString
aString( "BOOL=" );
1272 aString
+= (ULONG
)bValue
;
1273 aConfig
.WriteKey( aOption
, aString
);
1277 case SANE_TYPE_STRING
:
1279 String
aString( "STRING=" );
1281 if( mrSane
.GetOptionValue( i
, aValue
) )
1284 aConfig
.WriteKey( aOption
, aString
);
1288 case SANE_TYPE_FIXED
:
1291 String
aString( "NUMERIC=" );
1294 for( int n
= 0; n
< mrSane
.GetOptionElements( i
); n
++ )
1296 if( ! mrSane
.GetOptionValue( i
, fValue
, n
) )
1300 sprintf( buf
, "%lg", fValue
);
1303 if( n
>= mrSane
.GetOptionElements( i
) )
1304 aConfig
.WriteKey( aOption
, aString
);
1312 static char const* pSaveOptions
[] = {
1320 i
< (sizeof(pSaveOptions
)/sizeof(pSaveOptions
[0]));
1323 ByteString aOption
= pSaveOptions
[i
];
1324 int nOption
= mrSane
.GetOptionByName( pSaveOptions
[i
] );
1327 SANE_Value_Type nType
= mrSane
.GetOptionType( nOption
);
1330 case SANE_TYPE_BOOL
:
1333 if( mrSane
.GetOptionValue( nOption
, bValue
) )
1335 ByteString
aString( "BOOL=" );
1336 aString
+= ByteString::CreateFromInt32(bValue
);
1337 aConfig
.WriteKey( aOption
, aString
);
1341 case SANE_TYPE_STRING
:
1343 ByteString
aString( "STRING=" );
1345 if( mrSane
.GetOptionValue( nOption
, aValue
) )
1348 aConfig
.WriteKey( aOption
, aString
);
1352 case SANE_TYPE_FIXED
:
1355 ByteString
aString( "NUMERIC=" );
1360 for( n
= 0; n
< mrSane
.GetOptionElements( nOption
); n
++ )
1362 if( ! mrSane
.GetOptionValue( nOption
, fValue
, n
) )
1366 sprintf( buf
, "%lg", fValue
);
1369 if( n
>= mrSane
.GetOptionElements( nOption
) )
1370 aConfig
.WriteKey( aOption
, aString
);
1382 BOOL
SaneDlg::SetAdjustedNumericalValue(
1383 const char* pOption
,
1388 if( ! Sane::IsSane() || ! mrSane
.IsOpen() || ( nOption
= mrSane
.GetOptionByName( pOption
) ) == -1 )
1391 if( nElement
< 0 || nElement
>= mrSane
.GetOptionElements( nOption
) )
1394 double* pValues
= NULL
;
1396 if( ( nValues
= mrSane
.GetRange( nOption
, pValues
) ) < 0 )
1399 #if OSL_DEBUG_LEVEL > 1
1400 fprintf( stderr
, "SaneDlg::SetAdjustedNumericalValue( \"%s\", %lg ) ",
1407 double fNearest
= 1e6
;
1408 for( int i
= 0; i
< nValues
; i
++ )
1410 if( fabs( fValue
- pValues
[ i
] ) < fNearest
)
1412 fNearest
= fabs( fValue
- pValues
[ i
] );
1416 fValue
= pValues
[ nNearest
];
1420 if( fValue
< pValues
[0] )
1421 fValue
= pValues
[0];
1422 if( fValue
> pValues
[1] )
1423 fValue
= pValues
[1];
1426 mrSane
.SetOptionValue( nOption
, fValue
, nElement
);
1427 #if OSL_DEBUG_LEVEL > 1
1428 fprintf( stderr
, "yields %lg\n", fValue
);