PropPage1.cpp
上传用户:wujian85
上传日期:2010-04-08
资源大小:227k
文件大小:6k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // PropPage1.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "printformeditor.h"
  5. #include "PropPage1.h"
  6. #include "Doc.h"
  7. #include "View.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CPropPage1 dialog
  15. extern bool bLockingProperty;
  16. CPropPage1::CPropPage1(CWnd* pParent /*=NULL*/)
  17. : CDialog(CPropPage1::IDD, pParent)
  18. {
  19. //{{AFX_DATA_INIT(CPropPage1)
  20. bBold = FALSE;
  21. bItalic = FALSE;
  22. bUnderline = FALSE;
  23. csFontName = _T("");
  24. csFontSize = _T("");
  25. //}}AFX_DATA_INIT
  26. pDoc = NULL;
  27. pView = NULL;
  28. }
  29. /*
  30. DDX_Control(pDX, IDC_ED_YSIZE, wndEditHeight);
  31. DDX_Control(pDX, IDC_ED_Y, wndEditY);
  32. DDX_Control(pDX, IDC_ED_XSIZE, wndEditWidth);
  33. DDX_Control(pDX, IDC_ED_X, wndEditX);
  34. */
  35. void CPropPage1::DoDataExchange(CDataExchange* pDX)
  36. {
  37. CDialog::DoDataExchange(pDX);
  38. DDX_Control(pDX, IDC_ED_YSIZE, wndEditHeight);
  39. DDX_Control(pDX, IDC_ED_Y, wndEditY);
  40. DDX_Control(pDX, IDC_ED_XSIZE, wndEditWidth);
  41. DDX_Control(pDX, IDC_ED_X, wndEditX);
  42. if (pDoc && pView && !(pDX->m_bSaveAndValidate))
  43. {
  44. if (pDoc->GetSelectedCount() > 0)
  45. {
  46. bool bMulti = pDoc->GetSelectedCount() > 1;
  47. wndEditX.EnableWindow(false);
  48. wndEditHeight.EnableWindow(false);
  49. wndEditY.EnableWindow(false);
  50. wndEditWidth.EnableWindow(false);
  51. if (bMulti)
  52. {
  53. wndEditX.EnableWindow(false);
  54. wndEditHeight.EnableWindow(false);
  55. wndEditY.EnableWindow(false);
  56. wndEditWidth.EnableWindow(false);
  57. wndEditX.SetWindowText("");
  58. wndEditHeight.SetWindowText("");
  59. wndEditY.SetWindowText("");
  60. wndEditWidth.SetWindowText("");
  61. }
  62. /* else
  63. {
  64. wndEditX.EnableWindow(true);
  65. wndEditHeight.EnableWindow(true);
  66. wndEditY.EnableWindow(true);
  67. wndEditWidth.EnableWindow(true);
  68. }
  69. */
  70. CString cs;
  71. for (int t = 0; t < pDoc->iFormObj; t++)
  72. {
  73. if (pDoc->ppObjs[t]->bSelected)
  74. {
  75. if (!bMulti)
  76. {
  77. cs.Format("%d", pDoc->ppObjs[t]->rc.left);
  78. wndEditX.SetWindowText(cs);
  79. cs.Format("%d", pDoc->ppObjs[t]->rc.Height());
  80. wndEditHeight.SetWindowText(cs);
  81. cs.Format("%d", pDoc->ppObjs[t]->rc.top);
  82. wndEditY.SetWindowText(cs);
  83. cs.Format("%d", pDoc->ppObjs[t]->rc.Width());
  84. wndEditWidth.SetWindowText(cs);
  85. }
  86. bBold = pDoc->ppObjs[t]->bBold;
  87. bItalic = pDoc->ppObjs[t]->bItalic;
  88. bUnderline = pDoc->ppObjs[t]->bUnderline;
  89. csFontName = pDoc->ppObjs[t]->cFont;
  90. csFontSize.Format("%d", pDoc->ppObjs[t]->iSize);
  91. }
  92. }
  93. }
  94. }
  95. //{{AFX_DATA_MAP(CPropPage1)
  96. DDX_Check(pDX, IDC_CHK_BOLD, bBold);
  97. DDX_Check(pDX, IDC_CHK_ITALIC, bItalic);
  98. DDX_Check(pDX, IDC_CHK_UNDERLINE, bUnderline);
  99. DDX_Text(pDX, IDC_STATIC_FONT, csFontName);
  100. DDX_Text(pDX, IDC_STATIC_SIZE, csFontSize);
  101. //}}AFX_DATA_MAP
  102. if (pDoc && pView && pDX->m_bSaveAndValidate && pDoc->GetSelectedCount() > 0)
  103. {
  104. bool bMulti = pDoc->GetSelectedCount() > 1;
  105. CString cs;
  106. for (int t = 0; t < pDoc->iFormObj; t++)
  107. {
  108. if (pDoc->ppObjs[t]->bSelected)
  109. {
  110. /* if (!bMulti)
  111. {
  112. wndEditX.GetWindowText(cs);
  113. pDoc->ppObjs[t]->rc.left = atoi(cs);
  114. wndEditWidth.GetWindowText(cs);
  115. pDoc->ppObjs[t]->rc.right = pDoc->ppObjs[t]->rc.left + atoi(cs);
  116. wndEditY.GetWindowText(cs);
  117. pDoc->ppObjs[t]->rc.top = atoi(cs);
  118. wndEditHeight.GetWindowText(cs);
  119. pDoc->ppObjs[t]->rc.bottom = pDoc->ppObjs[t]->rc.top + atoi(cs);
  120. }
  121. */
  122. pDoc->ppObjs[t]->bBold = bBold ? true : false;
  123. pDoc->ppObjs[t]->bItalic = bItalic ? true : false;
  124. pDoc->ppObjs[t]->bUnderline = bUnderline ? true : false;
  125. lstrcpy(pDoc->ppObjs[t]->cFont, csFontName);
  126. pDoc->ppObjs[t]->iSize = atoi(csFontSize);
  127. }
  128. }
  129. pView->Invalidate();
  130. }
  131. }
  132. BEGIN_MESSAGE_MAP(CPropPage1, CDialog)
  133. //{{AFX_MSG_MAP(CPropPage1)
  134. ON_BN_CLICKED(IDC_BT_FONT, OnBtFont)
  135. ON_WM_KILLFOCUS()
  136. ON_BN_CLICKED(IDC_CHK_BOLD, OnChkBold)
  137. ON_BN_CLICKED(IDC_CHK_ITALIC, OnChkItalic)
  138. ON_BN_CLICKED(IDC_CHK_UNDERLINE, OnChkUnderline)
  139. //}}AFX_MSG_MAP
  140. END_MESSAGE_MAP()
  141. /////////////////////////////////////////////////////////////////////////////
  142. // CPropPage1 message handlers
  143. void CPropPage1::OnBtFont() 
  144. {
  145. UpdateData(true);
  146. LOGFONT lf;
  147. ZeroMemory(&lf, sizeof(LOGFONT));
  148. CString cs;
  149. lstrcpy(lf.lfFaceName, csFontName);
  150. lf.lfHeight = atoi(csFontSize) + 2;
  151. if (bBold) lf.lfWeight = 700;
  152. lf.lfItalic = bItalic;
  153. lf.lfUnderline = bUnderline;
  154. bLockingProperty = true;
  155. CFontDialog cf(&lf, CF_EFFECTS | CF_SCREENFONTS, NULL, this);
  156. if (cf.DoModal())
  157. {
  158. SetDlgItemText(IDC_STATIC_FONT, cf.GetFaceName());
  159. SetDlgItemInt(IDC_STATIC_SIZE, cf.GetSize() / 10);
  160. // csFontSize.Format("%d", cf.GetSize() / 10 );
  161. CheckDlgButton(IDC_CHK_BOLD, cf.IsBold() ? 1 : 0);
  162. CheckDlgButton(IDC_CHK_ITALIC, cf.IsItalic() ? 1 : 0);
  163. CheckDlgButton(IDC_CHK_UNDERLINE, cf.IsUnderline() ? 1 : 0);
  164. // bBold = cf.IsBold();
  165. // bItalic = cf.IsBold();
  166. UpdateData(true);//false);
  167. }
  168. SetFocus();
  169. bLockingProperty = false;
  170. }
  171. void CPropPage1::OnCancel() { }
  172. void CPropPage1::OnOK() {}
  173. void CPropPage1::OnKillFocus(CWnd* pNewWnd) 
  174. {
  175. CDialog::OnKillFocus(pNewWnd);
  176. if (!pNewWnd || pNewWnd != GetParent())
  177. {
  178. GetParent()->SendMessage(WM_KILLFOCUS, (WPARAM) pNewWnd->GetSafeHwnd());
  179. }
  180. }
  181. void CPropPage1::OnChkBold() 
  182. {
  183. UpdateData();
  184. }
  185. void CPropPage1::OnChkItalic() 
  186. {
  187. UpdateData();
  188. }
  189. void CPropPage1::OnChkUnderline() 
  190. {
  191. UpdateData();
  192. }