ddraw: Fix a typo.
[wine] / dlls / oledlg / insobjdlg.c
1 /*
2  *      OLEDLG library
3  *
4  *      Copyright 2003  Ulrich Czekalla for CodeWeavers
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 <stdarg.h>
22 #include <stdio.h>
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winreg.h"
27 #include "winternl.h"
28 #include "winerror.h"
29 #include "wingdi.h"
30 #include "winuser.h"
31 #include "wine/debug.h"
32 #include "wine/unicode.h"
33
34 #include "oledlg.h"
35 #include "resource.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(oledlg);
38
39 typedef struct
40 {
41     HWND hwndSelf;
42     BOOL bObjListInit; /* Object list has been initialized */
43     LPOLEUIINSERTOBJECTA lpOleUIInsertObject;
44
45     HWND hwndObjTypeLBL;
46     HWND hwndObjTypeLB;
47     HWND hwndFileLBL;
48     HWND hwndFileTB;
49     HWND hwndCreateCtrlCB;
50     HWND hwndCreateNewCB;
51     HWND hwndCreateFromFileCB;
52     HWND hwndDisplayIconCB;
53     HWND hwndAddCtrlBTN;
54     HWND hwndBrowseBTN;
55     HWND hwndResultDesc;
56
57 } InsertObjectDlgInfo;
58
59 static INT_PTR CALLBACK UIInsertObjectDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
60 static LRESULT UIINSOBJDLG_OnWMCommand(HWND hwnd, WPARAM wParam, LPARAM lParam);
61 static void UIINSERTOBJECTDLG_InitDialog(InsertObjectDlgInfo* pdlgInfo);
62 static void UIINSERTOBJECTDLG_SelectCreateCtrl(InsertObjectDlgInfo* pdlgInfo);
63 static void UIINSERTOBJECTDLG_SelectCreateFromFile(InsertObjectDlgInfo* pdlgInfo);
64 static void UIINSERTOBJECTDLG_SelectCreateNew(InsertObjectDlgInfo* pdlgInfo);
65 static BOOL UIINSERTOBJECTDLG_PopulateObjectTypes(InsertObjectDlgInfo* pdlgInfo);
66 static void UIINSERTOBJECTDLG_FreeObjectTypes(InsertObjectDlgInfo* pdlgInfo);
67 static void UIINSERTOBJECTDLG_SelChange(InsertObjectDlgInfo* pdlgInfo);
68 static BOOL UIINSERTOBJECTDLG_OnOpen(InsertObjectDlgInfo* pdlgInfo);
69 static void UIINSERTOBJECTDLG_BrowseFile(InsertObjectDlgInfo* pdlgInfo);
70 static void UIINSERTOBJECTDLG_AddControl(InsertObjectDlgInfo* pdlgInfo);
71
72 typedef HRESULT (*DLLREGISTER)          (void);
73
74 extern HINSTANCE OLEDLG_hInstance;
75 static const char OleUIInsertObjectInfoStr[] = "OleUIInsertObjectInfoStr";
76
77 /***********************************************************************
78  *           OleUIInsertObjectA (OLEDLG.3)
79  */
80 UINT WINAPI OleUIInsertObjectA(LPOLEUIINSERTOBJECTA lpOleUIInsertObject)
81 {
82   LRESULT lRes;
83   LPCVOID template;
84   HRSRC hRes;
85   InsertObjectDlgInfo dlgInfo;
86   HANDLE hDlgTmpl = 0;
87
88   if (lpOleUIInsertObject->lpszTemplate || lpOleUIInsertObject->hResource)
89      FIXME("Customized template not supported\n");
90
91   /* Create the dialog from a template */
92   if(!(hRes = FindResourceA(OLEDLG_hInstance,MAKEINTRESOURCEA(UIINSERTOBJECT),
93       (LPSTR)RT_DIALOG)))
94   {
95       return OLEUI_ERR_FINDTEMPLATEFAILURE;
96   }
97
98   if (!(hDlgTmpl = LoadResource(OLEDLG_hInstance, hRes )) ||
99       !(template = LockResource( hDlgTmpl )))
100   {
101       return OLEUI_ERR_LOADTEMPLATEFAILURE;
102   }
103
104   /* Initialize InsertObjectDlgInfo structure */
105   dlgInfo.lpOleUIInsertObject = lpOleUIInsertObject;
106   dlgInfo.bObjListInit = FALSE;
107
108   lRes = DialogBoxIndirectParamA(OLEDLG_hInstance, (const DLGTEMPLATE*) template,
109       lpOleUIInsertObject->hWndOwner, UIInsertObjectDlgProc,
110       (LPARAM) &dlgInfo);
111
112     /* Unable to create the dialog */
113     if( lRes == -1)
114         return OLEUI_ERR_DIALOGFAILURE;
115
116     return lRes;
117 }
118
119
120 /***********************************************************************
121  *          UIInsertObjectDlgProc
122  *
123  * OLE UI Insert Object dialog procedure
124  */
125 INT_PTR CALLBACK UIInsertObjectDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
126 {
127   InsertObjectDlgInfo* pdlgInfo = GetPropA(hwnd,OleUIInsertObjectInfoStr);
128
129   switch(uMsg)
130   {
131     case WM_INITDIALOG:
132     {
133         InsertObjectDlgInfo* pdlgInfo = (InsertObjectDlgInfo*)lParam;
134
135         pdlgInfo->hwndSelf = hwnd;
136
137         SetPropA(hwnd, OleUIInsertObjectInfoStr, pdlgInfo);
138
139         UIINSERTOBJECTDLG_InitDialog(pdlgInfo);
140
141         return 0;
142     }
143
144     case WM_COMMAND:
145       return UIINSOBJDLG_OnWMCommand(hwnd, wParam, lParam);
146
147     case WM_DESTROY:
148       if (pdlgInfo)
149           UIINSERTOBJECTDLG_FreeObjectTypes(pdlgInfo);
150       RemovePropA(hwnd, OleUIInsertObjectInfoStr);
151       return FALSE;
152
153     default :
154       return FALSE;
155   }
156 }
157
158
159 /***********************************************************************
160  *      UIINSOBJDLG_OnWMCommand
161  *
162  * WM_COMMAND message handler
163  */
164 static LRESULT UIINSOBJDLG_OnWMCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
165 {
166   WORD wNotifyCode = HIWORD(wParam);
167   WORD wID = LOWORD(wParam);
168   InsertObjectDlgInfo* pdlgInfo = GetPropA(hwnd,OleUIInsertObjectInfoStr);
169
170   switch(wID)
171   {
172     case IDOK:
173       EndDialog(hwnd, UIINSERTOBJECTDLG_OnOpen(pdlgInfo));
174       break;
175
176     case IDCANCEL:
177       EndDialog(hwnd, FALSE);
178       break;
179
180     case IDC_CREATECONTROL:
181       UIINSERTOBJECTDLG_SelectCreateCtrl(pdlgInfo);
182       break;
183
184     case IDC_CREATENEW:
185       UIINSERTOBJECTDLG_SelectCreateNew(pdlgInfo);
186       break;
187
188     case IDC_CREATEFROMFILE:
189       UIINSERTOBJECTDLG_SelectCreateFromFile(pdlgInfo);
190       break;
191
192     case IDC_BROWSE:
193       UIINSERTOBJECTDLG_BrowseFile(pdlgInfo);
194       break;
195
196     case IDC_ADDCONTROL:
197       UIINSERTOBJECTDLG_AddControl(pdlgInfo);
198
199     case IDC_OBJTYPELIST:
200       if (wNotifyCode == LBN_SELCHANGE)
201         UIINSERTOBJECTDLG_SelChange(pdlgInfo);
202       break;
203   }
204   return 0;
205 }
206
207
208 /***********************************************************************
209  *      UIINSERTOBJECTDLG_InitDialog
210  *
211  * Initialize dialog display
212  */
213 static void UIINSERTOBJECTDLG_InitDialog(InsertObjectDlgInfo* pdlgInfo)
214 {
215   /* Initialize InsertObjectDlgInfo data structure */
216   pdlgInfo->hwndObjTypeLB = GetDlgItem(pdlgInfo->hwndSelf, IDC_OBJTYPELIST);
217   pdlgInfo->hwndObjTypeLBL = GetDlgItem(pdlgInfo->hwndSelf, IDC_OBJTYPELBL);
218   pdlgInfo->hwndFileLBL = GetDlgItem(pdlgInfo->hwndSelf, IDC_FILELBL);
219   pdlgInfo->hwndFileTB = GetDlgItem(pdlgInfo->hwndSelf, IDC_FILE);
220   pdlgInfo->hwndCreateCtrlCB = GetDlgItem(pdlgInfo->hwndSelf, IDC_CREATECONTROL);
221   pdlgInfo->hwndCreateNewCB = GetDlgItem(pdlgInfo->hwndSelf, IDC_CREATENEW);
222   pdlgInfo->hwndCreateFromFileCB = GetDlgItem(pdlgInfo->hwndSelf, IDC_CREATEFROMFILE);
223   pdlgInfo->hwndDisplayIconCB = GetDlgItem(pdlgInfo->hwndSelf, IDC_ASICON);
224   pdlgInfo->hwndAddCtrlBTN = GetDlgItem(pdlgInfo->hwndSelf, IDC_ADDCONTROL);
225   pdlgInfo->hwndBrowseBTN = GetDlgItem(pdlgInfo->hwndSelf, IDC_BROWSE);
226   pdlgInfo->hwndResultDesc = GetDlgItem(pdlgInfo->hwndSelf, IDC_RESULTDESC);
227
228   /* Setup dialog controls based on flags */
229   if (pdlgInfo->lpOleUIInsertObject->lpszCaption)
230      SetWindowTextA(pdlgInfo->hwndSelf, pdlgInfo->lpOleUIInsertObject->lpszCaption);
231
232   ShowWindow(pdlgInfo->hwndCreateCtrlCB, (pdlgInfo->lpOleUIInsertObject->dwFlags &
233     IOF_SHOWINSERTCONTROL) ? SW_SHOW : SW_HIDE);
234   ShowWindow(pdlgInfo->hwndDisplayIconCB, (pdlgInfo->lpOleUIInsertObject->dwFlags &
235     IOF_CHECKDISPLAYASICON) ? SW_SHOW : SW_HIDE);
236   EnableWindow(pdlgInfo->hwndDisplayIconCB, (pdlgInfo->lpOleUIInsertObject->dwFlags &
237     IOF_DISABLEDISPLAYASICON) ? FALSE : TRUE);
238
239   if (pdlgInfo->lpOleUIInsertObject->dwFlags & IOF_SELECTCREATECONTROL)
240     UIINSERTOBJECTDLG_SelectCreateCtrl(pdlgInfo);
241   else if (pdlgInfo->lpOleUIInsertObject->dwFlags & IOF_SELECTCREATEFROMFILE)
242     UIINSERTOBJECTDLG_SelectCreateFromFile(pdlgInfo);
243   else /* (pdlgInfo->lpOleUIInsertObject->dwFlags & IOF_SELECTCREATENEW) */
244     UIINSERTOBJECTDLG_SelectCreateNew(pdlgInfo);
245 }
246
247
248 /***********************************************************************
249  *      UIINSERTOBJECTDLG_SelectCreateCtrl
250  *
251  * Select Create Control Radio Button
252  */
253 static void UIINSERTOBJECTDLG_SelectCreateCtrl(InsertObjectDlgInfo* pdlgInfo)
254 {
255   ShowWindow(pdlgInfo->hwndDisplayIconCB, SW_HIDE);
256   ShowWindow(pdlgInfo->hwndFileLBL, SW_HIDE);
257   ShowWindow(pdlgInfo->hwndFileTB, SW_HIDE);
258   ShowWindow(pdlgInfo->hwndBrowseBTN, SW_HIDE);
259
260   ShowWindow(pdlgInfo->hwndObjTypeLBL, SW_SHOW);
261   ShowWindow(pdlgInfo->hwndObjTypeLB, SW_SHOW);
262   ShowWindow(pdlgInfo->hwndAddCtrlBTN, SW_SHOW);
263
264   SendMessageA(pdlgInfo->hwndCreateCtrlCB, BM_SETCHECK, BST_CHECKED, 0);
265
266   /* Populate object type listbox */
267   if (!pdlgInfo->bObjListInit)
268      UIINSERTOBJECTDLG_PopulateObjectTypes(pdlgInfo);
269 }
270
271
272 /***********************************************************************
273  *      UIINSERTOBJECTDLG_SelectCreateNew
274  *
275  * Select Create New Radio Button
276  */
277 static void UIINSERTOBJECTDLG_SelectCreateNew(InsertObjectDlgInfo* pdlgInfo)
278 {
279   ShowWindow(pdlgInfo->hwndFileLBL, SW_HIDE);
280   ShowWindow(pdlgInfo->hwndFileTB, SW_HIDE);
281   ShowWindow(pdlgInfo->hwndAddCtrlBTN, SW_HIDE);
282   ShowWindow(pdlgInfo->hwndBrowseBTN, SW_HIDE);
283
284   if (pdlgInfo->lpOleUIInsertObject->dwFlags & IOF_CHECKDISPLAYASICON)
285     ShowWindow(pdlgInfo->hwndDisplayIconCB, SW_SHOW);
286
287   ShowWindow(pdlgInfo->hwndObjTypeLBL, SW_SHOW);
288   ShowWindow(pdlgInfo->hwndObjTypeLB, SW_SHOW);
289
290   SendMessageA(pdlgInfo->hwndCreateNewCB, BM_SETCHECK, BST_CHECKED, 0);
291
292   if (!pdlgInfo->bObjListInit)
293      UIINSERTOBJECTDLG_PopulateObjectTypes(pdlgInfo);
294
295   UIINSERTOBJECTDLG_SelChange(pdlgInfo);
296 }
297
298
299 /***********************************************************************
300  *      UIINSERTOBJECTDLG_SelectCreateFromFile
301  *
302  * Select Create From File Radio Button
303  */
304 static void UIINSERTOBJECTDLG_SelectCreateFromFile(InsertObjectDlgInfo* pdlgInfo)
305 {
306   WCHAR resstr[MAX_PATH];
307
308   ShowWindow(pdlgInfo->hwndAddCtrlBTN, SW_HIDE);
309   ShowWindow(pdlgInfo->hwndObjTypeLBL, SW_HIDE);
310   ShowWindow(pdlgInfo->hwndObjTypeLB, SW_HIDE);
311
312   if (pdlgInfo->lpOleUIInsertObject->dwFlags & IOF_CHECKDISPLAYASICON)
313     ShowWindow(pdlgInfo->hwndDisplayIconCB, SW_SHOW);
314
315   ShowWindow(pdlgInfo->hwndFileLBL, SW_SHOW);
316   ShowWindow(pdlgInfo->hwndFileTB, SW_SHOW);
317   ShowWindow(pdlgInfo->hwndBrowseBTN, SW_SHOW);
318
319   SendMessageW(pdlgInfo->hwndCreateFromFileCB, BM_SETCHECK, BST_CHECKED, 0);
320
321   if (LoadStringW(OLEDLG_hInstance, IDS_RESULTFILEOBJDESC, resstr, MAX_PATH))
322      SendMessageW(pdlgInfo->hwndResultDesc, WM_SETTEXT, 0, (LPARAM)resstr);
323 }
324
325
326 /***********************************************************************
327  *      UIINSERTOBJECTDLG_PopulateObjectTypes
328  *
329  * Populate Object Type listbox
330  */
331 static BOOL UIINSERTOBJECTDLG_PopulateObjectTypes(InsertObjectDlgInfo* pdlgInfo)
332 {
333   static const WCHAR szClsid[] = {'C','L','S','I','D',0};
334   static const WCHAR szInsertable[] = {'I','n','s','e','r','t','a','b','l','e',0};
335   static const WCHAR szNotInsertable[] = {'N','o','t','I','n','s','e','r','t','a','b','l','e',0};
336   DWORD i;
337   LONG len;
338   HKEY hkclsids;
339   HKEY hkey;
340   CLSID clsid;
341   LSTATUS ret;
342   WCHAR keydesc[MAX_PATH];
343   WCHAR keyname[MAX_PATH];
344   WCHAR szclsid[128];
345   DWORD index = 0;
346
347   UIINSERTOBJECTDLG_FreeObjectTypes(pdlgInfo);
348
349   RegOpenKeyExW(HKEY_CLASSES_ROOT, szClsid, 0, KEY_READ, &hkclsids);
350
351   while (ERROR_SUCCESS == (ret = RegEnumKeyW(hkclsids, index, szclsid, sizeof(szclsid)/sizeof(szclsid[0]))))
352   {
353     index++;
354
355     RegOpenKeyExW(hkclsids, szclsid, 0, KEY_READ, &hkey);
356
357     len = sizeof(keyname);
358     if (ERROR_SUCCESS != RegQueryValueW(hkey, szInsertable, keyname, &len))
359         continue;
360
361     len = sizeof(keyname);
362     if (ERROR_SUCCESS == RegQueryValueW(hkey, szNotInsertable, keyname, &len))
363         continue;
364
365     CLSIDFromString(szclsid, &clsid);
366
367     for (i = 0; i < pdlgInfo->lpOleUIInsertObject->cClsidExclude; i++)
368       if (IsEqualGUID(&pdlgInfo->lpOleUIInsertObject->lpClsidExclude[i], &clsid))
369         break;
370
371     if (i < pdlgInfo->lpOleUIInsertObject->cClsidExclude)
372       continue;
373
374     len = sizeof(keydesc);
375     if (ERROR_SUCCESS == RegQueryValueW(hkey, NULL, keydesc, &len))
376     {
377        CLSID* lpclsid = HeapAlloc(GetProcessHeap(), 0, sizeof(CLSID));
378        *lpclsid = clsid;
379
380        len = SendMessageW(pdlgInfo->hwndObjTypeLB, LB_ADDSTRING, 0, (LPARAM)keydesc);
381        SendMessageW(pdlgInfo->hwndObjTypeLB, LB_SETITEMDATA, len, (LPARAM)lpclsid);
382     }
383   }
384
385   pdlgInfo->bObjListInit = (ret == ERROR_NO_MORE_ITEMS);
386
387   return pdlgInfo->bObjListInit;
388 }
389
390
391 /***********************************************************************
392  *      UIINSERTOBJECTDLG_FreeObjectTypes
393  *
394  * Free Object Types listbox
395  */
396 static void UIINSERTOBJECTDLG_FreeObjectTypes(InsertObjectDlgInfo* pdlgInfo)
397 {
398   UINT i, count;
399
400   count = SendMessageA(pdlgInfo->hwndObjTypeLB, LB_GETCOUNT, 0, 0);
401
402   for (i = 0; i < count; i++)
403   {
404       CLSID* lpclsid = (CLSID*) SendMessageA(pdlgInfo->hwndObjTypeLB, 
405          LB_GETITEMDATA, i, 0);
406       HeapFree(GetProcessHeap(), 0, lpclsid);
407   }
408 }
409
410
411 /***********************************************************************
412  *      UIINSERTOBJECTDLG_SelChange
413  *
414  * Handle object type selection change
415  */
416 static void UIINSERTOBJECTDLG_SelChange(InsertObjectDlgInfo* pdlgInfo)
417 {
418   INT index;
419   WCHAR objname[MAX_PATH];
420   WCHAR objdesc[MAX_PATH];
421   WCHAR resstr[MAX_PATH];
422
423   TRACE("\n");
424
425   if (LoadStringW(OLEDLG_hInstance, IDS_RESULTOBJDESC, resstr, MAX_PATH) &&
426      ((index = SendMessageW(pdlgInfo->hwndObjTypeLB, LB_GETCURSEL, 0, 0)) >= 0) &&
427      SendMessageW(pdlgInfo->hwndObjTypeLB, LB_GETTEXT, index, (LPARAM)objname))
428        wsprintfW(objdesc, resstr, objname);
429   else
430     objdesc[0] = 0;
431
432   SendMessageW(pdlgInfo->hwndResultDesc, WM_SETTEXT, 0, (LPARAM)objdesc);
433 }
434
435
436 /***********************************************************************
437  *      UIINSERTOBJECTDLG_SelChange
438  *
439  * Handle OK Button
440  */
441 static BOOL UIINSERTOBJECTDLG_OnOpen(InsertObjectDlgInfo* pdlgInfo)
442 {
443   BOOL bret = FALSE;
444
445   if (BST_CHECKED == SendMessageA(pdlgInfo->hwndCreateCtrlCB, BM_GETCHECK, 0, 0) ||
446       BST_CHECKED == SendMessageA(pdlgInfo->hwndCreateNewCB, BM_GETCHECK, 0, 0))
447   {
448     INT index = SendMessageA(pdlgInfo->hwndObjTypeLB, LB_GETCURSEL, 0, 0);
449
450     if (index >= 0)
451     {
452        CLSID* clsid = (CLSID*) SendMessageA(pdlgInfo->hwndObjTypeLB, 
453           LB_GETITEMDATA, index, 0);
454        pdlgInfo->lpOleUIInsertObject->clsid = *clsid;
455
456        if (pdlgInfo->lpOleUIInsertObject->dwFlags & IOF_CREATENEWOBJECT)
457        {
458           pdlgInfo->lpOleUIInsertObject->sc= OleCreate(
459              &pdlgInfo->lpOleUIInsertObject->clsid,
460              &pdlgInfo->lpOleUIInsertObject->iid,
461              pdlgInfo->lpOleUIInsertObject->oleRender,
462              pdlgInfo->lpOleUIInsertObject->lpFormatEtc,
463              pdlgInfo->lpOleUIInsertObject->lpIOleClientSite,
464              pdlgInfo->lpOleUIInsertObject->lpIStorage,
465              pdlgInfo->lpOleUIInsertObject->ppvObj);
466        }
467
468        bret = TRUE;
469     }
470   }
471   else if (BST_CHECKED == SendMessageA(pdlgInfo->hwndCreateFromFileCB, BM_GETCHECK, 0, 0))
472   {
473     if (pdlgInfo->lpOleUIInsertObject->lpszFile)
474     {
475       HRESULT hres;
476       WCHAR wcsFile[MAX_PATH];
477
478       if (SendMessageW(pdlgInfo->hwndFileTB, WM_GETTEXT, MAX_PATH, (LPARAM)wcsFile))
479           WideCharToMultiByte(CP_ACP, 0, wcsFile, -1,
480               pdlgInfo->lpOleUIInsertObject->lpszFile, pdlgInfo->lpOleUIInsertObject->cchFile, NULL, NULL);
481
482       if (ERROR_SUCCESS == (hres = GetClassFile(wcsFile, &pdlgInfo->lpOleUIInsertObject->clsid)))
483       {
484          if (pdlgInfo->lpOleUIInsertObject->dwFlags & IOF_CREATEFILEOBJECT)
485          {
486            hres = OleCreateFromFile(
487              &pdlgInfo->lpOleUIInsertObject->clsid,
488              wcsFile,
489              &pdlgInfo->lpOleUIInsertObject->iid,
490              pdlgInfo->lpOleUIInsertObject->oleRender,
491              pdlgInfo->lpOleUIInsertObject->lpFormatEtc,
492              pdlgInfo->lpOleUIInsertObject->lpIOleClientSite,
493              pdlgInfo->lpOleUIInsertObject->lpIStorage,
494              pdlgInfo->lpOleUIInsertObject->ppvObj);
495          }
496
497          bret = TRUE;
498       }
499       pdlgInfo->lpOleUIInsertObject->sc = hres;
500     }
501   }
502
503   return bret;
504 }
505
506
507 /***********************************************************************
508  *      UIINSERTOBJECTDLG_BrowseFile
509  *
510  * Browse for the file
511  */
512 static void UIINSERTOBJECTDLG_BrowseFile(InsertObjectDlgInfo* pdlgInfo)
513 {
514    OPENFILENAMEA fn;
515    char fname[MAX_PATH];
516    char title[32];
517
518    fn.lStructSize = sizeof(OPENFILENAMEA);
519    fn.hwndOwner = pdlgInfo->hwndSelf;
520    fn.hInstance = 0;
521    fn.lpstrFilter = "All Files\0*.*\0\0";
522    fn.lpstrCustomFilter = NULL;
523    fn.nMaxCustFilter = 0;
524    fn.nFilterIndex = 0;
525
526    SendMessageA(pdlgInfo->hwndFileTB, WM_GETTEXT, MAX_PATH, (LPARAM)fname);
527    fn.lpstrFile = fname;
528    fn.nMaxFile = MAX_PATH;
529
530    fn.lpstrFileTitle = NULL;
531    fn.nMaxFileTitle = 0;
532    fn.lpstrInitialDir = NULL;
533
534    LoadStringA(OLEDLG_hInstance, IDS_BROWSE, title, 32);
535    fn.lpstrTitle = title;
536
537    fn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST |
538       OFN_HIDEREADONLY | OFN_LONGNAMES;
539    fn.nFileOffset = 0;
540    fn.nFileExtension = 0;
541    fn.lpstrDefExt = NULL;
542    fn.lCustData = 0;
543    fn.lpfnHook = NULL;
544    fn.lpTemplateName = NULL;
545
546    if (GetOpenFileNameA(&fn))
547       SendMessageA(pdlgInfo->hwndFileTB, WM_SETTEXT, 0, (LPARAM)fn.lpstrFile);
548 }
549
550
551 /***********************************************************************
552  *      UIINSERTOBJECTDLG_AddControl
553  *
554  * Add control to Object Type
555  */
556 static void UIINSERTOBJECTDLG_AddControl(InsertObjectDlgInfo* pdlgInfo)
557 {
558    OPENFILENAMEA fn;
559    char fname[MAX_PATH];
560    char title[32];
561
562    fn.lStructSize = sizeof(OPENFILENAMEA);
563    fn.hwndOwner = pdlgInfo->hwndSelf;
564    fn.hInstance = 0;
565    fn.lpstrFilter = "OLE Controls\0*.ocx\0Libraries\0*.dll\0All Files\0*.*\0\0";
566    fn.lpstrCustomFilter = NULL;
567    fn.nMaxCustFilter = 0;
568    fn.nFilterIndex = 0;
569
570    fname[0] = 0;
571    fn.lpstrFile = fname;
572    fn.nMaxFile = MAX_PATH;
573
574    fn.lpstrFileTitle = NULL;
575    fn.nMaxFileTitle = 0;
576    fn.lpstrInitialDir = NULL;
577
578    LoadStringA(OLEDLG_hInstance, IDS_BROWSE, title, 32);
579    fn.lpstrTitle = title;
580
581    fn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST |
582       OFN_HIDEREADONLY | OFN_LONGNAMES;
583    fn.nFileOffset = 0;
584    fn.nFileExtension = 0;
585    fn.lpstrDefExt = NULL;
586    fn.lCustData = 0;
587    fn.lpfnHook = NULL;
588    fn.lpTemplateName = NULL;
589
590    if (GetOpenFileNameA(&fn))
591    {
592       HMODULE hMod;
593       BOOL bValid = FALSE;
594
595       hMod = LoadLibraryA(fn.lpstrFile);
596
597       if (hMod)
598       {
599           DLLREGISTER regproc;
600
601           regproc = (DLLREGISTER) GetProcAddress(hMod, "DllRegisterServer");
602           if (regproc)
603           {
604              if (S_OK == regproc())
605              {
606                 UIINSERTOBJECTDLG_PopulateObjectTypes(pdlgInfo);
607                 bValid = TRUE;
608              }
609           }
610
611           FreeLibrary(hMod);
612       }
613
614       if (!bValid)
615       {
616           WCHAR title[32];
617           WCHAR msg[256];
618
619           LoadStringW(OLEDLG_hInstance, IDS_NOTOLEMODCAPTION, title, 32);
620           LoadStringW(OLEDLG_hInstance, IDS_NOTOLEMOD, msg, 256);
621
622           MessageBoxW(pdlgInfo->hwndSelf, msg, title, MB_ICONEXCLAMATION);
623       }
624    }
625 }