kernelbase: Use the correct machine type for ARM.
[wine/zf.git] / dlls / gphoto2.ds / ui.c
blobc521e3e29cf0cb7c0840a98dfe7eabe41b7b5220
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 #include "gphoto2_i.h"
28 #include "winuser.h"
29 #include "winnls.h"
30 #include "wingdi.h"
31 #include "winreg.h"
32 #include "commctrl.h"
33 #include "prsht.h"
34 #include "wine/debug.h"
35 #include "resource.h"
37 static const char settings_key[] = "Software\\Wine\\Gphoto2";
38 static const char settings_value[] = "SkipUI";
39 static BOOL disable_dialog;
40 static HBITMAP static_bitmap;
42 static INT_PTR CALLBACK ConnectingProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
44 return FALSE;
47 static void on_disable_dialog_clicked(HWND dialog)
49 if (IsDlgButtonChecked(dialog, IDC_SKIP) == BST_CHECKED)
50 disable_dialog = TRUE;
51 else
52 disable_dialog = FALSE;
55 static void UI_EndDialog(HWND hwnd, INT_PTR rc)
57 if (disable_dialog)
59 HKEY key;
60 const DWORD data = 1;
61 if (RegCreateKeyExA(HKEY_CURRENT_USER, settings_key, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &key, NULL) == ERROR_SUCCESS)
63 RegSetValueExA(key, settings_value, 0, REG_DWORD, (const BYTE *)&data, sizeof(DWORD));
64 RegCloseKey(key);
67 EndDialog(hwnd, rc);
70 static BOOL GetAllImages(void)
72 struct gphoto2_file *file;
73 BOOL has_images = FALSE;
75 LIST_FOR_EACH_ENTRY( file, &activeDS.files, struct gphoto2_file, entry)
77 if (strstr(file->filename,".JPG") || strstr(file->filename,".jpg"))
79 file->download = TRUE;
80 has_images = TRUE;
83 return has_images;
86 static void PopulateListView(HWND List)
88 struct gphoto2_file *file;
89 LVITEMA item;
90 int index = 0;
92 LIST_FOR_EACH_ENTRY( file, &activeDS.files, struct gphoto2_file, entry)
94 if (strstr(file->filename,".JPG") || strstr(file->filename,".jpg"))
96 item.mask = LVIF_PARAM | LVIF_TEXT | LVIF_IMAGE ;
97 item.iItem = index;
98 item.iSubItem = 0;
99 item.pszText = file->filename;
100 item.iImage = index;
101 item.lParam= (LPARAM)file;
103 SendMessageA(List, LVM_INSERTITEMA,0,(LPARAM)&item);
104 index ++;
109 static void PopulateImageList(HIMAGELIST *iList, HWND list)
111 struct gphoto2_file *file;
112 HWND progress_dialog;
114 progress_dialog =
115 CreateDialogW(GPHOTO2_instance,(LPWSTR)MAKEINTRESOURCE(IDD_CONNECTING),
116 NULL, ConnectingProc);
118 LIST_FOR_EACH_ENTRY( file, &activeDS.files, struct gphoto2_file, entry)
120 if (strstr(file->filename,".JPG") || strstr(file->filename,".jpg"))
122 HBITMAP bitmap;
123 BITMAP bmpInfo;
125 #ifdef HAVE_GPHOTO2
126 _get_gphoto2_file_as_DIB(file->folder, file->filename,
127 GP_FILE_TYPE_PREVIEW, 0, &bitmap);
128 #else
129 bitmap = 0;
130 #endif
131 GetObjectA(bitmap,sizeof(BITMAP),&bmpInfo);
133 if (*iList == 0)
135 *iList = ImageList_Create(bmpInfo.bmWidth,
136 bmpInfo.bmHeight,ILC_COLOR24, 10,10);
138 SendMessageW(list, LVM_SETICONSPACING, 0,
139 MAKELONG(bmpInfo.bmWidth+6, bmpInfo.bmHeight+15) ); }
141 ImageList_Add(*iList, bitmap, 0);
143 DeleteObject(static_bitmap);
144 static_bitmap = bitmap;
145 SendMessageW(GetDlgItem(progress_dialog,IDC_BITMAP),STM_SETIMAGE,
146 IMAGE_BITMAP, (LPARAM)static_bitmap);
147 RedrawWindow(progress_dialog,NULL,NULL,RDW_INTERNALPAINT|RDW_UPDATENOW|RDW_ALLCHILDREN);
150 EndDialog(progress_dialog,0);
154 static INT_PTR CALLBACK DialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
156 switch(msg)
158 case WM_INITDIALOG:
160 disable_dialog = FALSE;
161 EnableWindow(GetDlgItem(hwnd,IDC_IMPORT),FALSE);
163 break;
164 case WM_NOTIFY:
165 if (((LPNMHDR)lParam)->code == LVN_ITEMCHANGED)
167 HWND list = GetDlgItem(hwnd,IDC_LIST1);
168 int count = SendMessageA(list,LVM_GETSELECTEDCOUNT,0,0);
169 if (count > 0)
170 EnableWindow(GetDlgItem(hwnd,IDC_IMPORT),TRUE);
171 else
172 EnableWindow(GetDlgItem(hwnd,IDC_IMPORT),FALSE);
174 break;
175 case WM_COMMAND:
176 switch (LOWORD(wParam))
178 case IDC_SKIP:
179 on_disable_dialog_clicked(hwnd);
180 break;
181 case IDC_EXIT:
182 UI_EndDialog(hwnd,0);
183 break;
184 case IDC_IMPORT:
186 HWND list = GetDlgItem(hwnd,IDC_LIST1);
187 int count = SendMessageA(list,LVM_GETSELECTEDCOUNT,0,0);
188 int i;
190 if (count ==0)
192 UI_EndDialog(hwnd,0);
193 return FALSE;
196 count = SendMessageA(list,LVM_GETITEMCOUNT,0,0);
197 for ( i = 0; i < count; i++)
199 INT state = 0x00000000;
201 state = SendMessageA(list,LVM_GETITEMSTATE,i,
202 LVIS_SELECTED);
204 if (state)
206 LVITEMA item;
207 struct gphoto2_file *file;
210 item.mask = LVIF_PARAM;
211 item.iItem = i;
213 item.iSubItem = 0;
214 SendMessageA(list,LVM_GETITEMA,0,(LPARAM)&item);
216 file = (struct gphoto2_file*)item.lParam;
217 file->download = TRUE;
221 UI_EndDialog(hwnd,1);
223 break;
224 case IDC_IMPORTALL:
226 if (!GetAllImages())
228 UI_EndDialog(hwnd,0);
229 return FALSE;
231 UI_EndDialog(hwnd,1);
233 break;
234 case IDC_FETCH:
236 HIMAGELIST ilist = 0;
237 HWND list = GetDlgItem(hwnd,IDC_LIST1);
238 PopulateImageList(&ilist,list);
240 SendMessageA(list, LVM_SETIMAGELIST,LVSIL_NORMAL,(LPARAM)ilist);
241 PopulateListView(list);
242 EnableWindow(GetDlgItem(hwnd,IDC_FETCH),FALSE);
244 break;
246 break;
248 return FALSE;
251 BOOL DoCameraUI(void)
253 HKEY key;
254 DWORD data = 0;
255 DWORD size = sizeof(data);
256 if (RegOpenKeyExA(HKEY_CURRENT_USER, settings_key, 0, KEY_READ, &key) == ERROR_SUCCESS) {
257 RegQueryValueExA(key, settings_value, NULL, NULL, (LPBYTE) &data, &size);
258 RegCloseKey(key);
259 if (data)
260 return GetAllImages();
262 return DialogBoxW(GPHOTO2_instance,
263 (LPWSTR)MAKEINTRESOURCE(IDD_CAMERAUI),NULL, DialogProc);
266 static INT_PTR CALLBACK ProgressProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
267 lParam)
269 return FALSE;
272 HWND TransferringDialogBox(HWND dialog, LONG progress)
274 if (!dialog)
275 dialog = CreateDialogW(GPHOTO2_instance,
276 (LPWSTR)MAKEINTRESOURCE(IDD_DIALOG1), NULL, ProgressProc);
278 if (progress == -1)
280 EndDialog(dialog,0);
281 return NULL;
284 RedrawWindow(dialog,NULL,NULL,
285 RDW_INTERNALPAINT|RDW_UPDATENOW|RDW_ALLCHILDREN);
287 return dialog;