insobjdlg.c 18.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 *	OLEDLG library
 *
 *	Copyright 2003	Ulrich Czekalla for CodeWeavers
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
 */

#include <stdarg.h>
#include <stdio.h>

#include "windef.h"
#include "winbase.h"
#include "winreg.h"
#include "winternl.h"
#include "winerror.h"
#include "wingdi.h"
#include "winuser.h"
#include "wine/debug.h"
#include "wine/unicode.h"

#include "oledlg.h"
#include "resource.h"

WINE_DEFAULT_DEBUG_CHANNEL(oledlg);

typedef struct
{
    HWND hwndSelf;
    BOOL bObjListInit; /* Object list has been initialized */
    LPOLEUIINSERTOBJECTA lpOleUIInsertObject;

    HWND hwndObjTypeLBL;
    HWND hwndObjTypeLB;
    HWND hwndFileLBL;
    HWND hwndFileTB;
    HWND hwndCreateCtrlCB;
    HWND hwndCreateNewCB;
    HWND hwndCreateFromFileCB;
    HWND hwndDisplayIconCB;
    HWND hwndAddCtrlBTN;
    HWND hwndBrowseBTN;
    HWND hwndResultDesc;

} InsertObjectDlgInfo;

59
static INT_PTR CALLBACK UIInsertObjectDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
static LRESULT UIINSOBJDLG_OnWMCommand(HWND hwnd, WPARAM wParam, LPARAM lParam);
static void UIINSERTOBJECTDLG_InitDialog(InsertObjectDlgInfo* pdlgInfo);
static void UIINSERTOBJECTDLG_SelectCreateCtrl(InsertObjectDlgInfo* pdlgInfo);
static void UIINSERTOBJECTDLG_SelectCreateFromFile(InsertObjectDlgInfo* pdlgInfo);
static void UIINSERTOBJECTDLG_SelectCreateNew(InsertObjectDlgInfo* pdlgInfo);
static BOOL UIINSERTOBJECTDLG_PopulateObjectTypes(InsertObjectDlgInfo* pdlgInfo);
static void UIINSERTOBJECTDLG_FreeObjectTypes(InsertObjectDlgInfo* pdlgInfo);
static void UIINSERTOBJECTDLG_SelChange(InsertObjectDlgInfo* pdlgInfo);
static BOOL UIINSERTOBJECTDLG_OnOpen(InsertObjectDlgInfo* pdlgInfo);
static void UIINSERTOBJECTDLG_BrowseFile(InsertObjectDlgInfo* pdlgInfo);
static void UIINSERTOBJECTDLG_AddControl(InsertObjectDlgInfo* pdlgInfo);

typedef HRESULT (*DLLREGISTER)          (void);

extern HINSTANCE OLEDLG_hInstance;
75
static const char OleUIInsertObjectInfoStr[] = "OleUIInsertObjectInfoStr";
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107

/***********************************************************************
 *           OleUIInsertObjectA (OLEDLG.3)
 */
UINT WINAPI OleUIInsertObjectA(LPOLEUIINSERTOBJECTA lpOleUIInsertObject)
{
  LRESULT lRes;
  LPCVOID template;
  HRSRC hRes;
  InsertObjectDlgInfo dlgInfo;
  HANDLE hDlgTmpl = 0;

  if (lpOleUIInsertObject->lpszTemplate || lpOleUIInsertObject->hResource)
     FIXME("Customized template not supported\n");

  /* Create the dialog from a template */
  if(!(hRes = FindResourceA(OLEDLG_hInstance,MAKEINTRESOURCEA(UIINSERTOBJECT),
      (LPSTR)RT_DIALOG)))
  {
      return OLEUI_ERR_FINDTEMPLATEFAILURE;
  }

  if (!(hDlgTmpl = LoadResource(OLEDLG_hInstance, hRes )) ||
      !(template = LockResource( hDlgTmpl )))
  {
      return OLEUI_ERR_LOADTEMPLATEFAILURE;
  }

  /* Initialize InsertObjectDlgInfo structure */
  dlgInfo.lpOleUIInsertObject = lpOleUIInsertObject;
  dlgInfo.bObjListInit = FALSE;

Eric Pouech's avatar
Eric Pouech committed
108
  lRes = DialogBoxIndirectParamA(OLEDLG_hInstance, (const DLGTEMPLATE*) template,
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
      lpOleUIInsertObject->hWndOwner, UIInsertObjectDlgProc,
      (LPARAM) &dlgInfo);

    /* Unable to create the dialog */
    if( lRes == -1)
        return OLEUI_ERR_DIALOGFAILURE;

    return lRes;
}


