crypt32: Use skip to avoid failures where support is missing.
[wine] / dlls / gphoto2.ds / ui.c
1 /*
2 * TWAIN32 Options UI
3 *
4 * Copyright 2006 CodeWeavers, Aric Stewart
5 *
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.
10 *
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.
15 *
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
19 */
20
21 #include "config.h"
22
23 #include <stdlib.h>
24 #include <stdarg.h>
25 #include <stdio.h>
26
27 #define NONAMELESSUNION
28 #define NONAMELESSSTRUCT
29 #include "windef.h"
30 #include "winbase.h"
31 #include "winuser.h"
32 #include "winnls.h"
33 #include "wingdi.h"
34 #include "commctrl.h"
35 #include "prsht.h"
36 #include "twain.h"
37 #include "gphoto2_i.h"
38 #include "wine/debug.h"
39 #include "resource.h"
40
41 static HBITMAP static_bitmap;
42
43 static INT_PTR CALLBACK ConnectingProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
44 {
45         return FALSE;
46 }
47
48 static void PopulateListView(HWND List)
49 {
50         struct gphoto2_file *file;
51         LVITEMA item;
52         int index = 0;
53
54         LIST_FOR_EACH_ENTRY( file, &activeDS.files, struct gphoto2_file, entry)
55         {
56                 if (strstr(file->filename,".JPG") || strstr(file->filename,".jpg")) 
57                 {
58                         item.mask = LVIF_PARAM | LVIF_TEXT | LVIF_IMAGE ;
59                         item.iItem = index;
60                         item.iSubItem = 0;
61                         item.pszText = file->filename;
62                         item.iImage = index;
63                         item.lParam= (LPARAM)file;
64
65                         SendMessageA(List, LVM_INSERTITEMA,0,(LPARAM)&item);
66                         index ++;
67                 }
68         }
69 }
70
71 static void PopulateImageList(HIMAGELIST *iList, HWND list)
72 {
73         struct gphoto2_file *file;
74         INT rc;
75         HWND    progress_dialog;
76
77         progress_dialog =
78                 CreateDialogW(GPHOTO2_instance,(LPWSTR)MAKEINTRESOURCE(IDD_CONNECTING),
79                                 NULL, ConnectingProc);
80         
81         LIST_FOR_EACH_ENTRY( file, &activeDS.files, struct gphoto2_file, entry)
82         {
83                 if (strstr(file->filename,".JPG") || strstr(file->filename,".jpg")) 
84                 {
85                         HBITMAP         bitmap;
86                         BITMAP          bmpInfo;
87
88 #ifdef HAVE_GPHOTO2
89                         _get_gphoto2_file_as_DIB(file->folder, file->filename,
90                                         GP_FILE_TYPE_PREVIEW, 0, &bitmap); 
91 #else
92                         bitmap = 0;
93 #endif
94                         GetObjectA(bitmap,sizeof(BITMAP),(LPVOID)&bmpInfo);
95
96                         if (*iList == 0)
97                         {
98                                 *iList = ImageList_Create(bmpInfo.bmWidth,
99                                                 bmpInfo.bmHeight,ILC_COLOR24, 10,10);
100
101                                 SendMessageW(list, LVM_SETICONSPACING, 0,
102                                                 MAKELONG(bmpInfo.bmWidth+6, bmpInfo.bmHeight+15) ); }
103                         
104                         rc = ImageList_Add(*iList, bitmap, 0);
105
106                         DeleteObject(static_bitmap);
107                         static_bitmap = bitmap;
108                         SendMessageW(GetDlgItem(progress_dialog,IDC_BITMAP),STM_SETIMAGE,
109                                         IMAGE_BITMAP, (LPARAM)static_bitmap);
110                         RedrawWindow(progress_dialog,NULL,NULL,RDW_INTERNALPAINT|RDW_UPDATENOW|RDW_ALLCHILDREN);
111                 }
112         }
113         EndDialog(progress_dialog,0);
114         
115 }
116
117 static INT_PTR CALLBACK DialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
118 {
119         switch(msg)
120         {
121                 case WM_INITDIALOG:
122                         {
123                                 HIMAGELIST ilist = 0;
124                                 HWND list = GetDlgItem(hwnd,IDC_LIST1);
125                                 EnableWindow(GetDlgItem(hwnd,IDC_IMPORT),FALSE);
126
127                                 PopulateImageList(&ilist,list);
128
129                                 SendMessageA(list, LVM_SETIMAGELIST,LVSIL_NORMAL,(LPARAM)ilist);
130                                 PopulateListView(list);
131                         }
132                         break;
133                 case WM_NOTIFY:
134                         if (((LPNMHDR)lParam)->code == LVN_ITEMCHANGED)
135                         {
136                                 HWND list = GetDlgItem(hwnd,IDC_LIST1);
137                                 int count = SendMessageA(list,LVM_GETSELECTEDCOUNT,0,0);
138                                 if (count > 0)
139                                         EnableWindow(GetDlgItem(hwnd,IDC_IMPORT),TRUE);
140                                 else
141                                         EnableWindow(GetDlgItem(hwnd,IDC_IMPORT),FALSE);
142                         }
143                         break;
144                 case WM_COMMAND:
145                         switch LOWORD(wParam)
146                         {
147                                 case IDC_EXIT:
148                                         EndDialog(hwnd,0);
149                                         break;
150                                 case IDC_IMPORT:
151                                         {
152                                                 HWND list = GetDlgItem(hwnd,IDC_LIST1);
153                                                 int count = SendMessageA(list,LVM_GETSELECTEDCOUNT,0,0);
154                                                 int i;
155
156                                                 if (count ==0)
157                                                 {
158                                                         EndDialog(hwnd,0);
159                                                         return FALSE;
160                                                 }
161
162                                                 count = SendMessageA(list,LVM_GETITEMCOUNT,0,0);
163                                                 for ( i = 0; i < count; i++)
164                                                 {
165                                                         INT state = 0x00000000;
166
167                                                         state = SendMessageA(list,LVM_GETITEMSTATE,i,
168                                                                         LVIS_SELECTED);
169
170                                                         if (state)
171                                                         {
172                                                                 LVITEMA item;
173                                                                 struct gphoto2_file *file;
174
175
176                                                                 item.mask = LVIF_PARAM;
177                                                                 item.iItem = i;
178
179                                                                 item.iSubItem = 0;
180                                                                 SendMessageA(list,LVM_GETITEMA,0,(LPARAM)&item);
181
182                                                                 file = (struct gphoto2_file*)item.lParam;
183                                                                 file->download = TRUE;
184                                                         }
185                                                 }
186
187                                                 EndDialog(hwnd,1);
188                                         }
189                                         break;
190                                 case IDC_IMPORTALL:
191                                         {
192                                                 HWND list = GetDlgItem(hwnd,IDC_LIST1);
193                                                 int count = SendMessageA(list,LVM_GETITEMCOUNT,0,0);
194                                                 int i;
195
196                                                 if (count ==0)
197                                                 {
198                                                         EndDialog(hwnd,0);
199                                                         return FALSE;
200                                                 }
201
202                                                 for ( i = 0; i < count; i++)
203                                                 {
204                                                         LVITEMA item;
205                                                         struct gphoto2_file *file;
206
207
208                                                         item.mask = LVIF_PARAM;
209                                                         item.iItem = i;
210                                                         item.iSubItem = 0;
211
212                                                         SendMessageA(list,LVM_GETITEMA,0,(LPARAM)&item);
213
214                                                         file = (struct gphoto2_file*)item.lParam;
215                                                         file->download = TRUE;
216                                                 }
217
218                                                 EndDialog(hwnd,1);
219                                         }
220                                         break;
221                         }
222                         break;
223         }
224         return FALSE;
225 }
226
227 BOOL DoCameraUI(void)
228 {
229         return DialogBoxW(GPHOTO2_instance,
230                         (LPWSTR)MAKEINTRESOURCE(IDD_CAMERAUI),NULL, DialogProc);
231 }
232
233 static INT_PTR CALLBACK ProgressProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
234                 lParam)
235 {
236             return FALSE;
237 }   
238
239 HWND TransferringDialogBox(HWND dialog, DWORD progress)
240 {
241         if (!dialog)
242                 dialog = CreateDialogW(GPHOTO2_instance,
243                                 (LPWSTR)MAKEINTRESOURCE(IDD_DIALOG1), NULL, ProgressProc);
244                                 
245         if (progress == -1)
246         {
247                 EndDialog(dialog,0);
248                 return NULL;
249         }
250
251         RedrawWindow(dialog,NULL,NULL,
252                         RDW_INTERNALPAINT|RDW_UPDATENOW|RDW_ALLCHILDREN);
253
254         return dialog;
255 }