Back to index

lightning-sunbird  0.9+nobinonly
CMarginHeaderFooter.cpp
Go to the documentation of this file.
00001 // MarginHeaderFooter.cpp : implementation file
00002 //
00003 
00004 #include "stdafx.h"
00005 #include "mfcembed.h"
00006 #include "CMarginHeaderFooter.h"
00007 #include "CCustomPromptDialog.h"
00008 
00009 #ifdef _DEBUG
00010 #define new DEBUG_NEW
00011 #undef THIS_FILE
00012 static char THIS_FILE[] = __FILE__;
00013 #endif
00014 
00015 static TCHAR* sCBXTitles[] = {
00016     _T("--Blank--"), _T("Title"), _T("URL"), _T("Date/Time"), _T("Page #"),
00017     _T("Page # of #"), _T("Custom..."), NULL};
00018 static TCHAR* sCBXValues[] = {
00019     _T(""), _T("&T"), _T("&U"), _T("&D"), _T("&P"), _T("&PT"), _T(""), NULL};
00020 
00022 // CMarginHeaderFooter property page
00023 
00024 IMPLEMENT_DYNCREATE(CMarginHeaderFooter, CPropertyPage)
00025 
00026 CMarginHeaderFooter::CMarginHeaderFooter() : CPropertyPage(CMarginHeaderFooter::IDD)
00027 {
00028          //{{AFX_DATA_INIT(CMarginHeaderFooter)
00029          m_BottomMarginText = _T("");
00030          m_LeftMarginText = _T("");
00031          m_RightMarginText = _T("");
00032          m_TopMarginText = _T("");
00033          //}}AFX_DATA_INIT
00034 
00035          m_FooterLeftText = _T("");
00036          m_FooterCenterText = _T("");
00037          m_FooterRightText = _T("");
00038          m_HeaderLeftText = _T("");
00039          m_HeaderCenterText = _T("");
00040          m_HeaderRightText = _T("");
00041 }
00042 
00043 CMarginHeaderFooter::~CMarginHeaderFooter()
00044 {
00045 }
00046 
00047 void CMarginHeaderFooter::DoDataExchange(CDataExchange* pDX)
00048 {
00049          CPropertyPage::DoDataExchange(pDX);
00050          //{{AFX_DATA_MAP(CMarginHeaderFooter)
00051          DDX_Text(pDX, IDC_BOTTOM_MARGIN_TXT, m_BottomMarginText);
00052          DDX_Text(pDX, IDC_LEFT_MARGIN_TXT, m_LeftMarginText);
00053          DDX_Text(pDX, IDC_RIGHT_MARGIN_TXT, m_RightMarginText);
00054          DDX_Text(pDX, IDC_TOP_MARGIN_TXT, m_TopMarginText);
00055          //}}AFX_DATA_MAP
00056 }
00057 
00058 
00059 BEGIN_MESSAGE_MAP(CMarginHeaderFooter, CPropertyPage)
00060        //{{AFX_MSG_MAP(CMarginHeaderFooter)
00061        ON_CBN_SELCHANGE(IDC_FTR_LEFT_CMBX, OnEditchangeFTRLeft)
00062        ON_CBN_SELCHANGE(IDC_FTR_CENTER_CMBX, OnEditchangeFTRCenter)
00063        ON_CBN_SELCHANGE(IDC_FTR_RIGHT_CMBX, OnEditchangeFTRRight)
00064        ON_CBN_SELCHANGE(IDC_HDR_LEFT_CMBX, OnEditchangeHDRLeft)
00065        ON_CBN_SELCHANGE(IDC_HDR_CENTER_CMBX, OnEditchangeHDRCenter)
00066        ON_CBN_SELCHANGE(IDC_HDR_RIGHT_CMBX, OnEditchangeHDRRight)
00067        //}}AFX_MSG_MAP
00068 END_MESSAGE_MAP()
00069 
00071 // CMarginHeaderFooter message handlers
00072 
00073 void CMarginHeaderFooter::SetComboboxValue(int aId, const TCHAR *aItem)
00074 {
00075     CComboBox* cbx = (CComboBox*)GetDlgItem(aId);
00076     if (cbx) 
00077     {
00078         int inx = 0;
00079         while (sCBXValues[inx] != NULL) 
00080         {
00081             if (!_tcscmp(sCBXValues[inx], aItem)) 
00082             {
00083                 cbx->SetCurSel(inx);
00084                 return;
00085             }
00086             inx++;
00087         }
00088         cbx->SetCurSel(inx-1);
00089     }
00090 }
00091 
00092 void CMarginHeaderFooter::AddCBXItem(int aId, const TCHAR * aItem)
00093 {
00094     CComboBox* cbx = (CComboBox*)GetDlgItem(aId);
00095     if (cbx) 
00096     {
00097         cbx->AddString(aItem);
00098     }
00099 }
00100 
00101 BOOL CMarginHeaderFooter::OnInitDialog() 
00102 {
00103        CDialog::OnInitDialog();
00104 
00105     int inx = 0;
00106     while (sCBXTitles[inx] != NULL) 
00107     {
00108         AddCBXItem(IDC_HDR_LEFT_CMBX,   sCBXTitles[inx]);
00109         AddCBXItem(IDC_HDR_CENTER_CMBX, sCBXTitles[inx]);
00110         AddCBXItem(IDC_HDR_RIGHT_CMBX,  sCBXTitles[inx]);
00111         AddCBXItem(IDC_FTR_LEFT_CMBX,   sCBXTitles[inx]);
00112         AddCBXItem(IDC_FTR_CENTER_CMBX, sCBXTitles[inx]);
00113         AddCBXItem(IDC_FTR_RIGHT_CMBX,  sCBXTitles[inx]);
00114         inx++;
00115     }
00116          SetComboboxValue(IDC_HDR_LEFT_CMBX, m_HeaderLeftText);
00117          SetComboboxValue(IDC_HDR_CENTER_CMBX, m_HeaderCenterText);
00118          SetComboboxValue(IDC_HDR_RIGHT_CMBX, m_HeaderRightText);
00119          SetComboboxValue(IDC_FTR_LEFT_CMBX, m_FooterLeftText);
00120          SetComboboxValue(IDC_FTR_CENTER_CMBX, m_FooterCenterText);
00121          SetComboboxValue(IDC_FTR_RIGHT_CMBX, m_FooterRightText);
00122 
00123          return TRUE;  // return TRUE unless you set the focus to a control
00124                        // EXCEPTION: OCX Property Pages should return FALSE
00125 }
00126 
00127 void CMarginHeaderFooter::SetCombobox(int aId, CString& aText) 
00128 {
00129     CComboBox* cbx = (CComboBox*)GetDlgItem(aId);
00130          int inx = cbx->GetCurSel();
00131     if (inx == 6) 
00132     {
00133         CCustomPromptDialog prompt(this);
00134         prompt.m_CustomText = aText;
00135         if(prompt.DoModal() == IDOK)
00136         {
00137             aText = prompt.m_CustomText;
00138         }
00139     } else {
00140       aText = sCBXValues[inx];
00141     }
00142 }
00143 
00144 void CMarginHeaderFooter::OnEditchangeFTRLeft() 
00145 {
00146     SetCombobox(IDC_FTR_LEFT_CMBX, m_FooterLeftText);
00147 }
00148 
00149 void CMarginHeaderFooter::OnEditchangeFTRCenter() 
00150 {
00151     SetCombobox(IDC_FTR_CENTER_CMBX, m_FooterCenterText);
00152 }
00153 
00154 void CMarginHeaderFooter::OnEditchangeFTRRight() 
00155 {
00156     SetCombobox(IDC_FTR_CENTER_CMBX, m_FooterCenterText);
00157 }
00158 
00159 void CMarginHeaderFooter::OnEditchangeHDRLeft() 
00160 {
00161     SetCombobox(IDC_HDR_LEFT_CMBX, m_HeaderLeftText);
00162 }
00163 
00164 void CMarginHeaderFooter::OnEditchangeHDRCenter() 
00165 {
00166     SetCombobox(IDC_HDR_CENTER_CMBX, m_HeaderCenterText);
00167 }
00168 
00169 void CMarginHeaderFooter::OnEditchangeHDRRight() 
00170 {
00171     SetCombobox(IDC_HDR_CENTER_CMBX, m_HeaderCenterText);
00172 }