/***********************************************************************
 *          UIInsertObjectDlgProc
 *
 * OLE UI Insert Object dialog procedure
 */
INT_PTR CALLBACK UIInsertObjectDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
127
  InsertObjectDlgInfo* pdlgInfo = GetPropA(hwnd,OleUIInsertObjectInfoStr);
128 129 130 131 132 133 134 135 136

  switch(uMsg)
  {
    case WM_INITDIALOG:
    {
        InsertObjectDlgInfo* pdlgInfo = (InsertObjectDlgInfo*)lParam;

        pdlgInfo->hwndSelf = hwnd;

137
        SetPropA(hwnd, OleUIInsertObjectInfoStr, pdlgInfo);
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167

        UIINSERTOBJECTDLG_InitDialog(pdlgInfo);

        return 0;
    }

    case WM_COMMAND:
      return UIINSOBJDLG_OnWMCommand(hwnd, wParam, lParam);

    case WM_DESTROY:
      if (pdlgInfo)
          UIINSERTOBJECTDLG_FreeObjectTypes(pdlgInfo);
      RemovePropA(hwnd, OleUIInsertObjectInfoStr);
      return FALSE;

    default :
      return FALSE;
  }
}


/***********************************************************************
 *      UIINSOBJDLG_OnWMCommand
 *
 * WM_COMMAND message handler
 */
static LRESULT UIINSOBJDLG_OnWMCommand(HWND hwnd, WPARAM wParam, LPARAM lParam)
{
  WORD wNotifyCode = HIWORD(wParam);
  WORD wID = LOWORD(wParam);
168
  InsertObjectDlgInfo* pdlgInfo = GetPropA(hwnd,OleUIInsertObjectInfoStr);
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197

  switch(wID)
  {
    case IDOK:
      EndDialog(hwnd, UIINSERTOBJECTDLG_OnOpen(pdlgInfo));
      break;

    case IDCANCEL:
      EndDialog(hwnd, FALSE);
      break;

    case IDC_CREATECONTROL:
      UIINSERTOBJECTDLG_SelectCreateCtrl(pdlgInfo);
      break;

    case IDC_CREATENEW:
      UIINSERTOBJECTDLG_SelectCreateNew(pdlgInfo);
      break;

    case IDC_CREATEFROMFILE:
      UIINSERTOBJECTDLG_SelectCreateFromFile(pdlgInfo);
      break;

    case IDC_BROWSE:
      UIINSERTOBJECTDLG_BrowseFile(pdlgInfo);
      break;

    case IDC_ADDCONTROL:
      UIINSERTOBJECTDLG_AddControl(pdlgInfo);
198
      break;
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236

    case IDC_OBJTYPELIST:
      if (wNotifyCode == LBN_SELCHANGE)
        UIINSERTOBJECTDLG_SelChange(pdlgInfo);
      break;
  }
  return 0;
}


/***********************************************************************
 *      UIINSERTOBJECTDLG_InitDialog
 *
 * Initialize dialog display
 */
