push 599a9d3db769aad8dabfd10a59120f719b00f4ee
[wine/hacks.git] / dlls / gphoto2.ds / ui.c
blob7d43744765d0af5cd755b0156a75e9966b095279
1 /*
2 * TWAIN32 Options UI
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
21 #include "config.h"
23 #include <stdlib.h>
24 #include <stdarg.h>
25 #include <stdio.h>
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 "winreg.h"
35 #include "commctrl.h"
36 #include "prsht.h"
37 #include "twain.h"
38 #include "gphoto2_i.h"
39 #include "wine/debug.h"
40 #include "resource.h"
42 LPCSTR settings_key = "Software\\Wine\\Gphoto2";
43 LPCSTR settings_value = "SkipUI";
44 static BOOL disable_dialog;
45 static HBITMAP static_bitmap;
47 static INT_PTR CALLBACK ConnectingProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
49 return FALSE;
52 static void on_disable_dialog_clicked(HWND dialog)
54 if (IsDlgButtonChecked(dialog, IDC_SKIP) == BST_CHECKED)
55 disable_dialog = TRUE;
56 else
57 disable_dialog = FALSE;
60 static void UI_EndDialog(HWND hwnd, INT_PTR rc)
62 if (disable_dialog)
64 HKEY key;
65 const DWORD data = 1;
66 if (RegCreateKeyExA(HKEY_CURRENT_USER, settings_key, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &key, NULL) == ERROR_SUCCESS)
68 RegSetValueExA(key, settings_value, 0, REG_DWORD, (const BYTE *)&data, sizeof(DWORD));
69 RegCloseKey(key);
72 EndDialog(hwnd, rc);
75 static int GetAllImages()
77 struct gphoto2_file *file;
78 int has_images = 0;
80 LIST_FOR_EACH_ENTRY( file, &activeDS.files, struct gphoto2_file, entry)
82 if (strstr(file->filename,".JPG") || strstr(file->filename,".jpg"))
83 file->download = TRUE;
84 has_images = 1;
86 return has_images;
89 static void PopulateListView(HWND List)
91 struct gphoto2_file *file;
92 LVITEMA item;
93 int index = 0;
95 LIST_FOR_EACH_ENTRY( file, &activeDS.files, struct gphoto2_file, entry)
97 if (strstr(file->filename,".JPG") || strstr(file->filename,".jpg"))
99 item.mask = LVIF_PARAM | LVIF_TEXT | LVIF_IMAGE ;
100 item.iItem = index;
101 item.iSubItem = 0;
102 item.pszText = file->filename;
103 item.iImage = index;
104 item.lParam= (LPARAM)file;
106 SendMessageA(List, LVM_INSERTITEMA,0,(LPARAM)&item);
107 index ++;
112 static void PopulateImageList(HIMAGELIST *iList, HWND list)
114 struct gphoto2_file *file;
115 INT rc;
116 HWND progress_dialog;
118 progress_dialog =
119 CreateDialogW(GPHOTO2_instance,(LPWSTR)MAKEINTRESOURCE(IDD_CONNECTING),
120 NULL, ConnectingProc);
122 LIST_FOR_EACH_ENTRY( file, &activeDS.files, struct gphoto2_file, entry)
124 if (strstr(file->filename,".JPG") || strstr(file->filename,".jpg"))
126 HBITMAP bitmap;
127 BITMAP bmpInfo;
129 #ifdef HAVE_GPHOTO2
130 _get_gphoto2_file_as_DIB(file->folder, file->filename,
131 GP_FILE_TYPE_PREVIEW, 0, &bitmap);
132 #else
133 bitmap = 0;
134 #endif
135 GetObjectA(bitmap,sizeof(BITMAP),(LPVOID)&bmpInfo);
137 if (*iList == 0)
139 *iList = ImageList_Create(bmpInfo.bmWidth,
140 bmpInfo.bmHeight,ILC_COLOR24, 10,10);
142 SendMessageW(list, LVM_SETICONSPACING, 0,
143 MAKELONG(bmpInfo.bmWidth+6, bmpInfo.bmHeight+15) ); }
145 rc = ImageList_Add(*iList, bitmap, 0);
147 DeleteObject(static_bitmap);
148 static_bitmap = bitmap;
149 SendMessageW(GetDlgItem(progress_dialog,IDC_BITMAP),STM_SETIMAGE,
150 IMAGE_BITMAP, (LPARAM)static_bitmap);
151 RedrawWindow(progress_dialog,NULL,NULL,RDW_INTERNALPAINT|RDW_UPDATENOW|RDW_ALLCHILDREN);
154 EndDialog(progress_dialog,0);
158 static INT_PTR CALLBACK DialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
160 switch(msg)
162 case WM_INITDIALOG:
164 disable_dialog = FALSE;
165 EnableWindow(GetDlgItem(hwnd,IDC_IMPORT),FALSE);
167 break;
168 case WM_NOTIFY:
169 if (((LPNMHDR)lParam)->code == LVN_ITEMCHANGED)
171 HWND list = GetDlgItem(hwnd,IDC_LIST1);
172 int count = SendMessageA(list,LVM_GETSELECTEDCOUNT,0,0);
173 if (count > 0)
174 EnableWindow(GetDlgItem(hwnd,IDC_IMPORT),TRUE);
175 else
176 EnableWindow(GetDlgItem(hwnd,IDC_IMPORT),FALSE);
178 break;
179 case WM_COMMAND:
180 switch LOWORD(wParam)
182 case IDC_SKIP:
183 on_disable_dialog_clicked(hwnd);
184 break;
185 case IDC_EXIT:
186 UI_EndDialog(hwnd,0);
187 break;
188 case IDC_IMPORT:
190 HWND list = GetDlgItem(hwnd,IDC_LIST1);
191 int count = SendMessageA(list,LVM_GETSELECTEDCOUNT,0,0);
192 int i;
194 if (count ==0)
196 UI_EndDialog(hwnd,0);
197 return FALSE;
200 count = SendMessageA(list,LVM_GETITEMCOUNT,0,0);
201 for ( i = 0; i < count; i++)
203 INT state = 0x00000000;
205 state = SendMessageA(list,LVM_GETITEMSTATE,i,
206 LVIS_SELECTED);
208 if (state)
210 LVITEMA item;
211 struct gphoto2_file *file;
214 item.mask = LVIF_PARAM;
215 item.iItem = i;
217 item.iSubItem = 0;
218 SendMessageA(list,LVM_GETITEMA,0,(LPARAM)&item);
220 file = (struct gphoto2_file*)item.lParam;
221 file->download = TRUE;
225 UI_EndDialog(hwnd,1);
227 break;
228 case IDC_IMPORTALL:
230 if (!GetAllImages())
232 UI_EndDialog(hwnd,0);
233 return FALSE;
235 UI_EndDialog(hwnd,1);
237 break;
238 case IDC_FETCH:
240 HIMAGELIST ilist = 0;
241 HWND list = GetDlgItem(hwnd,IDC_LIST1);
242 PopulateImageList(&ilist,list);
244 SendMessageA(list, LVM_SETIMAGELIST,LVSIL_NORMAL,(LPARAM)ilist);
245 PopulateListView(list);
246 EnableWindow(GetDlgItem(hwnd,IDC_FETCH),FALSE);
248 break;
250 break;
252 return FALSE;
255 BOOL DoCameraUI(void)
257 HKEY key;
258 DWORD data = 0;
259 DWORD size = sizeof(data);
260 if (RegOpenKeyExA(HKEY_CURRENT_USER, settings_key, 0, KEY_READ, &key) == ERROR_SUCCESS) {
261 RegQueryValueExA(key, settings_value, NULL, NULL, (LPBYTE) &data, &size);
262 RegCloseKey(key);
263 if (data)
264 return GetAllImages();
266 return DialogBoxW(GPHOTO2_instance,
267 (LPWSTR)MAKEINTRESOURCE(IDD_CAMERAUI),NULL, DialogProc);
270 static INT_PTR CALLBACK ProgressProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
271 lParam)
273 return FALSE;
276 HWND TransferringDialogBox(HWND dialog, DWORD progress)
278 if (!dialog)
279 dialog = CreateDialogW(GPHOTO2_instance,
280 (LPWSTR)MAKEINTRESOURCE(IDD_DIALOG1), NULL, ProgressProc);
282 if (progress == -1)
284 EndDialog(dialog,0);
285 return NULL;
288 RedrawWindow(dialog,NULL,NULL,
289 RDW_INTERNALPAINT|RDW_UPDATENOW|RDW_ALLCHILDREN);
291 return dialog;