user32: Fix TabbedTextOut.
[wine/wine-kai.git] / dlls / gphoto2.ds / ui.c
blobe709984fac7643ae4b1a0ff6dfec4a802a3a8629
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 "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 static HBITMAP static_bitmap;
43 static INT_PTR CALLBACK ConnectingProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
45 return FALSE;
48 static void PopulateListView(HWND List)
50 struct gphoto2_file *file;
51 LVITEMA item;
52 int index = 0;
54 LIST_FOR_EACH_ENTRY( file, &activeDS.files, struct gphoto2_file, entry)
56 if (strstr(file->filename,".JPG") || strstr(file->filename,".jpg"))
58 item.mask = LVIF_PARAM | LVIF_TEXT | LVIF_IMAGE ;
59 item.iItem = index;
60 item.iSubItem = 0;
61 item.pszText = file->filename;
62 item.iImage = index;
63 item.lParam= (LPARAM)file;
65 SendMessageA(List, LVM_INSERTITEMA,0,(LPARAM)&item);
66 index ++;
71 static void PopulateImageList(HIMAGELIST *iList, HWND list)
73 struct gphoto2_file *file;
74 INT rc;
75 HWND progress_dialog;
77 progress_dialog =
78 CreateDialogW(GPHOTO2_instance,(LPWSTR)MAKEINTRESOURCE(IDD_CONNECTING),
79 NULL, ConnectingProc);
81 LIST_FOR_EACH_ENTRY( file, &activeDS.files, struct gphoto2_file, entry)
83 if (strstr(file->filename,".JPG") || strstr(file->filename,".jpg"))
85 HBITMAP bitmap;
86 BITMAP bmpInfo;
88 #ifdef HAVE_GPHOTO2
89 _get_gphoto2_file_as_DIB(file->folder, file->filename,
90 GP_FILE_TYPE_PREVIEW, 0, &bitmap);
91 #else
92 bitmap = 0;
93 #endif
94 GetObjectA(bitmap,sizeof(BITMAP),(LPVOID)&bmpInfo);
96 if (*iList == 0)
98 *iList = ImageList_Create(bmpInfo.bmWidth,
99 bmpInfo.bmHeight,ILC_COLOR24, 10,10);
101 SendMessageW(list, LVM_SETICONSPACING, 0,
102 MAKELONG(bmpInfo.bmWidth+6, bmpInfo.bmHeight+15) ); }
104 rc = ImageList_Add(*iList, bitmap, 0);
106 DeleteObject(static_bitmap);
107 static_bitmap = bitmap;
108 SendMessageW(GetDlgItem(progress_dialog,IDC_BITMAP),STM_SETIMAGE,
109 IMAGE_BITMAP, (LPARAM)static_bitmap);
110 RedrawWindow(progress_dialog,NULL,NULL,RDW_INTERNALPAINT|RDW_UPDATENOW|RDW_ALLCHILDREN);
113 EndDialog(progress_dialog,0);
117 static INT_PTR CALLBACK DialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
119 switch(msg)
121 case WM_INITDIALOG:
123 HIMAGELIST ilist = 0;
124 HWND list = GetDlgItem(hwnd,IDC_LIST1);
125 EnableWindow(GetDlgItem(hwnd,IDC_IMPORT),FALSE);
127 PopulateImageList(&ilist,list);
129 SendMessageA(list, LVM_SETIMAGELIST,LVSIL_NORMAL,(LPARAM)ilist);
130 PopulateListView(list);
132 break;
133 case WM_NOTIFY:
134 if (((LPNMHDR)lParam)->code == LVN_ITEMCHANGED)
136 HWND list = GetDlgItem(hwnd,IDC_LIST1);
137 int count = SendMessageA(list,LVM_GETSELECTEDCOUNT,0,0);
138 if (count > 0)
139 EnableWindow(GetDlgItem(hwnd,IDC_IMPORT),TRUE);
140 else
141 EnableWindow(GetDlgItem(hwnd,IDC_IMPORT),FALSE);
143 break;
144 case WM_COMMAND:
145 switch LOWORD(wParam)
147 case IDC_EXIT:
148 EndDialog(hwnd,0);
149 break;
150 case IDC_IMPORT:
152 HWND list = GetDlgItem(hwnd,IDC_LIST1);
153 int count = SendMessageA(list,LVM_GETSELECTEDCOUNT,0,0);
154 int i;
156 if (count ==0)
158 EndDialog(hwnd,0);
159 return FALSE;
162 count = SendMessageA(list,LVM_GETITEMCOUNT,0,0);
163 for ( i = 0; i < count; i++)
165 INT state = 0x00000000;
167 state = SendMessageA(list,LVM_GETITEMSTATE,i,
168 LVIS_SELECTED);
170 if (state)
172 LVITEMA item;
173 struct gphoto2_file *file;
176 item.mask = LVIF_PARAM;
177 item.iItem = i;
179 item.iSubItem = 0;
180 SendMessageA(list,LVM_GETITEMA,0,(LPARAM)&item);
182 file = (struct gphoto2_file*)item.lParam;
183 file->download = TRUE;
187 EndDialog(hwnd,1);
189 break;
190 case IDC_IMPORTALL:
192 HWND list = GetDlgItem(hwnd,IDC_LIST1);
193 int count = SendMessageA(list,LVM_GETITEMCOUNT,0,0);
194 int i;
196 if (count ==0)
198 EndDialog(hwnd,0);
199 return FALSE;
202 for ( i = 0; i < count; i++)
204 LVITEMA item;
205 struct gphoto2_file *file;
208 item.mask = LVIF_PARAM;
209 item.iItem = i;
210 item.iSubItem = 0;
212 SendMessageA(list,LVM_GETITEMA,0,(LPARAM)&item);
214 file = (struct gphoto2_file*)item.lParam;
215 file->download = TRUE;
218 EndDialog(hwnd,1);
220 break;
222 break;
224 return FALSE;
227 BOOL DoCameraUI(void)
229 return DialogBoxW(GPHOTO2_instance,
230 (LPWSTR)MAKEINTRESOURCE(IDD_CAMERAUI),NULL, DialogProc);
233 static INT_PTR CALLBACK ProgressProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
234 lParam)
236 return FALSE;
239 HWND TransferringDialogBox(HWND dialog, DWORD progress)
241 if (!dialog)
242 dialog = CreateDialogW(GPHOTO2_instance,
243 (LPWSTR)MAKEINTRESOURCE(IDD_DIALOG1), NULL, ProgressProc);
245 if (progress == -1)
247 EndDialog(dialog,0);
248 return NULL;
251 RedrawWindow(dialog,NULL,NULL,
252 RDW_INTERNALPAINT|RDW_UPDATENOW|RDW_ALLCHILDREN);
254 return dialog;