msi: Move the preview code to dialog.c.
[wine/multimedia.git] / dlls / gphoto2.ds / ui.c
blobdf798754536bc0e54b681dfdf3f270df1f5cbd45
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 "gphoto2_i.h"
30 #include "winuser.h"
31 #include "winnls.h"
32 #include "wingdi.h"
33 #include "winreg.h"
34 #include "commctrl.h"
35 #include "prsht.h"
36 #include "wine/debug.h"
37 #include "resource.h"
39 static const char settings_key[] = "Software\\Wine\\Gphoto2";
40 static const char settings_value[] = "SkipUI";
41 static BOOL disable_dialog;
42 static HBITMAP static_bitmap;
44 static INT_PTR CALLBACK ConnectingProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
46 return FALSE;
49 static void on_disable_dialog_clicked(HWND dialog)
51 if (IsDlgButtonChecked(dialog, IDC_SKIP) == BST_CHECKED)
52 disable_dialog = TRUE;
53 else
54 disable_dialog = FALSE;
57 static void UI_EndDialog(HWND hwnd, INT_PTR rc)
59 if (disable_dialog)
61 HKEY key;
62 const DWORD data = 1;
63 if (RegCreateKeyExA(HKEY_CURRENT_USER, settings_key, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &key, NULL) == ERROR_SUCCESS)
65 RegSetValueExA(key, settings_value, 0, REG_DWORD, (const BYTE *)&data, sizeof(DWORD));
66 RegCloseKey(key);
69 EndDialog(hwnd, rc);
72 static int GetAllImages(void)
74 struct gphoto2_file *file;
75 int has_images = 0;
77 LIST_FOR_EACH_ENTRY( file, &activeDS.files, struct gphoto2_file, entry)
79 if (strstr(file->filename,".JPG") || strstr(file->filename,".jpg"))
81 file->download = TRUE;
82 has_images = 1;
85 return has_images;
88 static void PopulateListView(HWND List)
90 struct gphoto2_file *file;
91 LVITEMA item;
92 int index = 0;
94 LIST_FOR_EACH_ENTRY( file, &activeDS.files, struct gphoto2_file, entry)
96 if (strstr(file->filename,".JPG") || strstr(file->filename,".jpg"))
98 item.mask = LVIF_PARAM | LVIF_TEXT | LVIF_IMAGE ;
99 item.iItem = index;
100 item.iSubItem = 0;
101 item.pszText = file->filename;
102 item.iImage = index;
103 item.lParam= (LPARAM)file;
105 SendMessageA(List, LVM_INSERTITEMA,0,(LPARAM)&item);
106 index ++;
111 static void PopulateImageList(HIMAGELIST *iList, HWND list)
113 struct gphoto2_file *file;
114 HWND progress_dialog;
116 progress_dialog =
117 CreateDialogW(GPHOTO2_instance,(LPWSTR)MAKEINTRESOURCE(IDD_CONNECTING),
118 NULL, ConnectingProc);
120 LIST_FOR_EACH_ENTRY( file, &activeDS.files, struct gphoto2_file, entry)
122 if (strstr(file->filename,".JPG") || strstr(file->filename,".jpg"))
124 HBITMAP bitmap;
125 BITMAP bmpInfo;
127 #ifdef HAVE_GPHOTO2
128 _get_gphoto2_file_as_DIB(file->folder, file->filename,
129 GP_FILE_TYPE_PREVIEW, 0, &bitmap);
130 #else
131 bitmap = 0;
132 #endif
133 GetObjectA(bitmap,sizeof(BITMAP),&bmpInfo);
135 if (*iList == 0)
137 *iList = ImageList_Create(bmpInfo.bmWidth,
138 bmpInfo.bmHeight,ILC_COLOR24, 10,10);
140 SendMessageW(list, LVM_SETICONSPACING, 0,
141 MAKELONG(bmpInfo.bmWidth+6, bmpInfo.bmHeight+15) ); }
143 ImageList_Add(*iList, bitmap, 0);
145 DeleteObject(static_bitmap);
146 static_bitmap = bitmap;
147 SendMessageW(GetDlgItem(progress_dialog,IDC_BITMAP),STM_SETIMAGE,
148 IMAGE_BITMAP, (LPARAM)static_bitmap);
149 RedrawWindow(progress_dialog,NULL,NULL,RDW_INTERNALPAINT|RDW_UPDATENOW|RDW_ALLCHILDREN);
152 EndDialog(progress_dialog,0);
156 static INT_PTR CALLBACK DialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
158 switch(msg)
160 case WM_INITDIALOG:
162 disable_dialog = FALSE;
163 EnableWindow(GetDlgItem(hwnd,IDC_IMPORT),FALSE);
165 break;
166 case WM_NOTIFY:
167 if (((LPNMHDR)lParam)->code == LVN_ITEMCHANGED)
169 HWND list = GetDlgItem(hwnd,IDC_LIST1);
170 int count = SendMessageA(list,LVM_GETSELECTEDCOUNT,0,0);
171 if (count > 0)
172 EnableWindow(GetDlgItem(hwnd,IDC_IMPORT),TRUE);
173 else
174 EnableWindow(GetDlgItem(hwnd,IDC_IMPORT),FALSE);
176 break;
177 case WM_COMMAND:
178 switch LOWORD(wParam)
180 case IDC_SKIP:
181 on_disable_dialog_clicked(hwnd);
182 break;
183 case IDC_EXIT:
184 UI_EndDialog(hwnd,0);
185 break;
186 case IDC_IMPORT:
188 HWND list = GetDlgItem(hwnd,IDC_LIST1);
189 int count = SendMessageA(list,LVM_GETSELECTEDCOUNT,0,0);
190 int i;
192 if (count ==0)
194 UI_EndDialog(hwnd,0);
195 return FALSE;
198 count = SendMessageA(list,LVM_GETITEMCOUNT,0,0);
199 for ( i = 0; i < count; i++)
201 INT state = 0x00000000;
203 state = SendMessageA(list,LVM_GETITEMSTATE,i,
204 LVIS_SELECTED);
206 if (state)
208 LVITEMA item;
209 struct gphoto2_file *file;
212 item.mask = LVIF_PARAM;
213 item.iItem = i;
215 item.iSubItem = 0;
216 SendMessageA(list,LVM_GETITEMA,0,(LPARAM)&item);
218 file = (struct gphoto2_file*)item.lParam;
219 file->download = TRUE;
223 UI_EndDialog(hwnd,1);
225 break;
226 case IDC_IMPORTALL:
228 if (!GetAllImages())
230 UI_EndDialog(hwnd,0);
231 return FALSE;
233 UI_EndDialog(hwnd,1);
235 break;
236 case IDC_FETCH:
238 HIMAGELIST ilist = 0;
239 HWND list = GetDlgItem(hwnd,IDC_LIST1);
240 PopulateImageList(&ilist,list);
242 SendMessageA(list, LVM_SETIMAGELIST,LVSIL_NORMAL,(LPARAM)ilist);
243 PopulateListView(list);
244 EnableWindow(GetDlgItem(hwnd,IDC_FETCH),FALSE);
246 break;
248 break;
250 return FALSE;
253 BOOL DoCameraUI(void)
255 HKEY key;
256 DWORD data = 0;
257 DWORD size = sizeof(data);
258 if (RegOpenKeyExA(HKEY_CURRENT_USER, settings_key, 0, KEY_READ, &key) == ERROR_SUCCESS) {
259 RegQueryValueExA(key, settings_value, NULL, NULL, (LPBYTE) &data, &size);
260 RegCloseKey(key);
261 if (data)
262 return GetAllImages();
264 return DialogBoxW(GPHOTO2_instance,
265 (LPWSTR)MAKEINTRESOURCE(IDD_CAMERAUI),NULL, DialogProc);
268 static INT_PTR CALLBACK ProgressProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
269 lParam)
271 return FALSE;
274 HWND TransferringDialogBox(HWND dialog, LONG progress)
276 if (!dialog)
277 dialog = CreateDialogW(GPHOTO2_instance,
278 (LPWSTR)MAKEINTRESOURCE(IDD_DIALOG1), NULL, ProgressProc);
280 if (progress == -1)
282 EndDialog(dialog,0);
283 return NULL;
286 RedrawWindow(dialog,NULL,NULL,
287 RDW_INTERNALPAINT|RDW_UPDATENOW|RDW_ALLCHILDREN);
289 return dialog;