wrc: Store version and characteristics as simple integers.
[wine.git] / dlls / gphoto2.ds / ui.c
bloba385b1139cb7b85ae1e99b2d231e8def7246342f
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 <stdlib.h>
22 #include <stdarg.h>
23 #include <stdio.h>
25 #include "gphoto2_i.h"
26 #include "winuser.h"
27 #include "winnls.h"
28 #include "wingdi.h"
29 #include "winreg.h"
30 #include "commctrl.h"
31 #include "prsht.h"
32 #include "unixlib.h"
33 #include "wine/debug.h"
34 #include "resource.h"
36 static const char settings_key[] = "Software\\Wine\\Gphoto2";
37 static const char settings_value[] = "SkipUI";
38 static BOOL disable_dialog;
39 static HBITMAP static_bitmap;
41 static INT_PTR CALLBACK ConnectingProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
43 return FALSE;
46 static void on_disable_dialog_clicked(HWND dialog)
48 if (IsDlgButtonChecked(dialog, IDC_SKIP) == BST_CHECKED)
49 disable_dialog = TRUE;
50 else
51 disable_dialog = FALSE;
54 static void UI_EndDialog(HWND hwnd, INT_PTR rc)
56 if (disable_dialog)
58 HKEY key;
59 const DWORD data = 1;
60 if (RegCreateKeyExA(HKEY_CURRENT_USER, settings_key, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &key, NULL) == ERROR_SUCCESS)
62 RegSetValueExA(key, settings_value, 0, REG_DWORD, (const BYTE *)&data, sizeof(DWORD));
63 RegCloseKey(key);
66 EndDialog(hwnd, rc);
69 static BOOL GetAllImages(void)
71 unsigned int i;
73 for (i = 0; i < activeDS.file_count; i++) activeDS.download_flags[i] = TRUE;
74 activeDS.download_count = activeDS.file_count;
75 return activeDS.download_count > 0;
78 static void PopulateListView(HWND List)
80 LVITEMA item;
81 char buffer[1024];
82 struct get_file_name_params params = { 0, sizeof(buffer), buffer };
84 for (params.idx = 0; params.idx < activeDS.file_count; params.idx++)
86 GPHOTO2_CALL( get_file_name, &params );
87 item.mask = LVIF_PARAM | LVIF_TEXT | LVIF_IMAGE;
88 item.iItem = params.idx;
89 item.iSubItem = 0;
90 item.pszText = buffer;
91 item.iImage = params.idx;
92 item.lParam = 0;
93 SendMessageA(List, LVM_INSERTITEMA,0,(LPARAM)&item);
97 static void PopulateImageList(HIMAGELIST *iList, HWND list)
99 unsigned int i;
100 HWND progress_dialog;
102 progress_dialog =
103 CreateDialogW(GPHOTO2_instance,(LPWSTR)MAKEINTRESOURCE(IDD_CONNECTING),
104 NULL, ConnectingProc);
106 for (i = 0; i < activeDS.file_count; i++)
108 HBITMAP bitmap;
109 BITMAP bmpInfo;
111 _get_gphoto2_file_as_DIB( i, TRUE, 0, &bitmap );
112 GetObjectA(bitmap,sizeof(BITMAP),&bmpInfo);
114 if (*iList == 0)
116 *iList = ImageList_Create(bmpInfo.bmWidth,
117 bmpInfo.bmHeight,ILC_COLOR24, 10,10);
119 SendMessageW(list, LVM_SETICONSPACING, 0,
120 MAKELONG(bmpInfo.bmWidth+6, bmpInfo.bmHeight+15) ); }
122 ImageList_Add(*iList, bitmap, 0);
124 DeleteObject(static_bitmap);
125 static_bitmap = bitmap;
126 SendMessageW(GetDlgItem(progress_dialog,IDC_BITMAP),STM_SETIMAGE,
127 IMAGE_BITMAP, (LPARAM)static_bitmap);
128 RedrawWindow(progress_dialog,NULL,NULL,RDW_INTERNALPAINT|RDW_UPDATENOW|RDW_ALLCHILDREN);
130 EndDialog(progress_dialog,0);
133 static INT_PTR CALLBACK DialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
135 switch(msg)
137 case WM_INITDIALOG:
139 disable_dialog = FALSE;
140 EnableWindow(GetDlgItem(hwnd,IDC_IMPORT),FALSE);
142 break;
143 case WM_NOTIFY:
144 if (((LPNMHDR)lParam)->code == LVN_ITEMCHANGED)
146 HWND list = GetDlgItem(hwnd,IDC_LIST1);
147 int count = SendMessageA(list,LVM_GETSELECTEDCOUNT,0,0);
148 if (count > 0)
149 EnableWindow(GetDlgItem(hwnd,IDC_IMPORT),TRUE);
150 else
151 EnableWindow(GetDlgItem(hwnd,IDC_IMPORT),FALSE);
153 break;
154 case WM_COMMAND:
155 switch (LOWORD(wParam))
157 case IDC_SKIP:
158 on_disable_dialog_clicked(hwnd);
159 break;
160 case IDC_EXIT:
161 UI_EndDialog(hwnd,0);
162 break;
163 case IDC_IMPORT:
165 HWND list = GetDlgItem(hwnd,IDC_LIST1);
166 unsigned int i;
168 if (activeDS.file_count == 0)
170 UI_EndDialog(hwnd,0);
171 return FALSE;
174 for (i = 0; i < activeDS.file_count; i++)
176 if (SendMessageA(list,LVM_GETITEMSTATE,i, LVIS_SELECTED))
178 if (!activeDS.download_flags[i]) activeDS.download_count++;
179 activeDS.download_flags[i] = TRUE;
183 UI_EndDialog(hwnd,1);
185 break;
186 case IDC_IMPORTALL:
188 if (!GetAllImages())
190 UI_EndDialog(hwnd,0);
191 return FALSE;
193 UI_EndDialog(hwnd,1);
195 break;
196 case IDC_FETCH:
198 HIMAGELIST ilist = 0;
199 HWND list = GetDlgItem(hwnd,IDC_LIST1);
200 PopulateImageList(&ilist,list);
202 SendMessageA(list, LVM_SETIMAGELIST,LVSIL_NORMAL,(LPARAM)ilist);
203 PopulateListView(list);
204 EnableWindow(GetDlgItem(hwnd,IDC_FETCH),FALSE);
206 break;
208 break;
210 return FALSE;
213 BOOL DoCameraUI(void)
215 HKEY key;
216 DWORD data = 0;
217 DWORD size = sizeof(data);
218 if (RegOpenKeyExA(HKEY_CURRENT_USER, settings_key, 0, KEY_READ, &key) == ERROR_SUCCESS) {
219 RegQueryValueExA(key, settings_value, NULL, NULL, (LPBYTE) &data, &size);
220 RegCloseKey(key);
221 if (data)
222 return GetAllImages();
224 return DialogBoxW(GPHOTO2_instance,
225 (LPWSTR)MAKEINTRESOURCE(IDD_CAMERAUI),NULL, DialogProc);
228 static INT_PTR CALLBACK ProgressProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
229 lParam)
231 return FALSE;
234 HWND TransferringDialogBox(HWND dialog, LONG progress)
236 if (!dialog)
237 dialog = CreateDialogW(GPHOTO2_instance,
238 (LPWSTR)MAKEINTRESOURCE(IDD_DIALOG1), NULL, ProgressProc);
240 if (progress == -1)
242 EndDialog(dialog,0);
243 return NULL;
246 RedrawWindow(dialog,NULL,NULL,
247 RDW_INTERNALPAINT|RDW_UPDATENOW|RDW_ALLCHILDREN);
249 return dialog;