rpcrt4: CContext can be NULL in NDRCContextMarshall, in which case we should marshall...
[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 "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"
40
41 WINE_DEFAULT_DEBUG_CHANNEL(twain);
42
43 static HBITMAP static_bitmap;
44
45 static INT_PTR CALLBACK ConnectingProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
46 {
47         return FALSE;
48 }
49
50 static void PopulateListView(HWND List)
51 {
52         struct gphoto2_file *file;
53         LVITEMA item;
54         int index = 0;
55
56         LIST_FOR_EACH_ENTRY( file, &activeDS.files, struct gphoto2_file, entry)
57         {
58                 if (strstr(file->filename,".JPG") || strstr(file->filename,".jpg")) 
59                 {
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;
66
67                         SendMessageA(List, LVM_INSERTITEMA,0,(LPARAM)&item);
68                         index ++;
69                 }
70         }
71 }
72
73 static void PopulateImageList(HIMAGELIST *iList, HWND list)
74 {
75         struct gphoto2_file *file;
76         INT rc;
77         HWND    progress_dialog;
78
79         progress_dialog =
80                 CreateDialogW(GPHOTO2_instance,(LPWSTR)MAKEINTRESOURCE(IDD_CONNECTING),
81                                 NULL, ConnectingProc);
82         
83         LIST_FOR_EACH_ENTRY( file, &activeDS.files, struct gphoto2_file, entry)
84         {
85                 if (strstr(file->filename,".JPG") || strstr(file->filename,".jpg")) 
86                 {
87                         HBITMAP         bitmap;
88                         BITMAP          bmpInfo;
89
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);
97
98                         if (*iList == 0)
99                         {
100                                 *iList = ImageList_Create(bmpInfo.bmWidth,
101                                                 bmpInfo.bmHeight,ILC_COLOR24, 10,10);
102
103                                 SendMessageW(list, LVM_SETICONSPACING, 0,
104                                                 MAKELONG(bmpInfo.bmWidth+6, bmpInfo.bmHeight+15) ); }
105                         
106                         rc = ImageList_Add(*iList, bitmap, 0);
107
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);
113                 }
114         }
115         EndDialog(progress_dialog,0);
116         
117 }
118
119 static INT_PTR CALLBACK DialogProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
120 {
121         switch(msg)
122         {
123                 case WM_INITDIALOG:
124                         {
125                                 HIMAGELIST ilist = 0;
126                                 HWND list = GetDlgItem(hwnd,IDC_LIST1);
127                                 EnableWindow(GetDlgItem(hwnd,IDC_IMPORT),FALSE);
128
129                                 PopulateImageList(&ilist,list);
130
131                                 SendMessageA(list, LVM_SETIMAGELIST,LVSIL_NORMAL,(LPARAM)ilist);
132                                 PopulateListView(list);
133                         }
134                         break;
135                 case WM_NOTIFY:
136                         if (((LPNMHDR)lParam)->code == LVN_ITEMCHANGED)
137                         {
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);
144                         }
145                         break;
146                 case WM_COMMAND:
147                         switch LOWORD(wParam)
148                         {
149                                 case IDC_EXIT:
150                                         EndDialog(hwnd,0);
151                                         break;
152                                 case IDC_IMPORT:
153                                         {
154                                                 HWND list = GetDlgItem(hwnd,IDC_LIST1);
155                                                 int count = SendMessageA(list,LVM_GETSELECTEDCOUNT,0,0);
156                                                 int i;
157
158                                                 if (count ==0)
159                                                 {
160                                                         EndDialog(hwnd,0);
161                                                         return FALSE;
162                                                 }
163
164                                                 count = SendMessageA(list,LVM_GETITEMCOUNT,0,0);
165                                                 for ( i = 0; i < count; i++)
166                                                 {
167                                                         INT state = 0x00000000;
168
169                                                         state = SendMessageA(list,LVM_GETITEMSTATE,i,
170                                                                         LVIS_SELECTED);
171
172                                                         if (state)
173                                                         {
174                                                                 LVITEMA item;
175                                                                 struct gphoto2_file *file;
176
177                                                                 memset(&item,0,sizeof(item));
178
179                                                                 item.mask = LVIF_PARAM;
180                                                                 item.iItem = i;
181
182                                                                 SendMessageA(list,LVM_GETITEMA,0,(LPARAM)&item);
183
184                                                                 file = (struct gphoto2_file*)item.lParam;
185                                                                 file->download = TRUE;
186                                                         }
187                                                 }
188
189                                                 EndDialog(hwnd,1);
190                                         }
191                                         break;
192                                 case IDC_IMPORTALL:
193                                         {
194                                                 HWND list = GetDlgItem(hwnd,IDC_LIST1);
195                                                 int count = SendMessageA(list,LVM_GETITEMCOUNT,0,0);
196                                                 int i;
197
198                                                 if (count ==0)
199                                                 {
200                                                         EndDialog(hwnd,0);
201                                                         return FALSE;
202                                                 }
203
204                                                 for ( i = 0; i < count; i++)
205                                                 {
206                                                         LVITEMA item;
207                                                         struct gphoto2_file *file;
208
209                                                         memset(&item,0,sizeof(item));
210
211                                                         item.mask = LVIF_PARAM;
212                                                         item.iItem = i;
213
214                                                         SendMessageA(list,LVM_GETITEMA,0,(LPARAM)&item);
215
216                                                         file = (struct gphoto2_file*)item.lParam;
217                                                         file->download = TRUE;
218                                                 }
219
220                                                 EndDialog(hwnd,1);
221                                         }
222                                         break;
223                         }
224                         break;
225         }
226         return FALSE;
227 }
228
229 BOOL DoCameraUI()
230 {
231         return DialogBoxW(GPHOTO2_instance,
232                         (LPWSTR)MAKEINTRESOURCE(IDD_CAMERAUI),NULL, DialogProc);
233 }
234
235 static INT_PTR CALLBACK ProgressProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
236                 lParam)
237 {
238             return FALSE;
239 }   
240
241 HWND TransferringDialogBox(HWND dialog, DWORD progress)
242 {
243         if (!dialog)
244                 dialog = CreateDialogW(GPHOTO2_instance,
245                                 (LPWSTR)MAKEINTRESOURCE(IDD_DIALOG1), NULL, ProgressProc);
246                                 
247         if (progress == -1)
248         {
249                 EndDialog(dialog,0);
250                 return NULL;
251         }
252
253         RedrawWindow(dialog,NULL,NULL,
254                         RDW_INTERNALPAINT|RDW_UPDATENOW|RDW_ALLCHILDREN);
255
256         return dialog;
257 }