4 * Copyright 2006 CodeWeavers, Aric Stewart
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
37 #include "wine/debug.h"
39 #include "wine/unicode.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(twain
);
46 #define ID_EDIT_BASE 0x1000
47 #define ID_STATIC_BASE 0x2000
49 static INT_PTR CALLBACK
DialogProc (HWND
, UINT
, WPARAM
, LPARAM
);
50 static INT CALLBACK
PropSheetProc(HWND
, UINT
,LPARAM
);
52 static int create_leading_static(HDC hdc
, LPCSTR text
,
53 LPDLGITEMTEMPLATEW
* template_out
, int y
, int id
)
55 LPDLGITEMTEMPLATEW tpl
= NULL
;
66 base
= GetDialogBaseUnits();
68 len
= MultiByteToWideChar(CP_ACP
,0,text
,-1,NULL
,0);
70 len
+= sizeof(DLGITEMTEMPLATE
);
71 len
+= 3*sizeof(WORD
);
73 tpl
= HeapAlloc(GetProcessHeap(),0,len
);
74 tpl
->style
=WS_VISIBLE
;
75 tpl
->dwExtendedStyle
= 0;
80 GetTextExtentPoint32A(hdc
,text
,lstrlenA(text
),&size
);
82 tpl
->cx
= MulDiv(size
.cx
,4,LOWORD(base
));
83 tpl
->cy
= MulDiv(size
.cy
,8,HIWORD(base
)) * 2;
84 ptr
= (LPBYTE
)tpl
+ sizeof(DLGITEMTEMPLATE
);
85 *(LPWORD
)ptr
= 0xffff;
87 *(LPWORD
)ptr
= 0x0082;
89 ptr
+= MultiByteToWideChar(CP_ACP
,0,text
,-1,(LPWSTR
)ptr
,len
) * sizeof(WCHAR
);
90 *(LPWORD
)ptr
= 0x0000;
96 static int create_trailing_edit(HDC hdc
, LPDLGITEMTEMPLATEW
* template_out
, int id
,
97 int y
, LPCSTR text
,BOOL is_int
)
99 LPDLGITEMTEMPLATEW tpl
= NULL
;
104 static const char int_base
[] = "0000 xxx";
105 static const char float_base
[] = "0000.0000 xxx";
107 base
= GetDialogBaseUnits();
109 len
= MultiByteToWideChar(CP_ACP
,0,text
,-1,NULL
,0);
110 len
*= sizeof(WCHAR
);
111 len
+= sizeof(DLGITEMTEMPLATE
);
112 len
+= 3*sizeof(WORD
);
114 tpl
= HeapAlloc(GetProcessHeap(),0,len
);
115 tpl
->style
=WS_VISIBLE
|ES_READONLY
|WS_BORDER
;
116 tpl
->dwExtendedStyle
= 0;
122 GetTextExtentPoint32A(hdc
,int_base
,lstrlenA(int_base
),&size
);
124 GetTextExtentPoint32A(hdc
,float_base
,lstrlenA(float_base
),&size
);
126 tpl
->cx
= MulDiv(size
.cx
*2,4,LOWORD(base
));
127 tpl
->cy
= MulDiv(size
.cy
,8,HIWORD(base
)) * 2;
129 ptr
= (LPBYTE
)tpl
+ sizeof(DLGITEMTEMPLATE
);
130 *(LPWORD
)ptr
= 0xffff;
132 *(LPWORD
)ptr
= 0x0081;
134 ptr
+= MultiByteToWideChar(CP_ACP
,0,text
,-1,(LPWSTR
)ptr
,len
) * sizeof(WCHAR
);
135 *(LPWORD
)ptr
= 0x0000;
142 static int create_item(HDC hdc
, const SANE_Option_Descriptor
*opt
,
143 INT id
, LPDLGITEMTEMPLATEW
*template_out
, int y
, int *cx
, int* count
)
145 LPDLGITEMTEMPLATEW tpl
= NULL
,rc
= NULL
;
147 DWORD styles
= WS_VISIBLE
;
149 LPDLGITEMTEMPLATEW lead_static
= NULL
;
150 LPDLGITEMTEMPLATEW trail_edit
= NULL
;
151 DWORD leading_len
= 0;
163 GetTextExtentPoint32A(hdc
,"X",1,&size
);
164 base
= GetDialogBaseUnits();
165 base_x
= MulDiv(size
.cx
,4,LOWORD(base
));
167 if (opt
->type
== SANE_TYPE_BOOL
)
169 class = 0x0080; /* Button */
170 styles
|= BS_AUTOCHECKBOX
;
171 local_len
+= MultiByteToWideChar(CP_ACP
,0,opt
->title
,-1,NULL
,0);
172 local_len
*= sizeof(WCHAR
);
175 else if (opt
->type
== SANE_TYPE_INT
)
179 psane_control_option(activeDS
.deviceHandle
, id
-ID_BASE
,
180 SANE_ACTION_GET_VALUE
, &i
,NULL
);
182 sprintf(buffer
,"%i",i
);
184 if (opt
->constraint_type
== SANE_CONSTRAINT_NONE
)
186 class = 0x0081; /* Edit*/
189 local_len
+= MultiByteToWideChar(CP_ACP
,0,title
,-1,NULL
,0);
190 local_len
*= sizeof(WCHAR
);
192 else if (opt
->constraint_type
== SANE_CONSTRAINT_RANGE
)
194 class = 0x0084; /* scroll */
195 ctl_cx
= 10 * base_x
;
196 trail_len
+= create_trailing_edit(hdc
, &trail_edit
, id
+
197 ID_EDIT_BASE
, y
,buffer
,TRUE
);
201 class= 0x0085; /* Combo */
202 ctl_cx
= 10 * base_x
;
203 styles
|= CBS_DROPDOWNLIST
;
205 leading_len
+= create_leading_static(hdc
, opt
->title
, &lead_static
, y
,
208 else if (opt
->type
== SANE_TYPE_FIXED
)
213 i
= HeapAlloc(GetProcessHeap(),0,opt
->size
*sizeof(SANE_Word
));
215 psane_control_option(activeDS
.deviceHandle
, id
-ID_BASE
,
216 SANE_ACTION_GET_VALUE
, i
, NULL
);
219 sprintf(buffer
,"%f",dd
);
220 HeapFree(GetProcessHeap(),0,i
);
222 if (opt
->constraint_type
== SANE_CONSTRAINT_NONE
)
224 class = 0x0081; /* Edit */
226 local_len
+= MultiByteToWideChar(CP_ACP
,0,title
,-1,NULL
,0);
227 local_len
*= sizeof(WCHAR
);
229 else if (opt
->constraint_type
== SANE_CONSTRAINT_RANGE
)
231 class= 0x0084; /* scroll */
232 ctl_cx
= 10 * base_x
;
233 trail_len
+= create_trailing_edit(hdc
, &trail_edit
, id
+
234 ID_EDIT_BASE
, y
,buffer
,FALSE
);
238 class= 0x0085; /* Combo */
239 ctl_cx
= 10 * base_x
;
240 styles
|= CBS_DROPDOWNLIST
;
242 leading_len
+= create_leading_static(hdc
, opt
->title
, &lead_static
, y
,
245 else if (opt
->type
== SANE_TYPE_STRING
)
247 if (opt
->constraint_type
== SANE_CONSTRAINT_NONE
)
249 class = 0x0081; /* Edit*/
253 class= 0x0085; /* Combo */
254 ctl_cx
= opt
->size
* base_x
;
255 styles
|= CBS_DROPDOWNLIST
;
257 leading_len
+= create_leading_static(hdc
, opt
->title
, &lead_static
, y
,
259 psane_control_option(activeDS
.deviceHandle
, id
-ID_BASE
,
260 SANE_ACTION_GET_VALUE
, buffer
,NULL
);
263 local_len
+= MultiByteToWideChar(CP_ACP
,0,title
,-1,NULL
,0);
264 local_len
*= sizeof(WCHAR
);
266 else if (opt
->type
== SANE_TYPE_BUTTON
)
268 class = 0x0080; /* Button */
269 local_len
+= MultiByteToWideChar(CP_ACP
,0,opt
->title
,-1,NULL
,0);
270 local_len
*= sizeof(WCHAR
);
273 else if (opt
->type
== SANE_TYPE_GROUP
)
275 class = 0x0080; /* Button */
276 styles
|= BS_GROUPBOX
;
277 local_len
+= MultiByteToWideChar(CP_ACP
,0,opt
->title
,-1,NULL
,0);
278 local_len
*= sizeof(WCHAR
);
282 local_len
+= sizeof(DLGITEMTEMPLATE
);
284 local_len
+= 3*sizeof(WORD
);
286 local_len
+= 4*sizeof(WORD
);
290 padding
= leading_len
% sizeof(DWORD
);
291 rc
= HeapReAlloc(GetProcessHeap(),0,lead_static
,leading_len
+local_len
+ padding
);
292 tpl
= (LPDLGITEMTEMPLATEW
)((LPBYTE
)rc
+ leading_len
+ padding
);
295 rc
= tpl
= HeapAlloc(GetProcessHeap(),0,local_len
);
298 tpl
->dwExtendedStyle
= 0;
300 tpl
->x
= lead_static
->x
+ lead_static
->cx
+ 1;
301 else if (opt
->type
== SANE_TYPE_GROUP
)
310 GetTextExtentPoint32A(hdc
,title
,lstrlenA(title
),&size
);
317 tpl
->cy
= lead_static
->cy
;
326 ptr
= (LPBYTE
)tpl
+ sizeof(DLGITEMTEMPLATE
);
327 *(LPWORD
)ptr
= 0xffff;
329 *(LPWORD
)ptr
= class;
333 ptr
+= MultiByteToWideChar(CP_ACP
,0,title
,-1,(LPWSTR
)ptr
,local_len
) * sizeof(WCHAR
);
337 *(LPWORD
)ptr
= 0x0000;
341 *((LPWORD
)ptr
) = 0x0000;
346 trail_edit
->x
= tpl
->cx
+ tpl
->x
+ 2;
347 *cx
= trail_edit
->x
+ trail_edit
->cx
;
349 padding2
= (leading_len
+ local_len
+ padding
)% sizeof(DWORD
);
351 rc
= HeapReAlloc(GetProcessHeap(),0,rc
,leading_len
+local_len
+ padding
352 +padding2
+trail_len
);
354 memcpy(((LPBYTE
)rc
) + leading_len
+ local_len
+ padding
+ padding2
,
355 trail_edit
,trail_len
);
358 *cx
= tpl
->cx
+ tpl
->x
;
369 return leading_len
+ local_len
+ padding
+ padding2
+ trail_len
;
373 static LPDLGTEMPLATEW
create_options_page(HDC hdc
, int *from_index
,
374 SANE_Int optcount
, BOOL split_tabs
)
378 LPDLGTEMPLATEW tpl
= NULL
;
379 LPBYTE all_controls
= NULL
;
380 DWORD control_len
= 0;
382 int group_max_cx
= 0;
384 int group_offset
= -1;
385 INT control_count
= 0;
387 for (i
= *from_index
; i
< optcount
; i
++)
389 LPDLGITEMTEMPLATEW item_tpl
= NULL
;
390 const SANE_Option_Descriptor
*opt
;
395 int hold_for_group
= 0;
397 opt
= psane_get_option_descriptor(activeDS
.deviceHandle
, i
);
400 if (opt
->type
== SANE_TYPE_GROUP
&& split_tabs
)
413 if (!SANE_OPTION_IS_ACTIVE (opt
->cap
))
416 len
= create_item(hdc
, opt
, ID_BASE
+ i
, &item_tpl
, y
, &x
, &count
);
418 control_count
+= count
;
426 y
+= item_tpl
->cy
+ 1;
427 max_cx
= max(max_cx
, x
+ 2);
428 group_max_cx
= max(group_max_cx
, x
);
430 padding
= len
% sizeof(DWORD
);
435 newone
= HeapReAlloc(GetProcessHeap(),0,all_controls
,
436 control_len
+ len
+ padding
);
437 all_controls
= newone
;
438 memcpy(all_controls
+control_len
,item_tpl
,len
);
439 memset(all_controls
+control_len
+len
,0xca,padding
);
440 HeapFree(GetProcessHeap(),0,item_tpl
);
446 all_controls
= (LPBYTE
)item_tpl
;
450 all_controls
= HeapAlloc(GetProcessHeap(),0,len
+ padding
);
451 memcpy(all_controls
,item_tpl
,len
);
452 memset(all_controls
+len
,0xcb,padding
);
453 HeapFree(GetProcessHeap(),0,item_tpl
);
457 if (opt
->type
== SANE_TYPE_GROUP
)
459 if (group_offset
== -1)
461 group_offset
= control_len
;
466 LPDLGITEMTEMPLATEW group
=
467 (LPDLGITEMTEMPLATEW
)(all_controls
+group_offset
);
469 group
->cy
= hold_for_group
- group
->y
;
470 group
->cx
= group_max_cx
;
472 group
= (LPDLGITEMTEMPLATEW
)(all_controls
+control_len
);
476 group_offset
= control_len
;
480 control_len
+= len
+ padding
;
483 if ( group_offset
&& !split_tabs
)
485 LPDLGITEMTEMPLATEW group
=
486 (LPDLGITEMTEMPLATEW
)(all_controls
+group_offset
);
487 group
->cy
= y
- group
->y
;
488 group
->cx
= group_max_cx
;
495 tpl
= HeapAlloc(GetProcessHeap(),0,sizeof(DLGTEMPLATE
) + 3*sizeof(WORD
) +
498 tpl
->style
= WS_VISIBLE
| WS_OVERLAPPEDWINDOW
;
499 tpl
->dwExtendedStyle
= 0;
500 tpl
->cdit
= control_count
;
503 tpl
->cx
= max_cx
+ 10;
505 ptr
= (LPBYTE
)tpl
+ sizeof(DLGTEMPLATE
);
506 *(LPWORD
)ptr
= 0x0000;
508 *(LPWORD
)ptr
= 0x0000;
510 *(LPWORD
)ptr
= 0x0000;
512 memcpy(ptr
,all_controls
,control_len
);
514 HeapFree(GetProcessHeap(),0,all_controls
);
519 BOOL
DoScannerUI(void)
522 PROPSHEETPAGEW psp
[10];
524 PROPSHEETHEADERW psh
;
534 memset(&psp
,0,sizeof(psp
));
535 rc
= psane_control_option(activeDS
.deviceHandle
, 0, SANE_ACTION_GET_VALUE
,
537 if (rc
!= SANE_STATUS_GOOD
)
539 ERR("Unable to read number of options\n");
543 while (index
< optcount
)
545 const SANE_Option_Descriptor
*opt
;
546 psp
[page_count
].u
.pResource
= create_options_page(hdc
, &index
,
548 opt
= psane_get_option_descriptor(activeDS
.deviceHandle
, index
);
550 if (opt
->type
== SANE_TYPE_GROUP
)
555 len
= MultiByteToWideChar(CP_ACP
,0,opt
->title
,-1,NULL
,0);
556 title
= HeapAlloc(GetProcessHeap(),0,len
* sizeof(WCHAR
));
557 MultiByteToWideChar(CP_ACP
,0,opt
->title
,-1,title
,len
);
559 psp
[page_count
].pszTitle
= title
;
562 if (psp
[page_count
].u
.pResource
)
564 psp
[page_count
].dwSize
= sizeof(PROPSHEETPAGEW
);
565 psp
[page_count
].dwFlags
= PSP_DLGINDIRECT
| PSP_USETITLE
;
566 psp
[page_count
].hInstance
= SANE_instance
;
567 psp
[page_count
].pfnDlgProc
= DialogProc
;
568 psp
[page_count
].lParam
= (LPARAM
)&activeDS
;
575 len
= lstrlenA(activeDS
.identity
.Manufacturer
)
576 + lstrlenA(activeDS
.identity
.ProductName
) + 2;
577 szCaption
= HeapAlloc(GetProcessHeap(),0,len
*sizeof(WCHAR
));
578 MultiByteToWideChar(CP_ACP
,0,activeDS
.identity
.Manufacturer
,-1,
580 szCaption
[lstrlenA(activeDS
.identity
.Manufacturer
)] = ' ';
581 MultiByteToWideChar(CP_ACP
,0,activeDS
.identity
.ProductName
,-1,
582 &szCaption
[lstrlenA(activeDS
.identity
.Manufacturer
)+1],len
);
583 psh
.dwSize
= sizeof(PROPSHEETHEADERW
);
584 psh
.dwFlags
= PSH_PROPSHEETPAGE
|PSH_PROPTITLE
|PSH_USECALLBACK
;
585 psh
.hwndParent
= activeDS
.hwndOwner
;
586 psh
.hInstance
= SANE_instance
;
588 psh
.pszCaption
= szCaption
;
589 psh
.nPages
= page_count
;
590 psh
.u2
.nStartPage
= 0;
591 psh
.u3
.ppsp
= (LPCPROPSHEETPAGEW
) &psp
;
592 psh
.pfnCallback
= PropSheetProc
;
594 psrc
= PropertySheetW(&psh
);
596 for(index
= 0; index
< page_count
; index
++)
598 HeapFree(GetProcessHeap(),0,(LPBYTE
)psp
[index
].u
.pResource
);
599 HeapFree(GetProcessHeap(),0,(LPBYTE
)psp
[index
].pszTitle
);
601 HeapFree(GetProcessHeap(),0,szCaption
);
609 static void UpdateRelevantEdit(HWND hwnd
, const SANE_Option_Descriptor
*opt
,
610 int index
, int position
)
616 if (opt
->type
== SANE_TYPE_INT
)
618 static const WCHAR formatW
[] = {'%','i',0};
621 if (opt
->constraint
.range
->quant
)
622 si
= position
* opt
->constraint
.range
->quant
;
626 len
= sprintfW( buffer
, formatW
, si
);
628 else if (opt
->type
== SANE_TYPE_FIXED
)
630 static const WCHAR formatW
[] = {'%','f',0};
633 s_quant
= SANE_UNFIX(opt
->constraint
.range
->quant
);
636 dd
= position
* s_quant
;
638 dd
= position
* 0.01;
640 len
= sprintfW( buffer
, formatW
, dd
);
645 LoadStringW( SANE_instance
, opt
->unit
, buffer
+ len
, sizeof(buffer
)/sizeof(WCHAR
) - len
);
647 edit_w
= GetDlgItem(hwnd
,index
+ID_BASE
+ID_EDIT_BASE
);
648 if (edit_w
) SetWindowTextW(edit_w
,buffer
);
652 static BOOL
UpdateSaneScrollOption(
653 const SANE_Option_Descriptor
*opt
, int index
, DWORD position
)
655 SANE_Status rc
= SANE_STATUS_GOOD
;
658 if (opt
->type
== SANE_TYPE_INT
)
662 if (opt
->constraint
.range
->quant
)
663 si
= position
* opt
->constraint
.range
->quant
;
667 rc
= psane_control_option (activeDS
.deviceHandle
,index
,
668 SANE_ACTION_SET_VALUE
, &si
, &result
);
671 else if (opt
->type
== SANE_TYPE_FIXED
)
676 s_quant
= SANE_UNFIX(opt
->constraint
.range
->quant
);
679 dd
= position
* s_quant
;
681 dd
= position
* 0.01;
683 sf
= HeapAlloc(GetProcessHeap(),0,opt
->size
*sizeof(SANE_Word
));
687 rc
= psane_control_option (activeDS
.deviceHandle
,index
,
688 SANE_ACTION_SET_VALUE
, sf
, &result
);
690 HeapFree(GetProcessHeap(),0,sf
);
693 if(rc
== SANE_STATUS_GOOD
)
695 if (result
& SANE_INFO_RELOAD_OPTIONS
||
696 result
& SANE_INFO_RELOAD_PARAMS
|| result
& SANE_INFO_INEXACT
)
702 static BOOL
UpdateSaneBoolOption(int index
, BOOL position
)
704 SANE_Status rc
= SANE_STATUS_GOOD
;
710 rc
= psane_control_option (activeDS
.deviceHandle
,index
,
711 SANE_ACTION_SET_VALUE
, &si
, &result
);
713 if(rc
== SANE_STATUS_GOOD
)
715 if (result
& SANE_INFO_RELOAD_OPTIONS
||
716 result
& SANE_INFO_RELOAD_PARAMS
|| result
& SANE_INFO_INEXACT
)
722 static BOOL
UpdateSaneStringOption(int index
, SANE_String value
)
724 SANE_Status rc
= SANE_STATUS_GOOD
;
727 rc
= psane_control_option (activeDS
.deviceHandle
,index
,
728 SANE_ACTION_SET_VALUE
, value
, &result
);
730 if(rc
== SANE_STATUS_GOOD
)
732 if (result
& SANE_INFO_RELOAD_OPTIONS
||
733 result
& SANE_INFO_RELOAD_PARAMS
|| result
& SANE_INFO_INEXACT
)
739 static INT_PTR
InitializeDialog(HWND hwnd
)
746 rc
= psane_control_option(activeDS
.deviceHandle
, 0, SANE_ACTION_GET_VALUE
,
748 if (rc
!= SANE_STATUS_GOOD
)
750 ERR("Unable to read number of options\n");
754 for ( i
= 1; i
< optcount
; i
++)
756 const SANE_Option_Descriptor
*opt
;
758 control
= GetDlgItem(hwnd
,i
+ID_BASE
);
763 opt
= psane_get_option_descriptor(activeDS
.deviceHandle
, i
);
765 TRACE("%i %s %i %i\n",i
,opt
->title
,opt
->type
,opt
->constraint_type
);
767 if (!SANE_OPTION_IS_ACTIVE(opt
->cap
))
768 EnableWindow(control
,FALSE
);
770 EnableWindow(control
,TRUE
);
772 SendMessageA(control
,CB_RESETCONTENT
,0,0);
773 /* initialize values */
774 if (opt
->type
== SANE_TYPE_STRING
&& opt
->constraint_type
!=
775 SANE_CONSTRAINT_NONE
)
779 while (opt
->constraint
.string_list
[j
]!=NULL
)
781 SendMessageA(control
,CB_ADDSTRING
,0,
782 (LPARAM
)opt
->constraint
.string_list
[j
]);
785 psane_control_option(activeDS
.deviceHandle
, i
, SANE_ACTION_GET_VALUE
, buffer
,NULL
);
786 SendMessageA(control
,CB_SELECTSTRING
,0,(LPARAM
)buffer
);
788 else if (opt
->type
== SANE_TYPE_BOOL
)
791 psane_control_option(activeDS
.deviceHandle
, i
,
792 SANE_ACTION_GET_VALUE
, &b
, NULL
);
794 SendMessageA(control
,BM_SETCHECK
,BST_CHECKED
,0);
797 else if (opt
->constraint_type
== SANE_CONSTRAINT_RANGE
)
799 if (opt
->type
== SANE_TYPE_INT
)
804 min
= (SANE_Int
)opt
->constraint
.range
->min
/
805 (((SANE_Int
)opt
->constraint
.range
->quant
)?
806 (SANE_Int
)opt
->constraint
.range
->quant
:1);
808 max
= (SANE_Int
)opt
->constraint
.range
->max
/
809 (((SANE_Int
)opt
->constraint
.range
->quant
)
810 ?(SANE_Int
)opt
->constraint
.range
->quant
:1);
812 SendMessageA(control
,SBM_SETRANGE
,min
,max
);
814 psane_control_option(activeDS
.deviceHandle
, i
,
815 SANE_ACTION_GET_VALUE
, &si
,NULL
);
816 if (opt
->constraint
.range
->quant
)
817 si
= si
/ opt
->constraint
.range
->quant
;
819 SendMessageW(control
,SBM_SETPOS
, si
, TRUE
);
820 UpdateRelevantEdit(hwnd
, opt
, i
, si
);
822 else if (opt
->type
== SANE_TYPE_FIXED
)
827 double s_min
,s_max
,s_quant
;
831 s_min
= SANE_UNFIX(opt
->constraint
.range
->min
);
832 s_max
= SANE_UNFIX(opt
->constraint
.range
->max
);
833 s_quant
= SANE_UNFIX(opt
->constraint
.range
->quant
);
837 min
= (s_min
/ s_quant
);
838 max
= (s_max
/ s_quant
);
846 SendMessageA(control
,SBM_SETRANGE
,min
,max
);
849 sf
= HeapAlloc(GetProcessHeap(),0,opt
->size
*sizeof(SANE_Word
));
850 psane_control_option(activeDS
.deviceHandle
, i
,
851 SANE_ACTION_GET_VALUE
, sf
,NULL
);
853 dd
= SANE_UNFIX(*sf
);
854 HeapFree(GetProcessHeap(),0,sf
);
857 pos
= (dd
/ s_quant
);
861 SendMessageW(control
, SBM_SETPOS
, pos
, TRUE
);
863 UpdateRelevantEdit(hwnd
, opt
, i
, pos
);
871 static INT_PTR
ProcessScroll(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
874 const SANE_Option_Descriptor
*opt
;
878 index
= GetDlgCtrlID((HWND
)lParam
)- ID_BASE
;
882 opt
= psane_get_option_descriptor(activeDS
.deviceHandle
, index
);
887 scroll
= LOWORD(wParam
);
892 case SB_THUMBPOSITION
:
895 si
.cbSize
= sizeof(SCROLLINFO
);
896 si
.fMask
= SIF_TRACKPOS
;
897 GetScrollInfo((HWND
)lParam
,SB_CTL
, &si
);
898 position
= si
.nTrackPos
;
904 position
= SendMessageW((HWND
)lParam
,SBM_GETPOS
,0,0);
910 position
= SendMessageW((HWND
)lParam
,SBM_GETPOS
,0,0);
914 position
= SendMessageW((HWND
)lParam
,SBM_GETPOS
,0,0);
917 SendMessageW((HWND
)lParam
,SBM_SETPOS
, position
, TRUE
);
918 position
= SendMessageW((HWND
)lParam
,SBM_GETPOS
,0,0);
920 UpdateRelevantEdit(hwnd
, opt
, index
, position
);
921 if (UpdateSaneScrollOption(opt
, index
, position
))
922 InitializeDialog(hwnd
);
928 static void ButtonClicked(HWND hwnd
, INT id
, HWND control
)
931 const SANE_Option_Descriptor
*opt
;
933 index
= id
- ID_BASE
;
937 opt
= psane_get_option_descriptor(activeDS
.deviceHandle
, index
);
942 if (opt
->type
== SANE_TYPE_BOOL
)
944 BOOL r
= SendMessageW(control
,BM_GETCHECK
,0,0)==BST_CHECKED
;
945 if (UpdateSaneBoolOption(index
, r
))
946 InitializeDialog(hwnd
);
950 static void ComboChanged(HWND hwnd
, INT id
, HWND control
)
955 const SANE_Option_Descriptor
*opt
;
958 index
= id
- ID_BASE
;
962 opt
= psane_get_option_descriptor(activeDS
.deviceHandle
, index
);
967 selection
= SendMessageW(control
,CB_GETCURSEL
,0,0);
968 len
= SendMessageW(control
,CB_GETLBTEXTLEN
,selection
,0);
971 value
= HeapAlloc(GetProcessHeap(),0,len
);
972 SendMessageA(control
,CB_GETLBTEXT
,selection
,(LPARAM
)value
);
974 if (opt
->type
== SANE_TYPE_STRING
)
976 if (UpdateSaneStringOption(index
, value
))
977 InitializeDialog(hwnd
);
982 static INT_PTR CALLBACK
DialogProc(HWND hwndDlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
987 return InitializeDialog(hwndDlg
);
989 return ProcessScroll(hwndDlg
, wParam
, lParam
);
992 LPPSHNOTIFY psn
= (LPPSHNOTIFY
)lParam
;
993 switch (((NMHDR
*)lParam
)->code
)
996 if (psn
->lParam
== TRUE
)
998 activeDS
.currentState
= 6;
999 activeDS
.pendingEvent
.TWMessage
= MSG_XFERREADY
;
1002 case PSN_QUERYCANCEL
:
1003 activeDS
.pendingEvent
.TWMessage
= MSG_CLOSEDSREQ
;
1006 InitializeDialog(hwndDlg
);
1012 switch (HIWORD(wParam
))
1015 ButtonClicked(hwndDlg
,LOWORD(wParam
),
1019 ComboChanged(hwndDlg
,LOWORD(wParam
),
1028 static int CALLBACK
PropSheetProc(HWND hwnd
, UINT msg
, LPARAM lParam
)
1030 if (msg
== PSCB_INITIALIZED
)
1032 /* rename OK button to Scan */
1033 HWND scan
= GetDlgItem(hwnd
,IDOK
);
1034 SetWindowTextA(scan
,"Scan");
1040 static INT_PTR CALLBACK
ScanningProc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1045 HWND
ScanningDialogBox(HWND dialog
, LONG progress
)
1048 dialog
= CreateDialogW(SANE_instance
,
1049 (LPWSTR
)MAKEINTRESOURCE(IDD_DIALOG1
), NULL
, ScanningProc
);
1053 EndDialog(dialog
,0);
1057 RedrawWindow(dialog
,NULL
,NULL
,
1058 RDW_INTERNALPAINT
|RDW_UPDATENOW
|RDW_ALLCHILDREN
);
1063 #else /* SONAME_LIBSANE */
1065 BOOL
DoScannerUI(void)
1070 #endif /* SONAME_LIBSANE */