PageSetupDlg.cpp
上传用户:cding2008
上传日期:2007-01-03
资源大小:1812k
文件大小:16k
- /////////////////////////////////////////////////////////////////////////////
- // PageSetupDlg.cpp : implementation of the CPageSetupDlg class
- //
- // ModelMagic 3D and 'glOOP' (OpenGL Object Oriented Programming library)
- // Copyright (c) Craig Fahrnbach 1997, 1999
- //
- // OpenGL is a registered trademark of Silicon Graphics
- //
- //
- // This program is provided for educational and personal use only and
- // is provided without guarantee or warrantee expressed or implied.
- //
- // Commercial use is strickly prohibited without written permission
- // from ImageWare Development.
- //
- /////////////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "ModelMagic3D.h"
- #include "PageSetupDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CPageSetupDlg local variables
- #define NUM_CHOICES 80
- #define MARGIN_START 0.5f
- static CString szMargin[] = {"0.0"", "0.1"", "0.2"", "0.3"", "0.4"", "0.5"", "0.6"", "0.7"", "0.8"", "0.9"",
- "1.0"", "1.1"", "1.2"", "1.3"", "1.4"", "1.5"", "1.6"", "1.7"", "1.8"", "1.9"",
- "2.0"", "2.1"", "2.2"", "2.3"", "2.4"", "2.5"", "2.6"", "2.7"", "2.8"", "2.9"",
- "3.0"", "3.1"", "3.2"", "3.3"", "3.4"", "3.5"", "3.6"", "3.7"", "3.8"", "3.9"",
- "4.0"", "4.1"", "4.2"", "4.3"", "4.4"", "4.5"", "4.6"", "4.7"", "4.8"", "4.9"",
- "5.0"", "5.1"", "5.2"", "5.3"", "5.4"", "5.5"", "5.6"", "5.7"", "5.8"", "5.9"",
- "6.0"", "6.1"", "6.2"", "6.3"", "6.4"", "6.5"", "6.6"", "6.7"", "6.8"", "6.9"",
- "7.0"", "7.1"", "7.2"", "7.3"", "7.4"", "7.5"", "7.6"", "7.7"", "7.8"", "7.9"",
- };
- /////////////////////////////////////////////////////////////////////////////
- // CPageSetupDlg dialog
- CPageSetupDlg::CPageSetupDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CPageSetupDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CPageSetupDlg)
- m_iCenterImage = -1;
- m_fTopMargin = MARGIN_START;
- m_fBottomMargin = MARGIN_START;
- m_fLeftMargin = MARGIN_START;
- m_fRightMargin = MARGIN_START;
- m_fHeaderMargin = MARGIN_START;
- m_fFooterMargin = MARGIN_START;
- //}}AFX_DATA_INIT
- }
- void CPageSetupDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CPageSetupDlg)
- DDX_Control(pDX, IDC_TOP, m_EditTop);
- DDX_Control(pDX, IDC_RIGHT, m_EditRight);
- DDX_Control(pDX, IDC_LEFT, m_EditLeft);
- DDX_Control(pDX, IDC_HEADER, m_EditHeader);
- DDX_Control(pDX, IDC_FOOTER, m_EditFooter);
- DDX_Control(pDX, IDC_BOTTOM, m_EditBottom);
- DDX_Control(pDX, IDC_SPIN_TOP, m_SpinTop);
- DDX_Control(pDX, IDC_SPIN_RIGHT, m_SpinRight);
- DDX_Control(pDX, IDC_SPIN_LEFT, m_SpinLeft);
- DDX_Control(pDX, IDC_SPIN_HEADER, m_SpinHeader);
- DDX_Control(pDX, IDC_SPIN_FOOTER, m_SpinFooter);
- DDX_Control(pDX, IDC_SPIN_BOTTOM, m_SpinBottom);
- DDX_Radio(pDX, IDC_RADIO_CENTER_IMAGE, m_iCenterImage);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CPageSetupDlg, CDialog)
- //{{AFX_MSG_MAP(CPageSetupDlg)
- ON_BN_CLICKED(ID_PRINT_SETUP, OnPrintSetup)
- ON_BN_CLICKED(IDC_RADIO_CENTER_IMAGE, OnRadioCenterImage)
- ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_TOP, OnDeltaposSpinTop)
- ON_EN_UPDATE(IDC_TOP, OnUpdateTop)
- ON_EN_UPDATE(IDC_BOTTOM, OnUpdateBottom)
- ON_EN_UPDATE(IDC_LEFT, OnUpdateLeft)
- ON_EN_UPDATE(IDC_RIGHT, OnUpdateRight)
- ON_EN_UPDATE(IDC_HEADER, OnUpdateHeader)
- ON_EN_UPDATE(IDC_FOOTER, OnUpdateFooter)
- ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_BOTTOM, OnDeltaposSpinBottom)
- ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_LEFT, OnDeltaposSpinLeft)
- ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_RIGHT, OnDeltaposSpinRight)
- ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_HEADER, OnDeltaposSpinHeader)
- ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_FOOTER, OnDeltaposSpinFooter)
- ON_WM_PAINT()
- ON_EN_CHANGE(IDC_PAGE_PREVIEW, OnChangePagePreview)
- ON_EN_UPDATE(IDC_PAGE_PREVIEW, OnUpdatePagePreview)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CPageSetupDlg procedures
- void CPageSetupDlg::SetSpinPosn(CSpinButtonCtrl* pSpinCtrl, float fValue)
- {
- ASSERT(pSpinCtrl); // Ensure we have a valid pointer
- // Get the position of the floating point value within
- // the margin table. If valid, set the spin controls'
- // position
- int iPosn;
- iPosn = GetMarginPosition(fValue);
- if(iPosn != -1)
- pSpinCtrl->SetPos(iPosn);
- }
- int CPageSetupDlg::GetMarginPosition(float fSelect)
- {
- // Convert the floating point value to a string, rounded
- // to the nearest 1/10" inch.
- CString szString;
- szString.Format("%1.1f"", fSelect);
- // See if we have a match within the margin table
- for(int i=0; i<NUM_CHOICES; i++)
- {
- int iRetn = szMargin[i].Compare(szString);
- if(iRetn == 0)
- return i; // Found a Match!
- }
- return -1; // Not in the table!
- }
- void CPageSetupDlg::SetEditText(CEdit* pEdit, float fValue)
- {
- ASSERT(pEdit); // Ensure we have a valid pointer
- // Format the string to two decimal points and set the
- // CEdit control box text.
- CString szMargin;
- szMargin.Format("%1.2f"", fValue);
- pEdit->SetWindowText(szMargin);
- }
- void CPageSetupDlg::DrawPageOutline()
- {
- HBRUSH brush;
- HDC hDC;
- CRect rect, rectWnd, rectPage;
- // Calculate the window dimensions.
- ::GetWindowRect(m_wndPagePreview, &rect);
- rectWnd.top = 0;
- rectWnd.left = 0;
- rectWnd.right = rect.right - rect.left;
- rectWnd.bottom = rect.bottom - rect.top;
- // Get a device context to our window
- hDC = ::GetDC(m_wndPagePreview);
- // Calculate the dimensions of the page
- rectPage.top = (rectWnd.bottom-75)/2;
- rectPage.left = (rectWnd.right-60)/2;
- rectPage.right = 60;
- rectPage.bottom = 75;
- // Create a white brush and draw the outline of the page
- brush = CreateSolidBrush(0x00ff00ff);
- SelectObject(hDC, brush);
- FillRect(hDC, &rectPage, brush);
- DeleteObject(brush);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CPageSetupDlg message handlers
- BOOL CPageSetupDlg::OnInitDialog()
- {
- // let the base class do the default work
- CDialog::OnInitDialog();
- // Set the initial range of the spinner controls
- // to match the range within our margin table.
- // where:
- // nLower = 0.0"
- // nUpper = 7.9"
- m_SpinTop.SetRange(0, NUM_CHOICES-1);
- m_SpinBottom.SetRange(0, NUM_CHOICES-1);
- m_SpinLeft.SetRange(0, NUM_CHOICES-1);
- m_SpinRight.SetRange(0, NUM_CHOICES-1);
- m_SpinHeader.SetRange(0, NUM_CHOICES-1);
- m_SpinFooter.SetRange(0, NUM_CHOICES-1);
- // Set the initial position of the spinner controls
- SetSpinPosn(&m_SpinTop, m_fTopMargin);
- SetSpinPosn(&m_SpinBottom, m_fBottomMargin);
- SetSpinPosn(&m_SpinLeft, m_fLeftMargin);
- SetSpinPosn(&m_SpinRight, m_fRightMargin);
- SetSpinPosn(&m_SpinHeader, m_fHeaderMargin);
- SetSpinPosn(&m_SpinFooter, m_fFooterMargin);
- // Set the CEdit box text to match the initial values
- SetEditText(&m_EditTop, m_fTopMargin);
- SetEditText(&m_EditBottom, m_fBottomMargin);
- SetEditText(&m_EditLeft, m_fLeftMargin);
- SetEditText(&m_EditRight, m_fRightMargin);
- SetEditText(&m_EditHeader, m_fHeaderMargin);
- SetEditText(&m_EditFooter, m_fFooterMargin);
- /*
- // Create the Page Preview window
- CRect rect;
- rect.top = 24;
- rect.bottom = 162;
- rect.left = 203;
- rect.right = 368;
- GetDlgItem(IDC_PAGE_PREVIEW)->GetWindowRect(&rect);
- ScreenToClient(&rect);
- m_wndPagePreview.Create(NULL, // lpszClassName
- NULL, // lpszWindowName
- WS_CHILD | WS_VISIBLE | // dwStyle
- WS_BORDER,
- rect, // rect
- this, // CWnd* pParentWnd
- NULL, // UINT nID
- 0); // pContext
-
- */
- m_wndPagePreview = ::GetDlgItem(this->m_hWnd, IDC_PAGE_PREVIEW);
- HDC hDC = ::GetDC(m_wndPagePreview);
- // m_wndPagePreview.GetDC()->SetBkColor(0x00C0C0C0);//Light Gray
- SetBkColor(hDC, 0x00C0C0C0);//Light Gray
- ::InvalidateRect(m_wndPagePreview, NULL, TRUE);
- // m_wndPagePreview.EnableWindow(TRUE);
- // DrawPageOutline();
- // Dialog box is being initialized (FALSE) or
- // data is being retrieved (TRUE).
- UpdateData(FALSE);
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void CPageSetupDlg::OnOK()
- {
- // TODO: Add extra validation here
-
- CDialog::OnOK();
- }
- void CPageSetupDlg::OnPrintSetup()
- {
- // CMyglApp* pApp = (CMyglApp*) AfxGetApp( );
- // ASSERT(pApp);
- // pApp->OnFilePrintSetup();
- CPrintDialog pDlg(TRUE);
- // pDlg.GetDefaults();
- pDlg.DoModal();
- GlobalFree(pDlg.m_pd.hDevMode);
- GlobalFree(pDlg.m_pd.hDevNames);
- }
- void CPageSetupDlg::OnRadioCenterImage()
- {
- // Simple toggle
- if(m_iCenterImage == -1)
- m_iCenterImage = 0;
- else
- m_iCenterImage = -1;
-
- // Dialog box is being initialized (FALSE) or
- // data is being retrieved (TRUE).
- UpdateData(FALSE);
- }
- void CPageSetupDlg::OnDeltaposSpinTop(NMHDR* pNMHDR, LRESULT* pResult)
- {
- NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
- // Our static Spin Control position variable
- static int i = (int)(MARGIN_START*10);
- // Note: We do not use the member variable
- // pNMUpDown->iPos because its value
- // is not reported properly when the
- // user spins from Up/Down or Down/Up..
- //
- // Instead, we add or subtract to our static
- // variable accordingly..
- i += pNMUpDown->iDelta;
- // Limit check the spinner's position
- if(i<0)
- i=0;
- if(i>NUM_CHOICES)
- i = NUM_CHOICES;
- // Get the margin value from the local array and
- // set the edit box text.
- sscanf(szMargin[i], "%f", &m_fTopMargin);
- SetEditText(&m_EditTop, m_fTopMargin);
- // Dialog box is being initialized (FALSE) or
- // data is being retrieved (TRUE).
- UpdateData(FALSE);
- // Accept the changes (return FALSE)
- *pResult = 0;
- }
- void CPageSetupDlg::OnDeltaposSpinBottom(NMHDR* pNMHDR, LRESULT* pResult)
- {
- NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
- // Our static Spin Control position variable
- static int i = (int)(MARGIN_START*10);
- // Note: We do not use the member variable
- // pNMUpDown->iPos because its value
- // is not reported properly when the
- // user spins from Up/Down or Down/Up..
- //
- // Instead, we add or subtract to our static
- // variable accordingly..
- i += pNMUpDown->iDelta;
- // Limit check the spinner's position
- if(i<0)
- i=0;
- if(i>NUM_CHOICES)
- i = NUM_CHOICES;
- // Get the margin value from the local array and
- // set the edit box text.
- sscanf(szMargin[i], "%f", &m_fBottomMargin);
- SetEditText(&m_EditBottom, m_fBottomMargin);
- // Dialog box is being initialized (FALSE) or
- // data is being retrieved (TRUE).
- UpdateData(FALSE);
- // Accept the changes (return FALSE)
- *pResult = 0;
- }
- void CPageSetupDlg::OnDeltaposSpinLeft(NMHDR* pNMHDR, LRESULT* pResult)
- {
- NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
- // Our static Spin Control position variable
- static int i = (int)(MARGIN_START*10);
- // Note: We do not use the member variable
- // pNMUpDown->iPos because its value
- // is not reported properly when the
- // user spins from Up/Down or Down/Up..
- //
- // Instead, we add or subtract to our static
- // variable accordingly..
- i += pNMUpDown->iDelta;
- // Limit check the spinner's position
- if(i<0)
- i=0;
- if(i>NUM_CHOICES)
- i = NUM_CHOICES;
- // Get the margin value from the local array and
- // set the edit box text.
- sscanf(szMargin[i], "%f", &m_fLeftMargin);
- SetEditText(&m_EditLeft, m_fLeftMargin);
- // Dialog box is being initialized (FALSE) or
- // data is being retrieved (TRUE).
- UpdateData(FALSE);
- // Accept the changes (return FALSE)
- *pResult = 0;
- }
- void CPageSetupDlg::OnDeltaposSpinRight(NMHDR* pNMHDR, LRESULT* pResult)
- {
- NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
- // Our static Spin Control position variable
- static int i = (int)(MARGIN_START*10);
- // Note: We do not use the member variable
- // pNMUpDown->iPos because its value
- // is not reported properly when the
- // user spins from Up/Down or Down/Up..
- //
- // Instead, we add or subtract to our static
- // variable accordingly..
- i += pNMUpDown->iDelta;
- // Limit check the spinner's position
- if(i<0)
- i=0;
- if(i>NUM_CHOICES)
- i = NUM_CHOICES;
- // Get the margin value from the local array and
- // set the edit box text.
- sscanf(szMargin[i], "%f", &m_fRightMargin);
- SetEditText(&m_EditRight, m_fRightMargin);
- // Dialog box is being initialized (FALSE) or
- // data is being retrieved (TRUE).
- UpdateData(FALSE);
- // Accept the changes (return FALSE)
- *pResult = 0;
- }
- void CPageSetupDlg::OnDeltaposSpinHeader(NMHDR* pNMHDR, LRESULT* pResult)
- {
- NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
- // Our static Spin Control position variable
- static int i = (int)(MARGIN_START*10);
- // Note: We do not use the member variable
- // pNMUpDown->iPos because its value
- // is not reported properly when the
- // user spins from Up/Down or Down/Up..
- //
- // Instead, we add or subtract to our static
- // variable accordingly..
- i += pNMUpDown->iDelta;
- // Limit check the spinner's position
- if(i<0)
- i=0;
- if(i>NUM_CHOICES)
- i = NUM_CHOICES;
- // Get the margin value from the local array and
- // set the edit box text.
- sscanf(szMargin[i], "%f", &m_fHeaderMargin);
- SetEditText(&m_EditHeader, m_fHeaderMargin);
- // Dialog box is being initialized (FALSE) or
- // data is being retrieved (TRUE).
- UpdateData(FALSE);
- // Accept the changes (return FALSE)
- *pResult = 0;
- }
- void CPageSetupDlg::OnDeltaposSpinFooter(NMHDR* pNMHDR, LRESULT* pResult)
- {
- NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
- // Our static Spin Control position variable
- static int i = (int)(MARGIN_START*10);
- // Note: We do not use the member variable
- // pNMUpDown->iPos because its value
- // is not reported properly when the
- // user spins from Up/Down or Down/Up..
- //
- // Instead, we add or subtract to our static
- // variable accordingly..
- i += pNMUpDown->iDelta;
- // Limit check the spinner's position
- if(i<0)
- i=0;
- if(i>NUM_CHOICES)
- i = NUM_CHOICES;
- // Get the margin value from the local array and
- // set the edit box text.
- sscanf(szMargin[i], "%f", &m_fFooterMargin);
- SetEditText(&m_EditFooter, m_fFooterMargin);
- // Dialog box is being initialized (FALSE) or
- // data is being retrieved (TRUE).
- UpdateData(FALSE);
- // Accept the changes (return FALSE)
- *pResult = 0;
- }
- void CPageSetupDlg::OnUpdateTop()
- {
- // Get the user entered values
- char buf[10];
- int nChars = m_EditTop.GetLine(0, &buf[0], 10);
- sscanf(&buf[0], "%f", &m_fTopMargin);
- // Set the spinner position
- SetSpinPosn(&m_SpinTop, m_fTopMargin);
- }
- void CPageSetupDlg::OnUpdateBottom()
- {
- // Get the user entered values
- char buf[10];
- int nChars = m_EditBottom.GetLine(0, &buf[0], 10);
- sscanf(&buf[0], "%f", &m_fBottomMargin);
- // Set the spinner position
- SetSpinPosn(&m_SpinBottom, m_fBottomMargin);
- }
- void CPageSetupDlg::OnUpdateLeft()
- {
- // Get the user entered values
- char buf[10];
- int nChars = m_EditLeft.GetLine(0, &buf[0], 10);
- sscanf(&buf[0], "%f", &m_fLeftMargin);
- // Set the spinner position
- SetSpinPosn(&m_SpinLeft, m_fLeftMargin);
- }
- void CPageSetupDlg::OnUpdateRight()
- {
- // Get the user entered values
- char buf[10];
- int nChars = m_EditRight.GetLine(0, &buf[0], 10);
- sscanf(&buf[0], "%f", &m_fRightMargin);
- // Set the spinner position
- SetSpinPosn(&m_SpinRight, m_fRightMargin);
- }
- void CPageSetupDlg::OnUpdateHeader()
- {
- // Get the user entered values
- char buf[10];
- int nChars = m_EditHeader.GetLine(0, &buf[0], 10);
- sscanf(&buf[0], "%f", &m_fHeaderMargin);
- // Set the spinner position
- SetSpinPosn(&m_SpinHeader, m_fHeaderMargin);
- }
- void CPageSetupDlg::OnUpdateFooter()
- {
- // Get the user entered values
- char buf[10];
- int nChars = m_EditFooter.GetLine(0, &buf[0], 10);
- sscanf(&buf[0], "%f", &m_fFooterMargin);
- // Set the spinner position
- SetSpinPosn(&m_SpinFooter, m_fFooterMargin);
- }
- void CPageSetupDlg::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
- DrawPageOutline();
- // TODO: Add your message handler code here
-
- // Do not call CDialog::OnPaint() for painting messages
- }
- void CPageSetupDlg::OnChangePagePreview()
- {
- // TODO: Add your control notification handler code here
- DrawPageOutline();
-
- }
- void CPageSetupDlg::OnUpdatePagePreview()
- {
- // TODO: Add your control notification handler code here
- DrawPageOutline();
- }