static void UIINSERTOBJECTDLG_InitDialog(InsertObjectDlgInfo* pdlgInfo)
{
  /* Initialize InsertObjectDlgInfo data structure */
  pdlgInfo->hwndObjTypeLB = GetDlgItem(pdlgInfo->hwndSelf, IDC_OBJTYPELIST);
  pdlgInfo->hwndObjTypeLBL = GetDlgItem(pdlgInfo->hwndSelf, IDC_OBJTYPELBL);
  pdlgInfo->hwndFileLBL = GetDlgItem(pdlgInfo->hwndSelf, IDC_FILELBL);
  pdlgInfo->hwndFileTB = GetDlgItem(pdlgInfo->hwndSelf, IDC_FILE);
  pdlgInfo->hwndCreateCtrlCB = GetDlgItem(pdlgInfo->hwndSelf, IDC_CREATECONTROL);
  pdlgInfo->hwndCreateNewCB = GetDlgItem(pdlgInfo->hwndSelf, IDC_CREATENEW);
  pdlgInfo->hwndCreateFromFileCB = GetDlgItem(pdlgInfo->hwndSelf, IDC_CREATEFROMFILE);
  pdlgInfo->hwndDisplayIconCB = GetDlgItem(pdlgInfo->hwndSelf, IDC_ASICON);
  pdlgInfo->hwndAddCtrlBTN = GetDlgItem(pdlgInfo->hwndSelf, IDC_ADDCONTROL);
  pdlgInfo->hwndBrowseBTN = GetDlgItem(pdlgInfo->hwndSelf, IDC_BROWSE);
  pdlgInfo->hwndResultDesc = GetDlgItem(pdlgInfo->hwndSelf, IDC_RESULTDESC);

  /* Setup dialog controls based on flags */
  if (pdlgInfo->lpOleUIInsertObject->lpszCaption)
     SetWindowTextA(pdlgInfo->hwndSelf, pdlgInfo->lpOleUIInsertObject->lpszCaption);

  ShowWindow(pdlgInfo->hwndCreateCtrlCB, (pdlgInfo->lpOleUIInsertObject->dwFlags &
    IOF_SHOWINSERTCONTROL) ? SW_SHOW : SW_HIDE);
  ShowWindow(pdlgInfo->hwndDisplayIconCB, (pdlgInfo->lpOleUIInsertObject->dwFlags &
    IOF_CHECKDISPLAYASICON) ? SW_SHOW : SW_HIDE);
237 238
  EnableWindow(pdlgInfo->hwndDisplayIconCB, !(pdlgInfo->lpOleUIInsertObject->dwFlags &
    IOF_DISABLEDISPLAYASICON));
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306

  if (pdlgInfo->lpOleUIInsertObject->dwFlags & IOF_SELECTCREATECONTROL)
    UIINSERTOBJECTDLG_SelectCreateCtrl(pdlgInfo);
  else if (pdlgInfo->lpOleUIInsertObject->dwFlags & IOF_SELECTCREATEFROMFILE)
    UIINSERTOBJECTDLG_SelectCreateFromFile(pdlgInfo);
  else /* (pdlgInfo->lpOleUIInsertObject->dwFlags & IOF_SELECTCREATENEW) */
    UIINSERTOBJECTDLG_SelectCreateNew(pdlgInfo);
}


/***********************************************************************
 *      UIINSERTOBJECTDLG_SelectCreateCtrl
 *
 * Select Create Control Radio Button
 */
static void UIINSERTOBJECTDLG_SelectCreateCtrl(InsertObjectDlgInfo* pdlgInfo)
{
  ShowWindow(pdlgInfo->hwndDisplayIconCB, SW_HIDE);
  ShowWindow(pdlgInfo->hwndFileLBL, SW_HIDE);
  ShowWindow(pdlgInfo->hwndFileTB, SW_HIDE);
  ShowWindow(pdlgInfo->hwndBrowseBTN, SW_HIDE);

  ShowWindow(pdlgInfo->hwndObjTypeLBL, SW_SHOW);
  ShowWindow(pdlgInfo->hwndObjTypeLB, SW_SHOW);
  ShowWindow(pdlgInfo->hwndAddCtrlBTN, SW_SHOW);

  SendMessageA(pdlgInfo->hwndCreateCtrlCB, BM_SETCHECK, BST_CHECKED, 0);

  /* Populate object type listbox */
  if (!pdlgInfo->bObjListInit)
     UIINSERTOBJECTDLG_PopulateObjectTypes(pdlgInfo);
}


