home *** CD-ROM | disk | FTP | other *** search
- /*---------------------------------------------------------------------------*\
- | Controls.cpp - CtlHTML(tm) Control Library Test Program |
- | Windmill Point Software, Alburg, VT 05440 |
- | Copyright (c) 1999, Windmill Point Software |
- | All Rights Reserved. |
- \*---------------------------------------------------------------------------*/
-
- #include "stdafx.h"
- #include "CtlHTML Demo.h"
- #include "DevUI.h"
- #include "..\CtlHtml.h"
- #include "Controls.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
-
- // example partial ownerdraw callback function
- BOOL MyPartialOwnerDraw (HWND hWnd, HDC hDC, LPSTR szText, RECT *pClientRect, RECT *pTextRect,
- int textStyle, BOOL isPushButton, BOOL hasFocus, BOOL isDown, BOOL calcSize)
- {
- int id;
-
- id = GetDlgCtrlID(hWnd);
- if (id == IDC_OWNDERDRAW)
- {
- HBRUSH hBrush, hOldBrush;
- HPEN hPen, hOldPen;
-
- // in this case, the ownerdraw doesn't change the size
- if (calcSize)
- return FALSE;
-
- // set the brush and pen
- if (IsWindowEnabled(hWnd))
- {
- hBrush = CreateSolidBrush(RGB(0, 0, 0xc0));
- hPen = (HPEN)GetStockObject(BLACK_PEN);
- }
- else
- {
- hBrush = (HBRUSH)GetStockObject(HOLLOW_BRUSH);
- hPen = CreatePen(PS_SOLID, 1, RGB(0, 0, 0x40));
- }
- hOldBrush = (HBRUSH)SelectObject(hDC, hBrush);
- hOldPen = (HPEN)SelectObject(hDC, hPen);
-
- // do drawing
- if (isPushButton)
- {
- if (isDown)
- Rectangle(hDC, pTextRect->left + 5, pTextRect->top + 5, pTextRect->right - 3, pTextRect->bottom - 3);
- else
- Rectangle(hDC, pTextRect->left + 4, pTextRect->top + 4, pTextRect->right - 4, pTextRect->bottom - 4);
- }
- else
- Rectangle(hDC, pTextRect->left, pTextRect->top, pTextRect->right, pTextRect->bottom);
-
- // be sure to restore all GDI objects
- SelectObject(hDC, hOldBrush);
- SelectObject(hDC, hOldPen);
-
- // set DC for text drawing
- SetBkMode(hDC, TRANSPARENT);
- if (IsWindowEnabled(hWnd))
- SetTextColor(hDC, RGB(0xff, 0xff, 0xff)); // use white text on a blue background
-
- // return FALSE to draw the text
- return FALSE;
- }
- else if (id == IDC_OWNERDRAWRB1 || id == IDC_OWNERDRAWRB2 || id == IDC_OWNERDRAWRB3)
- {
- // in this case, the ownerdraw doesn't change the size
- if (calcSize)
- return TRUE;
-
- COLORREF color;
- HBRUSH hBrush, hOldBrush;
- HPEN hPen, hOldPen;
-
- // set the brush and pen
- if (IsWindowEnabled(hWnd))
- {
- sscanf(szText, "%x", &color);
- hBrush = CreateSolidBrush(color);
- }
- else
- hBrush = GetSysColorBrush(COLOR_GRAYTEXT); // use same color as disabled text
- hPen = (HPEN)GetStockObject(BLACK_PEN);
- hOldBrush = (HBRUSH)SelectObject(hDC, hBrush);
- hOldPen = (HPEN)SelectObject(hDC, hPen);
-
- // do drawing
- if (isPushButton)
- {
- if (isDown)
- Rectangle(hDC, pTextRect->left + 5, pTextRect->top + 5, pTextRect->right - 3, pTextRect->bottom - 3);
- else
- Rectangle(hDC, pTextRect->left + 4, pTextRect->top + 4, pTextRect->right - 4, pTextRect->bottom - 4);
- }
- else
- Rectangle(hDC, pTextRect->left, pTextRect->top, pTextRect->right, pTextRect->bottom);
-
- // be sure to restore all GDI objects
- SelectObject(hDC, hOldBrush);
- SelectObject(hDC, hOldPen);
-
- // draw the focus rect
- if (hasFocus)
- {
- RECT focusRect;
-
- focusRect = *pTextRect;
- InflateRect(&focusRect, -2, -2);
- DrawFocusRect(hDC, &focusRect);
- }
-
- // return TRUE to not draw the text
- return TRUE;
- }
- else
- return FALSE;
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CButtons property page
-
- IMPLEMENT_DYNCREATE(CButtons, CPropertyPage)
-
- BEGIN_MESSAGE_MAP(CButtons, CPropertyPage)
- //{{AFX_MSG_MAP(CButtons)
- ON_WM_ACTIVATE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- CButtons::CButtons() : CPropertyPage(CButtons::IDD)
- {
- //{{AFX_DATA_INIT(CButtons)
- //}}AFX_DATA_INIT
- }
-
- CButtons::~CButtons()
- {
- }
-
- void CButtons::DoDataExchange(CDataExchange* pDX)
- {
- CPropertyPage::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CButtons)
- //}}AFX_DATA_MAP
- }
-
- BOOL CButtons::OnInitDialog()
- {
- CPropertyPage::OnInitDialog();
- CtlHTMLSubclassDialog(m_hWnd);
- return TRUE;
- }
-
- void CButtons::OnActivate (UINT nState, CWnd* pWndOther, BOOL bMinimized)
- {
- CPropertyPage::OnActivate(nState, pWndOther, bMinimized);
- if (DisableControls)
- CtlHTMLDialogEnable(m_hWnd, nState != WA_INACTIVE);
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CCheckBoxes property page
-
- IMPLEMENT_DYNCREATE(CCheckBoxes, CPropertyPage)
-
- BEGIN_MESSAGE_MAP(CCheckBoxes, CPropertyPage)
- //{{AFX_MSG_MAP(CCheckBoxes)
- ON_WM_ACTIVATE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- CCheckBoxes::CCheckBoxes() : CPropertyPage(CCheckBoxes::IDD)
- {
- //{{AFX_DATA_INIT(CCheckBoxes)
- //}}AFX_DATA_INIT
- }
-
- CCheckBoxes::~CCheckBoxes()
- {
- }
-
- void CCheckBoxes::DoDataExchange(CDataExchange* pDX)
- {
- BOOL enable = TRUE;
-
- CPropertyPage::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CCheckBoxes)
- DDX_Check(pDX, IDC_READONLY, enable);
- //}}AFX_DATA_MAP
- }
-
- BOOL CCheckBoxes::OnInitDialog()
- {
- CPropertyPage::OnInitDialog();
- CtlHTMLSubclassDialog(m_hWnd);
- return TRUE;
- }
-
- void CCheckBoxes::OnActivate (UINT nState, CWnd* pWndOther, BOOL bMinimized)
- {
- CPropertyPage::OnActivate(nState, pWndOther, bMinimized);
- if (DisableControls)
- CtlHTMLDialogEnable(m_hWnd, nState != WA_INACTIVE);
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CText property page
-
- IMPLEMENT_DYNCREATE(CText, CPropertyPage)
-
- BEGIN_MESSAGE_MAP(CText, CPropertyPage)
- //{{AFX_MSG_MAP(CText)
- ON_WM_ACTIVATE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- CText::CText() : CPropertyPage(CText::IDD)
- {
- //{{AFX_DATA_INIT(CText)
- //}}AFX_DATA_INIT
- }
-
- CText::~CText()
- {
- }
-
- void CText::DoDataExchange(CDataExchange* pDX)
- {
- CPropertyPage::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CText)
- //}}AFX_DATA_MAP
- }
-
- BOOL CText::OnInitDialog()
- {
- CPropertyPage::OnInitDialog();
-
- CWnd *pWnd;
-
- // Note: Must set edit box text before calling CtlHTMLSubclassDialog, otherwise these controls
- // will not be subclassed
- if ((pWnd = GetDlgItem(IDC_EDIT1)) != 0)
- pWnd->SetWindowText("<HTML>Left</HTML>");
- if ((pWnd = GetDlgItem(IDC_EDIT2)) != 0)
- pWnd->SetWindowText("<HTML>Center</HTML>");
- if ((pWnd = GetDlgItem(IDC_EDIT3)) != 0)
- pWnd->SetWindowText("<HTML>Right</HTML>");
- if ((pWnd = GetDlgItem(IDC_EDIT4)) != 0)
- pWnd->SetWindowText("<HTML><P align = \"left\">Left attribute</P></HTML>");
- if ((pWnd = GetDlgItem(IDC_EDIT5)) != 0)
- pWnd->SetWindowText("<HTML><P align = \"center\">Center attribute</P></HTML>");
- if ((pWnd = GetDlgItem(IDC_EDIT6)) != 0)
- pWnd->SetWindowText("<HTML><P align = \"right\">Right attribute</P></HTML>");
-
- CtlHTMLSubclassDialog(m_hWnd);
-
- return TRUE;
- }
-
- void CText::OnActivate (UINT nState, CWnd* pWndOther, BOOL bMinimized)
- {
- CPropertyPage::OnActivate(nState, pWndOther, bMinimized);
- if (DisableControls)
- CtlHTMLDialogEnable(m_hWnd, nState != WA_INACTIVE);
- }
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CControls
-
- static int ActivePage = 0;
-
- IMPLEMENT_DYNAMIC(CControls, CMcPropertySheet)
-
- BEGIN_MESSAGE_MAP(CControls, CMcPropertySheet)
- //{{AFX_MSG_MAP(CControls)
- ON_WM_DESTROY()
- ON_WM_ACTIVATE()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- CControls::CControls(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
- : CMcPropertySheet(nIDCaption, pParentWnd, iSelectPage)
- {
- AddPage(&m_Buttons);
- AddPage(&m_CheckBoxes);
- AddPage(&m_Text);
- }
-
- CControls::CControls(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
- : CMcPropertySheet(pszCaption, pParentWnd, iSelectPage)
- {
- AddPage(&m_Buttons);
- AddPage(&m_CheckBoxes);
- AddPage(&m_Text);
- }
-
- CControls::~CControls()
- {
- }
-
- BOOL CControls::OnInitDialog()
- {
- // remove the Apply and Cancel buttons
- RemoveApplyButton();
- RemoveCancelButton();
-
- // init the dialog
- BOOL bResult = CMcPropertySheet::OnInitDialog();
-
- // restore the active page
- SetActivePage(ActivePage);
-
- // handle window placement
- CMcWindowPlacement wp;
- wp.RestoreWindowPlacement(_T("Controls"), _T("WindowPlacement"), this, TRUE);
-
- // set the ownerdraw function
- CtlHTMLPartialOwnerDraw(MyPartialOwnerDraw);
-
- // init the dialog
- return bResult;
- }
-
- void CControls::OnDestroy()
- {
- // save active page
- ActivePage = GetActiveIndex();
-
- // handle window placement
- CMcWindowPlacement wp;
- wp.SaveWindowPlacement(_T("Controls"), _T("WindowPlacement"), this);
-
- CMcPropertySheet::OnDestroy();
- }
-
- void CControls::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
- {
- CMcPropertySheet::OnActivate(nState, pWndOther, bMinimized);
- if (DisableControls)
- CtlHTMLDialogEnable(m_hWnd, nState != WA_INACTIVE);
- }
-
-