PageSetupDlg.cpp
上传用户:cding2008
上传日期:2007-01-03
资源大小:1812k
文件大小:16k
源码类别:

OpenGL

开发平台:

Visual C++

  1. /////////////////////////////////////////////////////////////////////////////
  2. // PageSetupDlg.cpp : implementation of the CPageSetupDlg class
  3. //
  4. // ModelMagic 3D and 'glOOP' (OpenGL Object Oriented Programming library)
  5. // Copyright (c) Craig Fahrnbach 1997, 1999
  6. //
  7. // OpenGL is a registered trademark of Silicon Graphics
  8. //
  9. //
  10. // This program is provided for educational and personal use only and
  11. // is provided without guarantee or warrantee expressed or implied.
  12. //
  13. // Commercial use is strickly prohibited without written permission
  14. // from ImageWare Development.
  15. //
  16. /////////////////////////////////////////////////////////////////////////////
  17. #include "stdafx.h"
  18. #include "ModelMagic3D.h"
  19. #include "PageSetupDlg.h"
  20. #ifdef _DEBUG
  21. #define new DEBUG_NEW
  22. #undef THIS_FILE
  23. static char THIS_FILE[] = __FILE__;
  24. #endif
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CPageSetupDlg local variables
  27. #define NUM_CHOICES 80
  28. #define MARGIN_START 0.5f
  29. static CString szMargin[] = {"0.0"", "0.1"", "0.2"", "0.3"", "0.4"", "0.5"", "0.6"", "0.7"", "0.8"", "0.9"",
  30.  "1.0"", "1.1"", "1.2"", "1.3"", "1.4"", "1.5"", "1.6"", "1.7"", "1.8"", "1.9"",
  31.  "2.0"", "2.1"", "2.2"", "2.3"", "2.4"", "2.5"", "2.6"", "2.7"", "2.8"", "2.9"",
  32.  "3.0"", "3.1"", "3.2"", "3.3"", "3.4"", "3.5"", "3.6"", "3.7"", "3.8"", "3.9"",
  33.  "4.0"", "4.1"", "4.2"", "4.3"", "4.4"", "4.5"", "4.6"", "4.7"", "4.8"", "4.9"",
  34.  "5.0"", "5.1"", "5.2"", "5.3"", "5.4"", "5.5"", "5.6"", "5.7"", "5.8"", "5.9"",
  35.  "6.0"", "6.1"", "6.2"", "6.3"", "6.4"", "6.5"", "6.6"", "6.7"", "6.8"", "6.9"",
  36.  "7.0"", "7.1"", "7.2"", "7.3"", "7.4"", "7.5"", "7.6"", "7.7"", "7.8"", "7.9"",
  37.  };
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CPageSetupDlg dialog
  40. CPageSetupDlg::CPageSetupDlg(CWnd* pParent /*=NULL*/)
  41. : CDialog(CPageSetupDlg::IDD, pParent)
  42. {
  43. //{{AFX_DATA_INIT(CPageSetupDlg)
  44. m_iCenterImage = -1;
  45. m_fTopMargin    = MARGIN_START;
  46. m_fBottomMargin = MARGIN_START;
  47. m_fLeftMargin   = MARGIN_START;
  48. m_fRightMargin  = MARGIN_START;
  49. m_fHeaderMargin = MARGIN_START;
  50. m_fFooterMargin = MARGIN_START;
  51. //}}AFX_DATA_INIT
  52. }
  53. void CPageSetupDlg::DoDataExchange(CDataExchange* pDX)
  54. {
  55. CDialog::DoDataExchange(pDX);
  56. //{{AFX_DATA_MAP(CPageSetupDlg)
  57. DDX_Control(pDX, IDC_TOP, m_EditTop);
  58. DDX_Control(pDX, IDC_RIGHT, m_EditRight);
  59. DDX_Control(pDX, IDC_LEFT, m_EditLeft);
  60. DDX_Control(pDX, IDC_HEADER, m_EditHeader);
  61. DDX_Control(pDX, IDC_FOOTER, m_EditFooter);
  62. DDX_Control(pDX, IDC_BOTTOM, m_EditBottom);
  63. DDX_Control(pDX, IDC_SPIN_TOP, m_SpinTop);
  64. DDX_Control(pDX, IDC_SPIN_RIGHT, m_SpinRight);
  65. DDX_Control(pDX, IDC_SPIN_LEFT, m_SpinLeft);
  66. DDX_Control(pDX, IDC_SPIN_HEADER, m_SpinHeader);
  67. DDX_Control(pDX, IDC_SPIN_FOOTER, m_SpinFooter);
  68. DDX_Control(pDX, IDC_SPIN_BOTTOM, m_SpinBottom);
  69. DDX_Radio(pDX, IDC_RADIO_CENTER_IMAGE, m_iCenterImage);
  70. //}}AFX_DATA_MAP
  71. }
  72. BEGIN_MESSAGE_MAP(CPageSetupDlg, CDialog)
  73. //{{AFX_MSG_MAP(CPageSetupDlg)
  74. ON_BN_CLICKED(ID_PRINT_SETUP, OnPrintSetup)
  75. ON_BN_CLICKED(IDC_RADIO_CENTER_IMAGE, OnRadioCenterImage)
  76. ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_TOP, OnDeltaposSpinTop)
  77. ON_EN_UPDATE(IDC_TOP, OnUpdateTop)
  78. ON_EN_UPDATE(IDC_BOTTOM, OnUpdateBottom)
  79. ON_EN_UPDATE(IDC_LEFT, OnUpdateLeft)
  80. ON_EN_UPDATE(IDC_RIGHT, OnUpdateRight)
  81. ON_EN_UPDATE(IDC_HEADER, OnUpdateHeader)
  82. ON_EN_UPDATE(IDC_FOOTER, OnUpdateFooter)
  83. ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_BOTTOM, OnDeltaposSpinBottom)
  84. ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_LEFT, OnDeltaposSpinLeft)
  85. ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_RIGHT, OnDeltaposSpinRight)
  86. ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_HEADER, OnDeltaposSpinHeader)
  87. ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN_FOOTER, OnDeltaposSpinFooter)
  88. ON_WM_PAINT()
  89. ON_EN_CHANGE(IDC_PAGE_PREVIEW, OnChangePagePreview)
  90. ON_EN_UPDATE(IDC_PAGE_PREVIEW, OnUpdatePagePreview)
  91. //}}AFX_MSG_MAP
  92. END_MESSAGE_MAP()
  93. /////////////////////////////////////////////////////////////////////////////
  94. // CPageSetupDlg procedures
  95. void CPageSetupDlg::SetSpinPosn(CSpinButtonCtrl* pSpinCtrl, float fValue)
  96. {
  97. ASSERT(pSpinCtrl); // Ensure we have a valid pointer
  98. // Get the position of the floating point value within
  99. // the margin table.  If valid, set the spin controls' 
  100. // position
  101. int iPosn;
  102. iPosn = GetMarginPosition(fValue);
  103. if(iPosn != -1)
  104. pSpinCtrl->SetPos(iPosn);
  105. }
  106. int CPageSetupDlg::GetMarginPosition(float fSelect)
  107. {
  108. // Convert the floating point value to a string, rounded
  109. // to the nearest 1/10" inch.
  110. CString szString;
  111. szString.Format("%1.1f"", fSelect);
  112. // See if we have a match within the margin table
  113. for(int i=0; i<NUM_CHOICES; i++)
  114. {
  115. int iRetn = szMargin[i].Compare(szString);
  116. if(iRetn == 0)
  117. return i; // Found a Match!
  118. }
  119. return -1; // Not in the table!
  120. }
  121. void CPageSetupDlg::SetEditText(CEdit* pEdit, float fValue)
  122. {
  123. ASSERT(pEdit); // Ensure we have a valid pointer
  124. // Format the string to two decimal points and set the 
  125. // CEdit control box text.
  126. CString szMargin;
  127. szMargin.Format("%1.2f"", fValue);
  128. pEdit->SetWindowText(szMargin);
  129. }
  130. void CPageSetupDlg::DrawPageOutline()
  131. {
  132. HBRUSH brush;
  133. HDC hDC;
  134. CRect rect, rectWnd, rectPage;
  135. // Calculate the window dimensions.
  136. ::GetWindowRect(m_wndPagePreview, &rect);
  137. rectWnd.top  = 0;
  138. rectWnd.left = 0;
  139. rectWnd.right  = rect.right - rect.left;
  140. rectWnd.bottom = rect.bottom - rect.top;
  141. // Get a device context to our window
  142. hDC = ::GetDC(m_wndPagePreview);
  143. // Calculate the dimensions of the page
  144. rectPage.top  = (rectWnd.bottom-75)/2;
  145. rectPage.left = (rectWnd.right-60)/2;
  146. rectPage.right  = 60;
  147. rectPage.bottom = 75;
  148. // Create a white brush and draw the outline of the page
  149. brush = CreateSolidBrush(0x00ff00ff);
  150. SelectObject(hDC, brush);
  151. FillRect(hDC, &rectPage, brush);
  152. DeleteObject(brush);
  153. }
  154. /////////////////////////////////////////////////////////////////////////////
  155. // CPageSetupDlg message handlers
  156. BOOL CPageSetupDlg::OnInitDialog() 
  157. {
  158. // let the base class do the default work
  159. CDialog::OnInitDialog();
  160. // Set the initial range of the spinner controls
  161. // to match the range within our margin table.
  162. //    where:
  163. // nLower = 0.0"
  164. // nUpper = 7.9"
  165. m_SpinTop.SetRange(0, NUM_CHOICES-1);
  166. m_SpinBottom.SetRange(0, NUM_CHOICES-1);
  167. m_SpinLeft.SetRange(0, NUM_CHOICES-1);
  168. m_SpinRight.SetRange(0, NUM_CHOICES-1);
  169. m_SpinHeader.SetRange(0, NUM_CHOICES-1);
  170. m_SpinFooter.SetRange(0, NUM_CHOICES-1);
  171. // Set the initial position of the spinner controls
  172. SetSpinPosn(&m_SpinTop,    m_fTopMargin);
  173. SetSpinPosn(&m_SpinBottom, m_fBottomMargin);
  174. SetSpinPosn(&m_SpinLeft,   m_fLeftMargin);
  175. SetSpinPosn(&m_SpinRight,  m_fRightMargin);
  176. SetSpinPosn(&m_SpinHeader, m_fHeaderMargin);
  177. SetSpinPosn(&m_SpinFooter, m_fFooterMargin);
  178. // Set the CEdit box text to match the initial values
  179. SetEditText(&m_EditTop,    m_fTopMargin);
  180. SetEditText(&m_EditBottom, m_fBottomMargin);
  181. SetEditText(&m_EditLeft,   m_fLeftMargin);
  182. SetEditText(&m_EditRight,  m_fRightMargin);
  183. SetEditText(&m_EditHeader, m_fHeaderMargin);
  184. SetEditText(&m_EditFooter, m_fFooterMargin);
  185. /*
  186. // Create the Page Preview window
  187. CRect rect;
  188. rect.top = 24;
  189. rect.bottom = 162;
  190. rect.left = 203;
  191. rect.right = 368;
  192. GetDlgItem(IDC_PAGE_PREVIEW)->GetWindowRect(&rect);
  193. ScreenToClient(&rect);
  194. m_wndPagePreview.Create(NULL, // lpszClassName
  195. NULL, // lpszWindowName
  196. WS_CHILD | WS_VISIBLE | // dwStyle
  197. WS_BORDER,
  198. rect, // rect
  199. this, // CWnd* pParentWnd
  200. NULL, // UINT  nID
  201. 0); // pContext
  202. */
  203. m_wndPagePreview = ::GetDlgItem(this->m_hWnd, IDC_PAGE_PREVIEW);
  204. HDC hDC = ::GetDC(m_wndPagePreview);
  205. // m_wndPagePreview.GetDC()->SetBkColor(0x00C0C0C0);//Light Gray
  206. SetBkColor(hDC, 0x00C0C0C0);//Light Gray
  207. ::InvalidateRect(m_wndPagePreview, NULL, TRUE);
  208. // m_wndPagePreview.EnableWindow(TRUE);
  209. // DrawPageOutline();
  210. // Dialog box is being initialized (FALSE) or
  211. // data is being retrieved (TRUE).
  212. UpdateData(FALSE);
  213. return TRUE;  // return TRUE unless you set the focus to a control
  214.               // EXCEPTION: OCX Property Pages should return FALSE
  215. }
  216. void CPageSetupDlg::OnOK() 
  217. {
  218. // TODO: Add extra validation here
  219. CDialog::OnOK();
  220. }
  221. void CPageSetupDlg::OnPrintSetup() 
  222. {
  223. // CMyglApp* pApp = (CMyglApp*) AfxGetApp( );
  224. // ASSERT(pApp);
  225. // pApp->OnFilePrintSetup();
  226. CPrintDialog pDlg(TRUE);
  227. // pDlg.GetDefaults();
  228. pDlg.DoModal();
  229. GlobalFree(pDlg.m_pd.hDevMode);
  230. GlobalFree(pDlg.m_pd.hDevNames);
  231. }
  232. void CPageSetupDlg::OnRadioCenterImage() 
  233. {
  234. // Simple toggle
  235. if(m_iCenterImage == -1)
  236. m_iCenterImage = 0;
  237. else
  238. m_iCenterImage = -1;
  239. // Dialog box is being initialized (FALSE) or
  240. // data is being retrieved (TRUE).
  241. UpdateData(FALSE);
  242. }
  243. void CPageSetupDlg::OnDeltaposSpinTop(NMHDR* pNMHDR, LRESULT* pResult) 
  244. {
  245. NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
  246. // Our static Spin Control position variable
  247. static int i = (int)(MARGIN_START*10);
  248. // Note:  We do not use the member variable
  249. //   pNMUpDown->iPos because its value
  250. //   is not reported properly when the
  251. //   user spins from Up/Down or Down/Up..
  252. // 
  253. // Instead, we add or subtract to our static 
  254. // variable accordingly..
  255. i += pNMUpDown->iDelta;
  256. // Limit check the spinner's position
  257. if(i<0)
  258. i=0;
  259. if(i>NUM_CHOICES)
  260. i = NUM_CHOICES;
  261. // Get the margin value from the local array and
  262. // set the edit box text.
  263. sscanf(szMargin[i], "%f", &m_fTopMargin);
  264. SetEditText(&m_EditTop, m_fTopMargin);
  265. // Dialog box is being initialized (FALSE) or
  266. // data is being retrieved (TRUE).
  267. UpdateData(FALSE);
  268. // Accept the changes (return FALSE)
  269. *pResult = 0;
  270. }
  271. void CPageSetupDlg::OnDeltaposSpinBottom(NMHDR* pNMHDR, LRESULT* pResult) 
  272. {
  273. NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
  274. // Our static Spin Control position variable
  275. static int i = (int)(MARGIN_START*10);
  276. // Note:  We do not use the member variable
  277. //   pNMUpDown->iPos because its value
  278. //   is not reported properly when the
  279. //   user spins from Up/Down or Down/Up..
  280. // 
  281. // Instead, we add or subtract to our static 
  282. // variable accordingly..
  283. i += pNMUpDown->iDelta;
  284. // Limit check the spinner's position
  285. if(i<0)
  286. i=0;
  287. if(i>NUM_CHOICES)
  288. i = NUM_CHOICES;
  289. // Get the margin value from the local array and
  290. // set the edit box text.
  291. sscanf(szMargin[i], "%f", &m_fBottomMargin);
  292. SetEditText(&m_EditBottom, m_fBottomMargin);
  293. // Dialog box is being initialized (FALSE) or
  294. // data is being retrieved (TRUE).
  295. UpdateData(FALSE);
  296. // Accept the changes (return FALSE)
  297. *pResult = 0;
  298. }
  299. void CPageSetupDlg::OnDeltaposSpinLeft(NMHDR* pNMHDR, LRESULT* pResult) 
  300. {
  301. NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
  302. // Our static Spin Control position variable
  303. static int i = (int)(MARGIN_START*10);
  304. // Note:  We do not use the member variable
  305. //   pNMUpDown->iPos because its value
  306. //   is not reported properly when the
  307. //   user spins from Up/Down or Down/Up..
  308. // 
  309. // Instead, we add or subtract to our static 
  310. // variable accordingly..
  311. i += pNMUpDown->iDelta;
  312. // Limit check the spinner's position
  313. if(i<0)
  314. i=0;
  315. if(i>NUM_CHOICES)
  316. i = NUM_CHOICES;
  317. // Get the margin value from the local array and
  318. // set the edit box text.
  319. sscanf(szMargin[i], "%f", &m_fLeftMargin);
  320. SetEditText(&m_EditLeft, m_fLeftMargin);
  321. // Dialog box is being initialized (FALSE) or
  322. // data is being retrieved (TRUE).
  323. UpdateData(FALSE);
  324. // Accept the changes (return FALSE)
  325. *pResult = 0;
  326. }
  327. void CPageSetupDlg::OnDeltaposSpinRight(NMHDR* pNMHDR, LRESULT* pResult) 
  328. {
  329. NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
  330. // Our static Spin Control position variable
  331. static int i = (int)(MARGIN_START*10);
  332. // Note:  We do not use the member variable
  333. //   pNMUpDown->iPos because its value
  334. //   is not reported properly when the
  335. //   user spins from Up/Down or Down/Up..
  336. // 
  337. // Instead, we add or subtract to our static 
  338. // variable accordingly..
  339. i += pNMUpDown->iDelta;
  340. // Limit check the spinner's position
  341. if(i<0)
  342. i=0;
  343. if(i>NUM_CHOICES)
  344. i = NUM_CHOICES;
  345. // Get the margin value from the local array and
  346. // set the edit box text.
  347. sscanf(szMargin[i], "%f", &m_fRightMargin);
  348. SetEditText(&m_EditRight, m_fRightMargin);
  349. // Dialog box is being initialized (FALSE) or
  350. // data is being retrieved (TRUE).
  351. UpdateData(FALSE);
  352. // Accept the changes (return FALSE)
  353. *pResult = 0;
  354. }
  355. void CPageSetupDlg::OnDeltaposSpinHeader(NMHDR* pNMHDR, LRESULT* pResult) 
  356. {
  357. NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
  358. // Our static Spin Control position variable
  359. static int i = (int)(MARGIN_START*10);
  360. // Note:  We do not use the member variable
  361. //   pNMUpDown->iPos because its value
  362. //   is not reported properly when the
  363. //   user spins from Up/Down or Down/Up..
  364. // 
  365. // Instead, we add or subtract to our static 
  366. // variable accordingly..
  367. i += pNMUpDown->iDelta;
  368. // Limit check the spinner's position
  369. if(i<0)
  370. i=0;
  371. if(i>NUM_CHOICES)
  372. i = NUM_CHOICES;
  373. // Get the margin value from the local array and
  374. // set the edit box text.
  375. sscanf(szMargin[i], "%f", &m_fHeaderMargin);
  376. SetEditText(&m_EditHeader, m_fHeaderMargin);
  377. // Dialog box is being initialized (FALSE) or
  378. // data is being retrieved (TRUE).
  379. UpdateData(FALSE);
  380. // Accept the changes (return FALSE)
  381. *pResult = 0;
  382. }
  383. void CPageSetupDlg::OnDeltaposSpinFooter(NMHDR* pNMHDR, LRESULT* pResult) 
  384. {
  385. NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
  386. // Our static Spin Control position variable
  387. static int i = (int)(MARGIN_START*10);
  388. // Note:  We do not use the member variable
  389. //   pNMUpDown->iPos because its value
  390. //   is not reported properly when the
  391. //   user spins from Up/Down or Down/Up..
  392. // 
  393. // Instead, we add or subtract to our static 
  394. // variable accordingly..
  395. i += pNMUpDown->iDelta;
  396. // Limit check the spinner's position
  397. if(i<0)
  398. i=0;
  399. if(i>NUM_CHOICES)
  400. i = NUM_CHOICES;
  401. // Get the margin value from the local array and
  402. // set the edit box text.
  403. sscanf(szMargin[i], "%f", &m_fFooterMargin);
  404. SetEditText(&m_EditFooter, m_fFooterMargin);
  405. // Dialog box is being initialized (FALSE) or
  406. // data is being retrieved (TRUE).
  407. UpdateData(FALSE);
  408. // Accept the changes (return FALSE)
  409. *pResult = 0;
  410. }
  411. void CPageSetupDlg::OnUpdateTop() 
  412. {
  413. // Get the user entered values
  414. char buf[10];
  415. int nChars =  m_EditTop.GetLine(0, &buf[0], 10);
  416. sscanf(&buf[0], "%f", &m_fTopMargin);
  417. // Set the spinner position
  418. SetSpinPosn(&m_SpinTop, m_fTopMargin);
  419. }
  420. void CPageSetupDlg::OnUpdateBottom() 
  421. {
  422. // Get the user entered values
  423. char buf[10];
  424. int nChars =  m_EditBottom.GetLine(0, &buf[0], 10);
  425. sscanf(&buf[0], "%f", &m_fBottomMargin);
  426. // Set the spinner position
  427. SetSpinPosn(&m_SpinBottom, m_fBottomMargin);
  428. }
  429. void CPageSetupDlg::OnUpdateLeft() 
  430. {
  431. // Get the user entered values
  432. char buf[10];
  433. int nChars =  m_EditLeft.GetLine(0, &buf[0], 10);
  434. sscanf(&buf[0], "%f", &m_fLeftMargin);
  435. // Set the spinner position
  436. SetSpinPosn(&m_SpinLeft, m_fLeftMargin);
  437. }
  438. void CPageSetupDlg::OnUpdateRight() 
  439. {
  440. // Get the user entered values
  441. char buf[10];
  442. int nChars =  m_EditRight.GetLine(0, &buf[0], 10);
  443. sscanf(&buf[0], "%f", &m_fRightMargin);
  444. // Set the spinner position
  445. SetSpinPosn(&m_SpinRight, m_fRightMargin);
  446. }
  447. void CPageSetupDlg::OnUpdateHeader() 
  448. {
  449. // Get the user entered values
  450. char buf[10];
  451. int nChars =  m_EditHeader.GetLine(0, &buf[0], 10);
  452. sscanf(&buf[0], "%f", &m_fHeaderMargin);
  453. // Set the spinner position
  454. SetSpinPosn(&m_SpinHeader, m_fHeaderMargin);
  455. }
  456. void CPageSetupDlg::OnUpdateFooter() 
  457. {
  458. // Get the user entered values
  459. char buf[10];
  460. int nChars =  m_EditFooter.GetLine(0, &buf[0], 10);
  461. sscanf(&buf[0], "%f", &m_fFooterMargin);
  462. // Set the spinner position
  463. SetSpinPosn(&m_SpinFooter, m_fFooterMargin);
  464. }
  465. void CPageSetupDlg::OnPaint() 
  466. {
  467. CPaintDC dc(this); // device context for painting
  468. DrawPageOutline();
  469. // TODO: Add your message handler code here
  470. // Do not call CDialog::OnPaint() for painting messages
  471. }
  472. void CPageSetupDlg::OnChangePagePreview() 
  473. {
  474. // TODO: Add your control notification handler code here
  475. DrawPageOutline();
  476. }
  477. void CPageSetupDlg::OnUpdatePagePreview() 
  478. {
  479. // TODO: Add your control notification handler code here
  480. DrawPageOutline();
  481. }