/***********************************************************************
 *      UIINSERTOBJECTDLG_SelectCreateNew
 *
 * Select Create New Radio Button
 */
static void UIINSERTOBJECTDLG_SelectCreateNew(InsertObjectDlgInfo* pdlgInfo)
{
  ShowWindow(pdlgInfo->hwndFileLBL, SW_HIDE);
  ShowWindow(pdlgInfo->hwndFileTB, SW_HIDE);
  ShowWindow(pdlgInfo->hwndAddCtrlBTN, SW_HIDE);
  ShowWindow(pdlgInfo->hwndBrowseBTN, SW_HIDE);

  if (pdlgInfo->lpOleUIInsertObject->dwFlags & IOF_CHECKDISPLAYASICON)
    ShowWindow(pdlgInfo->hwndDisplayIconCB, SW_SHOW);

  ShowWindow(pdlgInfo->hwndObjTypeLBL, SW_SHOW);
  ShowWindow(pdlgInfo->hwndObjTypeLB, SW_SHOW);

  SendMessageA(pdlgInfo->hwndCreateNewCB, BM_SETCHECK, BST_CHECKED, 0);

  if (!pdlgInfo->bObjListInit)
     UIINSERTOBJECTDLG_PopulateObjectTypes(pdlgInfo);

  UIINSERTOBJECTDLG_SelChange(pdlgInfo);
}


/***********************************************************************
 *      UIINSERTOBJECTDLG_SelectCreateFromFile
 *
 * Select Create From File Radio Button
 */
static void UIINSERTOBJECTDLG_SelectCreateFromFile(InsertObjectDlgInfo* pdlgInfo)
{
307
  WCHAR resstr[MAX_PATH];
308 309 310 311 312 313 314 315 316 317 318 319

  ShowWindow(pdlgInfo->hwndAddCtrlBTN, SW_HIDE);
  ShowWindow(pdlgInfo->hwndObjTypeLBL, SW_HIDE);
  ShowWindow(pdlgInfo->hwndObjTypeLB, SW_HIDE);

  if (pdlgInfo->lpOleUIInsertObject->dwFlags & IOF_CHECKDISPLAYASICON)
    ShowWindow(pdlgInfo->hwndDisplayIconCB, SW_SHOW);

  ShowWindow(pdlgInfo->hwndFileLBL, SW_SHOW);
  ShowWindow(pdlgInfo->hwndFileTB, SW_SHOW);
  ShowWindow(pdlgInfo->hwndBrowseBTN, SW_SHOW);

320
  SendMessageW(pdlgInfo->hwndCreateFromFileCB, BM_SETCHECK, BST_CHECKED, 0);
321

322 323
  if (LoadStringW(OLEDLG_hInstance, IDS_RESULTFILEOBJDESC, resstr, MAX_PATH))
     SendMessageW(pdlgInfo->hwndResultDesc, WM_SETTEXT, 0, (LPARAM)resstr);
324 325 326 327 328 329 330 331 332 333
}


/***********************************************************************
 *      UIINSERTOBJECTDLG_PopulateObjectTypes
 *
 * Populate Object Type listbox
 */
