home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / eddialog.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  43.2 KB  |  1,425 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. // eddialog.cpp : Dialogs used by the CNetscapeEditView class
  20. //
  21. //
  22. // Created 10/11/96 by CLM
  23. //
  24. #include "stdafx.h"
  25. #include "edview.h"
  26. #include "edt.h"
  27. #include "secnav.h"
  28. #include "prefapi.h"
  29. #include "nethelp.h"
  30. #include "xp_help.h"
  31. // the dialog box & string resources are in edtrcdll DLL
  32. #include "edtrcdll\src\resource.h"
  33.  
  34. #ifdef _DEBUG
  35. #undef THIS_FILE
  36. static char BASED_CODE THIS_FILE[] = __FILE__;
  37. #endif
  38.  
  39. extern char *EDT_NEW_DOC_NAME;
  40.  
  41. /////////////////////////////////////////////////////////////////////////////
  42. // CLoadingImageDlg dialog
  43. // 
  44. CLoadingImageDlg::CLoadingImageDlg(CWnd* pParent, MWContext * pMWContext)
  45.     : CDialog(CLoadingImageDlg::IDD, pParent)
  46. {
  47.     //{{AFX_DATA_INIT(CLoadingImageDlg)
  48.         // NOTE: the ClassWizard will add member initialization here
  49.     //}}AFX_DATA_INIT
  50.     ASSERT(pParent);
  51.     ASSERT(pMWContext);
  52.  
  53.     m_pMWContext = pMWContext;
  54.  
  55.     if (!CDialog::Create(CLoadingImageDlg::IDD, pParent))
  56.     {
  57.         TRACE0("Warning: creation of CLoadingImageDlg dialog failed\n");
  58.         return;
  59.     }
  60.  
  61.     // Center the window relative to parent    
  62.     CRect cRectParent;
  63.     CRect cRectDlg;
  64.     pParent->GetWindowRect(&cRectParent);
  65.     GetWindowRect(&cRectDlg);
  66.     int iTop = 200;
  67.     int iLeft = 200;
  68.     if ( cRectParent.Height() > cRectDlg.Height() ){
  69.         iTop = cRectParent.top + ( (cRectParent.Height() - cRectDlg.Height()) / 2 );
  70.     }
  71.     if ( cRectParent.Width() > cRectDlg.Width() ){
  72.         iLeft = cRectParent.left + ( (cRectParent.Width() - cRectDlg.Width()) / 2 );
  73.     }
  74.     
  75.     SetWindowPos( &wndTopMost, iLeft, iTop, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
  76.  
  77.     // Switch back to NETSCAPE.EXE for resource hInstance
  78.     m_ResourceSwitcher.Reset();
  79. }
  80.  
  81.  
  82. void CLoadingImageDlg::DoDataExchange(CDataExchange* pDX)
  83. {
  84.     CDialog::DoDataExchange(pDX);
  85.     //{{AFX_DATA_MAP(CLoadingImageDlg)
  86.         // NOTE: the ClassWizard will add DDX and DDV calls here
  87.     //}}AFX_DATA_MAP
  88. }
  89.  
  90.  
  91. BEGIN_MESSAGE_MAP(CLoadingImageDlg, CDialog)
  92.     //{{AFX_MSG_MAP(CLoadingImageDlg)
  93.     //}}AFX_MSG_MAP
  94. END_MESSAGE_MAP()
  95.  
  96. /////////////////////////////////////////////////////////////////////////////
  97. // CLoadingImageDlg message handlers
  98. void CLoadingImageDlg::OnCancel() 
  99. {
  100.     // Tell edit core to end loading
  101.     // Note: This will result in call to FE_ImageLoadDialogDestroy,
  102.     //       which will do DestroyWindow();
  103.     EDT_ImageLoadCancel(m_pMWContext);
  104. }
  105.  
  106. void CLoadingImageDlg::PostNcDestroy() 
  107. {
  108.     CDialog::PostNcDestroy();
  109.     delete this;
  110. }
  111.  
  112. /////////////////////////////////////////////////////////////////////
  113. CSaveNewDlg::CSaveNewDlg(CWnd * pParent)
  114.     : CDialog(CSaveNewDlg::IDD, pParent)
  115. {
  116.     //{{AFX_DATA_INIT(CSaveNewDlg)
  117.     //}}AFX_DATA_INIT
  118. }
  119.  
  120.  
  121. BOOL CSaveNewDlg::OnInitDialog() 
  122. {
  123.     // Switch back to NETSCAPE.EXE for resource hInstance
  124.     m_ResourceSwitcher.Reset();
  125.  
  126.     CDialog::OnInitDialog();
  127.     
  128.     CStatic * wndIcon = (CStatic *)GetDlgItem(IDC_INFO_ICON);
  129.     wndIcon->SetIcon(theApp.LoadStandardIcon(IDI_ASTERISK));
  130.     
  131.     return TRUE;  // return TRUE unless you set the focus to a control
  132.                   // EXCEPTION: OCX Property Pages should return FALSE
  133. }
  134.  
  135. BEGIN_MESSAGE_MAP(CSaveNewDlg, CDialog)
  136.     //{{AFX_MSG_MAP(CSaveNewDlg)
  137.     //}}AFX_MSG_MAP
  138. END_MESSAGE_MAP()
  139.  
  140. /////////////////////////////////////////////////////////////////////////////
  141. // CSaveFileDlg dialog
  142. //
  143. CSaveFileDlg::CSaveFileDlg(CWnd* pParent,
  144.                            MWContext * pMWContext,
  145.                            int  iFileCount,
  146.                            ED_SaveDialogType saveType )
  147.     : CDialog(CSaveFileDlg::IDD, pParent),
  148.       m_pParent(pParent),
  149.       m_hTimer(0)
  150. {
  151.     ASSERT(pMWContext);
  152.     m_pMWContext = pMWContext;
  153.     m_iFileCount = iFileCount;
  154.     m_iCurrentFile = 0;
  155.     m_bUpload = saveType == ED_SAVE_DLG_PUBLISH;
  156.     
  157.     // For simplicity, create right here
  158.     if (!CDialog::Create(CSaveFileDlg::IDD, pParent))
  159.     {
  160.         TRACE0("Warning: creation of CSaveFileDlg dialog failed\n");
  161.         return;
  162.     }
  163.  
  164.         // Change dialog caption and message to use for uploading;
  165.     UINT nID = 0;
  166.     BOOL bPublishing = TRUE;
  167.     UINT nIDCaption = IDS_PUBLISHING_DOCUMENT;
  168.     switch ( saveType ){
  169.         case ED_SAVE_DLG_SAVE_LOCAL:
  170.             nID = IDS_SAVING_FILE;
  171.             bPublishing = FALSE; // Use Caption in dialog resource
  172.             break;
  173.         case ED_SAVE_DLG_PREPARE_PUBLISH:
  174.             nID = IDS_PREPARING_PUBLISH;
  175.             break;
  176.         case ED_SAVE_DLG_PUBLISH:
  177.             nID = IDS_UPLOADING_FILE;
  178.             break;
  179.     }
  180.     if( bPublishing ){
  181.         SetWindowText(szLoadString(IDS_PUBLISHING_DOCUMENT));
  182.     }
  183.     if( nID ){
  184.         GetDlgItem(IDC_SAVE_FILE_LABEL)->SetWindowText(szLoadString(nID));
  185.     }
  186.  
  187.     // Clear our place-holder string
  188.     GetDlgItem(IDC_FILE_COUNT_MSG)->SetWindowText("");
  189.  
  190.     // Start a short timer -- we don't show window until timer is hit
  191.     // This prevents ugly flashing of this dialog when saving proceeds 
  192.     //   real quick on local drive
  193.     m_hTimer = SetTimer(1, 200, NULL);
  194.  
  195.     // Why doesn't this center on parent window automatically!
  196.     CRect cRectParent;
  197.     CRect cRectDlg;
  198.     GetWindowRect(&cRectDlg);
  199.     // Center in screen
  200.     int iLeft;
  201.     int iTop;
  202.     UINT nStyle = SWP_NOSIZE;
  203.  
  204.     if( pParent ){
  205.         pParent->GetWindowRect(&cRectParent);
  206.         if ( cRectParent.Height() > cRectDlg.Height() ){
  207.             iTop = cRectParent.top + ( (cRectParent.Height() - cRectDlg.Height()) / 2 );
  208.         } else {
  209.             iTop = cRectParent.top + GetSystemMetrics(SM_CYCAPTION);
  210.         }
  211.         if ( cRectParent.Width() > cRectDlg.Width() ){
  212.             iLeft = cRectParent.left + ( (cRectParent.Width() - cRectDlg.Width()) / 2 );
  213.         } else {
  214.             iLeft = cRectParent.left;
  215.         }
  216.     } else {
  217.         iLeft = (sysInfo.m_iScreenWidth / 2) - (cRectDlg.Width()/2);
  218.         iTop  = (sysInfo.m_iScreenHeight / 2) - (cRectDlg.Height()/2);
  219.     }
  220.  
  221.     if( m_hTimer ){
  222.         // Hide window until timer fires or File system closes us
  223.         nStyle |= SWP_HIDEWINDOW;
  224.     } else {
  225.         // No timer - we better show the dialog now
  226.         nStyle |= SWP_SHOWWINDOW;
  227.     }
  228.     // Don't use &wndTopmost because CSaveFileOverwriteDlg
  229.     //  will be popping up over us.
  230.     SetWindowPos(NULL, iLeft, iTop, 0, 0, nStyle);
  231. }
  232.  
  233. void CSaveFileDlg::OnTimer(UINT nIDEvent)
  234. {
  235.     ShowWindow(SW_SHOW);
  236.     KillTimer(1);
  237.     m_hTimer = 0;
  238.     TRACE("CSaveFileDlg::OnTimer - Show window now\n");
  239. }
  240.  
  241. void CSaveFileDlg::StartFileSave(char * pFilename)
  242. {
  243.     GetDlgItem(IDC_SAVE_FILENAME)->SetWindowText(pFilename);
  244.     // Report file number if we have more than 1 total
  245.     if( m_iFileCount > 1 ){
  246.         m_iCurrentFile++;
  247.         CString csFileCount;
  248.         csFileCount.Format(szLoadString(IDS_FILE_COUNT_FORMAT), m_iCurrentFile, m_iFileCount );
  249.         GetDlgItem(IDC_FILE_COUNT_MSG)->SetWindowText(csFileCount);
  250.     }
  251. }
  252.  
  253. void CSaveFileDlg::DoDataExchange(CDataExchange* pDX)
  254. {
  255.     CDialog::DoDataExchange(pDX);
  256.     //{{AFX_DATA_MAP(CSaveFileDlg)
  257.         // NOTE: the ClassWizard will add DDX and DDV calls here
  258.     //}}AFX_DATA_MAP
  259. }
  260.  
  261. BEGIN_MESSAGE_MAP(CSaveFileDlg, CDialog)
  262.     //{{AFX_MSG_MAP(CSaveFileDlg)
  263.     ON_WM_TIMER()
  264.     ON_WM_DESTROY()
  265.     //}}AFX_MSG_MAP
  266. END_MESSAGE_MAP()
  267.  
  268. /////////////////////////////////////////////////////////////////////////////
  269. // CSaveFileDlg message handlers
  270.  
  271. void CSaveFileDlg::OnDestroy() 
  272. {
  273.     if( m_hTimer ){
  274.         KillTimer(1); 
  275.     }
  276. }
  277.  
  278. void CSaveFileDlg::OnCancel() 
  279. {
  280.     if( m_bUpload ){
  281.         // Get a window context from MWContext
  282.         CWinCX *pContext = VOID2CX(m_pMWContext->fe.cx, CWinCX);
  283.         if( pContext ){
  284.             pContext->Interrupt();
  285.         }
  286.         // NET_SilentInterruptWindow(m_pMWContext);
  287.     } else {
  288.         EDT_SaveCancel(m_pMWContext);
  289.     }
  290.     // Do NOT call CDialog::OnCancel(),
  291.     //  Edit core will call to destroy us
  292. }
  293.  
  294. void CSaveFileDlg::PostNcDestroy() 
  295. {
  296.     CDialog::PostNcDestroy();
  297. }
  298.  
  299. /////////////////////////////////////////////////////////////////////////////
  300. // CSaveFileOverwriteDlg dialog
  301.  
  302.  
  303. CSaveFileOverwriteDlg::CSaveFileOverwriteDlg(CWnd* pParent /*=NULL*/,
  304.                                              char * pFilename,
  305.                                              CSaveFileDlg * pSaveDlg)
  306.             : CDialog(CSaveFileOverwriteDlg::IDD, pParent )
  307. {
  308.     //{{AFX_DATA_INIT(CSaveFileOverwriteDlg)
  309.         // NOTE: the ClassWizard will add member initialization here
  310.     //}}AFX_DATA_INIT
  311.     m_pFilename = pFilename;
  312.     m_pSaveFileDlg = pSaveDlg;
  313. }
  314.  
  315.  
  316. BOOL CSaveFileOverwriteDlg::OnInitDialog() 
  317. {
  318.     // Switch back to NETSCAPE.EXE for resource hInstance
  319.     m_ResourceSwitcher.Reset();
  320.  
  321.     CDialog::OnInitDialog();
  322.     CFont * pfontBold = CFont::FromHandle((HFONT)GetStockObject(SYSTEM_FONT));
  323.     CWnd * pWnd = GetDlgItem(IDC_SAVE_FILENAME);
  324.     if ( pWnd ) {
  325.         pWnd->SetFont(pfontBold);
  326.         if ( m_pFilename ) {
  327.             char *pName = XP_STRRCHR(m_pFilename, '\\');
  328.             if( pName ){
  329.                 pName++;
  330.             } else {
  331.                 pName = m_pFilename;
  332.             }
  333.             pWnd->SetWindowText(pName);
  334.         }
  335.     }
  336.  
  337.     // Set the question icon
  338.     CStatic * wndIcon = (CStatic *)GetDlgItem(IDC_OVERWRITE_ICON);
  339.     wndIcon->SetIcon(theApp.LoadStandardIcon(IDI_EXCLAMATION)); // sIDI_QUESTION));
  340.     return TRUE;  // return TRUE unless you set the focus to a control
  341.                   // EXCEPTION: OCX Property Pages should return FALSE
  342. }
  343.  
  344. void CSaveFileOverwriteDlg::DoDataExchange(CDataExchange* pDX)
  345. {
  346.     CDialog::DoDataExchange(pDX);
  347.     //{{AFX_DATA_MAP(CSaveFileOverwriteDlg)
  348.         // NOTE: the ClassWizard will add DDX and DDV calls here
  349.     //}}AFX_DATA_MAP
  350. }
  351.  
  352.  
  353. BEGIN_MESSAGE_MAP(CSaveFileOverwriteDlg, CDialog)
  354.     //{{AFX_MSG_MAP(CSaveFileOverwriteDlg)
  355.     ON_BN_CLICKED(IDC_DONT_OVERWRITE_ALL, OnDontOverwriteAll)
  356.     ON_BN_CLICKED(IDC_DONT_OVERWRITE_ONE, OnDontOverwriteOne)
  357.     ON_BN_CLICKED(IDC_OVERWRITE_ALL, OnOverwriteAll)
  358.     ON_BN_CLICKED(IDC_OVERWRITE_ONE, OnOverwriteOne)
  359.     ON_WM_CREATE()
  360.     //}}AFX_MSG_MAP
  361. END_MESSAGE_MAP()
  362.  
  363.  
  364. /////////////////////////////////////////////////////////////////////////////
  365. // CSaveFileOverwriteDlg message handlers
  366.  
  367. int CSaveFileOverwriteDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  368. {
  369.     if (CDialog::OnCreate(lpCreateStruct) == -1)
  370.         return -1;
  371.  
  372.     // Offset dialog to upper left of parent
  373.     //  Gives a cascade look relative to CSaveFileDlg
  374.     if ( m_pSaveFileDlg ) {
  375.         RECT rectParent;
  376.         m_pSaveFileDlg->GetClientRect(&rectParent);
  377.         m_pSaveFileDlg->ClientToScreen(&rectParent);
  378.         SetWindowPos( 0, /*&wndTopMost,*/ 
  379.                       rectParent.left, rectParent.top,
  380.                      0, 0, SWP_NOSIZE | SWP_NOZORDER);
  381.     }
  382.  
  383.     return 0;
  384. }
  385.  
  386. void CSaveFileOverwriteDlg::OnOK()
  387. {
  388.     CDialog::OnOK();
  389. }
  390.  
  391. void CSaveFileOverwriteDlg::OnDontOverwriteAll() 
  392. {
  393.     m_Result = ED_SAVE_DONT_OVERWRITE_ALL;
  394.     OnOK();
  395. }
  396.  
  397. void CSaveFileOverwriteDlg::OnDontOverwriteOne() 
  398. {
  399.     m_Result = ED_SAVE_DONT_OVERWRITE_THIS;
  400.     OnOK();
  401. }
  402.  
  403. void CSaveFileOverwriteDlg::OnOverwriteAll() 
  404. {
  405.     m_Result = ED_SAVE_OVERWRITE_ALL;
  406.     OnOK();
  407. }
  408.  
  409. void CSaveFileOverwriteDlg::OnOverwriteOne() 
  410. {
  411.     
  412.     m_Result = ED_SAVE_OVERWRITE_THIS;
  413.     OnOK();
  414. }
  415.  
  416. void CSaveFileOverwriteDlg::OnCancel() 
  417. {
  418.     m_Result = ED_SAVE_CANCEL;
  419.     OnOK();
  420. }
  421.  
  422.  
  423. /////////////////////////////////////////////////////////////////////////////
  424. // Local helpers for publish string manipulation
  425.  
  426. static void FreeStrings(char ** pStrings)
  427. {
  428.     if(pStrings){
  429.         int i = 0;
  430.         while( pStrings[i] ){
  431.             XP_FREE(pStrings[i]);
  432.             pStrings[i] = NULL;
  433.             i++;
  434.         }
  435.         XP_FREE(pStrings);
  436.     }
  437. }
  438.  
  439. /////////////////////////////////////////////////////////////////////////////
  440. // CPublishDlg dialog
  441.  
  442.  
  443. CPublishDlg::CPublishDlg(CWnd *pParent,
  444.                          MWContext *pMWContext,
  445.                          char *pUrl)
  446.     : CDialog(CPublishDlg::IDD, pParent),
  447.     m_pMWContext(pMWContext),
  448.     m_pCurrentUrl(pUrl),
  449.     m_pCurrentFile(0),
  450.     m_pCurrentDirectory(0),
  451.     m_pImageFiles(0),
  452.     m_pSelectedDefault(0),
  453.     m_ppAllFiles(0),
  454.     m_bIsRootDirectory(0),
  455.     m_ppUserList(0),
  456.     m_ppPasswordList(0),
  457.     m_pFullLocation(0),
  458.     m_ppImageList(0),
  459.     m_iFileCount(0)
  460. {
  461.   // m_pCurrentFile may be NULL, but m_pCurrentUrl won't be.
  462.   // m_pCurrentFile will be non-NULL iff we are publishing a local file.
  463.   //
  464.   // if (pUrl != file:///Untitled)
  465.   if (XP_STRCMP(pUrl,EDT_NEW_DOC_NAME)) {
  466.     XP_ConvertUrlToLocalFile( pUrl, &m_pCurrentFile );
  467.   }
  468.  
  469.     //{{AFX_DATA_INIT(CPublishDlg)
  470.     m_csUserName = _T("");
  471.     m_csPassword = _T("");
  472.     m_csTitle = _T("");
  473.     m_csFilename = _T("");
  474.     m_bRememberPassword = TRUE;
  475.     //}}AFX_DATA_INIT
  476.     ASSERT( pMWContext );
  477. }
  478.  
  479. CPublishDlg::~CPublishDlg()
  480. {
  481.     XP_FREEIF(m_pCurrentFile);
  482.     XP_FREEIF(m_pCurrentDirectory);
  483.     XP_FREEIF(m_pImageFiles);
  484.     XP_FREEIF(m_pSelectedDefault);
  485.     XP_FREEIF(m_pFullLocation);
  486.     FreeStrings(m_ppImageList);
  487.     FreeStrings(m_ppAllFiles);
  488.     FreeStrings(m_ppUserList);
  489.     FreeStrings(m_ppPasswordList);
  490.     //NOTE: DO NOT try to free m_ppIncludedFiles list - EDT_PublishFile will do that
  491.  
  492. }
  493.  
  494. void CPublishDlg::DoDataExchange(CDataExchange* pDX)
  495. {
  496.     CDialog::DoDataExchange(pDX);
  497.     //{{AFX_DATA_MAP(CPublishDlg)
  498.     DDX_Text(pDX, IDC_PUBLISH_USER, m_csUserName);
  499.     DDX_Text(pDX, IDC_PUBLISH_PASSWORD, m_csPassword);
  500.     DDX_Text(pDX, IDC_DOC_TITLE, m_csTitle);
  501.     DDX_Text(pDX, IDC_PUBLISH_FILENAME, m_csFilename);
  502.     DDX_Check(pDX, IDC_PUBLISH_REMEMBER_PASSWORD, m_bRememberPassword);
  503.     //}}AFX_DATA_MAP
  504. }
  505.  
  506.  
  507. BEGIN_MESSAGE_MAP(CPublishDlg, CDialog)
  508.     //{{AFX_MSG_MAP(CPublishDlg)
  509.     ON_BN_CLICKED(ID_HELP, OnHelp)
  510.     ON_BN_CLICKED(IDC_SELECT_ALL, OnSelectAll)
  511.     ON_BN_CLICKED(IDC_SELECT_NONE, OnSelectNone)
  512.     ON_BN_CLICKED(IDC_INCLUDE_ALL_FILES, OnIncludeAllFiles)
  513.     ON_BN_CLICKED(IDC_INCLUDE_IMAGE_FILES, OnIncludeImageFiles)
  514.     ON_CBN_KILLFOCUS(IDC_PUBLISH_LOCATION_LIST, OnKillfocusPublishLocationList)
  515.     ON_BN_CLICKED(IDC_PUBLISH_DEFAULT_LOCATION, OnPublishDefaultLocation)
  516.     ON_CBN_SELCHANGE(IDC_PUBLISH_LOCATION_LIST, OnSelchangePublishLocation)
  517.     //}}AFX_MSG_MAP
  518. #ifdef XP_WIN32
  519.     ON_WM_HELPINFO()
  520. #endif //XP_WIN32
  521. END_MESSAGE_MAP()
  522.  
  523. BOOL CPublishDlg::OnInitDialog() 
  524. {
  525.     // Switch back to NETSCAPE.EXE for resource hInstance
  526.     m_ResourceSwitcher.Reset();
  527.  
  528.     // TODO: Compress long url name, so fits in list box.
  529.     CString csURL = m_pCurrentFile ? m_pCurrentFile : m_pCurrentUrl;
  530.     WFE_CondenseURL(csURL, 50, FALSE);
  531.     
  532.     CString csCaption;
  533.     csCaption.Format(szLoadString(IDS_PUBLISH_CAPTION), csURL);
  534.     // Display the main filepath (or URL) in dialog Caption
  535.     SetWindowText(csCaption);
  536.  
  537.     CComboBox *pLocationComboBox;
  538.     VERIFY(pLocationComboBox = (CComboBox*)GetDlgItem(IDC_PUBLISH_LOCATION_LIST));
  539.  
  540.     XP_Bool bRem;
  541.     PREF_GetBoolPref("editor.publish_save_password",&bRem);
  542.     m_bRememberPassword = bRem;
  543.  
  544.     char * pPassword = NULL;
  545.     char * pFilename = NULL;
  546.     char * pLastLoc = NULL;
  547.     char * pInitLocation = NULL;
  548.     char * pInitUserName = NULL;
  549.  
  550.     // Get the default publish URL and password
  551.     pInitLocation = EDT_GetDefaultPublishURL(m_pMWContext, &pFilename, &pInitUserName, &pPassword);
  552.     if( pFilename ){
  553.         m_csFilename = pFilename;
  554.         // Don't free yet - we may use it for title
  555.     }
  556.  
  557.     if( pPassword ){
  558.         m_csPassword = pPassword;
  559.         XP_FREEIF(pPassword);
  560.     }
  561.  
  562.     // It would be nice to use CString::GetBuffer, but we can't XP_FREE its contents!
  563.     m_csLocation = pInitLocation;
  564.     m_csUserName = pInitUserName;
  565.     
  566.     // Don't use DDX for this
  567.     pLocationComboBox->SetWindowText(pInitLocation);
  568.  
  569.     XP_FREEIF(m_pFullLocation);
  570.     XP_FREEIF(pInitUserName);
  571.  
  572.     EDT_PageData * pPageData = EDT_GetPageData(m_pMWContext);
  573.     if( pPageData ){
  574.         m_csTitle = pPageData->pTitle;
  575.         EDT_FreePageData(pPageData);
  576.     }
  577.  
  578.     // If empty, fill in title with Filename without extension
  579.     if( m_csTitle.IsEmpty() && pFilename ){
  580.         char * pTitle = EDT_GetPageTitleFromFilename(pFilename);
  581.         if( pTitle ){
  582.             m_csTitle = pTitle;
  583.             XP_FREE(pTitle);
  584.         }
  585.     }
  586.     XP_FREEIF(pFilename);
  587.     
  588.     // Enable the "Default location" button only if we have a preference
  589.     char *prefStr = NULL;
  590.     PREF_CopyCharPref("editor.publish_location", &prefStr);
  591.     if (prefStr) XP_FREE(prefStr);
  592.  
  593.     // Build lists of 10 most-recently-visited sites saved in preferences
  594.     // ComboBox will contain locations,
  595.     //  we store username and password in local lists, same order (no sorting)
  596.     VERIFY(m_ppUserList = (char**) XP_ALLOC((MAX_PUBLISH_LOCATIONS+1) * sizeof(char*)));
  597.     VERIFY(m_ppPasswordList = (char**) XP_ALLOC((MAX_PUBLISH_LOCATIONS+1) * sizeof(char*)));
  598.             
  599.     // Fill the lists of user names and passwords that maps
  600.     //  to the preference list. First item = most recently-added
  601.     int i;
  602.     BOOL bLocationFound = FALSE;
  603.     for( i= 0; i < MAX_PUBLISH_LOCATIONS; i++ ){
  604.         m_ppUserList[i] = NULL;
  605.         m_ppPasswordList[i] = NULL;
  606.         char *pLocation = NULL;
  607.         if( EDT_GetPublishingHistory( i, &pLocation, &m_ppUserList[i], &m_ppPasswordList[i] ) &&
  608.             pLocation && *pLocation ){
  609.             pLocationComboBox->AddString(pLocation);
  610.             // If previous location = the initial new location,
  611.             //  then use the previous username and password 
  612.             if( !bLocationFound && !strcmp(pLocation, pInitLocation) ){
  613.                 // Should there ever be an existing initial username? (not likely!)
  614.                 //if( m_csUserName.IsEmpty() ){
  615.                 m_csUserName = m_ppUserList[i]; 
  616.                 m_csPassword = m_ppPasswordList[i];
  617.                 // Don't check again once we found the most recent entry
  618.                 bLocationFound = TRUE;
  619.             }
  620.         } else {
  621.             break;
  622.         }
  623.         XP_FREEIF(pLocation);
  624.     } 
  625.  
  626.     // Terminate the lists
  627.     m_ppUserList[i] = NULL;
  628.     m_ppPasswordList[i] = NULL;
  629.  
  630.     XP_FREEIF(pInitLocation);
  631.  
  632.     // Copy the directory part of our source file
  633.     // Weird: XP_OPENDIR needs a slash at beginning!
  634.     if (m_pCurrentFile) {
  635.         m_pCurrentDirectory = (char*)XP_ALLOC(XP_STRLEN(m_pCurrentFile)+2);
  636.     }
  637.     // Space for "/."
  638.     else {
  639.         m_pCurrentDirectory = (char*)XP_ALLOC(3);
  640.     }
  641.  
  642.     if( !m_pCurrentDirectory ){
  643.         // No memory!
  644.         TRACE0("Not enough memory for publish string creation.\n");
  645.         EndDialog(IDCANCEL);
  646.         return TRUE;
  647.     }
  648.     XP_STRCPY(m_pCurrentDirectory,"/");  // So trailing \0 if m_pCurrentFile is NULL.
  649.     // *m_pCurrentDirectory = '/';
  650.     if (m_pCurrentFile) {
  651.       XP_STRCPY((m_pCurrentDirectory+1),m_pCurrentFile);
  652.     }
  653.  
  654.     // Find last slash '\' 
  655.     char *pSlash =  strrchr(m_pCurrentDirectory, '\\'); 
  656.     if( pSlash ){
  657.         // Keep terminal slash if we are a root directory
  658.         if( *(pSlash-1) == ':' ){
  659.             m_bIsRootDirectory = TRUE;
  660.             pSlash++;
  661.         }
  662.         *pSlash = '\0';
  663.     } else {
  664.         // No directory? Assume current?
  665.         XP_STRCPY((m_pCurrentDirectory+1),".");
  666.     }
  667.  
  668.     // Fill the list with image files contained in this document
  669.     XP_FREEIF(m_pSelectedDefault);
  670.  
  671.     XP_Bool bKeepImages;
  672.     PREF_GetBoolPref("editor.publish_keep_images",&bKeepImages);
  673.     m_pImageFiles = EDT_GetAllDocumentFilesSelected( m_pMWContext, &m_pSelectedDefault, bKeepImages );
  674.     if( m_pImageFiles ){
  675.         // Start with just the list of images in current file
  676.         OnIncludeImageFiles();
  677.     } else {
  678.         // No images, disable buttons
  679.         GetDlgItem(IDC_INCLUDE_IMAGE_FILES)->EnableWindow(FALSE);    
  680.         GetDlgItem(IDC_SELECT_ALL)->EnableWindow(FALSE);
  681.         GetDlgItem(IDC_SELECT_NONE)->EnableWindow(FALSE);
  682.     }
  683.     if( !m_pCurrentFile ) {
  684.         GetDlgItem(IDC_INCLUDE_ALL_FILES)->EnableWindow(FALSE);    
  685.     }
  686.  
  687.     ((CButton*)GetDlgItem(IDC_INCLUDE_IMAGE_FILES))->SetCheck(m_pImageFiles ? 1 : 0);
  688.  
  689.      CDialog::OnInitDialog();
  690.  
  691.     return TRUE;  // return TRUE unless you set the focus to a control
  692.                   // EXCEPTION: OCX Property Pages should return FALSE
  693. }
  694.  
  695. void CPublishDlg::OnOK() 
  696. {
  697.     UpdateData(TRUE);
  698.  
  699.     // Extract any username:password@ and filename from location editbox
  700.     //  into m_csUserName, m_csPassword, and m_csFilename
  701.     OnKillfocusPublishLocationList();
  702.         
  703.     m_csFilename.TrimLeft();
  704.     m_csFilename.TrimRight();
  705.     m_csTitle.TrimLeft();
  706.     m_csTitle.TrimRight();
  707.  
  708.  
  709.     // Prompt for a filename
  710.     if( m_csFilename.IsEmpty() &&
  711.         IDNO == MessageBox( szLoadString(IDS_ENTER_PUBLISH_FILENAME),
  712.                             szLoadString(IDS_PUBLISH_PAGE),
  713.                             MB_ICONEXCLAMATION | MB_YESNO) ){
  714.         GetDlgItem(IDC_PUBLISH_FILENAME)->SetFocus();
  715.         return;
  716.     }
  717.  
  718.     if( m_csTitle.IsEmpty() ){
  719.         char * pSuggested = EDT_GetPageTitleFromFilename((char*)LPCSTR(m_csFilename));        
  720.         
  721.         // Use same dialog we use after SaveAs to prompt user for a title
  722.         CPageTitleDlg dlg(this, &pSuggested);
  723.         if( dlg.DoModal() == IDOK ){
  724.             m_csTitle = pSuggested;
  725.         } else {
  726.             // User canceled. Put them back in Publish dialog
  727.             GetDlgItem(IDC_DOC_TITLE)->SetFocus();
  728.             XP_FREEIF(pSuggested);
  729.             return;
  730.         }
  731.         XP_FREEIF(pSuggested);
  732.     }
  733.  
  734.     EDT_PageData * pPageData = EDT_GetPageData(m_pMWContext);
  735.     if( pPageData ){
  736.       char *pNewTitle;
  737.       if( m_csTitle.IsEmpty() ){
  738.           pNewTitle = NULL;
  739.       } else {    
  740.           pNewTitle = XP_STRDUP(LPCSTR(m_csTitle));
  741.       }
  742.  
  743.       // Only set if value has changed.  O.W. Messes up the editor dirty flag.
  744.       if (XP_STRCMP(pPageData->pTitle ? pPageData->pTitle : "",
  745.                     pNewTitle ? pNewTitle : "")) {
  746.         XP_FREEIF(pPageData->pTitle);
  747.         pPageData->pTitle = pNewTitle; 
  748.         EDT_SetPageData(m_pMWContext, pPageData);
  749.       }
  750.       else {
  751.         XP_FREEIF(pNewTitle);
  752.       }
  753.   
  754.       EDT_FreePageData(pPageData);
  755.     }
  756.  
  757.     ((CComboBox*)GetDlgItem(IDC_PUBLISH_LOCATION_LIST))->GetWindowText(m_csLocation);
  758.     m_csLocation.TrimLeft();
  759.     m_csLocation.TrimRight();
  760.     
  761.     int type = NET_URL_Type((char*)LPCSTR(m_csLocation));
  762.     if( type == FTP_TYPE_URL  ||
  763.         type == HTTP_TYPE_URL ||
  764.         type == SECURE_HTTP_TYPE_URL ){
  765.  
  766.         m_csUserName.TrimLeft();
  767.         m_csUserName.TrimRight();
  768.         m_csPassword.TrimLeft();
  769.         m_csPassword.TrimRight();
  770.         m_csLocation.TrimLeft();
  771.         m_csLocation.TrimRight();
  772.  
  773.         // Assemble a string WITH password to do actual upload
  774.         char * pLocation = NULL;
  775.         NET_MakeUploadURL( &pLocation, (char*)LPCSTR(m_csLocation), 
  776.                            (char*)LPCSTR(m_csUserName),
  777.                            (char*)LPCSTR(m_csPassword) );
  778.               
  779.         // Add filename to end of location URL for validation
  780.         // This is final string used by Publishing
  781.         m_pFullLocation = EDT_ReplaceFilename(pLocation, (char*)LPCSTR(m_csFilename), TRUE);
  782.         XP_FREEIF(pLocation);
  783.         
  784.         // HARDTS:        
  785.         // Tell user the URL they are publishing looks like it might be wrong.
  786.         // e.g. ends in a slash or does not have a file extension.
  787.         // Give the user the option of attempting to publish to the
  788.         // specified URL even if it looks suspicious.
  789.         if (!EDT_CheckPublishURL(m_pMWContext,m_pFullLocation)) {
  790.             return;
  791.         }
  792.  
  793.         CListBox * pIncludeListBox = (CListBox*)GetDlgItem(IDC_PUBLISH_OTHER_FILES);
  794.         int iCount = pIncludeListBox->GetSelCount();
  795.         
  796.         // Plus one extra string to terminate array
  797.         m_ppIncludedFiles = (char**) XP_ALLOC((iCount+1) * sizeof(char*));
  798.  
  799.         if( !m_ppIncludedFiles ){
  800.             // Unlikely! Not enough memory!
  801.             EndDialog(IDCANCEL);
  802.             return;
  803.         }
  804.         BOOL bUseImageList = ((CButton*)GetDlgItem(IDC_INCLUDE_IMAGE_FILES))->GetCheck();
  805.  
  806.         // Construct an array of included files
  807.         //   from just the selected items in listbox
  808.         if( iCount ){
  809.             int *pIndexes = (int*)XP_ALLOC(iCount * sizeof(int));
  810.             if( pIndexes ){
  811.                 pIncludeListBox->GetSelItems(iCount, pIndexes);
  812.                 CString csItem;
  813.                 for( int i=0; i < iCount; i++ ){
  814.                     if( bUseImageList ){
  815.                         // Copy the URL from the original, sorted list of image URLs
  816.                         csItem = m_ppImageList[pIndexes[i]];
  817.                     } else {
  818.                         pIncludeListBox->GetText(pIndexes[i], csItem);
  819.                     }
  820.                     m_ppIncludedFiles[i] = XP_STRDUP(LPCSTR(csItem));
  821.                 }
  822.                 XP_FREE(pIndexes);
  823.             }
  824.         }
  825.         // Terminate array
  826.         m_ppIncludedFiles[iCount] = NULL;
  827.  
  828.         // Don't use CDialog::OnOK() -- it will overwrite our changed m_csLocation
  829.         EndDialog(IDOK);
  830.     } else {
  831.         // Tell user they must use "ftp://" or "http://"
  832.         MessageBox(szLoadString(IDS_BAD_PUBLISH_URL),
  833.                    szLoadString(IDS_PUBLISH_FILES),
  834.                    MB_ICONEXCLAMATION | MB_OK);
  835.     }
  836. }
  837.  
  838. void CPublishDlg::OnHelp() 
  839. {
  840.     NetHelp(HELP_PUBLISH_FILES);
  841. }
  842.  
  843.  
  844.  
  845. #ifdef XP_WIN32
  846. BOOL CPublishDlg::OnHelpInfo(HELPINFO *)//32bit messagemapping.
  847. {
  848.     OnHelp();
  849.     return TRUE;
  850. }
  851. #endif//XP_WIN32
  852.  
  853.  
  854.  
  855. void CPublishDlg::OnCancel() 
  856. {
  857.     // TODO: Add extra cleanup here
  858.     
  859.     CDialog::OnCancel();
  860. }
  861.  
  862. // Implemented in edprops.cpp
  863. extern int CompareStrings( const void *arg1, const void *arg2 );
  864.  
  865. // Maximum number of characters of a URL in the Included Files listbox
  866. #define ED_MAX_URL_LENGTH 55
  867.  
  868. void CPublishDlg::OnIncludeImageFiles() 
  869. {
  870.     if( m_pImageFiles ){
  871.         FreeStrings(m_ppImageList);
  872.         m_iFileCount = 0;
  873.  
  874.         char * pString = m_pImageFiles;
  875.         int iLen;    
  876.         // Scan list once to count items
  877.         while( (iLen = XP_STRLEN(pString)) > 0 ) {
  878.             pString += iLen+1;
  879.             m_iFileCount++;
  880.         }
  881.         m_ppImageList = (char**)XP_ALLOC((m_iFileCount+1) * sizeof(char*));
  882.         if(!m_ppImageList){
  883.             return;
  884.         }
  885.  
  886.         int i = 0;
  887.         pString = m_pImageFiles;
  888.  
  889.         for( i = 0; i< m_iFileCount; i++){
  890.             iLen = XP_STRLEN(pString) + 1;
  891.             // Allocate room for string + 1 char at end for selected signal
  892.             //   (cause index list we have will be useless once names are sorted)
  893.             char * pItem = (char*)XP_ALLOC((iLen+1) * sizeof(char));
  894.             if( pItem ){
  895.                 strcpy(pItem,pString);
  896.                 pItem[iLen] = m_pSelectedDefault[i] ? ' ' : '\0';
  897.                 m_ppImageList[i] = pItem;
  898.             } else {
  899.                 FreeStrings(m_ppImageList);
  900.                 m_ppImageList = NULL;
  901.                 m_iFileCount = 0;
  902.                 return;
  903.             }
  904.             pString += iLen;
  905.         }
  906.         // Terminate the list
  907.         m_ppImageList[i] = NULL;
  908.  
  909.         // Sort the strings
  910.         qsort( (void *)m_ppImageList, (size_t)m_iFileCount, sizeof( char * ), CompareStrings );
  911.  
  912.         CListBox * pIncludeListBox = (CListBox*)GetDlgItem(IDC_PUBLISH_OTHER_FILES);
  913.         pIncludeListBox->ResetContent();
  914.         for(i = 0; i < m_iFileCount; i++){
  915.             // add to the end of the list
  916.             pString = m_ppImageList[i];
  917.             iLen = strlen(pString);
  918.             if( iLen > ED_MAX_URL_LENGTH ){
  919.                 CString csItem = pString;
  920.                 WFE_CondenseURL(csItem, ED_MAX_URL_LENGTH, FALSE);
  921.                 pIncludeListBox->AddString(LPCSTR(csItem));
  922.             } else {
  923.                 pIncludeListBox->AddString(pString);
  924.             }
  925.             char SelChar = pString[strlen(pString)+1];
  926.             // Last character past '\0' is " " for selected, or 0 if not selected by default
  927.             pIncludeListBox->SetSel(i, SelChar ? 1 : 0);
  928.         }
  929.  
  930.         GetDlgItem(IDC_SELECT_ALL)->EnableWindow(TRUE);
  931.         GetDlgItem(IDC_SELECT_NONE)->EnableWindow(TRUE);
  932.     }
  933. }
  934.  
  935. void CPublishDlg::OnIncludeAllFiles() 
  936. {
  937.     // Shouldn't be here when editing a remote URL.
  938.     if (!m_pCurrentFile) {
  939.       ASSERT(0);
  940.     }
  941.  
  942.     FreeStrings(m_ppAllFiles);
  943.  
  944.     // Always reread directory list in case use changes
  945.     //   with another program
  946.     m_ppAllFiles = NET_AssembleAllFilesInDirectory(m_pMWContext, 
  947.                                                    m_pCurrentDirectory);
  948.  
  949.     // Get the count of items
  950.     int i = 0;
  951.     while( m_ppAllFiles[i] ){
  952.         i++;
  953.     }
  954.  
  955.     // Sort the strings
  956.     qsort( (void *)m_ppAllFiles, (size_t)i, sizeof( char * ), CompareStrings );
  957.  
  958.     int iCount = 0;
  959.     if( m_ppAllFiles && *m_ppAllFiles ){
  960.         CListBox * pIncludeListBox = (CListBox*)GetDlgItem(IDC_PUBLISH_OTHER_FILES);
  961.         pIncludeListBox->ResetContent();
  962.         // Get current file without the directory
  963.         char *pMainFile = m_pCurrentFile + XP_STRLEN(m_pCurrentFile);
  964.         while( pMainFile != m_pCurrentFile && *pMainFile != '\\') pMainFile--;
  965.         if( pMainFile != m_pCurrentFile ) pMainFile++;
  966.         
  967.         i = 0;
  968.         char * pFilename;
  969.         while( m_ppAllFiles[i] ){
  970.             // Find just filename (skip over included directory)
  971.             pFilename = strrchr(m_ppAllFiles[i], '\\');
  972.             if( ! pFilename ){
  973.                 pFilename = strrchr(m_ppAllFiles[i], '/');
  974.             }
  975.             if( pFilename ){
  976.                 pFilename++;
  977.             } else {
  978.                 pFilename = m_ppAllFiles[i];
  979.             }
  980.             // Don't include the main file in the list
  981.             if( 0 != strcmpi(pFilename, pMainFile) ){
  982.                 pIncludeListBox->AddString(pFilename);
  983.                 iCount++;
  984.             }
  985.             i++;
  986.         }
  987.         pIncludeListBox->SetSel(-1, TRUE);
  988.     }
  989.     // If no other files in the directory, clear button
  990.     // (Note: we don't disable in case user copies files to 
  991.     //  directory while dialog is still active)
  992.     if( iCount == 0 ){
  993.         ((CButton*)GetDlgItem(IDC_INCLUDE_ALL_FILES))->SetCheck(0);
  994.     }
  995.     GetDlgItem(IDC_SELECT_ALL)->EnableWindow(iCount > 0);
  996.     GetDlgItem(IDC_SELECT_NONE)->EnableWindow(iCount > 0);
  997. }
  998.  
  999. void CPublishDlg::OnSelectAll() 
  1000. {
  1001.     // Select all strings in the listbox
  1002.     ((CListBox*)GetDlgItem(IDC_PUBLISH_OTHER_FILES))->SetSel(-1, TRUE);
  1003. }
  1004.  
  1005. void CPublishDlg::OnSelectNone() 
  1006. {
  1007.     // Unselect all strings in the listbox
  1008.     ((CListBox*)GetDlgItem(IDC_PUBLISH_OTHER_FILES))->SetSel(-1, FALSE);
  1009. }
  1010.  
  1011. void CPublishDlg::OnSelchangePublishLocation() 
  1012. {
  1013.     // Get the corresponding username and passwords
  1014.     //  to show in edit boxes
  1015.     int i = ((CComboBox*)GetDlgItem(IDC_PUBLISH_LOCATION_LIST))->GetCurSel();
  1016.  
  1017.     if( i >= 0 && m_ppUserList && m_ppPasswordList ){
  1018.         // This is lame. We can't use UpdateData 
  1019.         //  or setting selected item doesn't work right!
  1020.         GetDlgItem(IDC_PUBLISH_USER)->SetWindowText(m_ppUserList[i]);
  1021.         GetDlgItem(IDC_PUBLISH_PASSWORD)->SetWindowText(m_ppPasswordList[i]);
  1022.     }
  1023. }
  1024.  
  1025. // Parse editfield location into URL, Filename, UserName, and Password
  1026. //  NOTE: Anything found in this Location will override contents of 
  1027. //        individual Filename, UserName, and Password edit boxes
  1028. void CPublishDlg::OnKillfocusPublishLocationList()
  1029. {
  1030.     // If user included a filename, user name, or password within location string,
  1031.     //  use that instead of current edit fields
  1032.     UpdateData(TRUE);
  1033.  
  1034.     char *pUserName = NULL;
  1035.     char *pPassword = NULL;
  1036.     char *pLocation = NULL;
  1037.     char *pFilename = NULL;
  1038.     GetDlgItem(IDC_PUBLISH_LOCATION_LIST)->GetWindowText(m_csLocation);
  1039.     m_csLocation.TrimLeft();
  1040.     m_csLocation.TrimRight();
  1041.  
  1042.     NET_ParseUploadURL( (char*)LPCSTR(m_csLocation), &pLocation, 
  1043.                         &pUserName, &pPassword );
  1044.     if( pUserName ){
  1045.         CString csUser = pUserName;
  1046.         csUser.TrimLeft();
  1047.         csUser.TrimRight();
  1048.         if( !csUser.IsEmpty() ){
  1049.             m_csUserName = csUser;
  1050.         }
  1051.         XP_FREE(pUserName);
  1052.     }
  1053.     if( pPassword ){
  1054.         CString csPassword = pPassword;
  1055.         csPassword.TrimLeft();
  1056.         csPassword.TrimRight();
  1057.         if( !csPassword.IsEmpty() ){
  1058.             m_csPassword = csPassword;
  1059.         }
  1060.         XP_FREE(pPassword);
  1061.     }
  1062.     if( pLocation ){
  1063.         // Extract filename at end of Location
  1064.         //  ONLY if it ends in ".htm" or ".html" or ".shtml"
  1065.         pFilename = EDT_GetFilename(pLocation, TRUE);
  1066.         // Put in check for pFilename to be NULL.  hardts
  1067.         char * pDot = pFilename ? strchr(pFilename, '.') : NULL;
  1068.         if( pFilename && *pFilename && pDot &&
  1069.             (0 == stricmp(".htm", pDot) || 0 == stricmp(".html", pDot) || 0 == stricmp(".shtml", pDot)) ){
  1070.             m_csFilename = pFilename;
  1071.             XP_FREE(pFilename);
  1072.  
  1073.             // Save version with filename stripped off
  1074.             char * pURL = EDT_ReplaceFilename(pLocation, NULL, TRUE);
  1075.             m_csLocation = pURL;
  1076.             GetDlgItem(IDC_PUBLISH_LOCATION_LIST)->SetWindowText(pURL);
  1077.             XP_FREEIF(pURL);
  1078.         } else {
  1079.             m_csLocation = pLocation;
  1080.         }
  1081.         XP_FREE(pLocation);
  1082.     }
  1083.  
  1084.     // Update Filename, User name, and password controls
  1085.     UpdateData(FALSE);
  1086. }
  1087.  
  1088.  
  1089. void CPublishDlg::OnPublishDefaultLocation() 
  1090. {
  1091.     UpdateData(TRUE);
  1092.  
  1093.     GetDlgItem(IDC_PUBLISH_LOCATION_LIST)->GetWindowText(m_csLocation);
  1094.  
  1095.     char * pDefaultLocation = NULL;
  1096.     PREF_CopyCharPref("editor.publish_location", &pDefaultLocation);
  1097.     if( !pDefaultLocation){
  1098.         return;
  1099.     }
  1100.     char *pLocation = NULL;
  1101.     char *pUserName = NULL;
  1102.  
  1103.     // Parse the preference string to extract Username
  1104.     //  password is separate for security munging
  1105.     NET_ParseUploadURL( pDefaultLocation, &pLocation, 
  1106.                         &pUserName, NULL );
  1107.  
  1108.     // It would be nice to use CString::GetBuffer, but we can't XP_FREE its contents!
  1109.     m_csLocation = pLocation;
  1110.     m_csUserName = pUserName;
  1111.  
  1112.     char * pPass = NULL;
  1113.     PREF_CopyCharPref("editor.publish_password", &pPass);
  1114.     char * pPassword = SECNAV_UnMungeString(pPass);
  1115.     m_csPassword = pPassword;
  1116.     XP_FREEIF(pPassword);
  1117.  
  1118.     GetDlgItem(IDC_PUBLISH_LOCATION_LIST)->SetWindowText(pLocation);
  1119.     
  1120.     XP_FREEIF(pDefaultLocation);
  1121.     XP_FREEIF(pLocation);
  1122.     XP_FREEIF(pUserName);
  1123.     XP_FREEIF(pPass);
  1124.  
  1125.     UpdateData(FALSE);
  1126. }
  1127.  
  1128. /////////////////////////////////////////////////////////////////////////////
  1129. // CEditHintDlg dialog
  1130.  
  1131.  
  1132. CEditHintDlg::CEditHintDlg(CWnd* pParent,
  1133.                UINT  nID_Msg,
  1134.                UINT  nID_Caption,
  1135.                BOOL  bYesNo)     // Default style is MB_OK
  1136.     : CDialog(CEditHintDlg::IDD, pParent),
  1137.       m_nID_Msg(nID_Msg),
  1138.       m_nID_Caption(nID_Caption),
  1139.       m_bYesNo(bYesNo)
  1140. {
  1141.     //{{AFX_DATA_INIT(CEditHintDlg)
  1142.     m_bDontShowAgain = FALSE;
  1143.     m_cHintText = _T("");
  1144.     //}}AFX_DATA_INIT
  1145. }
  1146.  
  1147.  
  1148. void CEditHintDlg::DoDataExchange(CDataExchange* pDX)
  1149. {
  1150.     CDialog::DoDataExchange(pDX);
  1151.     //{{AFX_DATA_MAP(CEditHintDlg)
  1152.     DDX_Check(pDX, IDC_SHOW_HINT_AGAIN, m_bDontShowAgain);
  1153.     DDX_Text(pDX, IDC_EDIT_HINT, m_cHintText);
  1154.     //}}AFX_DATA_MAP
  1155. }
  1156.  
  1157.  
  1158. BEGIN_MESSAGE_MAP(CEditHintDlg, CDialog)
  1159.     //{{AFX_MSG_MAP(CEditHintDlg)
  1160.     ON_BN_CLICKED(IDYES, OnYes)
  1161.     ON_BN_CLICKED(IDNO, OnNo)
  1162.     //}}AFX_MSG_MAP
  1163. END_MESSAGE_MAP()
  1164.  
  1165.  
  1166. /////////////////////////////////////////////////////////////////////////////
  1167. // CEditHintDlg message handlers
  1168.  
  1169. BOOL CEditHintDlg::OnInitDialog() 
  1170. {
  1171.     m_ResourceSwitcher.Reset();
  1172.     
  1173.     CStatic * wndIcon = (CStatic *)GetDlgItem(IDC_INFO_ICON);
  1174.     wndIcon->SetIcon(theApp.LoadStandardIcon(IDI_ASTERISK));
  1175.     if( m_nID_Caption ){
  1176.         SetWindowText(szLoadString(m_nID_Caption));
  1177.     }
  1178.     if( m_nID_Msg ){
  1179.         m_cHintText.LoadString(m_nID_Msg);
  1180.     }
  1181.     if( m_bYesNo ){
  1182.         // Switch to Yes/No button pair
  1183.         GetDlgItem(IDOK)->ShowWindow(SW_HIDE);
  1184.         GetDlgItem(IDYES)->ShowWindow(SW_SHOW);
  1185.         GetDlgItem(IDNO)->ShowWindow(SW_SHOW);
  1186.     }
  1187.     CDialog::OnInitDialog();
  1188.     return TRUE;  // return TRUE unless you set the focus to a control
  1189.               // EXCEPTION: OCX Property Pages should return FALSE
  1190. }
  1191.  
  1192. void CEditHintDlg::OnOK() 
  1193. {
  1194.     // TODO: Add extra validation here
  1195.     
  1196.     CDialog::OnOK();
  1197. }
  1198.  
  1199. void CEditHintDlg::OnYes() 
  1200. {
  1201.     OnOK();             
  1202. }
  1203.  
  1204. void CEditHintDlg::OnNo() 
  1205. {
  1206.     CDialog::OnCancel();
  1207. }
  1208.  
  1209. /////////////////////////////////////////////////////////////////////////////
  1210. CGetLocationDlg::CGetLocationDlg(CWnd* pParent,
  1211.                UINT  nID_Msg,
  1212.                UINT  nID_Caption,
  1213.                UINT  nID_FileCaption)
  1214.     : CDialog(CGetLocationDlg::IDD, pParent),
  1215.       m_nID_Msg(nID_Msg),
  1216.       m_nID_Caption(nID_Caption),
  1217.       m_nID_FileCaption(nID_FileCaption)
  1218. {
  1219.     //{{AFX_DATA_INIT(CGetLocationDlg)
  1220.     m_csLocation = _T("");
  1221.     //}}AFX_DATA_INIT
  1222. }
  1223.  
  1224. void CGetLocationDlg::DoDataExchange(CDataExchange* pDX)
  1225. {
  1226.     CDialog::DoDataExchange(pDX);
  1227.     //{{AFX_DATA_MAP(CGetLocationDlg)
  1228.     DDX_Text(pDX, IDC_LOCATION, m_csLocation);
  1229.     //}}AFX_DATA_MAP
  1230. }
  1231.  
  1232. BEGIN_MESSAGE_MAP(CGetLocationDlg, CDialog)
  1233.     //{{AFX_MSG_MAP(CGetLocationDlg)
  1234.     ON_BN_CLICKED(IDC_BROWSE_FILE, OnChooseFile)
  1235.     //}}AFX_MSG_MAP
  1236. END_MESSAGE_MAP()
  1237.  
  1238. /////////////////////////////////////////////////////////////////////////////
  1239. // CGetLocationDlg message handlers
  1240.  
  1241. BOOL CGetLocationDlg::OnInitDialog() 
  1242. {
  1243.     m_ResourceSwitcher.Reset();
  1244.     
  1245.     if( m_nID_Caption ){
  1246.         SetWindowText(szLoadString(m_nID_Caption));
  1247.     }
  1248.     if( m_nID_Msg ){
  1249.         GetDlgItem(IDC_PREF_STRING_MSG)->SetWindowText(szLoadString(m_nID_Msg));
  1250.     }
  1251.     CDialog::OnInitDialog();
  1252.     return TRUE;
  1253. }
  1254.  
  1255. void CGetLocationDlg::OnOK() 
  1256. {
  1257.     CDialog::OnOK();
  1258.     m_csLocation.TrimLeft();
  1259.     m_csLocation.TrimRight();
  1260.  
  1261.     // In case user entered a local filename instead of using "Choose File"
  1262.     CString csLocation;
  1263.     WFE_ConvertFile2Url(csLocation, LPCSTR(m_csLocation));
  1264.     m_csLocation = csLocation;
  1265. }
  1266.  
  1267. void CGetLocationDlg::OnChooseFile() 
  1268. {
  1269.     char * szFilename = wfe_GetExistingImageFileName(this->m_hWnd, 
  1270.                                          szLoadString(m_nID_FileCaption), TRUE);
  1271.     if ( szFilename != NULL ){
  1272.         WFE_ConvertFile2Url(m_csLocation, szFilename);
  1273.         UpdateData(FALSE);
  1274.     }
  1275. }
  1276.  
  1277. /////////////////////////////////////////////////////////////////////////////
  1278. COpenTemplateDlg::COpenTemplateDlg(CWnd* pParent)
  1279.     : CDialog(COpenTemplateDlg::IDD, pParent)
  1280. {
  1281.     //{{AFX_DATA_INIT(COpenTemplateDlg)
  1282.     m_csLocation = _T("");
  1283.     //}}AFX_DATA_INIT
  1284. }
  1285.  
  1286. void COpenTemplateDlg::DoDataExchange(CDataExchange* pDX)
  1287. {
  1288.     CDialog::DoDataExchange(pDX);
  1289.     //{{AFX_DATA_MAP(COpenTemplateDlg)
  1290.     DDX_Text(pDX, IDC_LOCATION, m_csLocation);
  1291.     //}}AFX_DATA_MAP
  1292. }
  1293.  
  1294. BEGIN_MESSAGE_MAP(COpenTemplateDlg, CDialog)
  1295.     //{{AFX_MSG_MAP(COpenTemplateDlg)
  1296.     ON_BN_CLICKED(IDC_BROWSE_FILE, OnChooseFile)
  1297.     ON_BN_CLICKED(IDC_NETSCAPE_TEMPLATES, OnGotoNetscapeTemplates)
  1298.     //}}AFX_MSG_MAP
  1299. END_MESSAGE_MAP()
  1300.  
  1301. /////////////////////////////////////////////////////////////////////////////
  1302. // COpenTemplateDlg message handlers
  1303. BOOL COpenTemplateDlg::OnInitDialog() 
  1304. {
  1305.     m_ResourceSwitcher.Reset();
  1306.     
  1307.     CComboBox *pCombo = 
  1308.         (CComboBox*)(GetDlgItem(IDC_LOCATION));
  1309.  
  1310.     m_iTemplateLocationCount = theApp.m_iTemplateLocationCount;
  1311.     m_pHistoryBase = "editor.template_history_%d";
  1312.     //PREF_GetCharPref(,szLocation);
  1313.  
  1314.     if( m_iTemplateLocationCount ){
  1315.         // ComboBox will contain locations,
  1316.         //  we store username and password in local lists, same order (no sorting)
  1317.         VERIFY(m_pLocationList = (char**) XP_ALLOC((m_iTemplateLocationCount+1) * sizeof(char*)));
  1318.                 
  1319.         // Fill the lists of user names and passwords that maps
  1320.         //  to the preference list. First item = most recently-added
  1321.         int i;
  1322.         for( i= 0; i < m_iTemplateLocationCount; i++ ){
  1323.             m_pLocationList[i] = NULL;
  1324.             char pLoc[128];
  1325.             char *pLocation = NULL;
  1326.  
  1327.             wsprintf(pLoc, m_pHistoryBase,i);
  1328.             // Get the preference value - RETURNS NULL IF EMPTY STRING!
  1329.             PREF_CopyCharPref(pLoc,&pLocation);
  1330.             if( pLocation && pLocation[0] ){
  1331.                 pCombo->AddString(pLocation);
  1332.             }
  1333.             XP_FREEIF(pLocation);
  1334.         } 
  1335.         // Terminate list
  1336.         m_pLocationList[i] = NULL;
  1337.     }
  1338.     CDialog::OnInitDialog();
  1339.     pCombo->SetCurSel(0);
  1340.     
  1341.     return TRUE;
  1342. }
  1343.  
  1344. void COpenTemplateDlg::OnOK() 
  1345. {
  1346.     CDialog::OnOK();
  1347.     m_csLocation.TrimLeft();
  1348.     m_csLocation.TrimRight();
  1349.  
  1350.     // In case user entered a local filename instead of using "Choose File"
  1351.     CString csLocation;
  1352.     WFE_ConvertFile2Url(csLocation, LPCSTR(m_csLocation));
  1353.     m_csLocation = csLocation;
  1354. }
  1355.  
  1356. void COpenTemplateDlg::OnChooseFile() 
  1357. {
  1358.     char * pFilename = wfe_GetExistingFileName(this->m_hWnd, 
  1359.                                                szLoadString(IDS_SELECT_TEMPLATE_CAPTION), HTM_ONLY, TRUE);
  1360.     if ( pFilename != NULL ){
  1361.         WFE_ConvertFile2Url(m_csLocation, pFilename);
  1362.         UpdateData(FALSE);
  1363.     }
  1364. }
  1365.  
  1366. void COpenTemplateDlg::OnGotoNetscapeTemplates()
  1367. {
  1368.     char * pDefault;
  1369.     PREF_CopyCharPref("editor.default_template_location", &pDefault);
  1370.     m_csLocation = pDefault;
  1371.     XP_FREEIF(pDefault);
  1372.     UpdateData(FALSE);
  1373.     EndDialog(IDOK);
  1374. }
  1375.  
  1376. /////////////////////////////////////////////////////////////////////////////
  1377. CPageTitleDlg::CPageTitleDlg(CWnd* pParent, char** ppTitle)
  1378.     : CDialog(CPageTitleDlg::IDD, pParent),
  1379.     m_ppTitle(ppTitle)
  1380. {
  1381.     //{{AFX_DATA_INIT(CPageTitleDlg)
  1382.     m_csTitle = _T("");
  1383.     //}}AFX_DATA_INIT
  1384. }
  1385.  
  1386. void CPageTitleDlg::DoDataExchange(CDataExchange* pDX)
  1387. {
  1388.     CDialog::DoDataExchange(pDX);
  1389.     //{{AFX_DATA_MAP(CPageTitleDlg)
  1390.     DDX_Text(pDX, IDC_DOC_TITLE, m_csTitle);
  1391.     //}}AFX_DATA_MAP
  1392. }
  1393.  
  1394. BEGIN_MESSAGE_MAP(CPageTitleDlg, CDialog)
  1395.     //{{AFX_MSG_MAP(CPageTitleDlg)
  1396.     //}}AFX_MSG_MAP
  1397. END_MESSAGE_MAP()
  1398.  
  1399. /////////////////////////////////////////////////////////////////////////////
  1400. // CPageTitleDlg message handlers
  1401.  
  1402.  
  1403. BOOL CPageTitleDlg::OnInitDialog() 
  1404. {
  1405.     m_ResourceSwitcher.Reset();
  1406.     if( m_ppTitle && *m_ppTitle ){
  1407.         m_csTitle = *m_ppTitle;
  1408.     }
  1409.     CDialog::OnInitDialog();
  1410.     return TRUE;
  1411. }
  1412.  
  1413. void CPageTitleDlg::OnOK() 
  1414. {
  1415.     CDialog::OnOK();
  1416.     m_csTitle.TrimLeft();
  1417.     m_csTitle.TrimRight();
  1418.  
  1419.     // Return new string at location supplied
  1420.     if( m_ppTitle ){
  1421.         XP_FREEIF(*m_ppTitle);
  1422.         *m_ppTitle = XP_STRDUP(LPCSTR(m_csTitle));
  1423.     }
  1424. }
  1425.