Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

908 lines
20 KiB

  1. /*++
  2. Copyright (c) 1994-2001 Microsoft Corporation
  3. Module Name :
  4. docum.cpp
  5. Abstract:
  6. WWW Documents Page
  7. Author:
  8. Ronald Meijer (ronaldm)
  9. Sergei Antonov (sergeia)
  10. Project:
  11. Internet Services Manager
  12. Revision History:
  13. --*/
  14. #include "stdafx.h"
  15. #include "resource.h"
  16. #include "common.h"
  17. #include "inetmgrapp.h"
  18. #include "inetprop.h"
  19. #include "shts.h"
  20. #include "w3sht.h"
  21. #include "supdlgs.h"
  22. #include "docum.h"
  23. #include <lmcons.h>
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. //
  30. // CAddDefDocDlg dialog
  31. //
  32. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  33. CAddDefDocDlg::CAddDefDocDlg(CWnd * pParent OPTIONAL)
  34. : CDialog(CAddDefDocDlg::IDD, pParent)
  35. {
  36. //{{AFX_DATA_INIT(CAddDefDocDlg)
  37. m_strDefDocument = _T("");
  38. //}}AFX_DATA_INIT
  39. m_pParent = NULL;
  40. }
  41. void
  42. CAddDefDocDlg::DoDataExchange(CDataExchange * pDX)
  43. {
  44. CDialog::DoDataExchange(pDX);
  45. //{{AFX_DATA_MAP(CAddDefDocDlg)
  46. DDX_Control(pDX, IDOK, m_button_Ok);
  47. DDX_Control(pDX, IDC_EDIT_DEF_DOCUMENT, m_edit_DefDocument);
  48. DDX_Text(pDX, IDC_EDIT_DEF_DOCUMENT, m_strDefDocument);
  49. DDV_MaxCharsBalloon(pDX, m_strDefDocument, MAX_PATH);
  50. //}}AFX_DATA_MAP
  51. if (pDX->m_bSaveAndValidate)
  52. {
  53. m_strDefDocument.TrimRight();
  54. m_strDefDocument.TrimLeft();
  55. CString csPathMunged;
  56. CString csPathMungedCleaned;
  57. csPathMunged = m_strDefDocument;
  58. #ifdef SUPPORT_SLASH_SLASH_QUESTIONMARK_SLASH_TYPE_PATHS
  59. GetSpecialPathRealPath(0,m_strDefDocument,csPathMunged);
  60. #endif
  61. // Check if it has a '?' character in it...
  62. csPathMungedCleaned = csPathMunged;
  63. INT iQuestionMarkPos = csPathMunged.Find(_T("?"));
  64. if (iQuestionMarkPos >= 0)
  65. {
  66. // there is aquestion mark in there.
  67. // trim it off and create a new csPathMunged...
  68. csPathMungedCleaned = csPathMunged.Left(iQuestionMarkPos);
  69. }
  70. // Check if it's empty
  71. if (csPathMungedCleaned.IsEmpty())
  72. {
  73. DDV_ShowBalloonAndFail(pDX, IDS_ERR_INVALID_DOCNAME_CHARS);
  74. }
  75. // we could have only one forward slash here
  76. int pos = 0;
  77. if ((pos = csPathMungedCleaned.Find(_T('/'))) != -1
  78. && csPathMungedCleaned.ReverseFind(_T('/')) != pos)
  79. {
  80. DDV_ShowBalloonAndFail(pDX, IDS_ERR_NO_COMPLETE_PATH);
  81. }
  82. // check if it's a full path.
  83. //
  84. // PathIsFileSpec will return 0 if its c:\temp\myfile
  85. // PathIsFileSpec will erturn 1 if it doesn't find : or "\"
  86. if (!PathIsFileSpec(csPathMungedCleaned))
  87. {
  88. DDV_ShowBalloonAndFail(pDX, IDS_ERR_NO_COMPLETE_PATH);
  89. }
  90. // at this point we have something that doesn't have slash or : in it...
  91. // check if the filename has bad characters in it...
  92. //Bad Characters = _T("|<>*\"\t\r\n");
  93. BOOL bBadChar = FALSE;
  94. if (-1 != csPathMungedCleaned.Find(_T("|"))){bBadChar = TRUE;}
  95. else if (-1 != csPathMungedCleaned.Find(_T("<"))){bBadChar = TRUE;}
  96. else if (-1 != csPathMungedCleaned.Find(_T(">"))){bBadChar = TRUE;}
  97. else if (-1 != csPathMungedCleaned.Find(_T("*"))){bBadChar = TRUE;}
  98. else if (-1 != csPathMungedCleaned.Find(_T("\""))){bBadChar = TRUE;}
  99. else if (-1 != csPathMungedCleaned.Find(_T("\t"))){bBadChar = TRUE;}
  100. else if (-1 != csPathMungedCleaned.Find(_T("\r"))){bBadChar = TRUE;}
  101. else if (-1 != csPathMungedCleaned.Find(_T("\n"))){bBadChar = TRUE;}
  102. if (bBadChar)
  103. {
  104. DDV_ShowBalloonAndFail(pDX, IDS_ERR_INVALID_DOCNAME_CHARS);
  105. }
  106. ASSERT(m_pParent != NULL);
  107. if (LB_ERR != m_pParent->DocExistsInList(csPathMungedCleaned))
  108. {
  109. DDV_ShowBalloonAndFail(pDX, IDS_DUPLICATE_DOC);
  110. }
  111. }
  112. }
  113. //
  114. // Message Map
  115. //
  116. BEGIN_MESSAGE_MAP(CAddDefDocDlg, CDialog)
  117. //{{AFX_MSG_MAP(CAddDefDocDlg)
  118. ON_EN_CHANGE(IDC_EDIT_DEF_DOCUMENT, OnChangeEditDefDocument)
  119. //}}AFX_MSG_MAP
  120. END_MESSAGE_MAP()
  121. //
  122. // Message Handlers
  123. //
  124. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  125. void
  126. CAddDefDocDlg::OnChangeEditDefDocument()
  127. /*++
  128. Routine Description:
  129. Respond to a change in the default document edit box
  130. Arguments:
  131. None./
  132. --*/
  133. {
  134. m_button_Ok.EnableWindow(m_edit_DefDocument.GetWindowTextLength() > 0);
  135. }
  136. //
  137. // WWW Documents Property Page
  138. //
  139. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  140. IMPLEMENT_DYNCREATE(CW3DocumentsPage, CInetPropertyPage)
  141. //
  142. // Static Initialization
  143. //
  144. const LPCTSTR CW3DocumentsPage::s_lpstrSep = _T(",");
  145. const LPCTSTR CW3DocumentsPage::s_lpstrFILE = _T("FILE:");
  146. const LPCTSTR CW3DocumentsPage::s_lpstrSTRING = _T("STRING:");
  147. const LPCTSTR CW3DocumentsPage::s_lpstrURL = _T("URL:");
  148. CW3DocumentsPage::CW3DocumentsPage(CInetPropertySheet * pSheet)
  149. : CInetPropertyPage(CW3DocumentsPage::IDD, pSheet),
  150. m_dwBitRangeDirBrowsing(MD_DIRBROW_LOADDEFAULT)
  151. {
  152. #if 0 // Keep Class-wizard happy
  153. //{{AFX_DATA_INIT(CW3DocumentsPage)
  154. m_strFooter = _T("");
  155. m_fEnableDefaultDocument = FALSE;
  156. m_fEnableFooter = FALSE;
  157. //}}AFX_DATA_INIT
  158. #endif // 0
  159. }
  160. CW3DocumentsPage::~CW3DocumentsPage()
  161. /*++
  162. Routine Description:
  163. Destructor
  164. Arguments:
  165. N/A
  166. Return Value:
  167. N/A
  168. --*/
  169. {
  170. }
  171. void
  172. CW3DocumentsPage::MakeFooterCommand(CString & strFooter)
  173. /*++
  174. Routine Description:
  175. Convert the footer document to a full footer string.
  176. Arguments:
  177. CString & strFooter : On input this is the footer document,
  178. at output this will be a full footer command
  179. Return Value:
  180. None.
  181. Notes:
  182. Only support FILE: for now
  183. --*/
  184. {
  185. strFooter.TrimLeft();
  186. strFooter.TrimRight();
  187. ASSERT(!PathIsRelative(strFooter));
  188. strFooter = s_lpstrFILE + strFooter;
  189. }
  190. void
  191. CW3DocumentsPage::ParseFooterCommand(CString & strFooter)
  192. /*++
  193. Routine Description:
  194. Trim the command from the rest of this command
  195. Arguments:
  196. CString & strFooter : On input this is a footer command
  197. at output this will be just the footer document
  198. --*/
  199. {
  200. LPCTSTR lp = strFooter.GetBuffer(0);
  201. if (!_tcsnccmp(lp, s_lpstrFILE, 5))
  202. {
  203. lp += lstrlen(s_lpstrFILE);
  204. }
  205. else if (!_tcsnccmp(lp, s_lpstrSTRING, 7))
  206. {
  207. lp += lstrlen(s_lpstrSTRING);
  208. }
  209. else if (!::_tcsnccmp(lp, s_lpstrURL, 4))
  210. {
  211. lp += lstrlen(s_lpstrURL);
  212. }
  213. if (lp != strFooter.GetBuffer(0))
  214. {
  215. strFooter = lp;
  216. }
  217. strFooter.TrimLeft();
  218. }
  219. void
  220. CW3DocumentsPage::StringToListBox()
  221. /*++
  222. Routine Description:
  223. Parse the default document string, and add each doc
  224. to the listbox
  225. Arguments:
  226. None
  227. Return Value:
  228. None
  229. --*/
  230. {
  231. int start = 0, end;
  232. int skip = lstrlen(s_lpstrSep);
  233. BOOL done = FALSE;
  234. do
  235. {
  236. end = m_strDefaultDocument.Find(s_lpstrSep, start);
  237. if (end == -1)
  238. {
  239. done = TRUE;
  240. end = m_strDefaultDocument.GetLength();
  241. }
  242. CString str = m_strDefaultDocument.Mid(start, end - start);
  243. if (!str.IsEmpty())
  244. {
  245. str.TrimLeft();
  246. str.TrimRight();
  247. m_list_DefDocuments.AddString(str);
  248. }
  249. start = end + skip;
  250. }
  251. while (!done);
  252. }
  253. BOOL
  254. CW3DocumentsPage::StringFromListBox()
  255. /*++
  256. Routine Description:
  257. Build up list of default documents from the contents of
  258. the listbox.
  259. Arguments:
  260. None
  261. Return Value:
  262. TRUE if at least one document was added.
  263. --*/
  264. {
  265. m_strDefaultDocument.Empty();
  266. int i;
  267. for (i = 0; i < m_list_DefDocuments.GetCount(); ++i)
  268. {
  269. CString str;
  270. m_list_DefDocuments.GetText(i, str);
  271. if (i)
  272. {
  273. m_strDefaultDocument += s_lpstrSep;
  274. }
  275. m_strDefaultDocument += str;
  276. }
  277. return i > 0;
  278. }
  279. void
  280. CW3DocumentsPage::DoDataExchange(CDataExchange * pDX)
  281. {
  282. CInetPropertyPage::DoDataExchange(pDX);
  283. //{{AFX_DATA_MAP(CW3DocumentsPage)
  284. DDX_Check(pDX, IDC_CHECK_ENABLE_DEFAULT_DOCUMENT, m_fEnableDefaultDocument);
  285. DDX_Check(pDX, IDC_CHECK_ENABLE_DOCUMENT_FOOTER, m_fEnableFooter);
  286. DDX_Control(pDX, IDC_LIST_DEFAULT_DOCUMENT, m_list_DefDocuments);
  287. DDX_Control(pDX, IDC_EDIT_DOCUMENT_FOOTER, m_edit_Footer);
  288. DDX_Control(pDX, IDC_CHECK_ENABLE_DOCUMENT_FOOTER, m_check_EnableFooter);
  289. DDX_Control(pDX, IDC_BUTTON_ADD, m_button_Add);
  290. DDX_Control(pDX, IDC_BUTTON_REMOVE, m_button_Remove);
  291. DDX_Control(pDX, IDC_BUTTON_BROWSE, m_button_Browse);
  292. DDX_Control(pDX, IDC_BUTTON_UP, m_button_Up);
  293. DDX_Control(pDX, IDC_BUTTON_DOWN, m_button_Down);
  294. //}}AFX_DATA_MAP
  295. if (pDX->m_bSaveAndValidate)
  296. {
  297. if (m_fEnableDefaultDocument)
  298. {
  299. if (!StringFromListBox())
  300. {
  301. // EditShowBalloon(m_list_DefDocuments.m_hWnd, IDS_ERR_DOCUMENTS);
  302. DoHelpMessageBox(m_hWnd,IDS_ERR_DOCUMENTS, MB_APPLMODAL | MB_OK | MB_ICONINFORMATION, 0);
  303. pDX->Fail();
  304. }
  305. }
  306. if (m_fEnableFooter)
  307. {
  308. BeginWaitCursor();
  309. DDX_Text(pDX, IDC_EDIT_DOCUMENT_FOOTER, m_strFooter);
  310. DDV_MinMaxChars(pDX, m_strFooter, 1, MAX_PATH);
  311. CString csPathMunged;
  312. csPathMunged = m_strFooter;
  313. #ifdef SUPPORT_SLASH_SLASH_QUESTIONMARK_SLASH_TYPE_PATHS
  314. GetSpecialPathRealPath(0,m_strFooter,csPathMunged);
  315. #endif
  316. if (PathIsRelative(csPathMunged))
  317. {
  318. //
  319. // Footer doc must be a complete path
  320. //
  321. DDV_ShowBalloonAndFail(pDX, IDS_ERR_COMPLETE_PATH);
  322. }
  323. else if (IsLocal() && PathIsNetworkPath(csPathMunged))
  324. {
  325. //
  326. // Footer doc must be on local machine.
  327. //
  328. DDV_ShowBalloonAndFail(pDX, IDS_NOT_LOCAL_FOOTER);
  329. }
  330. else if (IsLocal() && (::GetFileAttributes(csPathMunged) & FILE_ATTRIBUTE_DIRECTORY))
  331. {
  332. //
  333. // And lastly, but not leastly, the footer document should exist
  334. //
  335. DDV_ShowBalloonAndFail(pDX, IDS_ERR_FILE_NOT_FOUND);
  336. }
  337. else
  338. {
  339. MakeFooterCommand(m_strFooter);
  340. }
  341. EndWaitCursor();
  342. }
  343. // else
  344. // {
  345. // csPathMunged.Empty();
  346. // }
  347. }
  348. else
  349. {
  350. ParseFooterCommand(m_strFooter);
  351. DDX_Text(pDX, IDC_EDIT_DOCUMENT_FOOTER, m_strFooter);
  352. DDV_MinMaxChars(pDX, m_strFooter, 1, MAX_PATH);
  353. }
  354. }
  355. //
  356. // Message Map
  357. //
  358. BEGIN_MESSAGE_MAP(CW3DocumentsPage, CInetPropertyPage)
  359. //{{AFX_MSG_MAP(CW3DocumentsPage)
  360. ON_BN_CLICKED(IDC_CHECK_ENABLE_DEFAULT_DOCUMENT, OnCheckEnableDefaultDocument)
  361. ON_BN_CLICKED(IDC_CHECK_ENABLE_DOCUMENT_FOOTER, OnCheckEnableDocumentFooter)
  362. ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
  363. ON_BN_CLICKED(IDC_BUTTON_REMOVE, OnButtonRemove)
  364. ON_BN_CLICKED(IDC_BUTTON_BROWSE, OnButtonBrowse)
  365. ON_BN_CLICKED(IDC_BUTTON_UP, OnButtonUp)
  366. ON_BN_CLICKED(IDC_BUTTON_DOWN, OnButtonDown)
  367. ON_LBN_SELCHANGE(IDC_LIST_DEFAULT_DOCUMENT, OnSelchangeListDefaultDocument)
  368. //}}AFX_MSG_MAP
  369. ON_EN_CHANGE(IDC_EDIT_DEFAULT_DOCUMENT, OnItemChanged)
  370. ON_EN_CHANGE(IDC_EDIT_DOCUMENT_FOOTER, OnItemChanged)
  371. END_MESSAGE_MAP()
  372. void
  373. CW3DocumentsPage::SetUpDownStates()
  374. {
  375. int nLast = m_list_DefDocuments.GetCount() - 1;
  376. int nSel = m_list_DefDocuments.GetCurSel();
  377. m_button_Up.EnableWindow(nSel > 0);
  378. m_button_Down.EnableWindow(nSel >= 0 && nSel < nLast);
  379. }
  380. BOOL
  381. CW3DocumentsPage::SetRemoveState()
  382. {
  383. BOOL fEnabled = m_fEnableDefaultDocument
  384. && (m_list_DefDocuments.GetCurSel() != LB_ERR);
  385. m_button_Remove.EnableWindow(fEnabled);
  386. return fEnabled;
  387. }
  388. BOOL
  389. CW3DocumentsPage::SetDefDocumentState(BOOL fEnabled)
  390. /*++
  391. Routine Description:
  392. Set the enabled states of the Default Documents state
  393. Arguments:
  394. BOOL fEnabled : TRUE if default document is on
  395. Return Value:
  396. TRUE if default document is on
  397. --*/
  398. {
  399. m_button_Add.EnableWindow(fEnabled);
  400. m_button_Up.EnableWindow(fEnabled);
  401. m_button_Down.EnableWindow(fEnabled);
  402. m_list_DefDocuments.EnableWindow(fEnabled);
  403. SetRemoveState();
  404. return fEnabled;
  405. }
  406. BOOL
  407. CW3DocumentsPage::SetDocFooterState(BOOL fEnabled)
  408. /*++
  409. Routine Description:
  410. Set the enabled state of the footer documents
  411. Arguments:
  412. BOOL fEnabled : TRUE if footers are on
  413. Return Value:
  414. TRUE if footers are on
  415. --*/
  416. {
  417. m_edit_Footer.EnableWindow(fEnabled);
  418. m_button_Browse.EnableWindow(IsLocal() && fEnabled);
  419. return fEnabled;
  420. }
  421. //
  422. // Message Handlers
  423. //
  424. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  425. void
  426. CW3DocumentsPage::OnItemChanged()
  427. {
  428. SetModified(TRUE);
  429. }
  430. void
  431. CW3DocumentsPage::OnCheckEnableDefaultDocument()
  432. {
  433. m_fEnableDefaultDocument = !m_fEnableDefaultDocument;
  434. SetDefDocumentState(m_fEnableDefaultDocument);
  435. OnItemChanged();
  436. }
  437. void
  438. CW3DocumentsPage::OnCheckEnableDocumentFooter()
  439. {
  440. m_fEnableFooter = !m_fEnableFooter;
  441. if (SetDocFooterState(m_fEnableFooter))
  442. {
  443. m_edit_Footer.SetSel(0,-1);
  444. m_edit_Footer.SetFocus();
  445. }
  446. OnItemChanged();
  447. }
  448. BOOL
  449. CW3DocumentsPage::OnInitDialog()
  450. {
  451. CInetPropertyPage::OnInitDialog();
  452. StringToListBox();
  453. SetDefDocumentState(m_fEnableDefaultDocument);
  454. SetDocFooterState(m_fEnableFooter);
  455. SetUpDownStates();
  456. SetRemoveState();
  457. #ifdef SUPPORT_SLASH_SLASH_QUESTIONMARK_SLASH_TYPE_PATHS
  458. LimitInputPath(CONTROL_HWND(IDC_EDIT_DOCUMENT_FOOTER),TRUE);
  459. LimitInputPath(CONTROL_HWND(IDC_EDIT_DEF_DOCUMENT),TRUE);
  460. #else
  461. LimitInputPath(CONTROL_HWND(IDC_EDIT_DOCUMENT_FOOTER),FALSE);
  462. LimitInputPath(CONTROL_HWND(IDC_EDIT_DEF_DOCUMENT),FALSE);
  463. #endif
  464. return TRUE;
  465. }
  466. /* virtual */
  467. HRESULT
  468. CW3DocumentsPage::FetchLoadedValues()
  469. {
  470. CError err;
  471. BEGIN_META_DIR_READ(CW3Sheet)
  472. FETCH_DIR_DATA_FROM_SHEET(m_dwDirBrowsing);
  473. FETCH_DIR_DATA_FROM_SHEET(m_strDefaultDocument);
  474. FETCH_DIR_DATA_FROM_SHEET(m_fEnableFooter);
  475. FETCH_DIR_DATA_FROM_SHEET(m_strFooter);
  476. m_fEnableDefaultDocument = IS_FLAG_SET(
  477. m_dwDirBrowsing,
  478. MD_DIRBROW_LOADDEFAULT
  479. );
  480. END_META_DIR_READ(err)
  481. return err;
  482. }
  483. HRESULT
  484. CW3DocumentsPage::SaveInfo()
  485. {
  486. ASSERT(IsDirty());
  487. TRACEEOLID("Saving W3 documents page now...");
  488. CError err;
  489. SET_FLAG_IF(m_fEnableDefaultDocument, m_dwDirBrowsing, MD_DIRBROW_LOADDEFAULT);
  490. BeginWaitCursor();
  491. BEGIN_META_DIR_WRITE(CW3Sheet)
  492. INIT_DIR_DATA_MASK(m_dwDirBrowsing, m_dwBitRangeDirBrowsing)
  493. STORE_DIR_DATA_ON_SHEET(m_strDefaultDocument)
  494. //STORE_DIR_DATA_ON_SHEET_MASK(m_dwDirBrowsing, m_dwBitRangeDirBrowsing)
  495. STORE_DIR_DATA_ON_SHEET(m_dwDirBrowsing)
  496. STORE_DIR_DATA_ON_SHEET(m_fEnableFooter)
  497. CString buf = m_strFooter;
  498. if (!m_fEnableFooter)
  499. {
  500. m_strFooter.Empty();
  501. }
  502. STORE_DIR_DATA_ON_SHEET(m_strFooter)
  503. m_strFooter = buf;
  504. END_META_DIR_WRITE(err)
  505. if (err.Succeeded())
  506. {
  507. err = ((CW3Sheet *)GetSheet())->SetKeyType();
  508. }
  509. EndWaitCursor();
  510. return err;
  511. }
  512. int
  513. CW3DocumentsPage::DocExistsInList(LPCTSTR lpDoc)
  514. /*++
  515. Routine Description:
  516. Check to see if the given document exists in the list
  517. Arguments:
  518. LPCTSTR lpDoc : Document to check
  519. Return Value:
  520. The index where the item exists or LB_ERR if it doesn't exist.
  521. --*/
  522. {
  523. CString str;
  524. for (int n = 0; n < m_list_DefDocuments.GetCount(); ++n)
  525. {
  526. m_list_DefDocuments.GetText(n, str);
  527. if (!str.CompareNoCase(lpDoc))
  528. {
  529. return n;
  530. }
  531. }
  532. return LB_ERR;
  533. }
  534. void
  535. CW3DocumentsPage::OnButtonAdd()
  536. {
  537. CAddDefDocDlg dlg;
  538. dlg.m_pParent = this;
  539. if (dlg.DoModal() == IDOK)
  540. {
  541. //
  542. // Check to see if it existed already
  543. //
  544. try
  545. {
  546. int nSel;
  547. CString strNewDoc(dlg.GetDefDocument());
  548. if ((nSel = DocExistsInList(strNewDoc)) != LB_ERR)
  549. {
  550. m_list_DefDocuments.SetCurSel(nSel);
  551. return;
  552. }
  553. nSel = m_list_DefDocuments.AddString(strNewDoc);
  554. if (nSel >= 0)
  555. {
  556. m_list_DefDocuments.SetCurSel(nSel);
  557. SetUpDownStates();
  558. SetRemoveState();
  559. OnItemChanged();
  560. }
  561. }
  562. catch(CMemoryException * e)
  563. {
  564. e->ReportError();
  565. e->Delete();
  566. }
  567. }
  568. }
  569. void
  570. CW3DocumentsPage::OnButtonRemove()
  571. {
  572. int nSel = m_list_DefDocuments.GetCurSel();
  573. if (nSel >= 0)
  574. {
  575. m_list_DefDocuments.DeleteString(nSel);
  576. if (nSel >= m_list_DefDocuments.GetCount())
  577. {
  578. --nSel;
  579. }
  580. m_list_DefDocuments.SetCurSel(nSel);
  581. SetUpDownStates();
  582. OnItemChanged();
  583. if (!SetRemoveState())
  584. {
  585. //
  586. // Make sure we don't focus on a disabled button
  587. //
  588. m_button_Add.SetFocus();
  589. }
  590. }
  591. }
  592. void
  593. CW3DocumentsPage::OnButtonBrowse()
  594. {
  595. ASSERT(IsLocal());
  596. //
  597. // Pop up the file dialog and let the user select the footer htm file.
  598. //
  599. CString str;
  600. str.LoadString(IDS_HTML_MASK);
  601. CFileDialog dlgBrowse(TRUE, NULL, NULL, OFN_HIDEREADONLY, str, this);
  602. //
  603. // If the new style of file-open dialog is requested, comment
  604. // out the DoModal, and remove the other two comments.
  605. //
  606. dlgBrowse.m_ofn.Flags &= ~(OFN_ENABLEHOOK);
  607. dlgBrowse.m_ofn.Flags |= OFN_DONTADDTORECENT|OFN_FILEMUSTEXIST;
  608. if (dlgBrowse.DoModal() == IDOK)
  609. //if (GetOpenFileName(&dlgBrowse.m_ofn))
  610. {
  611. m_edit_Footer.SetWindowText(dlgBrowse.GetPathName());
  612. }
  613. }
  614. void
  615. CW3DocumentsPage::ExchangeDocuments(
  616. IN int nLow,
  617. IN int nHigh
  618. )
  619. /*++
  620. Routine Description:
  621. Exchange two documents in the listbox
  622. Arguments:
  623. int nLow : Low item
  624. int nHigh : High item
  625. Return Value:
  626. None.
  627. --*/
  628. {
  629. ASSERT(nLow < nHigh);
  630. CString str;
  631. m_list_DefDocuments.GetText(nLow, str);
  632. m_list_DefDocuments.DeleteString(nLow);
  633. m_list_DefDocuments.InsertString(nHigh, str);
  634. OnItemChanged();
  635. }
  636. void
  637. CW3DocumentsPage::OnButtonUp()
  638. /*++
  639. Routine Description:
  640. Move the currently selected doc up
  641. Arguments:
  642. None.
  643. Return Value:
  644. None.
  645. --*/
  646. {
  647. int nCurSel = m_list_DefDocuments.GetCurSel();
  648. ExchangeDocuments(nCurSel - 1, nCurSel);
  649. m_list_DefDocuments.SetCurSel(nCurSel - 1);
  650. m_list_DefDocuments.SetFocus();
  651. SetUpDownStates();
  652. }
  653. void
  654. CW3DocumentsPage::OnButtonDown()
  655. /*++
  656. Routine Description:
  657. Move the currently selected doc down
  658. Arguments:
  659. None.
  660. Return Value:
  661. None.
  662. --*/
  663. {
  664. int nCurSel = m_list_DefDocuments.GetCurSel();
  665. ExchangeDocuments(nCurSel, nCurSel + 1);
  666. m_list_DefDocuments.SetCurSel(nCurSel + 1);
  667. m_list_DefDocuments.SetFocus();
  668. SetUpDownStates();
  669. }
  670. void
  671. CW3DocumentsPage::OnSelchangeListDefaultDocument()
  672. {
  673. SetUpDownStates();
  674. SetRemoveState();
  675. }