static BOOL UIINSERTOBJECTDLG_PopulateObjectTypes(InsertObjectDlgInfo* pdlgInfo)
{
334 335 336
  static const WCHAR szClsid[] = {'C','L','S','I','D',0};
  static const WCHAR szInsertable[] = {'I','n','s','e','r','t','a','b','l','e',0};
  static const WCHAR szNotInsertable[] = {'N','o','t','I','n','s','e','r','t','a','b','l','e',0};
337 338
  DWORD i;
  LONG len;
339 340 341
  HKEY hkclsids;
  HKEY hkey;
  CLSID clsid;
342
  LSTATUS ret;
343 344 345
  WCHAR keydesc[MAX_PATH];
  WCHAR keyname[MAX_PATH];
  WCHAR szclsid[128];
346 347 348 349
  DWORD index = 0;

  UIINSERTOBJECTDLG_FreeObjectTypes(pdlgInfo);

350
  RegOpenKeyExW(HKEY_CLASSES_ROOT, szClsid, 0, KEY_READ, &hkclsids);
351

352
  while (ERROR_SUCCESS == (ret = RegEnumKeyW(hkclsids, index, szclsid, sizeof(szclsid)/sizeof(szclsid[0]))))
353 354 355
  {
    index++;

356
    RegOpenKeyExW(hkclsids, szclsid, 0, KEY_READ, &hkey);
357

358 359
    len = sizeof(keyname);
    if (ERROR_SUCCESS != RegQueryValueW(hkey, szInsertable, keyname, &len))
360 361
        continue;

362 363
    len = sizeof(keyname);
    if (ERROR_SUCCESS == RegQueryValueW(hkey, szNotInsertable, keyname, &len))
364 365
        continue;

366
    CLSIDFromString(szclsid, &clsid);
367 368 369 370 371 372 373 374

    for (i = 0; i < pdlgInfo->lpOleUIInsertObject->cClsidExclude; i++)
      if (IsEqualGUID(&pdlgInfo->lpOleUIInsertObject->lpClsidExclude[i], &clsid))
        break;

    if (i < pdlgInfo->lpOleUIInsertObject->cClsidExclude)
      continue;

375 376
    len = sizeof(keydesc);
    if (ERROR_SUCCESS == RegQueryValueW(hkey, NULL, keydesc, &len))
377
    {
378
       CLSID* lpclsid = HeapAlloc(GetProcessHeap(), 0, sizeof(CLSID));
379
       *lpclsid = clsid;
380

381
       len = SendMessageW(pdlgInfo->hwndObjTypeLB, LB_ADDSTRING, 0, (LPARAM)keydesc);
382
       SendMessageW(pdlgInfo->hwndObjTypeLB, LB_SETITEMDATA, len, (LPARAM)lpclsid);
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
    }
  }

  pdlgInfo->bObjListInit = (ret == ERROR_NO_MORE_ITEMS);

  return pdlgInfo->bObjListInit;
}


/***********************************************************************
 *      UIINSERTOBJECTDLG_FreeObjectTypes
 *
 * Free Object Types listbox
 */
static void UIINSERTOBJECTDLG_FreeObjectTypes(InsertObjectDlgInfo* pdlgInfo)
{
  UINT i, count;

401
  count = SendMessageA(pdlgInfo->hwndObjTypeLB, LB_GETCOUNT, 0, 0);
402 403 404 405

  for (i = 0; i < count; i++)
  {
      CLSID* lpclsid = (CLSID*) SendMessageA(pdlgInfo->hwndObjTypeLB, 
406
         LB_GETITEMDATA, i, 0);
407 408 409 410 411 412 413 414 415 416 417 418 419
      HeapFree(GetProcessHeap(), 0, lpclsid);
  }
}


/***********************************************************************
 *      UIINSERTOBJECTDLG_SelChange
 *
 * Handle object type selection change
 */
static void UIINSERTOBJECTDLG_SelChange(InsertObjectDlgInfo* pdlgInfo)
{
  INT index;
420 421 422
  WCHAR objname[MAX_PATH];
  WCHAR objdesc[MAX_PATH];
  WCHAR resstr[MAX_PATH];
423 424 425

  TRACE("\n");

426 427
  if (LoadStringW(OLEDLG_hInstance, IDS_RESULTOBJDESC, resstr, MAX_PATH) &&
     ((index = SendMessageW(pdlgInfo->hwndObjTypeLB, LB_GETCURSEL, 0, 0)) >= 0) &&
428
     SendMessageW(pdlgInfo->hwndObjTypeLB, LB_GETTEXT, index, (LPARAM)objname))
429
       wsprintfW(objdesc, resstr, objname);
430 431 432
  else
    objdesc[0] = 0;

433
  SendMessageW(pdlgInfo->hwndResultDesc, WM_SETTEXT, 0, (LPARAM)objdesc);
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
}


