home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / ctlhtmlc / messageb.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-06  |  29.2 KB  |  1,078 lines

  1. /*---------------------------------------------------------------------------*\
  2.  | MessageBox.cpp - CtlHTML(tm) Control Library Test Program                 |
  3.  |                  Windmill Point Software, Alburg, VT 05440                |
  4.  |                  Copyright (c) 1999, Windmill Point Software              |
  5.  |                  All Rights Reserved.                                     |
  6. \*---------------------------------------------------------------------------*/
  7.  
  8. #include "stdafx.h"
  9. #include "CtlHTML Demo.h"
  10. #include "DevUI.h"
  11. #include "..\CtlHtml.h"
  12. #include "MessageBox.h"
  13.  
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19.  
  20. #define ID_TEST   100
  21.  
  22. // globals
  23.  
  24. int DefaultButtonID = 100;
  25.  
  26. // helper function
  27.  
  28. void ReloadComboList (CComboBox *pCombo, CMcMRUList *pComboMru, LPCTSTR editText);
  29.  
  30.  
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CMessageBoxOptions property page
  33.  
  34. IMPLEMENT_DYNCREATE(CMessageBoxOptions, CPropertyPage)
  35.  
  36. BEGIN_MESSAGE_MAP(CMessageBoxOptions, CPropertyPage)
  37.     //{{AFX_MSG_MAP(CMessageBoxOptions)
  38.     ON_CBN_SELCHANGE(IDC_STANDARD_BUTTONS, OnChangeStandardButtons)
  39.     ON_BN_CLICKED(IDC_CUSTOM_BUTTONS, OnCustomButtons)
  40.     ON_WM_ACTIVATE()
  41.     //}}AFX_MSG_MAP
  42. END_MESSAGE_MAP()
  43.  
  44. CMessageBoxOptions::CMessageBoxOptions() : CPropertyPage(CMessageBoxOptions::IDD)
  45. {
  46.     //{{AFX_DATA_INIT(CMessageBoxOptions)
  47.     m_DefaultButton = -1;
  48.     m_DisplayInFutureText = _T("");
  49.     m_HelpID = 0;
  50.     m_MessageText = _T("");
  51.     m_ResourceIcon = -1;
  52.     m_ReturnValue = _T("");
  53.     m_StandardButtons = -1;
  54.     m_StandardIcon = -1;
  55.     m_Timeout = -1;
  56.     m_TitleText = _T("");
  57.     //}}AFX_DATA_INIT
  58.  
  59.    m_ButtonList[0].ID = -1;
  60.    m_pButtonList = 0;
  61.    m_Flags       = 0;
  62.    m_IconNumber  = 0;
  63.    m_pTitleMRU   = m_pMessageMRU = m_pFutureMRU = 0;
  64. }
  65.  
  66. CMessageBoxOptions::~CMessageBoxOptions()
  67. {
  68. }
  69.  
  70. void CMessageBoxOptions::DoDataExchange(CDataExchange* pDX)
  71. {
  72.     CPropertyPage::DoDataExchange(pDX);
  73.  
  74.     //{{AFX_DATA_MAP(CMessageBoxOptions)
  75.     DDX_CBIndex(pDX, IDC_DEFAULT_BUTTONS, m_DefaultButton);
  76.     DDX_CBString(pDX, IDC_DISPLAY_IN_FUTURE, m_DisplayInFutureText);
  77.     DDX_Text(pDX, IDC_HELPID, m_HelpID);
  78.     DDX_CBString(pDX, IDC_MESSAGE_BOX, m_MessageText);
  79.     DDX_CBIndex(pDX, IDC_RESOURCE_ICON, m_ResourceIcon);
  80.     DDX_Text(pDX, IDC_RETURN_VALUE, m_ReturnValue);
  81.     DDX_CBIndex(pDX, IDC_STANDARD_BUTTONS, m_StandardButtons);
  82.     DDX_CBIndex(pDX, IDC_STANDARD_ICON, m_StandardIcon);
  83.     DDX_Text(pDX, IDC_TIMEOUT_TIME, m_Timeout);
  84.     DDV_MinMaxInt(pDX, m_Timeout, 0, 600);
  85.     DDX_CBString(pDX, IDC_TITLE_BOX, m_TitleText);
  86.     //}}AFX_DATA_MAP
  87.  
  88.    if (pDX->m_bSaveAndValidate)
  89.    {
  90.       // add current strings to MRU
  91.       m_pTitleMRU->AddString(m_TitleText);
  92.       m_pMessageMRU->AddString(m_MessageText);
  93.       m_pFutureMRU->AddString(m_DisplayInFutureText);
  94.  
  95.       // set m_pButtonList
  96.       if (m_StandardButtons == 0)
  97.          m_pButtonList = m_ButtonList;
  98.       else
  99.          m_pButtonList = 0;
  100.  
  101.       // set m_Flags
  102.       m_Flags = 0;
  103.       switch (m_StandardButtons)
  104.       {
  105.          case 1: m_Flags |= MB_ABORTRETRYIGNORE; break;
  106.          case 2: m_Flags |= HTMLMB_CANCEL;       break;
  107.          case 3: m_Flags |= HTMLMB_CONTINUE;     break;
  108.          case 4: m_Flags |= MB_OK;               break;
  109.          case 5: m_Flags |= MB_OKCANCEL;         break;
  110.          case 6: m_Flags |= MB_RETRYCANCEL;      break;
  111.          case 7: m_Flags |= MB_YESNO;            break;
  112.          case 8: m_Flags |= MB_YESNOCANCEL;      break;
  113.       }
  114.       switch (m_DefaultButton)
  115.       {
  116.          case 1: m_Flags |= MB_DEFBUTTON1;       break;
  117.          case 2: m_Flags |= MB_DEFBUTTON2;       break;
  118.          case 3: m_Flags |= MB_DEFBUTTON3;       break;
  119.          case 4: m_Flags |= MB_DEFBUTTON4;       break;
  120.       }
  121.       switch (m_StandardIcon)
  122.       {
  123.          case 1: m_Flags |= MB_ICONEXCLAMATION;  break;
  124.          case 2: m_Flags |= MB_ICONQUESTION;     break;
  125.          case 3: m_Flags |= MB_ICONSTOP;         break;
  126.          case 4: m_Flags |= MB_ICONWARNING;      break;
  127.       }
  128.  
  129.       // set m_IconNumber
  130.       m_IconNumber = 0;
  131.       switch (m_ResourceIcon)
  132.       {
  133.          case 1: m_IconNumber = IDR_MAINFRAME;  break;
  134.       }
  135.    }
  136. }
  137.  
  138. BOOL CMessageBoxOptions::OnInitDialog() 
  139. {
  140.     CPropertyPage::OnInitDialog();
  141.  
  142.    CSpinButtonCtrl *pSpin;
  143.  
  144.    if ((pSpin = (CSpinButtonCtrl *)GetDlgItem(IDC_SECONDS_SPIN)) != 0)
  145.    {
  146.       ASSERT_VALID(pSpin);
  147.       pSpin->SetRange(0, 600);
  148.    }
  149.    else
  150.       ASSERT(FALSE);
  151.  
  152.    InitCombos();
  153.    OnChangeStandardButtons();
  154.     return TRUE;
  155. }
  156.  
  157. void CMessageBoxOptions::InitCombos ()
  158. {
  159.    CComboBox *pTitle, *pMessage, *pFuture;
  160.  
  161.    if ((pTitle = (CComboBox *)GetDlgItem(IDC_TITLE_BOX)) != 0)
  162.       ReloadComboList(pTitle, m_pTitleMRU, m_TitleText);
  163.    else
  164.       ASSERT(FALSE);
  165.  
  166.    if ((pMessage = (CComboBox *)GetDlgItem(IDC_MESSAGE_BOX)) != 0)
  167.       ReloadComboList(pMessage, m_pMessageMRU, m_MessageText);
  168.    else
  169.       ASSERT(FALSE);
  170.  
  171.    if ((pFuture = (CComboBox *)GetDlgItem(IDC_DISPLAY_IN_FUTURE)) != 0)
  172.       ReloadComboList(pFuture, m_pFutureMRU, m_DisplayInFutureText);
  173.    else
  174.       ASSERT(FALSE);
  175. }
  176.  
  177. void CMessageBoxOptions::OnChangeStandardButtons() 
  178. {
  179.    CComboBox *pCombo;
  180.    CButton   *pCustomButtons;
  181.    int   index;  
  182.  
  183.    if ((pCombo         = (CComboBox *)GetDlgItem(IDC_STANDARD_BUTTONS)) != 0 &&
  184.        (pCustomButtons = (CButton   *)GetDlgItem(IDC_CUSTOM_BUTTONS)) != 0)
  185.    {
  186.       if ((index = pCombo->GetCurSel()) == 0)
  187.          pCustomButtons->EnableWindow(TRUE);
  188.       else
  189.          pCustomButtons->EnableWindow(FALSE);
  190.    }
  191.    else
  192.       ASSERT(FALSE);
  193. }
  194.  
  195. void CMessageBoxOptions::OnCustomButtons() 
  196. {
  197.    CButtonList dialog(m_ButtonList, this);
  198.    dialog.DoModal();
  199. }
  200.  
  201. void CMessageBoxOptions::OnActivate (UINT nState, CWnd* pWndOther, BOOL bMinimized)
  202. {
  203.    CPropertyPage::OnActivate(nState, pWndOther, bMinimized);
  204.    if (DisableControls)
  205.       CtlHTMLDialogEnable(m_hWnd, nState != WA_INACTIVE);
  206. }
  207.  
  208.  
  209. /////////////////////////////////////////////////////////////////////////////
  210. // CDetailsBoxOptions property page
  211.  
  212. IMPLEMENT_DYNCREATE(CDetailsBoxOptions, CPropertyPage)
  213.  
  214. BEGIN_MESSAGE_MAP(CDetailsBoxOptions, CPropertyPage)
  215.     //{{AFX_MSG_MAP(CDetailsBoxOptions)
  216.     ON_CBN_SELCHANGE(IDC_STANDARD_BUTTONS, OnChangeStandardButtons)
  217.     ON_BN_CLICKED(IDC_CUSTOM_BUTTONS, OnCustomButtons)
  218.     ON_WM_ACTIVATE()
  219.     //}}AFX_MSG_MAP
  220. END_MESSAGE_MAP()
  221.  
  222. CDetailsBoxOptions::CDetailsBoxOptions() : CPropertyPage(CDetailsBoxOptions::IDD)
  223. {
  224.     //{{AFX_DATA_INIT(CDetailsBoxOptions)
  225.     m_DefaultButton = -1;
  226.     m_DetailsText = _T("");
  227.     m_DisplayInFutureText = _T("");
  228.     m_HelpID = 0;
  229.     m_MessageText = _T("");
  230.     m_ResourceIcon = -1;
  231.     m_ReturnValue = _T("");
  232.     m_StandardButtons = -1;
  233.     m_StandardIcon = -1;
  234.     m_Timeout = -1;
  235.     m_TitleText = _T("");
  236.     //}}AFX_DATA_INIT
  237.  
  238.    m_ButtonList[0].ID = -1;
  239.    m_pButtonList = 0;
  240.    m_Flags      = 0;
  241.    m_IconNumber = 0;
  242.    m_pTitleMRU  = m_pMessageMRU = m_pDetailsMRU = m_pFutureMRU = 0;
  243. }
  244.  
  245. CDetailsBoxOptions::~CDetailsBoxOptions()
  246. {
  247. }
  248.  
  249. void CDetailsBoxOptions::DoDataExchange(CDataExchange* pDX)
  250. {
  251.     CPropertyPage::DoDataExchange(pDX);
  252.  
  253.     //{{AFX_DATA_MAP(CDetailsBoxOptions)
  254.     DDX_CBIndex(pDX, IDC_DEFAULT_BUTTONS, m_DefaultButton);
  255.     DDX_CBString(pDX, IDC_DETAILS_BOX, m_DetailsText);
  256.     DDX_CBString(pDX, IDC_DISPLAY_IN_FUTURE, m_DisplayInFutureText);
  257.     DDX_Text(pDX, IDC_HELPID, m_HelpID);
  258.     DDX_CBString(pDX, IDC_MESSAGE_BOX, m_MessageText);
  259.     DDX_CBIndex(pDX, IDC_RESOURCE_ICON, m_ResourceIcon);
  260.     DDX_Text(pDX, IDC_RETURN_VALUE, m_ReturnValue);
  261.     DDX_CBIndex(pDX, IDC_STANDARD_BUTTONS, m_StandardButtons);
  262.     DDX_CBIndex(pDX, IDC_STANDARD_ICON, m_StandardIcon);
  263.     DDX_Text(pDX, IDC_TIMEOUT_TIME, m_Timeout);
  264.     DDV_MinMaxInt(pDX, m_Timeout, 0, 600);
  265.     DDX_CBString(pDX, IDC_TITLE_BOX, m_TitleText);
  266.     //}}AFX_DATA_MAP
  267.  
  268.    if (pDX->m_bSaveAndValidate)
  269.    {
  270.       // add current strings to MRU
  271.       m_pTitleMRU->AddString(m_TitleText);
  272.       m_pMessageMRU->AddString(m_MessageText);
  273.       m_pDetailsMRU->AddString(m_DetailsText);
  274.       m_pFutureMRU->AddString(m_DisplayInFutureText);
  275.  
  276.       // set m_pButtonList
  277.       if (m_StandardButtons == 0)
  278.          m_pButtonList = m_ButtonList;
  279.       else
  280.          m_pButtonList = 0;
  281.  
  282.       // set m_Flags
  283.       m_Flags = 0;
  284.       switch (m_StandardButtons)
  285.       {
  286.          case 1: m_Flags |= HTMLMB_CANCEL;       break;
  287.          case 2: m_Flags |= HTMLMB_CONTINUE;     break;
  288.          case 3: m_Flags |= MB_OK;               break;
  289.          case 4: m_Flags |= MB_OKCANCEL;         break;
  290.          case 5: m_Flags |= MB_RETRYCANCEL;      break;
  291.          case 6: m_Flags |= MB_YESNO;            break;
  292.          case 7: m_Flags |= MB_YESNOCANCEL;      break;
  293.       }
  294.       switch (m_DefaultButton)
  295.       {
  296.          case 1: m_Flags |= MB_DEFBUTTON1;       break;
  297.          case 2: m_Flags |= MB_DEFBUTTON2;       break;
  298.          case 3: m_Flags |= MB_DEFBUTTON3;       break;
  299.          case 4: m_Flags |= MB_DEFBUTTON4;       break;
  300.       }
  301.       switch (m_StandardIcon)
  302.       {
  303.          case 1: m_Flags |= MB_ICONEXCLAMATION;  break;
  304.          case 2: m_Flags |= MB_ICONQUESTION;     break;
  305.          case 3: m_Flags |= MB_ICONSTOP;         break;
  306.          case 4: m_Flags |= MB_ICONWARNING;      break;
  307.       }
  308.  
  309.       // set m_IconNumber
  310.       m_IconNumber = 0;
  311.       switch (m_ResourceIcon)
  312.       {
  313.          case 1: m_IconNumber = IDR_MAINFRAME;  break;
  314.       }
  315.    }
  316. }
  317.  
  318. BOOL CDetailsBoxOptions::OnInitDialog() 
  319. {
  320.     CPropertyPage::OnInitDialog();
  321.  
  322.    CSpinButtonCtrl *pSpin;
  323.  
  324.    if ((pSpin = (CSpinButtonCtrl *)GetDlgItem(IDC_SECONDS_SPIN)) != 0)
  325.    {
  326.       ASSERT_VALID(pSpin);
  327.       pSpin->SetRange(0, 600);
  328.    }
  329.    else
  330.       ASSERT(FALSE);
  331.  
  332.    InitCombos();
  333.    OnChangeStandardButtons();
  334.     return TRUE;
  335. }
  336.  
  337. void CDetailsBoxOptions::InitCombos ()
  338. {
  339.    CComboBox *pTitle, *pMessage, *pDetails, *pFuture;
  340.  
  341.    if ((pTitle = (CComboBox *)GetDlgItem(IDC_TITLE_BOX)) != 0)
  342.       ReloadComboList(pTitle, m_pTitleMRU, m_TitleText);
  343.    else
  344.       ASSERT(FALSE);
  345.  
  346.    if ((pMessage = (CComboBox *)GetDlgItem(IDC_MESSAGE_BOX)) != 0)
  347.       ReloadComboList(pMessage, m_pMessageMRU, m_MessageText);
  348.    else
  349.       ASSERT(FALSE);
  350.  
  351.    if ((pDetails = (CComboBox *)GetDlgItem(IDC_DETAILS_BOX)) != 0)
  352.       ReloadComboList(pDetails, m_pDetailsMRU, m_DetailsText);
  353.    else
  354.       ASSERT(FALSE);
  355.  
  356.    if ((pFuture = (CComboBox *)GetDlgItem(IDC_DISPLAY_IN_FUTURE)) != 0)
  357.       ReloadComboList(pFuture, m_pFutureMRU, m_DisplayInFutureText);
  358.    else
  359.       ASSERT(FALSE);
  360. }
  361.  
  362. void CDetailsBoxOptions::OnChangeStandardButtons() 
  363. {
  364.    CComboBox *pCombo;
  365.    CButton   *pCustomButtons;
  366.    int   index;  
  367.  
  368.    if ((pCombo         = (CComboBox *)GetDlgItem(IDC_STANDARD_BUTTONS)) != 0 &&
  369.        (pCustomButtons = (CButton   *)GetDlgItem(IDC_CUSTOM_BUTTONS)) != 0)
  370.    {
  371.       if ((index = pCombo->GetCurSel()) == 0)
  372.          pCustomButtons->EnableWindow(TRUE);
  373.       else
  374.          pCustomButtons->EnableWindow(FALSE);
  375.    }
  376.    else
  377.       ASSERT(FALSE);
  378. }
  379.  
  380. void CDetailsBoxOptions::OnCustomButtons() 
  381. {
  382.    CButtonList dialog(m_ButtonList, this);
  383.    dialog.DoModal();
  384. }
  385.  
  386. void CDetailsBoxOptions::OnActivate (UINT nState, CWnd* pWndOther, BOOL bMinimized)
  387. {
  388.    CPropertyPage::OnActivate(nState, pWndOther, bMinimized);
  389.    if (DisableControls)
  390.       CtlHTMLDialogEnable(m_hWnd, nState != WA_INACTIVE);
  391. }
  392.  
  393.  
  394. /////////////////////////////////////////////////////////////////////////////
  395. // CFlashBoxOptions property page
  396.  
  397. IMPLEMENT_DYNCREATE(CFlashBoxOptions, CPropertyPage)
  398.  
  399. BEGIN_MESSAGE_MAP(CFlashBoxOptions, CPropertyPage)
  400.     //{{AFX_MSG_MAP(CFlashBoxOptions)
  401.     ON_WM_ACTIVATE()
  402.     //}}AFX_MSG_MAP
  403. END_MESSAGE_MAP()
  404.  
  405. CFlashBoxOptions::CFlashBoxOptions() : CPropertyPage(CFlashBoxOptions::IDD)
  406. {
  407.     //{{AFX_DATA_INIT(CFlashBoxOptions)
  408.     m_DisplayInFutureText = _T("");
  409.     m_MessageText = _T("");
  410.     m_ResourceIcon = -1;
  411.     m_StandardIcon = -1;
  412.     m_Timeout = -1;
  413.     m_TitleText = _T("");
  414.     //}}AFX_DATA_INIT
  415.  
  416.    m_Flags      = 0;
  417.    m_IconNumber = 0;
  418.    m_pTitleMRU  = m_pMessageMRU = m_pFutureMRU = 0;
  419. }
  420.  
  421. CFlashBoxOptions::~CFlashBoxOptions()
  422. {
  423. }
  424.  
  425. void CFlashBoxOptions::DoDataExchange(CDataExchange* pDX)
  426. {
  427.     CPropertyPage::DoDataExchange(pDX);
  428.     //{{AFX_DATA_MAP(CFlashBoxOptions)
  429.     DDX_CBString(pDX, IDC_DISPLAY_IN_FUTURE, m_DisplayInFutureText);
  430.     DDX_CBString(pDX, IDC_MESSAGE_BOX, m_MessageText);
  431.     DDX_CBIndex(pDX, IDC_RESOURCE_ICON, m_ResourceIcon);
  432.     DDX_CBIndex(pDX, IDC_STANDARD_ICON, m_StandardIcon);
  433.     DDX_Text(pDX, IDC_TIMEOUT_TIME, m_Timeout);
  434.     DDV_MinMaxInt(pDX, m_Timeout, 1, 600);
  435.     DDX_CBString(pDX, IDC_TITLE_BOX, m_TitleText);
  436.     //}}AFX_DATA_MAP
  437.  
  438.    if (pDX->m_bSaveAndValidate)
  439.    {
  440.       // add current strings to MRU
  441.       m_pTitleMRU->AddString(m_TitleText);
  442.       m_pMessageMRU->AddString(m_MessageText);
  443.       m_pFutureMRU->AddString(m_DisplayInFutureText);
  444.  
  445.       // set m_Flags
  446.       m_Flags = 0;
  447.       switch (m_StandardIcon)
  448.       {
  449.          case 1: m_Flags |= MB_ICONEXCLAMATION;  break;
  450.          case 2: m_Flags |= MB_ICONQUESTION;     break;
  451.          case 3: m_Flags |= MB_ICONSTOP;         break;
  452.          case 4: m_Flags |= MB_ICONWARNING;      break;
  453.       }
  454.  
  455.       // set m_IconNumber
  456.       m_IconNumber = 0;
  457.       switch (m_ResourceIcon)
  458.       {
  459.          case 1: m_IconNumber = IDR_MAINFRAME;  break;
  460.       }
  461.    }
  462. }
  463.  
  464. BOOL CFlashBoxOptions::OnInitDialog() 
  465. {
  466.     CPropertyPage::OnInitDialog();
  467.  
  468.    CSpinButtonCtrl *pSpin;
  469.  
  470.    if ((pSpin = (CSpinButtonCtrl *)GetDlgItem(IDC_SECONDS_SPIN)) != 0)
  471.    {
  472.       ASSERT_VALID(pSpin);
  473.       pSpin->SetRange(1, 600);
  474.    }
  475.    else
  476.       ASSERT(FALSE);
  477.  
  478.    InitCombos();
  479.     return TRUE;
  480. }
  481.  
  482. void CFlashBoxOptions::InitCombos ()
  483. {
  484.    CComboBox *pTitle, *pMessage, *pFuture;
  485.  
  486.    if ((pTitle = (CComboBox *)GetDlgItem(IDC_TITLE_BOX)) != 0)
  487.       ReloadComboList(pTitle, m_pTitleMRU, m_TitleText);
  488.    else
  489.       ASSERT(FALSE);
  490.  
  491.    if ((pMessage = (CComboBox *)GetDlgItem(IDC_MESSAGE_BOX)) != 0)
  492.       ReloadComboList(pMessage, m_pMessageMRU, m_MessageText);
  493.    else
  494.       ASSERT(FALSE);
  495.  
  496.    if ((pFuture = (CComboBox *)GetDlgItem(IDC_DISPLAY_IN_FUTURE)) != 0)
  497.       ReloadComboList(pFuture, m_pFutureMRU, m_DisplayInFutureText);
  498.    else
  499.       ASSERT(FALSE);
  500. }
  501.  
  502. void CFlashBoxOptions::OnActivate (UINT nState, CWnd* pWndOther, BOOL bMinimized)
  503. {
  504.    CPropertyPage::OnActivate(nState, pWndOther, bMinimized);
  505.    if (DisableControls)
  506.       CtlHTMLDialogEnable(m_hWnd, nState != WA_INACTIVE);
  507. }
  508.  
  509.  
  510. /////////////////////////////////////////////////////////////////////////////
  511. // CMessageOptions
  512.  
  513. static int ActivePage = 0;
  514.  
  515. IMPLEMENT_DYNAMIC(CMessageOptions, CMcPropertySheet)
  516.  
  517. BEGIN_MESSAGE_MAP(CMessageOptions, CMcPropertySheet)
  518.     //{{AFX_MSG_MAP(CMessageOptions)
  519.     ON_WM_DESTROY()
  520.     ON_COMMAND(ID_TEST, OnTest)
  521.     ON_WM_ACTIVATE()
  522.     //}}AFX_MSG_MAP
  523. END_MESSAGE_MAP()
  524.  
  525. CMessageOptions::CMessageOptions(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
  526.     :CMcPropertySheet(nIDCaption, pParentWnd, iSelectPage)
  527. {
  528.    AddPage(&m_MessageBoxOptions);
  529.    AddPage(&m_DetailsBoxOptions);
  530.    AddPage(&m_FlashBoxOptions);
  531. }
  532.  
  533. CMessageOptions::CMessageOptions(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
  534.     :CMcPropertySheet(pszCaption, pParentWnd, iSelectPage)
  535. {
  536.    AddPage(&m_MessageBoxOptions);
  537.    AddPage(&m_DetailsBoxOptions);
  538.    AddPage(&m_FlashBoxOptions);
  539. }
  540.  
  541. CMessageOptions::~CMessageOptions()
  542. {
  543. }
  544.  
  545. BOOL CMessageOptions::OnInitDialog() 
  546. {
  547.    McButtonList buttonList[4];
  548.    CRect rect;
  549.  
  550.    // create a button list
  551.    buttonList[0].Name = "OK";
  552.    buttonList[0].ID   = IDOK;
  553.    buttonList[0].IsDefault = FALSE;
  554.  
  555.    buttonList[1].Name = "Cancel";
  556.    buttonList[1].ID   = IDCANCEL;
  557.    buttonList[1].IsDefault = FALSE;
  558.  
  559.    buttonList[2].Name = "&Test";
  560.    buttonList[2].ID   = ID_TEST;
  561.    buttonList[2].IsDefault = TRUE;
  562.  
  563.    buttonList[3].ID   = -1;
  564.  
  565.    SetButtons(buttonList);
  566.  
  567.     BOOL bResult = CMcPropertySheet::OnInitDialog();
  568.  
  569.    // restore the active page
  570.     SetActivePage(ActivePage);
  571.  
  572.    // handle window placement    
  573.    CMcWindowPlacement wp;
  574.    wp.RestoreWindowPlacement(_T("Message Boxes"), _T("WindowPlacement"), this, TRUE);
  575.  
  576.     return bResult;
  577. }
  578.  
  579. void CMessageOptions::OnDestroy() 
  580. {
  581.    // save active page
  582.    ActivePage = GetActiveIndex();
  583.  
  584.    // handle window placement    
  585.    CMcWindowPlacement wp;
  586.    wp.SaveWindowPlacement(_T("Message Boxes"), _T("WindowPlacement"), this);
  587.  
  588.     CMcPropertySheet::OnDestroy();
  589. }
  590.  
  591. void CMessageOptions::OnTest() 
  592. {
  593.    CWnd     *pReturnValue;
  594.    CString  returnValue;
  595.    int      retVal = 0, value;
  596.  
  597.    if (GetActiveIndex() == 0)
  598.    {
  599.       if (m_MessageBoxOptions.UpdateData() == 0)
  600.          return;
  601.  
  602.       retVal = HTMLMessageBox(m_MessageBoxOptions.m_MessageText, m_MessageBoxOptions.m_TitleText, m_MessageBoxOptions.m_Flags,
  603.                   m_MessageBoxOptions.m_DisplayInFutureText, m_MessageBoxOptions.m_pButtonList,
  604.                   m_MessageBoxOptions.m_Timeout, m_MessageBoxOptions.m_IconNumber, m_MessageBoxOptions.m_HelpID);
  605.  
  606.       // set return value
  607.       if ((pReturnValue = m_MessageBoxOptions.GetDlgItem(IDC_RETURN_VALUE)) != 0)
  608.       {
  609.          value = retVal & ~HTMLID_DONTASKAGAIN;
  610.          returnValue.Format(_T("%d"), value);
  611.          if (retVal & HTMLID_DONTASKAGAIN)
  612.             returnValue += _T("   Don't ask in the future.");
  613.          pReturnValue->SetWindowText(returnValue);
  614.       }
  615.       else
  616.          ASSERT(FALSE);
  617.  
  618.       m_MessageBoxOptions.InitCombos();
  619.    }
  620.    else if (GetActiveIndex() == 1)
  621.    {
  622.       BOOL showUnfolded = FALSE;
  623.  
  624.       if (m_DetailsBoxOptions.UpdateData() == 0)
  625.          return;
  626.  
  627.       retVal = HTMLDetailsBox(m_DetailsBoxOptions.m_MessageText, m_DetailsBoxOptions.m_TitleText, 
  628.                   m_DetailsBoxOptions.m_DetailsText, CSize(200, 40), showUnfolded, m_DetailsBoxOptions.m_Flags,
  629.                   m_DetailsBoxOptions.m_DisplayInFutureText, m_DetailsBoxOptions.m_pButtonList,  
  630.                   m_DetailsBoxOptions.m_Timeout, m_DetailsBoxOptions.m_IconNumber, m_DetailsBoxOptions.m_HelpID);
  631.  
  632.       // set return value
  633.       if ((pReturnValue = m_DetailsBoxOptions.GetDlgItem(IDC_RETURN_VALUE)) != 0)
  634.       {
  635.          value = retVal & ~HTMLID_DONTASKAGAIN;
  636.          returnValue.Format(_T("%d"), value); 
  637.          if (retVal & HTMLID_DONTASKAGAIN)
  638.             returnValue += _T("   Don't ask in the future.");
  639.          pReturnValue->SetWindowText(returnValue);
  640.       }
  641.       else
  642.          ASSERT(FALSE);
  643.  
  644.       m_DetailsBoxOptions.InitCombos();
  645.    }
  646.    else
  647.    {
  648.       if (m_FlashBoxOptions.UpdateData() == 0)
  649.          return;
  650.  
  651.       retVal = HTMLFlashBox(m_FlashBoxOptions.m_MessageText, m_FlashBoxOptions.m_TitleText, 
  652.                   m_FlashBoxOptions.m_Timeout, m_FlashBoxOptions.m_Flags, m_FlashBoxOptions.m_DisplayInFutureText, 
  653.                   m_FlashBoxOptions.m_IconNumber);
  654.  
  655.       m_FlashBoxOptions.InitCombos();
  656.    }
  657. }
  658.  
  659. void CMessageOptions::OnActivate (UINT nState, CWnd* pWndOther, BOOL bMinimized)
  660. {
  661.    CMcPropertySheet::OnActivate(nState, pWndOther, bMinimized);
  662.    if (DisableControls)
  663.       CtlHTMLDialogEnable(m_hWnd, nState != WA_INACTIVE);
  664. }
  665.  
  666.  
  667. /////////////////////////////////////////////////////////////////////////////
  668. // CButtonList dialog
  669.  
  670. BEGIN_MESSAGE_MAP(CButtonList, CDialog)
  671.     //{{AFX_MSG_MAP(CButtonList)
  672.     ON_BN_CLICKED(IDC_NEW_ITEM, OnNewItem)
  673.     ON_BN_CLICKED(IDC_EDIT_ITEM, OnEditItem)
  674.     ON_BN_CLICKED(IDC_REMOVE_ALL, OnRemoveAll)
  675.     ON_BN_CLICKED(IDC_REMOVE_ITEM, OnRemoveItem)
  676.     ON_WM_ACTIVATE()
  677.     //}}AFX_MSG_MAP
  678. END_MESSAGE_MAP()
  679.  
  680. CButtonList::CButtonList(HTMLButtonList *pButtonList, CWnd* pParent /*=NULL*/)
  681.     : CDialog(CButtonList::IDD, pParent), m_pButtonList(pButtonList)
  682. {
  683.     //{{AFX_DATA_INIT(CButtonList)
  684.     //}}AFX_DATA_INIT
  685. }
  686.  
  687. void CButtonList::DoDataExchange(CDataExchange* pDX)
  688. {
  689.     CDialog::DoDataExchange(pDX);
  690.     //{{AFX_DATA_MAP(CButtonList)
  691.     //}}AFX_DATA_MAP
  692.  
  693.    if (pDX->m_bSaveAndValidate)
  694.    {
  695.       CListCtrl *pList;
  696.       CString  temp;
  697.       int      item, items;
  698.  
  699.       // ENHANCE: could improve by saving and restoring to registry
  700.       if ((pList = (CListCtrl *)GetDlgItem(IDC_BUTTON_LIST)) == 0)
  701.       {
  702.          ASSERT(FALSE);
  703.          return;
  704.       }
  705.  
  706.       // fill in the button list based on the selections
  707.       items = pList->GetItemCount();
  708.       for (item = 0; item < items; item++)
  709.       {
  710.          _tcscpy(m_pButtonList[item].Name, pList->GetItemText(item, 0));
  711.          temp = pList->GetItemText(item, 1);
  712.          m_pButtonList[item].ID = atoi(temp);
  713.          temp = pList->GetItemText(item, 2);
  714.          if (temp.IsEmpty())
  715.             m_pButtonList[item].IsDefault = FALSE;
  716.          else
  717.             m_pButtonList[item].IsDefault = TRUE;
  718.       }
  719.       m_pButtonList[item].ID = -1;
  720.    }
  721. }
  722.  
  723. BOOL CButtonList::OnInitDialog() 
  724. {
  725.    CListCtrl *pList;
  726.    CString  temp;
  727.    CRect    rect;
  728.  
  729.     CDialog::OnInitDialog();
  730.  
  731.    // init list
  732.    if ((pList = (CListCtrl *)GetDlgItem(IDC_BUTTON_LIST)) != 0)
  733.    {
  734.       // init columns
  735.       pList->GetClientRect(&rect);
  736.       pList->InsertColumn(0, _T("Name"), LVCFMT_LEFT,  rect.right / 2);
  737.       pList->InsertColumn(1, _T("ID"),   LVCFMT_RIGHT, rect.right / 4);
  738.       pList->InsertColumn(2, _T("Default"), LVCFMT_CENTER, rect.right / 4);
  739.  
  740.       // loop through button list
  741.       for (int i = 0; ; i++)
  742.       {
  743.          if (m_pButtonList[i].ID == -1)
  744.             break;
  745.          pList->InsertItem(i, m_pButtonList[i].Name);
  746.          temp.Format(_T("%d"), m_pButtonList[i].ID);
  747.          pList->SetItemText(i, 1, temp);
  748.          if (m_pButtonList[i].IsDefault)
  749.             temp = _T("x");
  750.          else
  751.             temp.Empty();
  752.          pList->SetItemText(i, 2, temp);
  753.       }
  754.    }
  755.    else
  756.       ASSERT(FALSE);
  757.  
  758.    EnableButtons();
  759.     
  760.     return TRUE;
  761. }
  762.  
  763. void CButtonList::OnNewItem() 
  764. {
  765.    CListCtrl *pList;
  766.    CString  temp;
  767.    int      item, items;
  768.  
  769.    if ((pList = (CListCtrl *)GetDlgItem(IDC_BUTTON_LIST)) == 0)
  770.    {
  771.       ASSERT(FALSE);
  772.       return;
  773.    }
  774.  
  775.    // enforce the maximum button count
  776.    if ((items = pList->GetItemCount()) >= MaxButtonsCount)
  777.    {
  778.       HTMLMessageBox(_T("The button list already has the maximum number of buttons.\nRemove another button and try again."), 0, MB_ICONSTOP);
  779.       return;
  780.    }
  781.  
  782.    if (items == 0)
  783.    {
  784.       // the list is empty, so we don't need to know the insertion location - use the CEditButton
  785.       CEditButton dialog(this, _T("Add Button"));
  786.  
  787.       if (dialog.DoModal() == IDOK)
  788.       {
  789.          pList->InsertItem(0, dialog.m_Name);
  790.          temp.Format(_T("%d"), dialog.m_ID);
  791.          pList->SetItemText(0, 1, temp);
  792.          if (dialog.m_IsDefault)
  793.             temp = _T("x");
  794.          else
  795.             temp.Empty();
  796.          pList->SetItemText(0, 2, temp);
  797.       }
  798.    }
  799.    else
  800.    {
  801.       LV_ITEM  itemInfo;
  802.  
  803.       // find the selected button
  804.       for (item = 0; item < MaxButtonsCount; item++)
  805.       {
  806.          ZeroMemory(&itemInfo, sizeof(itemInfo));
  807.          itemInfo.mask       = LVIF_STATE;
  808.          itemInfo.stateMask  = LVIS_SELECTED;
  809.          itemInfo.iItem = item;
  810.          if (pList->GetItem(&itemInfo) == 0)
  811.          {
  812.             // default to the last item
  813.             item = max(0, pList->GetItemCount() - 1);
  814.             break;
  815.          }
  816.          if (itemInfo.state & LVIS_SELECTED)
  817.             break;
  818.       }
  819.  
  820.       CAddButton dialog(this);
  821.  
  822.       if (dialog.DoModal() == IDOK)
  823.       {
  824.          if (dialog.m_InsertAfter)
  825.             item++;
  826.          pList->InsertItem(item, dialog.m_Name);
  827.          temp.Format(_T("%d"), dialog.m_ID);
  828.          pList->SetItemText(item, 1, temp);
  829.          if (dialog.m_IsDefault)
  830.             temp = _T("x");
  831.          else
  832.             temp.Empty();
  833.          pList->SetItemText(item, 2, temp);
  834.       }
  835.    }
  836.  
  837.    EnableButtons();
  838. }
  839.  
  840. void CButtonList::OnEditItem() 
  841. {
  842.    LV_ITEM  itemInfo;
  843.    CListCtrl *pList;
  844.    CString  temp;
  845.    int      item;
  846.  
  847.    if ((pList = (CListCtrl *)GetDlgItem(IDC_BUTTON_LIST)) == 0)
  848.    {
  849.       ASSERT(FALSE);
  850.       return;
  851.    }
  852.  
  853.    // find the selected button
  854.    for (item = 0; item < MaxButtonsCount; item++)
  855.    {
  856.       ZeroMemory(&itemInfo, sizeof(itemInfo));
  857.       itemInfo.mask       = LVIF_STATE;
  858.       itemInfo.stateMask  = LVIS_SELECTED;
  859.       itemInfo.iItem = item;
  860.       if (pList->GetItem(&itemInfo) == 0)
  861.       {
  862.          HTMLMessageBox(_T("You must select the button that you want to change."), 
  863.             0, MB_ICONWARNING);
  864.          return;
  865.       }
  866.       if (itemInfo.state & LVIS_SELECTED)
  867.          break;
  868.    }
  869.  
  870.    CEditButton dialog(this);
  871.  
  872.    // init values
  873.    dialog.m_Name = pList->GetItemText(item, 0);
  874.    temp = pList->GetItemText(item, 1);
  875.    dialog.m_ID = atoi(temp);
  876.    temp = pList->GetItemText(item, 2);
  877.    if (temp.IsEmpty())
  878.       dialog.m_IsDefault = FALSE;
  879.    else
  880.       dialog.m_IsDefault = TRUE;
  881.  
  882.    if (dialog.DoModal() == IDOK)
  883.    {
  884.       pList->SetItemText(item, 0, dialog.m_Name);
  885.       temp.Format(_T("%d"), dialog.m_ID);
  886.       pList->SetItemText(item, 1, temp);
  887.       if (dialog.m_IsDefault)
  888.          temp = _T("x");
  889.       else
  890.          temp.Empty();
  891.       pList->SetItemText(item, 2, temp);
  892.    }
  893. }
  894.  
  895. void CButtonList::OnRemoveAll() 
  896. {
  897.    CListCtrl *pList;
  898.  
  899.    if ((pList = (CListCtrl *)GetDlgItem(IDC_BUTTON_LIST)) != 0)
  900.       pList->DeleteAllItems();
  901.    else
  902.       ASSERT(FALSE);
  903.  
  904.    EnableButtons();
  905. }
  906.  
  907. void CButtonList::OnRemoveItem() 
  908. {
  909.    CListCtrl *pList;
  910.    LV_ITEM  itemInfo;
  911.    int item;
  912.  
  913.    if ((pList = (CListCtrl *)GetDlgItem(IDC_BUTTON_LIST)) == 0)
  914.    {
  915.       ASSERT(FALSE);
  916.       return;
  917.    }
  918.  
  919.    // find the selected button
  920.    for (item = 0; item < MaxButtonsCount; item++)
  921.    {
  922.       ZeroMemory(&itemInfo, sizeof(itemInfo));
  923.       itemInfo.mask       = LVIF_STATE;
  924.       itemInfo.stateMask  = LVIS_SELECTED;
  925.       itemInfo.iItem = item;
  926.       if (pList->GetItem(&itemInfo) == 0)
  927.          return;
  928.       if (itemInfo.state & LVIS_SELECTED)
  929.          break;
  930.    }
  931.  
  932.    // delete the selected item
  933.    pList->DeleteItem(item);
  934.  
  935.    EnableButtons();
  936. }
  937.  
  938. void CButtonList::EnableButtons() 
  939. {
  940.    CListCtrl *pList;
  941.    CButton *pEditItem, *pRemoveItem, *pRemoveAll, *pOK;
  942.    int   items;
  943.    BOOL  enableButtons = TRUE;
  944.  
  945.    if ((pList = (CListCtrl *)GetDlgItem(IDC_BUTTON_LIST)) == 0)
  946.    {
  947.       ASSERT(FALSE);
  948.       return;
  949.    }
  950.    if ((pOK = (CButton *)GetDlgItem(IDOK)) == 0)
  951.    {
  952.       ASSERT(FALSE);
  953.       return;
  954.    }
  955.    if ((pEditItem = (CButton *)GetDlgItem(IDC_EDIT_ITEM)) == 0)
  956.    {
  957.       ASSERT(FALSE);
  958.       return;
  959.    }
  960.    if ((pRemoveItem = (CButton *)GetDlgItem(IDC_REMOVE_ITEM)) == 0)
  961.    {
  962.       ASSERT(FALSE);
  963.       return;
  964.    }
  965.    if ((pRemoveAll = (CButton *)GetDlgItem(IDC_REMOVE_ALL)) == 0)
  966.    {
  967.       ASSERT(FALSE);
  968.       return;
  969.    }
  970.  
  971.    if ((items = pList->GetItemCount()) == 0)
  972.    {
  973.       enableButtons = FALSE;
  974.  
  975.       // set focus on OK, otherwise focus may get "trapped" on a diabled button
  976.       pOK->SetFocus();
  977.    }
  978.  
  979.    pEditItem->EnableWindow(enableButtons);
  980.    pRemoveItem->EnableWindow(enableButtons);
  981.    pRemoveAll->EnableWindow(enableButtons);
  982. }
  983.  
  984. void CButtonList::OnActivate (UINT nState, CWnd* pWndOther, BOOL bMinimized)
  985. {
  986.    CDialog::OnActivate(nState, pWndOther, bMinimized);
  987.    if (DisableControls)
  988.       CtlHTMLDialogEnable(m_hWnd, nState != WA_INACTIVE);
  989. }
  990.  
  991.  
  992. /////////////////////////////////////////////////////////////////////////////
  993. // CAddButton dialog
  994.  
  995. BEGIN_MESSAGE_MAP(CAddButton, CDialog)
  996.     //{{AFX_MSG_MAP(CAddButton)
  997.     ON_WM_ACTIVATE()
  998.     //}}AFX_MSG_MAP
  999. END_MESSAGE_MAP()
  1000.  
  1001. CAddButton::CAddButton(CWnd* pParent /*=NULL*/)
  1002.     : CDialog(CAddButton::IDD, pParent)
  1003. {
  1004.     //{{AFX_DATA_INIT(CAddButton)
  1005.     m_ID = DefaultButtonID++;
  1006.     m_InsertAfter = 1;
  1007.     m_IsDefault = FALSE;
  1008.     m_Name = _T("");
  1009.     //}}AFX_DATA_INIT
  1010. }
  1011.  
  1012. void CAddButton::DoDataExchange(CDataExchange* pDX)
  1013. {
  1014.     CDialog::DoDataExchange(pDX);
  1015.     //{{AFX_DATA_MAP(CAddButton)
  1016.     DDX_Text(pDX, IDC_ID, m_ID);
  1017.     DDV_MinMaxUInt(pDX, m_ID, 1, 65535);
  1018.     DDX_Radio(pDX, IDC_INSERT_BEFORE, m_InsertAfter);
  1019.     DDX_Check(pDX, IDC_IS_DEFAULT, m_IsDefault);
  1020.     DDX_Text(pDX, IDC_NAME, m_Name);
  1021.     //}}AFX_DATA_MAP
  1022. }
  1023.  
  1024. void CAddButton::OnActivate (UINT nState, CWnd* pWndOther, BOOL bMinimized)
  1025. {
  1026.    CDialog::OnActivate(nState, pWndOther, bMinimized);
  1027.    if (DisableControls)
  1028.       CtlHTMLDialogEnable(m_hWnd, nState != WA_INACTIVE);
  1029. }
  1030.  
  1031.  
  1032. /////////////////////////////////////////////////////////////////////////////
  1033. // CEditButton dialog
  1034.  
  1035. BEGIN_MESSAGE_MAP(CEditButton, CDialog)
  1036.     //{{AFX_MSG_MAP(CEditButton)
  1037.     ON_WM_ACTIVATE()
  1038.     //}}AFX_MSG_MAP
  1039. END_MESSAGE_MAP()
  1040.  
  1041. CEditButton::CEditButton(CWnd* pParent, LPCTSTR title)
  1042.     : CDialog(CEditButton::IDD, pParent), m_Title(title)
  1043. {
  1044.     //{{AFX_DATA_INIT(CEditButton)
  1045.     m_ID = 0;
  1046.     m_IsDefault = FALSE;
  1047.     m_Name = _T("");
  1048.     //}}AFX_DATA_INIT
  1049. }
  1050.  
  1051. void CEditButton::DoDataExchange(CDataExchange* pDX)
  1052. {
  1053.     CDialog::DoDataExchange(pDX);
  1054.     //{{AFX_DATA_MAP(CEditButton)
  1055.     DDX_Text(pDX, IDC_ID, m_ID);
  1056.     DDV_MinMaxUInt(pDX, m_ID, 1, 65535);
  1057.     DDX_Check(pDX, IDC_IS_DEFAULT, m_IsDefault);
  1058.     DDX_Text(pDX, IDC_NAME, m_Name);
  1059.     //}}AFX_DATA_MAP
  1060. }
  1061.  
  1062. BOOL CEditButton::OnInitDialog() 
  1063. {
  1064.     CDialog::OnInitDialog();
  1065.  
  1066.    if (m_Title)
  1067.       SetWindowText(m_Title);
  1068.     
  1069.     return TRUE;
  1070. }
  1071.  
  1072. void CEditButton::OnActivate (UINT nState, CWnd* pWndOther, BOOL bMinimized)
  1073. {
  1074.    CDialog::OnActivate(nState, pWndOther, bMinimized);
  1075.    if (DisableControls)
  1076.       CtlHTMLDialogEnable(m_hWnd, nState != WA_INACTIVE);
  1077. }
  1078.