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