/***********************************************************************
 *      UIINSERTOBJECTDLG_SelChange
 *
 * Handle OK Button
 */
static BOOL UIINSERTOBJECTDLG_OnOpen(InsertObjectDlgInfo* pdlgInfo)
{
  BOOL bret = FALSE;

  if (BST_CHECKED == SendMessageA(pdlgInfo->hwndCreateCtrlCB, BM_GETCHECK, 0, 0) ||
      BST_CHECKED == SendMessageA(pdlgInfo->hwndCreateNewCB, BM_GETCHECK, 0, 0))
  {
    INT index = SendMessageA(pdlgInfo->hwndObjTypeLB, LB_GETCURSEL, 0, 0);

    if (index >= 0)
    {
       CLSID* clsid = (CLSID*) SendMessageA(pdlgInfo->hwndObjTypeLB, 
454
          LB_GETITEMDATA, index, 0);
455
       pdlgInfo->lpOleUIInsertObject->clsid = *clsid;
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478

       if (pdlgInfo->lpOleUIInsertObject->dwFlags & IOF_CREATENEWOBJECT)
       {
          pdlgInfo->lpOleUIInsertObject->sc= OleCreate(
             &pdlgInfo->lpOleUIInsertObject->clsid,
             &pdlgInfo->lpOleUIInsertObject->iid,
             pdlgInfo->lpOleUIInsertObject->oleRender,
             pdlgInfo->lpOleUIInsertObject->lpFormatEtc,
             pdlgInfo->lpOleUIInsertObject->lpIOleClientSite,
             pdlgInfo->lpOleUIInsertObject->lpIStorage,
             pdlgInfo->lpOleUIInsertObject->ppvObj);
       }

       bret = TRUE;
    }
  }
  else if (BST_CHECKED == SendMessageA(pdlgInfo->hwndCreateFromFileCB, BM_GETCHECK, 0, 0))
  {
    if (pdlgInfo->lpOleUIInsertObject->lpszFile)
    {
      HRESULT hres;
      WCHAR wcsFile[MAX_PATH];

479 480 481
      if (SendMessageW(pdlgInfo->hwndFileTB, WM_GETTEXT, MAX_PATH, (LPARAM)wcsFile))
          WideCharToMultiByte(CP_ACP, 0, wcsFile, -1,
              pdlgInfo->lpOleUIInsertObject->lpszFile, pdlgInfo->lpOleUIInsertObject->cchFile, NULL, NULL);
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526

      if (ERROR_SUCCESS == (hres = GetClassFile(wcsFile, &pdlgInfo->lpOleUIInsertObject->clsid)))
      {
         if (pdlgInfo->lpOleUIInsertObject->dwFlags & IOF_CREATEFILEOBJECT)
         {
           hres = OleCreateFromFile(
             &pdlgInfo->lpOleUIInsertObject->clsid,
             wcsFile,
             &pdlgInfo->lpOleUIInsertObject->iid,
             pdlgInfo->lpOleUIInsertObject->oleRender,
             pdlgInfo->lpOleUIInsertObject->lpFormatEtc,
             pdlgInfo->lpOleUIInsertObject->lpIOleClientSite,
             pdlgInfo->lpOleUIInsertObject->lpIStorage,
             pdlgInfo->lpOleUIInsertObject->ppvObj);
         }

         bret = TRUE;
      }
      pdlgInfo->lpOleUIInsertObject->sc = hres;
    }
  }

  return bret;
}


/***********************************************************************
 *      UIINSERTOBJECTDLG_BrowseFile
 *
 * Browse for the file
 */
