gphoto2.ds: Spelling fix.
[wine.git] / dlls / gphoto2.ds / ui.c
blob1a6476aa67ea16c21b6a5d81b9ea03494c2869bf
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 "commctrl.h"
35 #include "prsht.h"
36 #include "twain.h"
37 #include "gphoto2_i.h"
38 #include "wine/debug.h"
39 #include "resource.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(twain);
43 static HBITMAP static_bitmap;
45 static INT_PTR CALLBACK ConnectingProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
47 return FALSE;
50 static void PopulateListView(HWND List)
52 struct gphoto2_file *file;
53 LVITEMA item;
54 int index = 0;
56 LIST_FOR_EACH_ENTRY( file, &activeDS.files, struct gphoto2_file, entry)
58 if (strstr(file->filename,".JPG") || strstr(file->filename,".jpg"))
60 memset(&item,0,sizeof(item));
61 item.mask = LVIF_PARAM | LVIF_TEXT | LVIF_IMAGE ;
62 item.iItem = index;
63 item.pszText = file->filename;
64 item.iImage = index;
65 item.lParam= (LPARAM)file;
67 SendMessageA(List, LVM_INSERTITEMA,0,(LPARAM)&item);
68 index ++;
73 static void PopulateImageList(HIMAGELIST *iList, HWND list)
75 struct gphoto2_file *file;
76 INT rc;
77 HWND progress_dialog;
79 progress_dialog =
80 CreateDialogW(GPHOTO2_instance,(LPWSTR)MAKEINTRESOURCE(IDD_CONNECTING),
81 NULL, ConnectingProc);
83 LIST_FOR_EACH_ENTRY( file, &activeDS.files, struct gphoto2_file, entry)
85 if (strstr(file->filename,".JPG") || strstr(file->filename,".jpg"))
87 HBITMAP bitmap;
88 BITMAP bmpInfo;
90 #ifdef HAVE_GPHOTO2
91 _get_gphoto2_file_as_DIB(file->folder, file->filename,
92 GP_FILE_TYPE_PREVIEW, 0, &bitmap);
93 #else
94 bitmap = 0;
95 #endif
96 GetObjectA(bitmap,sizeof(BITMAP),(LPVOID)&bmpInfo);
98 if (*iList == 0)
100 *iList = ImageList_Create(bmpInfo.bmWidth,
101 bmpInfo.bmHeight,ILC_COLOR24, 10,10);
103 SendMessageW(list, LVM_SETICONSPACING, 0,
104 MAKELONG(bmpInfo.bmWidth+6, bmpInfo.bmHeight+15) ); }
106 rc = ImageList_Add(*iList, bitmap, 0);
108 DeleteObject(static_bitmap);
109 static_bitmap = bitmap;
110 SendMessageW(GetDlgItem(progress_dialog,IDC_BITMAP),STM_SETIMAGE,
111 IMAGE_BITMAP, (LPARAM)static_bitmap);
112 RedrawWindow(progress_dialog,NULL,NULL,RDW_INTERNALPAINT|RDW_UPDATENOW|RDW_ALLCHILDREN);
115 EndDialog(progress_dialog,0);
119 static INT_PTR CALLBACK DialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
121 switch(msg)
123 case WM_INITDIALOG:
125 HIMAGELIST ilist = 0;
126 HWND list = GetDlgItem(hwnd,IDC_LIST1);
127 EnableWindow(GetDlgItem(hwnd,IDC_IMPORT),FALSE);
129 PopulateImageList(&ilist,list);
131 SendMessageA(list, LVM_SETIMAGELIST,LVSIL_NORMAL,(LPARAM)ilist);
132 PopulateListView(list);
134 break;
135 case WM_NOTIFY:
136 if (((LPNMHDR)lParam)->code == LVN_ITEMCHANGED)
138 HWND list = GetDlgItem(hwnd,IDC_LIST1);
139 int count = SendMessageA(list,LVM_GETSELECTEDCOUNT,0,0);
140 if (count > 0)
141 EnableWindow(GetDlgItem(hwnd,IDC_IMPORT),TRUE);
142 else
143 EnableWindow(GetDlgItem(hwnd,IDC_IMPORT),FALSE);
145 break;
146 case WM_COMMAND:
147 switch LOWORD(wParam)
149 case IDC_EXIT:
150 EndDialog(hwnd,0);
151 break;
152 case IDC_IMPORT:
154 HWND list = GetDlgItem(hwnd,IDC_LIST1);
155 int count = SendMessageA(list,LVM_GETSELECTEDCOUNT,0,0);
156 int i;
158 if (count ==0)
160 EndDialog(hwnd,0);
161 return FALSE;
164 count = SendMessageA(list,LVM_GETITEMCOUNT,0,0);
165 for ( i = 0; i < count; i++)
167 INT state = 0x00000000;
169 state = SendMessageA(list,LVM_GETITEMSTATE,i,
170 LVIS_SELECTED);
172 if (state)
174 LVITEMA item;
175 struct gphoto2_file *file;
177 memset(&item,0,sizeof(item));
179 item.mask = LVIF_PARAM;
180 item.iItem = i;
182 SendMessageA(list,LVM_GETITEMA,0,(LPARAM)&item);
184 file = (struct gphoto2_file*)item.lParam;
185 file->download = TRUE;
189 EndDialog(hwnd,1);
191 break;
192 case IDC_IMPORTALL:
194 HWND list = GetDlgItem(hwnd,IDC_LIST1);
195 int count = SendMessageA(list,LVM_GETITEMCOUNT,0,0);
196 int i;
198 if (count ==0)
200 EndDialog(hwnd,0);
201 return FALSE;
204 for ( i = 0; i < count; i++)
206 LVITEMA item;
207 struct gphoto2_file *file;
209 memset(&item,0,sizeof(item));
211 item.mask = LVIF_PARAM;
212 item.iItem = i;
214 SendMessageA(list,LVM_GETITEMA,0,(LPARAM)&item);
216 file = (struct gphoto2_file*)item.lParam;
217 file->download = TRUE;
220 EndDialog(hwnd,1);
222 break;
224 break;
226 return FALSE;
229 BOOL DoCameraUI()
231 return DialogBoxW(GPHOTO2_instance,
232 (LPWSTR)MAKEINTRESOURCE(IDD_CAMERAUI),NULL, DialogProc);
235 static INT_PTR CALLBACK ProgressProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
236 lParam)
238 return FALSE;
241 HWND TransferringDialogBox(HWND dialog, DWORD progress)
243 if (!dialog)
244 dialog = CreateDialogW(GPHOTO2_instance,
245 (LPWSTR)MAKEINTRESOURCE(IDD_DIALOG1), NULL, ProgressProc);
247 if (progress == -1)
249 EndDialog(dialog,0);
250 return NULL;
253 RedrawWindow(dialog,NULL,NULL,
254 RDW_INTERNALPAINT|RDW_UPDATENOW|RDW_ALLCHILDREN);
256 return dialog;