jscript: Fixed deleting property by ID from IDispatchEx interface.
[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 "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"
38
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;
43
44 static INT_PTR CALLBACK ConnectingProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
45 {
46         return FALSE;
47 }
48
49 static void on_disable_dialog_clicked(HWND dialog)
50 {
51     if (IsDlgButtonChecked(dialog, IDC_SKIP) == BST_CHECKED)
52         disable_dialog = TRUE;
53     else
54         disable_dialog = FALSE;
55 }
56
57 static void UI_EndDialog(HWND hwnd, INT_PTR rc)
58 {
59     if (disable_dialog)
60     {
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)
64         {
65             RegSetValueExA(key, settings_value, 0, REG_DWORD, (const BYTE *)&data, sizeof(DWORD));
66             RegCloseKey(key);
67         }
68     }
69     EndDialog(hwnd, rc);
70 }
71
72 static int GetAllImages(void)
73 {
74     struct gphoto2_file *file;
75     int has_images = 0;
76
77     LIST_FOR_EACH_ENTRY( file, &activeDS.files, struct gphoto2_file, entry)
78     {
79         if (strstr(file->filename,".JPG") || strstr(file->filename,".jpg"))
80         {
81             file->download = TRUE;
82             has_images = 1;
83         }
84     }
85     return has_images;
86 }
87
88 static void PopulateListView(HWND List)
89 {
90         struct gphoto2_file *file;
91         LVITEMA item;
92         int index = 0;
93
94         LIST_FOR_EACH_ENTRY( file, &activeDS.files, struct gphoto2_file, entry)
95         {
96                 if (strstr(file->filename,".JPG") || strstr(file->filename,".jpg")) 
97                 {
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;
104
105                         SendMessageA(List, LVM_INSERTITEMA,0,(LPARAM)&item);
106                         index ++;
107                 }
108         }
109 }
110
111 static void PopulateImageList(HIMAGELIST *iList, HWND list)
112 {
113         struct gphoto2_file *file;
114         HWND    progress_dialog;
115
116         progress_dialog =
117                 CreateDialogW(GPHOTO2_instance,(LPWSTR)MAKEINTRESOURCE(IDD_CONNECTING),
118                                 NULL, ConnectingProc);
119         
120         LIST_FOR_EACH_ENTRY( file, &activeDS.files, struct gphoto2_file, entry)
121         {
122                 if (strstr(file->filename,".JPG") || strstr(file->filename,".jpg")) 
123                 {
124                         HBITMAP         bitmap;
125                         BITMAP          bmpInfo;
126
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);
134
135                         if (*iList == 0)
136                         {
137                                 *iList = ImageList_Create(bmpInfo.bmWidth,
138                                                 bmpInfo.bmHeight,ILC_COLOR24, 10,10);
139
140                                 SendMessageW(list, LVM_SETICONSPACING, 0,
141                                                 MAKELONG(bmpInfo.bmWidth+6, bmpInfo.bmHeight+15) ); }
142
143                         ImageList_Add(*iList, bitmap, 0);
144
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);
150                 }
151         }
152         EndDialog(progress_dialog,0);
153         
154 }
155
156 static INT_PTR CALLBACK DialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
157 {
158         switch(msg)
159         {
160                 case WM_INITDIALOG:
161                         {
162                                 disable_dialog = FALSE;
163                                 EnableWindow(GetDlgItem(hwnd,IDC_IMPORT),FALSE);
164                         }
165                         break;
166                 case WM_NOTIFY:
167                         if (((LPNMHDR)lParam)->code == LVN_ITEMCHANGED)
168                         {
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);
175                         }
176                         break;
177                 case WM_COMMAND:
178                         switch LOWORD(wParam)
179                         {
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:
187                                         {
188                                                 HWND list = GetDlgItem(hwnd,IDC_LIST1);
189                                                 int count = SendMessageA(list,LVM_GETSELECTEDCOUNT,0,0);
190                                                 int i;
191
192                                                 if (count ==0)
193                                                 {
194                                                         UI_EndDialog(hwnd,0);
195                                                         return FALSE;
196                                                 }
197
198                                                 count = SendMessageA(list,LVM_GETITEMCOUNT,0,0);
199                                                 for ( i = 0; i < count; i++)
200                                                 {
201                                                         INT state = 0x00000000;
202
203                                                         state = SendMessageA(list,LVM_GETITEMSTATE,i,
204                                                                         LVIS_SELECTED);
205
206                                                         if (state)
207                                                         {
208                                                                 LVITEMA item;
209                                                                 struct gphoto2_file *file;
210
211
212                                                                 item.mask = LVIF_PARAM;
213                                                                 item.iItem = i;
214
215                                                                 item.iSubItem = 0;
216                                                                 SendMessageA(list,LVM_GETITEMA,0,(LPARAM)&item);
217
218                                                                 file = (struct gphoto2_file*)item.lParam;
219                                                                 file->download = TRUE;
220                                                         }
221                                                 }
222
223                                                 UI_EndDialog(hwnd,1);
224                                         }
225                                         break;
226                                 case IDC_IMPORTALL:
227                                         {
228                                                 if (!GetAllImages())
229                                                 {
230                                                         UI_EndDialog(hwnd,0);
231                                                         return FALSE;
232                                                 }
233                                                 UI_EndDialog(hwnd,1);
234                                         }
235                                         break;
236                                 case IDC_FETCH:
237                                         {
238                                                 HIMAGELIST ilist = 0;
239                                                 HWND list = GetDlgItem(hwnd,IDC_LIST1);
240                                                 PopulateImageList(&ilist,list);
241
242                                                 SendMessageA(list, LVM_SETIMAGELIST,LVSIL_NORMAL,(LPARAM)ilist);
243                                                 PopulateListView(list);
244                                                 EnableWindow(GetDlgItem(hwnd,IDC_FETCH),FALSE);
245                                         }
246                                         break;
247                         }
248                         break;
249         }
250         return FALSE;
251 }
252
253 BOOL DoCameraUI(void)
254 {
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();
263         }
264         return DialogBoxW(GPHOTO2_instance,
265                         (LPWSTR)MAKEINTRESOURCE(IDD_CAMERAUI),NULL, DialogProc);
266 }
267
268 static INT_PTR CALLBACK ProgressProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
269                 lParam)
270 {
271             return FALSE;
272 }   
273
274 HWND TransferringDialogBox(HWND dialog, LONG progress)
275 {
276         if (!dialog)
277                 dialog = CreateDialogW(GPHOTO2_instance,
278                                 (LPWSTR)MAKEINTRESOURCE(IDD_DIALOG1), NULL, ProgressProc);
279
280         if (progress == -1)
281         {
282                 EndDialog(dialog,0);
283                 return NULL;
284         }
285
286         RedrawWindow(dialog,NULL,NULL,
287                         RDW_INTERNALPAINT|RDW_UPDATENOW|RDW_ALLCHILDREN);
288
289         return dialog;
290 }