static void UIINSERTOBJECTDLG_BrowseFile(InsertObjectDlgInfo* pdlgInfo)
{
   OPENFILENAMEA fn;
   char fname[MAX_PATH];
   char title[32];

   fn.lStructSize = sizeof(OPENFILENAMEA);
   fn.hwndOwner = pdlgInfo->hwndSelf;
   fn.hInstance = 0;
   fn.lpstrFilter = "All Files\0*.*\0\0";
   fn.lpstrCustomFilter = NULL;
   fn.nMaxCustFilter = 0;
   fn.nFilterIndex = 0;

527
   SendMessageA(pdlgInfo->hwndFileTB, WM_GETTEXT, MAX_PATH, (LPARAM)fname);
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547
   fn.lpstrFile = fname;
   fn.nMaxFile = MAX_PATH;

   fn.lpstrFileTitle = NULL;
   fn.nMaxFileTitle = 0;
   fn.lpstrInitialDir = NULL;

   LoadStringA(OLEDLG_hInstance, IDS_BROWSE, title, 32);
   fn.lpstrTitle = title;

   fn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST |
      OFN_HIDEREADONLY | OFN_LONGNAMES;
   fn.nFileOffset = 0;
   fn.nFileExtension = 0;
   fn.lpstrDefExt = NULL;
   fn.lCustData = 0;
   fn.lpfnHook = NULL;
   fn.lpTemplateName = NULL;

   if (GetOpenFileNameA(&fn))
548
      SendMessageA(pdlgInfo->hwndFileTB, WM_SETTEXT, 0, (LPARAM)fn.lpstrFile);
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616
}


/***********************************************************************
 *      UIINSERTOBJECTDLG_AddControl
 *
 * Add control to Object Type
 */
static void UIINSERTOBJECTDLG_AddControl(InsertObjectDlgInfo* pdlgInfo)
{
   OPENFILENAMEA fn;
   char fname[MAX_PATH];
   char title[32];

   fn.lStructSize = sizeof(OPENFILENAMEA);
   fn.hwndOwner = pdlgInfo->hwndSelf;
   fn.hInstance = 0;
   fn.lpstrFilter = "OLE Controls\0*.ocx\0Libraries\0*.dll\0All Files\0*.*\0\0";
   fn.lpstrCustomFilter = NULL;
   fn.nMaxCustFilter = 0;
   fn.nFilterIndex = 0;

   fname[0] = 0;
   fn.lpstrFile = fname;
   fn.nMaxFile = MAX_PATH;

   fn.lpstrFileTitle = NULL;
   fn.nMaxFileTitle = 0;
   fn.lpstrInitialDir = NULL;

   LoadStringA(OLEDLG_hInstance, IDS_BROWSE, title, 32);
   fn.lpstrTitle = title;

   fn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST |
      OFN_HIDEREADONLY | OFN_LONGNAMES;
   fn.nFileOffset = 0;
   fn.nFileExtension = 0;
   fn.lpstrDefExt = NULL;
   fn.lCustData = 0;
   fn.lpfnHook = NULL;
   fn.lpTemplateName = NULL;

   if (GetOpenFileNameA(&fn))
   {
      HMODULE hMod;
      BOOL bValid = FALSE;

      hMod = LoadLibraryA(fn.lpstrFile);

      if (hMod)
      {
          DLLREGISTER regproc;

          regproc = (DLLREGISTER) GetProcAddress(hMod, "DllRegisterServer");
          if (regproc)
          {
             if (S_OK == regproc())
             {
                UIINSERTOBJECTDLG_PopulateObjectTypes(pdlgInfo);
                bValid = TRUE;
             }
          }

          FreeLibrary(hMod);
      }

      if (!bValid)
      {
617 618
          WCHAR title[32];
          WCHAR msg[256];
619

620 621
          LoadStringW(OLEDLG_hInstance, IDS_NOTOLEMODCAPTION, title, 32);
          LoadStringW(OLEDLG_hInstance, IDS_NOTOLEMOD, msg, 256);
622

623
          MessageBoxW(pdlgInfo->hwndSelf, msg, title, MB_ICONEXCLAMATION);
624 625 626
      }
   }
}