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

对话框与窗口

开发平台:

Visual C++

  1. // View.cpp : implementation of the View class
  2. //
  3. #include "stdafx.h"
  4. #include "PrintFormEditor.h"
  5. #include "Doc.h"
  6. #include "View.h"
  7. #include "MainFrm.h"
  8. #include "PagerSizeDlg.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. /////////////////////////////////////////////////////////////////////////////
  15. // View
  16. IMPLEMENT_DYNCREATE(View, CView)
  17. BEGIN_MESSAGE_MAP(View, CView)
  18. //{{AFX_MSG_MAP(View)
  19. ON_WM_SIZE()
  20. ON_WM_HSCROLL()
  21. ON_WM_VSCROLL()
  22. ON_WM_ERASEBKGND()
  23. ON_COMMAND(IDC_TOOL_ARROW, OnToolArrow)
  24. ON_UPDATE_COMMAND_UI(IDC_TOOL_ARROW, OnUpdateToolArrow)
  25. ON_COMMAND(IDC_TOOL_BORDER, OnToolBorder)
  26. ON_UPDATE_COMMAND_UI(IDC_TOOL_BORDER, OnUpdateToolBorder)
  27. ON_COMMAND(IDC_TOOL_CHECK, OnToolCheck)
  28. ON_UPDATE_COMMAND_UI(IDC_TOOL_CHECK, OnUpdateToolCheck)
  29. ON_COMMAND(IDC_TOOL_EDIT, OnToolEdit)
  30. ON_UPDATE_COMMAND_UI(IDC_TOOL_EDIT, OnUpdateToolEdit)
  31. ON_COMMAND(IDC_TOOL_IMAGE, OnToolImage)
  32. ON_UPDATE_COMMAND_UI(IDC_TOOL_IMAGE, OnUpdateToolImage)
  33. ON_COMMAND(IDC_TOOL_LINE, OnToolLine)
  34. ON_UPDATE_COMMAND_UI(IDC_TOOL_LINE, OnUpdateToolLine)
  35. ON_COMMAND(IDC_TOOL_RADIO, OnToolRadio)
  36. ON_UPDATE_COMMAND_UI(IDC_TOOL_RADIO, OnUpdateToolRadio)
  37. ON_COMMAND(IDC_TOOL_RECT, OnToolRect)
  38. ON_UPDATE_COMMAND_UI(IDC_TOOL_RECT, OnUpdateToolRect)
  39. ON_COMMAND(IDC_TOOL_SOTTOREPORT, OnToolSottoreport)
  40. ON_UPDATE_COMMAND_UI(IDC_TOOL_SOTTOREPORT, OnUpdateToolSottoreport)
  41. ON_COMMAND(IDC_TOOL_STATIC, OnToolStatic)
  42. ON_UPDATE_COMMAND_UI(IDC_TOOL_STATIC, OnUpdateToolStatic)
  43. ON_WM_LBUTTONUP()
  44. ON_WM_LBUTTONDOWN()
  45. ON_WM_MOUSEMOVE()
  46. ON_WM_SETCURSOR()
  47. ON_COMMAND(ID_EDIT_CUT, OnEditCut)
  48. ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, OnUpdateEditCut)
  49. ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
  50. ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateEditCopy)
  51. ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
  52. ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdateEditPaste)
  53. ON_COMMAND(IDC_TOOL_VLINE, OnToolVline)
  54. ON_UPDATE_COMMAND_UI(IDC_TOOL_VLINE, OnUpdateToolVline)
  55. ON_COMMAND(IDC_TOOL_HLINE, OnToolHline)
  56. ON_UPDATE_COMMAND_UI(IDC_TOOL_HLINE, OnUpdateToolHline)
  57. ON_COMMAND(IDC_PAPER_SIZE, OnPaperSize)
  58. ON_COMMAND(IDC_PROPERTY, OnProperty)
  59. ON_UPDATE_COMMAND_UI(IDC_PROPERTY, OnUpdateProperty)
  60. ON_COMMAND(ID_GFX_PROPERTY, OnGfxProperty)
  61. ON_UPDATE_COMMAND_UI(ID_GFX_PROPERTY, OnUpdateGfxProperty)
  62. ON_WM_DESTROY()
  63. ON_COMMAND(ID_ALIGN_BOTTOM, OnAlignBottom)
  64. ON_UPDATE_COMMAND_UI(ID_ALIGN_BOTTOM, OnUpdateAlignBottom)
  65. ON_COMMAND(ID_ALIGN_LEFT, OnAlignLeft)
  66. ON_UPDATE_COMMAND_UI(ID_ALIGN_LEFT, OnUpdateAlignLeft)
  67. ON_COMMAND(ID_ALIGN_RIGHT, OnAlignRight)
  68. ON_UPDATE_COMMAND_UI(ID_ALIGN_RIGHT, OnUpdateAlignRight)
  69. ON_COMMAND(ID_ALIGN_TOP, OnAlignTop)
  70. ON_UPDATE_COMMAND_UI(ID_ALIGN_TOP, OnUpdateAlignTop)
  71. ON_COMMAND(ID_SIZE_ALL, OnSizeAll)
  72. ON_UPDATE_COMMAND_UI(ID_SIZE_ALL, OnUpdateSizeAll)
  73. ON_COMMAND(ID_SIZE_HORZ, OnSizeHorz)
  74. ON_UPDATE_COMMAND_UI(ID_SIZE_HORZ, OnUpdateSizeHorz)
  75. ON_COMMAND(ID_SIZE_VERT, OnSizeVert)
  76. ON_UPDATE_COMMAND_UI(ID_SIZE_VERT, OnUpdateSizeVert)
  77. ON_WM_RBUTTONDOWN()
  78. //}}AFX_MSG_MAP
  79. // Standard printing commands
  80. ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  81. ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  82. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  83. END_MESSAGE_MAP()
  84. /////////////////////////////////////////////////////////////////////////////
  85. // View construction/destruction
  86. View::View()
  87. {
  88. iScy = GetSystemMetrics(SM_CYVTHUMB);
  89. iScx = GetSystemMetrics(SM_CXHTHUMB);
  90. iRx = 18;
  91. iRy = 18;
  92. pGridPen1 = new CPen(PS_SOLID, 1, RGB(192,192,192));
  93. pGridPen2 = new CPen(PS_DASHDOT, 1, RGB(192,192,192));
  94. cr3dFace = GetSysColor(COLOR_3DFACE);
  95. iType = -1;
  96. pTracker = NULL;
  97. iGridStep = 50;
  98. iDiv = 2;
  99. }
  100. View::~View()
  101. {
  102. if (pGridPen1) delete pGridPen1;
  103. if (pGridPen2) delete pGridPen2;
  104. if (pTracker)  delete pTracker;
  105. }
  106. BOOL View::PreCreateWindow(CREATESTRUCT& cs)
  107. {
  108. // TODO: Modify the Window class or styles here by modifying
  109. //  the CREATESTRUCT cs
  110. return CView::PreCreateWindow(cs);
  111. }
  112. /////////////////////////////////////////////////////////////////////////////
  113. // View drawing
  114. void View::OnDraw(CDC* pDC)
  115. {
  116. Doc* pDoc = GetDocument();
  117. ASSERT_VALID(pDoc);
  118. int x = wndHBar.GetSafeHwnd() ? wndHBar.GetScrollPos() : 0;
  119. int y = wndVBar.GetSafeHwnd() ? wndVBar.GetScrollPos() : 0;
  120. CRect rc;
  121. GetClientRect(rc);
  122. CDC MemDC, *origDc = pDC;
  123. MemDC.CreateCompatibleDC(pDC);
  124. CBitmap bmp;
  125. bmp.CreateCompatibleBitmap(pDC, rc.Width(), rc.Height());
  126. CBitmap * obm = MemDC.SelectObject(&bmp);
  127. pDC = &MemDC;
  128. int idcs = pDC->SaveDC();
  129. CRgn rgn;
  130. CRect rc1(rc);
  131. rc1.left += iRx + 2;
  132. rc1.top  += iRy + 2;
  133. rc1.bottom -= iScy;
  134. rc1.right  -= iScx;
  135. CRect bdrRc1(rc);
  136. bdrRc1.left += iRx;
  137. bdrRc1.top  += iRy;
  138. bdrRc1.right = bdrRc1.left + 2;
  139. bdrRc1.bottom -= iScy;
  140. pDC->FillSolidRect(bdrRc1, cr3dFace);
  141. bdrRc1 = rc;
  142. bdrRc1.left += iRx;
  143. bdrRc1.top  += iRy;
  144. bdrRc1.right-= iScx;
  145. bdrRc1.bottom = bdrRc1.top + 2;
  146. pDC->FillSolidRect(bdrRc1, cr3dFace);
  147. rgn.CreateRectRgnIndirect(&rc1);
  148. pDC->SelectClipRgn(&rgn);
  149. rgn.DeleteObject();
  150. int maxx = rc.Width();
  151. int maxy = rc.Height();
  152. if (pDoc->rcPaper.Width() / iDiv  + iRx < maxx) maxx = pDoc->rcPaper.Width() / iDiv + iRx ;
  153. if (pDoc->rcPaper.Height() / iDiv + iRy < maxy) maxy = pDoc->rcPaper.Height() / iDiv + iRy;
  154. CRect rcx(rc1.left, rc1.top, maxx, maxy);
  155. pDC->FillSolidRect(rc1, cr3dFace);
  156. pDC->FillSolidRect(rcx, GetSysColor(COLOR_WINDOW));
  157. int t;
  158. CPen * op = pDC->SelectObject(pGridPen1);
  159. for (t = iRx; t <= pDoc->rcPaper.Width() / iDiv; t += 100 / iDiv)
  160. {
  161. if (t - x > 0 && t - x < rc.right)
  162. {
  163. pDC->MoveTo(t - x, rc.top);
  164. pDC->LineTo(t - x, maxy);
  165. }
  166. if (t - x > rc.right) break;
  167. }
  168. for (t = iRy; t <= pDoc->rcPaper.Height() / iDiv; t += 100 / iDiv)
  169. {
  170. if (t - y > 0 && t - y < rc.bottom)
  171. {
  172. pDC->MoveTo(rc.left, t - y);
  173. pDC->LineTo(maxx, t - y);
  174. }
  175. if (t - y > rc.bottom) break;
  176. }
  177. pDC->SelectObject(pGridPen2);
  178. for (t = iRx + 50 / iDiv; t <= pDoc->rcPaper.Width() / iDiv; t += 100 / iDiv)
  179. {
  180. if (t - x > 0 && t - x < rc.right)
  181. {
  182. pDC->MoveTo(t - x, rc.top);
  183. pDC->LineTo(t - x, maxy);
  184. }
  185. if (t - x > rc.right) break;
  186. }
  187. for (t = iRy + 50 / iDiv; t <= pDoc->rcPaper.Height() / iDiv; t += 100 / iDiv)
  188. {
  189. if (t - y > 0 && t - y < rc.bottom)
  190. {
  191. pDC->MoveTo(rc.left, t - y);
  192. pDC->LineTo(maxx, t - y);
  193. }
  194. if (t - y > rc.bottom) break;
  195. }
  196. for (t = 0; t < pDoc->iFormObj; t++)
  197. {
  198. pDoc->ppObjs[t]->Draw(pDC, x - iRx - 2, y - iRy - 2, iDiv);
  199. }
  200. pDC->SelectObject(op);
  201. pDC->RestoreDC(idcs);
  202. origDc->BitBlt(rc1.left-2,rc1.top-2,rc1.Width()+2,rc1.Height()+2,&MemDC,rc1.left-2,rc1.top-2,SRCCOPY);
  203. pDC = origDc;
  204. MemDC.SelectObject(obm);
  205. pDC->FillSolidRect(CRect(0,0,iRx,iRy), cr3dFace);
  206. pDC->Draw3dRect(CRect(2,2,iRx-2,iRy-2), GetSysColor(COLOR_3DSHADOW), GetSysColor(COLOR_3DHIGHLIGHT));
  207. pDC->Draw3dRect(CRect(3,3,iRx-3,iRy-3), GetSysColor(COLOR_3DHIGHLIGHT), GetSysColor(COLOR_3DSHADOW));
  208. pDC->FillSolidRect(CRect(7,7,iRx-7,iRy-7), RGB(0,0,0));
  209. pDC->FillSolidRect(CRect(rc.right - iScx,rc.bottom - iScy,rc.right,rc.bottom), cr3dFace);
  210. pDC->DrawFrameControl(CRect(rc.right - iScx,rc.bottom - iScy,rc.right,rc.bottom), DFC_SCROLL, DFCS_SCROLLSIZEGRIP);
  211. }
  212. /////////////////////////////////////////////////////////////////////////////
  213. // View printing
  214. BOOL View::OnPreparePrinting(CPrintInfo* pInfo)
  215. {
  216. // default preparation
  217. return DoPreparePrinting(pInfo);
  218. }
  219. void View::OnBeginPrinting(CDC* pDC, CPrintInfo* /*pInfo*/)
  220. {
  221. pDC->SetMapMode(MM_LOMETRIC);
  222. }
  223. void View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  224. {
  225. // TODO: add cleanup after printing
  226. }
  227. void View::OnPrint(CDC* pDC, CPrintInfo* pInfo) 
  228. {
  229. Doc* pDoc = GetDocument();
  230. pDC->SetMapMode(MM_LOMETRIC);
  231. for (int t = 0; t < pDoc->iFormObj; t++)
  232. {
  233. pDoc->ppObjs[t]->Print(pDC, pDoc->rcPaper.TopLeft());
  234. }
  235. // CView::OnPrint(pDC, pInfo);
  236. }
  237. /////////////////////////////////////////////////////////////////////////////
  238. // View diagnostics
  239. #ifdef _DEBUG
  240. void View::AssertValid() const
  241. {
  242. CView::AssertValid();
  243. }
  244. void View::Dump(CDumpContext& dc) const
  245. {
  246. CView::Dump(dc);
  247. }
  248. Doc* View::GetDocument() // non-debug version is inline
  249. {
  250. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(Doc)));
  251. return (Doc*)m_pDocument;
  252. }
  253. #endif //_DEBUG
  254. /////////////////////////////////////////////////////////////////////////////
  255. // View message handlers
  256. void View::OnInitialUpdate() 
  257. {
  258. CView::OnInitialUpdate();
  259. ModifyStyle(0, WS_CLIPCHILDREN);
  260. ModifyStyleEx(WS_EX_CLIENTEDGE, 0/*WS_EX_STATICEDGE*/, SWP_FRAMECHANGED);
  261. CRect rc;
  262. GetClientRect(rc);
  263. CRect brc(rc.left, rc.bottom - iScy, rc.right - iScx, rc.bottom);
  264. wndHBar.Create(WS_CHILD|WS_VISIBLE|SBS_HORZ|SBS_BOTTOMALIGN/*|SBS_SIZEBOXBOTTOMRIGHTALIGN|SBS_SIZEBOX*/, brc, this, IDC_HBAR);
  265. brc.SetRect(rc.right - iScx, rc.top, rc.right, rc.bottom - iScy);
  266. wndVBar.Create(WS_CHILD|WS_VISIBLE|SBS_VERT|SBS_RIGHTALIGN, brc, this, IDC_VBAR);
  267. brc.SetRect(rc.left + iRx, rc.top, rc.right - iScx, rc.top + iRy);
  268. wndHRuler.Create("", WS_CHILD|WS_VISIBLE|BS_OWNERDRAW, brc, this, IDC_HRULER);
  269. wndHRuler.ModifyStyleEx(0, WS_EX_CLIENTEDGE, SWP_FRAMECHANGED);
  270. brc.SetRect(0, iRy, iRx, rc.bottom - iScy);
  271. wndVRuler.Create("", WS_CHILD|WS_VISIBLE|BS_OWNERDRAW, brc, this, IDC_VRULER);
  272. wndVRuler.ModifyStyleEx(0, WS_EX_CLIENTEDGE, SWP_FRAMECHANGED);
  273. Doc * pDoc = GetDocument();
  274. SetPaperRect(pDoc->rcPaper);
  275. }
  276. void View::DoSize(int cx, int cy)
  277. {
  278. Doc * pDoc = GetDocument();
  279. if (::IsWindow(wndHBar.GetSafeHwnd()))
  280. {
  281. CRect brc(0, cy - iScy, cx - iScx, cy);
  282. wndHBar.SetWindowPos(0, brc.left, brc.top, brc.Width(), brc.Height(), SWP_NOZORDER);
  283. SCROLLINFO si;
  284. si.cbSize = sizeof(SCROLLINFO);
  285. si.fMask  = SIF_PAGE|SIF_RANGE;
  286. si.nPage = cx - iRx - iScx;
  287. si.nMin = 0;//pDoc->rcPaper.left / iDiv;
  288. si.nMax = pDoc->rcPaper.Width() / iDiv; //pDoc->rcPaper.right / iDiv;
  289. wndHBar.SetScrollInfo(&si);
  290. }
  291. if (::IsWindow(wndVBar.GetSafeHwnd()))
  292. {
  293. CRect brc(cx - iScx, 0, cx, cy - iScy);
  294. wndVBar.SetWindowPos(0, brc.left, brc.top, brc.Width(), brc.Height(), SWP_NOZORDER);
  295. SCROLLINFO si;
  296. si.cbSize = sizeof(SCROLLINFO);
  297. si.fMask  = SIF_PAGE|SIF_RANGE;
  298. si.nPage = cy - iRy - iScy;
  299. si.nMin = 0;//pDoc->rcPaper.top / iDiv;
  300. si.nMax = pDoc->rcPaper.Height() / iDiv;//pDoc->rcPaper.bottom / iDiv;
  301. wndVBar.SetScrollInfo(&si);
  302. }
  303. if (::IsWindow(wndHRuler.GetSafeHwnd()))
  304. {
  305. CRect brc(iRx, 0, cx - iScx, iRy);
  306. wndHRuler.SetWindowPos(0, brc.left, brc.top, brc.Width(), brc.Height(), SWP_NOZORDER);
  307. int x = wndHBar.GetScrollPos();
  308. wndHRuler.SetPos(x);
  309. }
  310. if (::IsWindow(wndVRuler.GetSafeHwnd()))
  311. {
  312. CRect brc(0, iRy, iRx, cy - iScy);
  313. wndVRuler.SetWindowPos(0, brc.left, brc.top, brc.Width(), brc.Height(), SWP_NOZORDER);
  314. int y = wndVBar.GetScrollPos();
  315. wndVRuler.SetPos(y);
  316. }
  317. }
  318. void View::OnSize(UINT nType, int cx, int cy) 
  319. {
  320. CView::OnSize(nType, cx, cy);
  321. DoSize(cx,cy);
  322. }
  323. void View::SetPaperRect(const CRect & rc)
  324. {
  325. Doc * pDoc = GetDocument();
  326. pDoc->rcPaper = rc;
  327. if (::IsWindow(wndHBar.GetSafeHwnd())) wndHBar.SetScrollRange(0, rc.Width() / iDiv);
  328. if (::IsWindow(wndHRuler.GetSafeHwnd())) wndHRuler.SetRange(0, rc.Width());
  329. SCROLLINFO si;
  330. si.cbSize = sizeof(SCROLLINFO);
  331. si.fMask  = SIF_PAGE;
  332. si.nPage = rc.Width();
  333. if (::IsWindow(wndHBar.GetSafeHwnd())) wndHBar.SetScrollInfo(&si);
  334. si.nPage = rc.Height();
  335. if (::IsWindow(wndVBar.GetSafeHwnd())) 
  336. {
  337. wndVBar.SetScrollRange(0, rc.Height() / iDiv);
  338. wndVBar.SetScrollInfo(&si);
  339. }
  340. if (::IsWindow(wndVRuler.GetSafeHwnd())) wndVRuler.SetRange(0, rc.Height());
  341. CRect crc;
  342. GetClientRect(crc);
  343. DoSize(crc.Width(), crc.Height());
  344. }
  345. void View::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
  346. {
  347. int x = wndHBar.GetScrollPos();
  348. int xOrig = x;
  349. switch (nSBCode)//LOBYTE(nScrollCode))
  350. {
  351. case SB_TOP: x = 0; break;
  352. case SB_BOTTOM: x = wndHBar.GetScrollLimit(); break;
  353. case SB_LINEUP: x -= 1; break;
  354. case SB_LINEDOWN: x += 1; break;
  355. case SB_PAGEUP:
  356. {
  357. CRect rcClient;
  358. GetClientRect(&rcClient);
  359. x -= rcClient.Width();
  360. if (x<0) x = 0;
  361. break;
  362. }
  363. case SB_PAGEDOWN:
  364. {
  365. CRect rcClient;
  366. GetClientRect(&rcClient);
  367. x += rcClient.Width();
  368. if (x>wndHBar.GetScrollLimit()) x = wndHBar.GetScrollLimit();
  369. break;
  370. }
  371. case SB_THUMBTRACK: x = nPos; break;
  372. }
  373. wndHBar.SetScrollPos(x);
  374. wndHRuler.SetPos(x);
  375. Invalidate();
  376. }
  377. void View::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
  378. {
  379. int x = wndVBar.GetScrollPos();
  380. int xOrig = x;
  381. switch (nSBCode)//LOBYTE(nScrollCode))
  382. {
  383. case SB_TOP: x = 0; break;
  384. case SB_BOTTOM: x = wndVBar.GetScrollLimit(); break;
  385. case SB_LINEUP: x -= 1; break;
  386. case SB_LINEDOWN: x += 1; break;
  387. case SB_PAGEUP:
  388. {
  389. CRect rcClient;
  390. GetClientRect(&rcClient);
  391. x -= rcClient.Height();
  392. if (x<0) x = 0;
  393. break;
  394. }
  395. case SB_PAGEDOWN:
  396. {
  397. CRect rcClient;
  398. GetClientRect(&rcClient);
  399. x += rcClient.Height();
  400. if (x>wndVBar.GetScrollLimit()) x = wndVBar.GetScrollLimit();
  401. break;
  402. }
  403. case SB_THUMBTRACK: x = nPos; break;
  404. }
  405. wndVBar.SetScrollPos(x);
  406. wndVRuler.SetPos(x);
  407. Invalidate();
  408. }
  409. BOOL View::OnEraseBkgnd(CDC* pDC) 
  410. {
  411. return true;
  412. }
  413. void View::OnToolArrow() 
  414. {
  415. iType = -1;
  416. }
  417. void View::OnUpdateToolArrow(CCmdUI* pCmdUI) 
  418. {
  419. pCmdUI->SetCheck(iType == -1);
  420. }
  421. void View::OnToolBorder() 
  422. {
  423. iType = pfoFrame;
  424. }
  425. void View::OnUpdateToolBorder(CCmdUI* pCmdUI) 
  426. {
  427. pCmdUI->SetCheck(iType == pfoFrame);
  428. }
  429. void View::OnToolCheck() 
  430. {
  431. iType = pfoCheck;
  432. }
  433. void View::OnUpdateToolCheck(CCmdUI* pCmdUI) 
  434. {
  435. pCmdUI->Enable(false);
  436. }
  437. void View::OnToolEdit() 
  438. {
  439. iType = pfoEdit;
  440. }
  441. void View::OnUpdateToolEdit(CCmdUI* pCmdUI) 
  442. {
  443. pCmdUI->SetCheck(iType == pfoEdit);
  444. }
  445. void View::OnToolImage() 
  446. {
  447. iType = pfoImage;
  448. }
  449. void View::OnUpdateToolImage(CCmdUI* pCmdUI) 
  450. {
  451. pCmdUI->SetCheck(iType == pfoImage);
  452. }
  453. void View::OnToolLine() 
  454. {
  455. iType = pfoLine;
  456. }
  457. void View::OnUpdateToolLine(CCmdUI* pCmdUI) 
  458. {
  459. pCmdUI->SetCheck(iType == pfoLine);
  460. }
  461. void View::OnToolRadio() 
  462. {
  463. iType = pfoRadio;
  464. }
  465. void View::OnUpdateToolRadio(CCmdUI* pCmdUI) 
  466. {
  467. pCmdUI->Enable(false);
  468. }
  469. void View::OnToolRect() 
  470. {
  471. iType = pfoRect;
  472. }
  473. void View::OnUpdateToolRect(CCmdUI* pCmdUI) 
  474. {
  475. pCmdUI->SetCheck(iType == pfoRect);
  476. }
  477. void View::OnToolSottoreport() 
  478. {
  479. iType = pfoSubForm;
  480. }
  481. void View::OnToolVline() 
  482. {
  483. iType = pfoVLine;
  484. }
  485. void View::OnUpdateToolVline(CCmdUI* pCmdUI) 
  486. {
  487. pCmdUI->SetCheck(iType == pfoVLine);
  488. }
  489. void View::OnToolHline() 
  490. {
  491. iType = pfoHLine;
  492. }
  493. void View::OnUpdateToolHline(CCmdUI* pCmdUI) 
  494. {
  495. pCmdUI->SetCheck(iType == pfoHLine);
  496. }
  497. void View::OnUpdateToolSottoreport(CCmdUI* pCmdUI) 
  498. {
  499. pCmdUI->SetCheck(iType == pfoSubForm);
  500. }
  501. void View::OnToolStatic() 
  502. {
  503. Doc * pDoc = GetDocument();
  504. iType = pfoStatic;
  505. }
  506. void View::OnUpdateToolStatic(CCmdUI* pCmdUI) 
  507. {
  508. pCmdUI->SetCheck(iType == pfoStatic);
  509. }
  510. void View::OnLButtonUp(UINT nFlags, CPoint point) 
  511. {
  512. if (GetCapture() == this) ReleaseCapture();
  513. if (CRect(0,0,iRx,iRy).PtInRect(point))
  514. {
  515. CView::OnLButtonUp(nFlags, point);
  516. return;
  517. }
  518. if (pTracker) delete pTracker;
  519. pTracker = NULL;
  520. Doc * pDoc = GetDocument();
  521. CPoint pt(point);
  522. // FixPoint(pt);
  523. RealPoint(ptTrack);
  524. RealPoint(pt);
  525. if (iType >= 0)
  526. {
  527. FixPoint(ptTrack);
  528. FixPoint(pt);
  529. }
  530. CRect rc(ptTrack.x, ptTrack.y, pt.x, pt.y);
  531. rc.NormalizeRect();
  532. if (rc.Width() > 1 && rc.Height() > 1)
  533. {
  534. if (pDoc->GetSelectedCount() > 0) pDoc->ClearSelection();
  535. }
  536. {
  537. if (iType >= 0 && rc.Width() > 4 && rc.Height() > 4)//!(rc.IsRectEmpty()))
  538. {
  539. CPrintFormObject * ob = pDoc->AddObject(iType);
  540. ob->iType = iType;
  541. ob->rc = rc;
  542. }
  543. else
  544. {
  545. if (!(nFlags&MK_SHIFT))
  546. {
  547. pDoc->ClearSelection();
  548. }
  549. if (GfxIsProp2())
  550. {
  551. CGfxProperty * pg = GfxGetProp2();
  552. pg->DoIt();
  553. }
  554. if (pDoc->SelectObject(rc))
  555. {
  556. if (GfxIsProp2())
  557. {
  558. CGfxProperty * pg = GfxGetProp2();
  559. if (!(pg->pDocument == pDoc && pg->pWnd == this))
  560. {
  561. pg->ClearTabArray();
  562. dlgSheet1.pDoc = pDoc;
  563. dlgSheet1.pView = this;
  564. dlgSheet2.pDoc = pDoc;
  565. dlgSheet2.pView = this;
  566. dlgSheet3.pDoc = pDoc;
  567. dlgSheet3.pView = this;
  568. dlgSheet1.Create(CPropPage1::IDD, pg);
  569. dlgSheet2.Create(CPropPage2::IDD, pg);
  570. dlgSheet3.Create(CPropPage3::IDD, pg);
  571. pg->pDocument = pDoc;
  572. pg->pWnd = this;
  573. pg->AddPage(&dlgSheet1, "Generale");
  574. pg->AddPage(&dlgSheet2, "Ids");
  575. pg->AddPage(&dlgSheet3, "Other");
  576. pg->SetCurSel(0);
  577. }
  578. else
  579. {
  580. // pg->DoIt();
  581. dlgSheet1.UpdateData(false);
  582. dlgSheet2.UpdateData(false);
  583. dlgSheet3.UpdateData(false);
  584. }
  585. }
  586. }
  587. }
  588. }
  589. /* else
  590. {
  591. if (pDoc->GetSelectedCount() > 0) pDoc->ClearSelection();
  592. }
  593. */
  594. if (pDoc->GetSelectedCount() <= 0)
  595. {
  596. if (GfxIsProp2())
  597. {
  598. CGfxProperty * pg = GfxGetProp2();
  599. if (pg->pDocument == pDoc && pg->pWnd == this)
  600. pg->ClearTabArray();
  601. }
  602. }
  603. Invalidate();
  604. CView::OnLButtonUp(nFlags, point);
  605. }
  606. void View::OnLButtonDown(UINT nFlags, CPoint point) 
  607. {
  608. Doc * pDoc = GetDocument();
  609. if (CRect(0,0,iRx,iRy).PtInRect(point))
  610. {
  611. if (pDoc->GetSelectedCount() == pDoc->iFormObj)
  612. {
  613. pDoc->ClearSelection();
  614. }
  615. else
  616. {
  617. for (int t = 0; t < pDoc->iFormObj; t++)
  618. pDoc->ppObjs[t]->bSelected = true;
  619. }
  620. Invalidate();
  621. CView::OnLButtonDown(nFlags, point);
  622. return;
  623. }
  624. if (pTracker) delete pTracker;
  625. ptTrack = point;
  626. if (iType < 0)// && pDoc->GetSelectedCount() > 0)
  627. {
  628. CPoint trk(point);
  629. RealPoint(trk);
  630. CRect rcTrk;
  631. int idx;
  632. iSizingHit = pDoc->HitTest(trk, rcTrk, idx);
  633. bSizing = false;
  634. if (iSizingHit >= 0 && iSizingHit != CRectTracker::hitMiddle)
  635. {
  636. if (!(pDoc->ppObjs[idx]->bSelected))
  637. {
  638. CView::OnLButtonDown(nFlags, point);
  639. return;
  640. }
  641. CPoint pt1(rcTrk.TopLeft());
  642. CPoint pt2(rcTrk.BottomRight());
  643. ScaledPoint(pt1);
  644. ScaledPoint(pt2);
  645. rcSizing = CRect(pt1.x, pt1.y, pt2.x, pt2.y);
  646. pTracker = new CRectTracker(rcSizing, CRectTracker::hatchedBorder);
  647. pTracker->m_nHandleSize = 4;
  648. if (pTracker->Track(this, point))
  649. {
  650. CRect nrc(pTracker->m_rect);
  651. CPoint pt3(nrc.TopLeft());
  652. CPoint pt4(nrc.BottomRight());
  653. RealPoint2(pt3);
  654. RealPoint2(pt4);
  655. FixPoint(pt3);
  656. FixPoint(pt4);
  657. nrc.SetRect(pt3.x, pt3.y, pt4.x, pt4.y);
  658. nrc.NormalizeRect();
  659. pDoc->ppObjs[idx]->rc = nrc;
  660. if (GfxIsProp2())
  661. {
  662. CGfxProperty * pg = GfxGetProp2();
  663. if (pg->pDocument == pDoc && pg->pWnd == this)
  664. pg->DoIt();
  665. }
  666. Invalidate();
  667. }
  668. delete pTracker;
  669. pTracker = NULL;
  670. CView::OnLButtonDown(nFlags, point);
  671. return;
  672. }
  673. else
  674. {
  675. pTracker = new CRectTracker(CRect(point.x, point.y, point.x, point.y), CRectTracker::hatchedBorder);
  676. pTracker->m_nHandleSize = 4;
  677. CClientDC dc(this);
  678. ptTrack = point;
  679. // FixPoint(ptTrack);
  680. pTracker->DrawTrackerRect(CRect(ptTrack.x, ptTrack.y, ptTrack.x, ptTrack.y), this, &dc, this);
  681. }
  682. }
  683. else
  684. {
  685. if (!(nFlags&MK_SHIFT))
  686. {
  687. if (pDoc->GetSelectedCount() > 0)
  688. {
  689. pDoc->ClearSelection();
  690. Invalidate();
  691. }
  692. }
  693. pTracker = new CRectTracker(CRect(point.x, point.y, point.x, point.y), CRectTracker::hatchedBorder);
  694. pTracker->m_nHandleSize = 4;
  695. CClientDC dc(this);
  696. ptTrack = point;
  697. FixPoint(ptTrack);
  698. pTracker->DrawTrackerRect(CRect(ptTrack.x, ptTrack.y, ptTrack.x, ptTrack.y), this, &dc, this);
  699. }
  700. SetCapture();
  701. CView::OnLButtonDown(nFlags, point);
  702. }
  703. void StatusBarMessage(char* fmt, ...)
  704. {
  705. if (AfxGetApp() != NULL && AfxGetApp()->m_pMainWnd != NULL) 
  706. {
  707. char buffer[256];
  708. CStatusBar* pStatus = (CStatusBar*) AfxGetApp()->m_pMainWnd->GetDescendantWindow(AFX_IDW_STATUS_BAR);
  709. va_list argptr;
  710. va_start(argptr, fmt);
  711. vsprintf(buffer, fmt, argptr);
  712. va_end(argptr);
  713. if (pStatus != NULL) 
  714. {
  715. pStatus->SetPaneText(0, buffer);
  716. pStatus->UpdateWindow();
  717. }
  718. }
  719. }
  720. void View::OnMouseMove(UINT nFlags, CPoint point) 
  721. {
  722. {
  723. CPoint pt1(point);
  724. ClientToScreen(&pt1);
  725. CPoint pt2(pt1);
  726. wndHRuler.ScreenToClient(&pt1);
  727. wndHRuler.DrawMouse(pt1.x);
  728. wndVRuler.ScreenToClient(&pt2);
  729. wndVRuler.DrawMouse(pt2.y);
  730. }
  731. if (pTracker)
  732. {
  733. CPoint pt(point);
  734. if (iType >= 0) FixPoint2(pt);
  735. {
  736. CRect rc(ptTrack.x, ptTrack.y, pt.x, pt.y);
  737. rc.NormalizeRect();
  738. if (!(rc.IsRectEmpty()))
  739. {
  740. CClientDC dc(this);
  741. pTracker->DrawTrackerRect(rc, this, &dc, this);
  742. }
  743. }
  744. }
  745. CView::OnMouseMove(nFlags, point);
  746. }
  747. void View::FixPoint(CPoint & pt)
  748. {
  749. return;
  750. int px = wndHBar.GetScrollPos() / iDiv - iRx - 2;
  751. int py = wndVBar.GetScrollPos() / iDiv - iRy - 2;
  752. int x = pt.x;// + px;
  753. int r = x % iGridStep;
  754. if (r < iGridStep / 2) pt.x -= r;
  755. else pt.x += (iGridStep - r);
  756. int y = pt.y;// + py;
  757. r = y % iGridStep;
  758. if (r < iGridStep / 2) pt.y -= r;
  759. else pt.y += (iGridStep - r);
  760. }
  761. void View::FixPoint2(CPoint & pt)
  762. {
  763. return;
  764. int px = wndHBar.GetScrollPos() / iDiv - iRx - 2;
  765. int py = wndVBar.GetScrollPos() / iDiv - iRy - 2;
  766. CPoint pt1(pt);
  767. // RealPoint(pt1);
  768. int x = pt1.x + px;
  769. int r = x % iGridStep;
  770. if (r < iGridStep / 2) pt.x -= r;
  771. else pt.x += (iGridStep - r);
  772. int y = pt1.y + py;
  773. r = y % iGridStep;
  774. if (r < iGridStep / 2) pt.y -= r;
  775. else pt.y += (iGridStep - r);
  776. }
  777. void View::FixRect(CRect & rc)
  778. {
  779. return;
  780. CPoint pt = rc.TopLeft();
  781. FixPoint(pt);
  782. CPoint pt1 = rc.BottomRight();
  783. FixPoint(pt1);
  784. rc.SetRect(pt.x, pt.y, pt1.x, pt1.y);
  785. }
  786. void View::RealPoint(CPoint & pt)
  787. {
  788. int px = wndHBar.GetScrollPos() * iDiv;
  789. int py = wndVBar.GetScrollPos() * iDiv;
  790. CPoint pt1((pt.x - iRx - 2) * iDiv + px, (pt.y - iRy - 2) *iDiv + py);
  791. pt = pt1;
  792. }
  793. void View::RealPoint2(CPoint & pt)
  794. {
  795. int px = wndHBar.GetScrollPos() * iDiv;
  796. int py = wndVBar.GetScrollPos() * iDiv;
  797. // CPoint pt1((pt.x) * iDiv + px, (pt.y) *iDiv + py);
  798. CPoint pt1((pt.x - iRx - 2) * iDiv + px, (pt.y - iRy - 2) *iDiv + py);
  799. pt = pt1;
  800. }
  801. void View::ScaledPoint(CPoint & pt)
  802. {
  803. pt.x /= iDiv;
  804. pt.y /= iDiv;
  805. pt.x -= wndHBar.GetScrollPos() - iRx - 2;
  806. pt.y -= wndVBar.GetScrollPos() - iRy - 2;
  807. }
  808. BOOL View::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) 
  809. {
  810. Doc * pDoc = GetDocument();
  811. if (iType < 0 && pDoc->GetSelectedCount() > 0)
  812. {
  813. if (pTracker)
  814. {
  815. if (pTracker->SetCursor(this, nHitTest)) return true;
  816. }
  817. else
  818. {
  819. CPoint trk(GetMessagePos());
  820. ScreenToClient(&trk);
  821. RealPoint(trk);
  822. CRect rcTrk;
  823. int idx;
  824. if (pDoc->HitTest(trk, rcTrk, idx) >= 0)
  825. {
  826. if (pDoc->ppObjs[idx]->bSelected)
  827. {
  828. CPoint pt1(rcTrk.TopLeft());
  829. CPoint pt2(rcTrk.BottomRight());
  830. ScaledPoint(pt1);
  831. ScaledPoint(pt2);
  832. CRect rcSizing1 = CRect(pt1.x, pt1.y, pt2.x, pt2.y);
  833. pTracker = new CRectTracker(rcSizing1, CRectTracker::resizeInside);
  834. pTracker->m_nHandleSize = 4;
  835. bool bres = pTracker->SetCursor(this, nHitTest) ? true : false;
  836. delete pTracker;
  837. pTracker = NULL;
  838. if (bres) return true;
  839. }
  840. }
  841. }
  842. }
  843. return CView::OnSetCursor(pWnd, nHitTest, message);
  844. }
  845. void View::OnEditCut() 
  846. {
  847. Doc * pDoc = GetDocument();
  848. pDoc->CopySelected();
  849. pDoc->RemoveSelected();
  850. Invalidate();
  851. }
  852. void View::OnUpdateEditCut(CCmdUI* pCmdUI) 
  853. {
  854. Doc * pDoc = GetDocument();
  855. pCmdUI->Enable(pDoc->GetSelectedCount() > 0);
  856. }
  857. void View::OnEditCopy() 
  858. {
  859. Doc * pDoc = GetDocument();
  860. pDoc->CopySelected();
  861. }
  862. void View::OnUpdateEditCopy(CCmdUI* pCmdUI) 
  863. {
  864. Doc * pDoc = GetDocument();
  865. pCmdUI->Enable(pDoc->GetSelectedCount() > 0);
  866. }
  867. void View::OnEditPaste() 
  868. {
  869. Doc * pDoc = GetDocument();
  870. pDoc->PasteClip();
  871. Invalidate();
  872. }
  873. void View::OnUpdateEditPaste(CCmdUI* pCmdUI) 
  874. {
  875. Doc * pDoc = GetDocument();
  876. pCmdUI->Enable(iClipFormObj > 0);
  877. }
  878. void View::OnPaperSize() 
  879. {
  880. Doc * pDoc = GetDocument();
  881. CPagerSizeDlg dlg;
  882. dlg.iTop = pDoc->rcPaper.top;
  883. dlg.iLeft = pDoc->rcPaper.left;
  884. dlg.iRight = pDoc->rcPaper.right;
  885. dlg.iBottom = pDoc->rcPaper.bottom;
  886. dlg.csPageName = pDoc->name;
  887. if (dlg.DoModal() == IDOK)
  888. {
  889. CRect rc(dlg.iLeft, dlg.iTop, dlg.iLeft + dlg.iRight, dlg.iTop + dlg.iBottom);
  890. SetPaperRect(rc);
  891. pDoc->name = dlg.csPageName;
  892. CPapersBar * pb = GfxGetPaperList();
  893. pb->wndList.SetItemText(pDoc->iSelpage, 0, dlg.csPageName);
  894. Invalidate();
  895. }
  896. }
  897. void View::OnProperty() 
  898. {
  899. CPropDlg * pProp = GfxGetProp();
  900. pProp->SetObject(GetDocument(), this);
  901. }
  902. void View::OnUpdateProperty(CCmdUI* pCmdUI) 
  903. {
  904. pCmdUI->SetCheck(GfxIsProp());
  905. }
  906. void View::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) 
  907. {
  908. if (bActivate)
  909. {
  910. Doc * pDoc = GetDocument();
  911. CPapersBar * pb = GfxGetPaperList();
  912. pb->pDoc = pDoc;
  913. pDoc->FillList();
  914. }
  915. CView::OnActivateView(bActivate, pActivateView, pDeactiveView);
  916. }
  917. void View::OnGfxProperty() 
  918. {
  919. CGfxProperty * pg = GfxGetProp2();
  920. Doc * pDoc = GetDocument();
  921. if (!(pg->pDocument == pDoc && pg->pWnd == this))
  922. {
  923. pg->ClearTabArray();
  924. if (pDoc->GetSelectedCount() > 0)
  925. {
  926. dlgSheet1.pDoc = pDoc;
  927. dlgSheet1.pView = this;
  928. dlgSheet2.pDoc = pDoc;
  929. dlgSheet2.pView = this;
  930. dlgSheet3.pDoc = pDoc;
  931. dlgSheet3.pView = this;
  932. dlgSheet1.Create(CPropPage1::IDD, pg);
  933. dlgSheet2.Create(CPropPage2::IDD, pg);
  934. dlgSheet3.Create(CPropPage3::IDD, pg);
  935. pg->pDocument = pDoc;
  936. pg->pWnd = this;
  937. pg->AddPage(&dlgSheet1, "Generale");
  938. pg->AddPage(&dlgSheet2, "Ids");
  939. pg->AddPage(&dlgSheet3, "Other");
  940. pg->SetCurSel(0);
  941. }
  942. }
  943. else
  944. {
  945. if (pDoc->GetSelectedCount() <= 0)
  946. pg->ClearTabArray();
  947. }
  948. }
  949. void View::OnUpdateGfxProperty(CCmdUI* pCmdUI) 
  950. {
  951. pCmdUI->SetCheck(GfxIsProp2());
  952. }
  953. void View::OnDestroy() 
  954. {
  955. if (GfxIsProp2())
  956. {
  957. CGfxProperty * pg = GfxGetProp2();
  958. Doc * pDoc = GetDocument();
  959. if (pg->pDocument == pDoc && pg->pWnd == this) pg->ClearTabArray();
  960. }
  961. CView::OnDestroy();
  962. }
  963. void View::OnAlignBottom() 
  964. {
  965. Doc * pDoc = GetDocument();
  966. bool b = false;
  967. CRect rc;
  968. for (int t = 0; t < pDoc->iFormObj; t++)
  969. {
  970. if (pDoc->ppObjs[t]->bSelected)
  971. {
  972. if (!b) rc = pDoc->ppObjs[t]->rc;
  973. else if (rc.left > pDoc->ppObjs[t]->rc.left) rc = pDoc->ppObjs[t]->rc;
  974. b = true;
  975. }
  976. }
  977. if (b)
  978. {
  979. for (t = 0; t < pDoc->iFormObj; t++)
  980. {
  981. if (pDoc->ppObjs[t]->bSelected)
  982. {
  983. int h = pDoc->ppObjs[t]->rc.Height();
  984. pDoc->ppObjs[t]->rc.bottom = rc.bottom;
  985. pDoc->ppObjs[t]->rc.top = pDoc->ppObjs[t]->rc.bottom - h;
  986. }
  987. }
  988. }
  989. Invalidate();
  990. }
  991. void View::OnUpdateAlignBottom(CCmdUI* pCmdUI) 
  992. {
  993. Doc * pDoc = GetDocument();
  994. pCmdUI->Enable(pDoc->GetSelectedCount() > 0);
  995. }
  996. void View::OnAlignLeft() 
  997. {
  998. Doc * pDoc = GetDocument();
  999. bool b = false;
  1000. CRect rc;
  1001. for (int t = 0; t < pDoc->iFormObj; t++)
  1002. {
  1003. if (pDoc->ppObjs[t]->bSelected)
  1004. {
  1005. if (!b) rc = pDoc->ppObjs[t]->rc;
  1006. else if (rc.top > pDoc->ppObjs[t]->rc.top) rc = pDoc->ppObjs[t]->rc;
  1007. b = true;
  1008. }
  1009. }
  1010. if (b)
  1011. {
  1012. for (t = 0; t < pDoc->iFormObj; t++)
  1013. {
  1014. if (pDoc->ppObjs[t]->bSelected)
  1015. {
  1016. int w = pDoc->ppObjs[t]->rc.Width();
  1017. pDoc->ppObjs[t]->rc.left = rc.left;
  1018. pDoc->ppObjs[t]->rc.right = pDoc->ppObjs[t]->rc.left + w;
  1019. }
  1020. }
  1021. }
  1022. Invalidate();
  1023. }
  1024. void View::OnUpdateAlignLeft(CCmdUI* pCmdUI) 
  1025. {
  1026. Doc * pDoc = GetDocument();
  1027. pCmdUI->Enable(pDoc->GetSelectedCount() > 0);
  1028. }
  1029. void View::OnAlignRight() 
  1030. {
  1031. Doc * pDoc = GetDocument();
  1032. bool b = false;
  1033. CRect rc;
  1034. for (int t = 0; t < pDoc->iFormObj; t++)
  1035. {
  1036. if (pDoc->ppObjs[t]->bSelected)
  1037. {
  1038. if (!b) rc = pDoc->ppObjs[t]->rc;
  1039. else if (rc.top > pDoc->ppObjs[t]->rc.top) rc = pDoc->ppObjs[t]->rc;
  1040. b = true;
  1041. }
  1042. }
  1043. if (b)
  1044. {
  1045. for (t = 0; t < pDoc->iFormObj; t++)
  1046. {
  1047. if (pDoc->ppObjs[t]->bSelected)
  1048. {
  1049. int w = pDoc->ppObjs[t]->rc.Width();
  1050. pDoc->ppObjs[t]->rc.right = rc.right;
  1051. pDoc->ppObjs[t]->rc.left = pDoc->ppObjs[t]->rc.right - w;
  1052. }
  1053. }
  1054. }
  1055. Invalidate();
  1056. }
  1057. void View::OnUpdateAlignRight(CCmdUI* pCmdUI) 
  1058. {
  1059. Doc * pDoc = GetDocument();
  1060. pCmdUI->Enable(pDoc->GetSelectedCount() > 0);
  1061. }
  1062. void View::OnAlignTop() 
  1063. {
  1064. Doc * pDoc = GetDocument();
  1065. bool b = false;
  1066. CRect rc;
  1067. for (int t = 0; t < pDoc->iFormObj; t++)
  1068. {
  1069. if (pDoc->ppObjs[t]->bSelected)
  1070. {
  1071. if (!b) rc = pDoc->ppObjs[t]->rc;
  1072. else if (rc.left > pDoc->ppObjs[t]->rc.left) rc = pDoc->ppObjs[t]->rc;
  1073. b = true;
  1074. }
  1075. }
  1076. if (b)
  1077. {
  1078. for (t = 0; t < pDoc->iFormObj; t++)
  1079. {
  1080. if (pDoc->ppObjs[t]->bSelected)
  1081. {
  1082. int h = pDoc->ppObjs[t]->rc.Height();
  1083. pDoc->ppObjs[t]->rc.top = rc.top;
  1084. pDoc->ppObjs[t]->rc.bottom = pDoc->ppObjs[t]->rc.top + h;
  1085. }
  1086. }
  1087. }
  1088. Invalidate();
  1089. }
  1090. void View::OnUpdateAlignTop(CCmdUI* pCmdUI) 
  1091. {
  1092. Doc * pDoc = GetDocument();
  1093. pCmdUI->Enable(pDoc->GetSelectedCount() > 0);
  1094. }
  1095. void View::OnSizeAll() 
  1096. {
  1097. Doc * pDoc = GetDocument();
  1098. bool b = false;
  1099. CRect rc;
  1100. for (int t = 0; t < pDoc->iFormObj; t++)
  1101. {
  1102. if (pDoc->ppObjs[t]->bSelected)
  1103. {
  1104. if (!b) rc = pDoc->ppObjs[t]->rc;
  1105. else if (rc.top > pDoc->ppObjs[t]->rc.top) rc = pDoc->ppObjs[t]->rc;
  1106. else if (rc.top == pDoc->ppObjs[t]->rc.top && rc.left > pDoc->ppObjs[t]->rc.left) rc = pDoc->ppObjs[t]->rc;
  1107. b = true;
  1108. }
  1109. }
  1110. if (b)
  1111. {
  1112. for (t = 0; t < pDoc->iFormObj; t++)
  1113. {
  1114. if (pDoc->ppObjs[t]->bSelected)
  1115. {
  1116. pDoc->ppObjs[t]->rc.top = pDoc->ppObjs[t]->rc.bottom - rc.Height();
  1117. pDoc->ppObjs[t]->rc.right = pDoc->ppObjs[t]->rc.left + rc.Width();
  1118. }
  1119. }
  1120. }
  1121. Invalidate();
  1122. }
  1123. void View::OnUpdateSizeAll(CCmdUI* pCmdUI) 
  1124. {
  1125. Doc * pDoc = GetDocument();
  1126. pCmdUI->Enable(pDoc->GetSelectedCount() > 0);
  1127. }
  1128. void View::OnSizeHorz() 
  1129. {
  1130. Doc * pDoc = GetDocument();
  1131. bool b = false;
  1132. CRect rc;
  1133. for (int t = 0; t < pDoc->iFormObj; t++)
  1134. {
  1135. if (pDoc->ppObjs[t]->bSelected)
  1136. {
  1137. if (!b) rc = pDoc->ppObjs[t]->rc;
  1138. else if (rc.top > pDoc->ppObjs[t]->rc.top) rc = pDoc->ppObjs[t]->rc;
  1139. else if (rc.top == pDoc->ppObjs[t]->rc.top && rc.left > pDoc->ppObjs[t]->rc.left) rc = pDoc->ppObjs[t]->rc;
  1140. b = true;
  1141. }
  1142. }
  1143. if (b)
  1144. {
  1145. for (t = 0; t < pDoc->iFormObj; t++)
  1146. {
  1147. if (pDoc->ppObjs[t]->bSelected)
  1148. pDoc->ppObjs[t]->rc.right = pDoc->ppObjs[t]->rc.left + rc.Width();
  1149. }
  1150. }
  1151. Invalidate();
  1152. }
  1153. void View::OnUpdateSizeHorz(CCmdUI* pCmdUI) 
  1154. {
  1155. Doc * pDoc = GetDocument();
  1156. pCmdUI->Enable(pDoc->GetSelectedCount() > 0);
  1157. }
  1158. void View::OnSizeVert() 
  1159. {
  1160. Doc * pDoc = GetDocument();
  1161. bool b = false;
  1162. CRect rc;
  1163. for (int t = 0; t < pDoc->iFormObj; t++)
  1164. {
  1165. if (pDoc->ppObjs[t]->bSelected)
  1166. {
  1167. if (!b) rc = pDoc->ppObjs[t]->rc;
  1168. else if (rc.top > pDoc->ppObjs[t]->rc.top) rc = pDoc->ppObjs[t]->rc;
  1169. else if (rc.top == pDoc->ppObjs[t]->rc.top && rc.left > pDoc->ppObjs[t]->rc.left) rc = pDoc->ppObjs[t]->rc;
  1170. b = true;
  1171. }
  1172. }
  1173. if (b)
  1174. {
  1175. for (t = 0; t < pDoc->iFormObj; t++)
  1176. {
  1177. if (pDoc->ppObjs[t]->bSelected)
  1178. pDoc->ppObjs[t]->rc.top = pDoc->ppObjs[t]->rc.bottom - rc.Height();
  1179. }
  1180. }
  1181. Invalidate();
  1182. }
  1183. void View::OnUpdateSizeVert(CCmdUI* pCmdUI) 
  1184. {
  1185. Doc * pDoc = GetDocument();
  1186. pCmdUI->Enable(pDoc->GetSelectedCount() > 0);
  1187. }
  1188. void View::OnRButtonDown(UINT nFlags, CPoint point) 
  1189. {
  1190. CPoint pt(point);
  1191. ClientToScreen(&pt);
  1192. ((CMainFrame *) AfxGetMainWnd())->DoTrackMenu(IDR_POPS, 0, AfxGetMainWnd(), pt);
  1193. CView::OnRButtonDown(nFlags, point);
  1194. }