MarkupPadView.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:19k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // MarkupPadView.cpp : implementation of the CMarkupPadView class
  2. //
  3. #include "stdafx.h"
  4. #include "MarkupPad.h"
  5. #include "MarkupPadDoc.h"
  6. #include "MarkupPadView.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CMarkupPadView
  14. IMPLEMENT_DYNCREATE(CMarkupPadView, CView)
  15. BEGIN_MESSAGE_MAP(CMarkupPadView, CView)
  16. //{{AFX_MSG_MAP(CMarkupPadView)
  17. ON_WM_ERASEBKGND()
  18. ON_WM_PAINT()
  19. //}}AFX_MSG_MAP
  20. // Standard printing commands
  21. ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
  22. ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
  23. ON_COMMAND(ID_FILE_PRINT_PREVIEW, OnFilePrintPreview)
  24. END_MESSAGE_MAP()
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CMarkupPadView construction/destruction
  27. void StaticSetText2(CXTPMarkupObject* pSender, CXTPMarkupMouseEventArgs* /*pArgs*/)
  28. {
  29. ((CXTPMarkupTextBlock*)pSender)->SetText(L"Column4");
  30. }
  31. CMarkupPadView::CMarkupPadView()
  32. {
  33. m_pUIElement = NULL;
  34. m_bInRender = FALSE;
  35. AddHandler(CXTPMarkupHyperlink::m_pClickEvent, CreateMarkupClassDelegate(this, &CMarkupPadView::OnHyperlinkClick));
  36. SetDelegate(L"Border_MouseLeftButtonUp", CreateMarkupClassDelegate(this, &CMarkupPadView::OnBorderMouseLeftButtonUp));
  37. SetDelegate(L"TextBlock_MouseLeftButtonUp", CreateMarkupClassDelegate(this, &CMarkupPadView::OnTextBlockMouseLeftButtonUp));
  38. SetDelegate(L"Run_MouseLeftButtonUp", CreateMarkupClassDelegate(this, &CMarkupPadView::OnRunMouseLeftButtonUp));
  39. SetDelegate(L"MakeShapeRed", CreateMarkupClassDelegate(this, &CMarkupPadView::OnMakeShapeRed));
  40. SetDelegate(L"MakeShapeGreen", CreateMarkupClassDelegate(this, &CMarkupPadView::OnMakeShapeGreen));
  41. SetDelegate(L"MakeTextBold", CreateMarkupClassDelegate(this, &CMarkupPadView::OnMakeTextBold));
  42. SetDelegate(L"MakeTextNormal", CreateMarkupClassDelegate(this, &CMarkupPadView::OnMakeTextNormal));
  43. SetDelegate(L"MakeTextYellow", CreateMarkupClassDelegate(this, &CMarkupPadView::OnMakeTextYellow));
  44. SetDelegate(L"MakeTextGreen", CreateMarkupClassDelegate(this, &CMarkupPadView::OnMakeTextGreen));
  45. SetDelegate(L"MoveColumn3", CreateMarkupClassDelegate(this, &CMarkupPadView::OnMoveColumn3));
  46. SetDelegate(L"HideColumn4", CreateMarkupClassDelegate(this, &CMarkupPadView::OnHideColumn4));
  47. SetDelegate(L"ShowColumn4", CreateMarkupClassDelegate(this, &CMarkupPadView::OnShowColumn4));
  48. SetDelegate(L"SetText1", CreateMarkupClassDelegate(this, &CMarkupPadView::OnSetText1));
  49. SetDelegate(L"ToggleNextControl", CreateMarkupClassDelegate(this, &CMarkupPadView::ToggleNextControl));
  50. SetDelegate(L"SetText2", CreateMarkupClassDelegate(this, &CMarkupPadView::OnSetText2));
  51. //SetDelegate(L"SetText2", CreateMarkupFunctionDelegate(&StaticSetText2));
  52. }
  53. CMarkupPadView::~CMarkupPadView()
  54. {
  55. MARKUP_RELEASE(m_pUIElement);
  56. }
  57. BOOL CMarkupPadView::PreCreateWindow(CREATESTRUCT& cs)
  58. {
  59. // TODO: Modify the Window class or styles here by modifying
  60. //  the CREATESTRUCT cs
  61. return CView::PreCreateWindow(cs);
  62. }
  63. /////////////////////////////////////////////////////////////////////////////
  64. // CMarkupPadView drawing
  65. void CMarkupPadView::CreateCodeMarkup()
  66. {
  67. _int64 nPerfomanceEnd;
  68. _int64 nPerfomanceStart;
  69. QueryPerformanceCounter((LARGE_INTEGER*)&nPerfomanceStart);
  70. CXTPMarkupPage* pPage = MARKUP_CREATE(CXTPMarkupPage, this);
  71. CXTPMarkupBorder* pBorder = MARKUP_CREATE(CXTPMarkupBorder, this);
  72. pBorder->SetMargin(5);
  73. pBorder->SetPadding(5);
  74. pBorder->SetBorderThickness(10);
  75. pBorder->SetBackground(new CXTPMarkupSolidColorBrush(RGB(0, 0, 0xFF)));
  76. pBorder->SetBorderBrush(new CXTPMarkupSolidColorBrush(RGB(0, 0xFF, 00)));
  77. CXTPMarkupBorder* pBorder2 = MARKUP_CREATE(CXTPMarkupBorder, this);
  78. pBorder2->SetMargin(1);
  79. pBorder2->SetPadding(8);
  80. pBorder2->SetBorderThickness(1);
  81. pBorder2->SetBackground(new CXTPMarkupSolidColorBrush(0xFFFFFF));
  82. pBorder2->SetBorderBrush(new CXTPMarkupSolidColorBrush(RGB(0xFF, 0, 0 )));
  83. pBorder->SetChild(pBorder2);
  84. pPage->SetContent(pBorder);
  85. CXTPMarkupBorder* pBorder3 = MARKUP_CREATE(CXTPMarkupBorder, this);
  86. pBorder3->SetBackground(new CXTPMarkupSolidColorBrush(0));
  87. pBorder3->SetHorizontalAlignment(xtpMarkupHorizontalAlignmentRight);
  88. //pBorder3->SetPadding(CXTPMarkupThickness(10));
  89. pBorder3->SetVerticalAlignment(xtpMarkupVerticalAlignmentBottom);
  90. //pBorder3->SetWidth(40);
  91. //pBorder3->SetHeight(40);
  92. pBorder2->SetChild(pBorder3);
  93. pBorder3->SetPadding(10);
  94. CXTPMarkupStackPanel* pStack = MARKUP_CREATE(CXTPMarkupStackPanel, this);
  95. CXTPMarkupTextElement::SetForeground(pPage, new CXTPMarkupSolidColorBrush(RGB(0x80, 0x80, 0x80)));
  96. CXTPMarkupTextBlock* pTextBlock1 = MARKUP_CREATE(CXTPMarkupTextBlock, this);
  97. pTextBlock1->SetTextWrapping(1);
  98. pTextBlock1->SetText(L"You can increment or decrement the value of this"  
  99.                  L"textbox by simply clicking the mouse, hold and drag"
  100.                  L"up or down, right or left. Release when happy,with the value.");
  101. pTextBlock1->SetMargin(5, 0, 5, 0);
  102. pTextBlock1->SetBackground(new CXTPMarkupSolidColorBrush(RGB(0xFF, 0, 0)));
  103. pTextBlock1->SetForeground(new CXTPMarkupSolidColorBrush(RGB(0xFF, 0xFF, 0xFF)));
  104. pStack->GetChildren()->Add(pTextBlock1);
  105. CXTPMarkupTextBlock* pTextBlock2 = MARKUP_CREATE(CXTPMarkupTextBlock, this);
  106. pTextBlock2->SetText(L"Hi!");
  107. pTextBlock2->SetBackground(new CXTPMarkupSolidColorBrush(RGB(0xFF, 0, 0)));
  108. pTextBlock2->SetForeground(new CXTPMarkupSolidColorBrush(RGB(0xFF, 0xFF, 0)));
  109. pStack->GetChildren()->Add(pTextBlock2);
  110. CXTPMarkupTextBlock* pTextBlock3 = MARKUP_CREATE(CXTPMarkupTextBlock, this);
  111. pTextBlock3->SetTextAlignment(xtpMarkupTextAlignmentCenter);
  112. pTextBlock3->SetTextWrapping(1);
  113. CXTPMarkupRun* pRun = MARKUP_CREATE(CXTPMarkupRun, this);
  114. pRun->SetText(L"1234");
  115. pRun->SetForeground(new CXTPMarkupSolidColorBrush(RGB(0xFF, 0xFF, 0)));
  116. pTextBlock3->GetInlines()->Add(pRun);
  117. pRun = MARKUP_CREATE(CXTPMarkupRun, this);
  118. pRun->SetText(L" ");
  119. pTextBlock3->GetInlines()->Add(pRun);
  120. pRun = MARKUP_CREATE(CXTPMarkupRun, this);
  121. pRun->SetText(L"345");
  122. pRun->SetForeground(new CXTPMarkupSolidColorBrush(RGB(0xFF, 0xFF, 0xFF)));
  123. pTextBlock3->GetInlines()->Add(pRun);
  124. pRun = MARKUP_CREATE(CXTPMarkupRun, this);
  125. pRun->SetText(L" ");
  126. pTextBlock3->GetInlines()->Add(pRun);
  127. pRun = MARKUP_CREATE(CXTPMarkupRun, this);
  128. pRun->SetText(L"What?");
  129. pTextBlock3->GetInlines()->Add(pRun);
  130. pRun = MARKUP_CREATE(CXTPMarkupRun, this);
  131. pRun->SetText(L"Big Link Object HAHAHA?");
  132. pTextBlock3->GetInlines()->Add(pRun);
  133. pRun->SetForeground(new CXTPMarkupSolidColorBrush(RGB(0, 0, 0xFF)));
  134. pRun = MARKUP_CREATE(CXTPMarkupRun, this);
  135. pRun->SetText(L" 1234");
  136. pRun->SetForeground(new CXTPMarkupSolidColorBrush(RGB(0xFF, 0xFF, 0)));
  137. pRun->SetBackground(new CXTPMarkupSolidColorBrush(RGB(0, 0xFF, 0)));
  138. pTextBlock3->GetInlines()->Add(pRun);
  139. pRun = MARKUP_CREATE(CXTPMarkupRun, this);
  140. pRun->SetText(L" 345n");
  141. pRun->SetForeground(new CXTPMarkupSolidColorBrush(RGB(0xFF, 0xFF, 0xFF)));
  142. pTextBlock3->GetInlines()->Add(pRun);
  143. pRun = MARKUP_CREATE(CXTPMarkupRun, this);
  144. pRun->SetText(L"HinEEEE ew");
  145. pTextBlock3->GetInlines()->Add(pRun);
  146. pTextBlock3->GetInlines()->Add(MARKUP_CREATE(CXTPMarkupLineBreak, this));
  147. pRun = MARKUP_CREATE(CXTPMarkupRun, this);
  148. pRun->SetText(L"Hi");
  149. pTextBlock3->GetInlines()->Add(pRun);
  150. pRun = MARKUP_CREATE(CXTPMarkupRun, this);
  151. pRun->SetText(L"edede");
  152. pRun->SetFontSize(20);
  153. pTextBlock3->GetInlines()->Add(pRun);
  154. pStack->GetChildren()->Add(pTextBlock3);
  155. CXTPMarkupStackPanel* pStack2 = MARKUP_CREATE(CXTPMarkupStackPanel, this);
  156. CXTPMarkupTextElement::SetForeground(pStack2, new CXTPMarkupSolidColorBrush(RGB(0x30, 0x30, 0x30)));
  157. CXTPMarkupBorder* pBorder4 = MARKUP_CREATE(CXTPMarkupBorder, this);
  158. pBorder4->SetBackground(new CXTPMarkupSolidColorBrush(0xFF00FF));
  159. pBorder4->SetBorderBrush(new CXTPMarkupSolidColorBrush(0));
  160. pBorder4->SetBorderThickness(1);
  161. CXTPMarkupTextBlock* pTextBlock4 = MARKUP_CREATE(CXTPMarkupTextBlock, this);
  162. pTextBlock4->SetTextWrapping(1);
  163. CXTPMarkupBold* pBoldInline = MARKUP_CREATE(CXTPMarkupBold, this);
  164. pRun = MARKUP_CREATE(CXTPMarkupRun, this);
  165. pRun->SetText(L"Test Size!!!");
  166. pRun->SetBackground(0xFF);
  167. pRun->SetFontSize(30);
  168. pBoldInline->GetInlines()->Add(pRun);
  169. //pBoldInline->GetInlines()->Add(new CXTPMarkupLineBreak());
  170. pRun = MARKUP_CREATE(CXTPMarkupRun, this);
  171. pRun->SetText(L" Test Family!!!");
  172. pRun->SetFontFamily(L"Courier New");
  173. pBoldInline->GetInlines()->Add(pRun);
  174. CXTPMarkupInlineUIContainer* pInlineContainer = MARKUP_CREATE(CXTPMarkupInlineUIContainer, this);
  175. CXTPMarkupBorder* pBorder5 = MARKUP_CREATE(CXTPMarkupBorder, this);
  176. pBorder5->SetBackground(new CXTPMarkupSolidColorBrush(0xFFFF00));
  177. pBorder5->SetBorderBrush(new CXTPMarkupSolidColorBrush(0xFF));
  178. pBorder5->SetWidth(10);
  179. pBorder5->SetHeight(10);
  180. //pBorder5->SetMargin(8);
  181. pBorder5->SetBorderThickness(1);
  182. pInlineContainer->SetChild(pBorder5);
  183. pBoldInline->GetInlines()->Add(pInlineContainer);
  184. CXTPMarkupItalic* pItalicInline = MARKUP_CREATE(CXTPMarkupItalic, this);
  185. pRun = MARKUP_CREATE(CXTPMarkupRun, this);
  186. pRun->SetText(L" Test Italic!!!");
  187. pItalicInline->GetInlines()->Add(pRun);
  188. pBoldInline->GetInlines()->Add(pItalicInline);
  189. pTextBlock4->GetInlines()->Add(pBoldInline);
  190. CXTPMarkupUnderline* pUnderlineInline = MARKUP_CREATE(CXTPMarkupUnderline, this);
  191. pRun = MARKUP_CREATE(CXTPMarkupRun, this);
  192. pRun->SetText(L" Test Underline!!!");
  193. pUnderlineInline->GetInlines()->Add(pRun);
  194. pTextBlock4->GetInlines()->Add(pUnderlineInline);
  195. pBorder4->SetChild(pTextBlock4);
  196. pStack2->GetChildren()->Add(pBorder4);
  197. pStack2->GetChildren()->Add(pStack); 
  198. pBorder3->SetChild(pStack2);
  199. QueryPerformanceCounter((LARGE_INTEGER*)&nPerfomanceEnd);
  200. TRACE(_T("Parse   = %i n"), int(nPerfomanceEnd - nPerfomanceStart));
  201. MARKUP_RELEASE(m_pUIElement);
  202. m_pUIElement = pPage;
  203. }
  204. BOOL CMarkupPadView::OnWndMsg(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pResult)
  205. {
  206. if (m_pUIElement)
  207. {
  208. if (CXTPMarkupContext::OnWndMsg(m_pUIElement, message, wParam, lParam, pResult))
  209. return TRUE;
  210. }
  211. return CView::OnWndMsg(message, wParam, lParam, pResult);
  212. }
  213. void CMarkupPadView::OnInitialUpdate()
  214. {
  215. CView::OnInitialUpdate();
  216. //MARKUP_RELEASE(m_pUIElement);
  217. m_hContextWnd = m_hWnd;
  218. }
  219. void CMarkupPadView::OnDraw(CDC* /*pDC*/)
  220. {
  221. ASSERT(FALSE);
  222. }
  223. void CMarkupPadView::DrawMarkup(CXTPMarkupDrawingContext* pDC, CRect rc)
  224. {
  225. CXTPMarkupUIElement* pElement = m_pUIElement;
  226. if (!pElement)
  227. return;
  228. if (m_bInRender)
  229. return;
  230. m_bInRender = TRUE;
  231. _int64 nPerfomanceEnd;
  232. _int64 nPerfomanceStart;
  233. QueryPerformanceCounter((LARGE_INTEGER*)&nPerfomanceStart);
  234. pElement->Measure(pDC, rc.Size());
  235. pElement->Arrange(rc);
  236. QueryPerformanceCounter((LARGE_INTEGER*)&nPerfomanceEnd);
  237. int nArrange = int(nPerfomanceEnd - nPerfomanceStart);
  238. nPerfomanceStart = nPerfomanceEnd;
  239. pElement->Render(pDC);
  240. QueryPerformanceCounter((LARGE_INTEGER*)&nPerfomanceEnd);
  241. int nRender = int(nPerfomanceEnd - nPerfomanceStart);
  242. TRACE(_T("Arrange = %i n"), nArrange);
  243. TRACE(_T("Render  = %i n"), nRender);
  244. if (pElement->FindName(L"Test"))
  245. {
  246. TRACE(_T("Name Found n"));
  247. }
  248. m_bInRender = FALSE;
  249. }
  250. void CMarkupPadView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
  251. {
  252. CXTPMarkupPrintingContext dc(pDC->m_hDC, pDC->m_hAttribDC);
  253. DrawMarkup(&dc, pInfo->m_rectDraw);
  254. }
  255. /////////////////////////////////////////////////////////////////////////////
  256. // CMarkupPadView printing
  257. BOOL CMarkupPadView::OnPreparePrinting(CPrintInfo* pInfo)
  258. {
  259. pInfo->m_nNumPreviewPages = 1;
  260. pInfo->SetMinPage(1);
  261. pInfo->SetMaxPage(1);
  262. // default preparation
  263. return DoPreparePrinting(pInfo);
  264. }
  265. void CMarkupPadView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  266. {
  267. // TODO: add extra initialization before printing
  268. }
  269. void CMarkupPadView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  270. {
  271. // TODO: add cleanup after printing
  272. }
  273. /////////////////////////////////////////////////////////////////////////////
  274. // CMarkupPadView diagnostics
  275. #ifdef _DEBUG
  276. void CMarkupPadView::AssertValid() const
  277. {
  278. CView::AssertValid();
  279. }
  280. void CMarkupPadView::Dump(CDumpContext& dc) const
  281. {
  282. CView::Dump(dc);
  283. }
  284. CMarkupPadDoc* CMarkupPadView::GetDocument() // non-debug version is inline
  285. {
  286. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMarkupPadDoc)));
  287. return (CMarkupPadDoc*)m_pDocument;
  288. }
  289. #endif //_DEBUG
  290. /////////////////////////////////////////////////////////////////////////////
  291. // CMarkupPadView message handlers
  292. BOOL CMarkupPadView::OnEraseBkgnd(CDC* /*pDC*/) 
  293. {
  294. return TRUE;
  295. }
  296. void CMarkupPadView::OnPaint() 
  297. {
  298. CPaintDC dc(this); // device context for painting
  299. CXTPClientRect rc(this);
  300. CXTPBufferDC dcMem(dc);
  301. dcMem.FillSolidRect(rc, GetSysColor(COLOR_WINDOW));
  302. CXTPMarkupDrawingContext dcMarkup(dcMem);
  303. DrawMarkup(&dcMarkup, rc);
  304. }
  305. void CMarkupPadView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
  306. {
  307. ASSERT_VALID(this);
  308. ASSERT_VALID(pDC);
  309. ASSERT(pInfo != NULL);  // overriding OnPaint -- never get this.
  310. if (!pInfo)
  311. return;
  312. pDC->SetMapMode(MM_ANISOTROPIC);
  313. pDC->SetViewportExt(pDC->GetDeviceCaps(LOGPIXELSX),
  314. pDC->GetDeviceCaps(LOGPIXELSY));
  315. pDC->SetWindowExt(100, 100);
  316. // ptOrg is in logical coordinates
  317. pDC->OffsetWindowOrg(0, 0);
  318. }
  319. void CMarkupPadView::OnHyperlinkClick(CXTPMarkupObject* pSender, CXTPMarkupRoutedEventArgs* pArgs)
  320. {
  321. if (pSender->IsKindOf(MARKUP_TYPE(CXTPMarkupHyperlink)))
  322. {
  323. AfxMessageBox(_T("Hyperlink Clicked"));
  324. //CXTPMarkupString* pTag = STATIC_DOWNCAST(CXTPMarkupString, ((CXTPMarkupHyperlink*)pSender)->GetTag());
  325. //((CXTPMarkupHyperlink*)pSender)->SetBackground(RGB(0, 255, 255));
  326. pArgs->SetHandled();
  327. }
  328. }
  329. void CMarkupPadView::OnRunMouseLeftButtonUp(CXTPMarkupObject* /*pSender*/, CXTPMarkupMouseButtonEventArgs* pArgs)
  330. {
  331. TRACE(_T("RunMouseLeftButtonUpn"));
  332. pArgs->SetHandled();
  333. }
  334. void CMarkupPadView::OnBorderMouseLeftButtonUp(CXTPMarkupObject* /*pSender*/, CXTPMarkupMouseButtonEventArgs* /*pArgs*/)
  335. {
  336. TRACE(_T("BorderMouseLeftButtonUpn"));
  337. }
  338. void CMarkupPadView::OnTextBlockMouseLeftButtonUp(CXTPMarkupObject* /*pSender*/, CXTPMarkupMouseButtonEventArgs* /*pArgs*/)
  339. {
  340. TRACE(_T("TextBlockMouseLeftButtonUpn"));
  341. }
  342. void CMarkupPadView::OnMakeShapeRed(CXTPMarkupObject* /*pSender*/, CXTPMarkupMouseEventArgs* pArgs)
  343. {
  344. if (pArgs->GetSource()->IsKindOf(MARKUP_TYPE(CXTPMarkupShape)))
  345. {
  346. ((CXTPMarkupShape*)pArgs->GetSource())->SetFill(new CXTPMarkupSolidColorBrush(RGB(255, 0, 0)));
  347. }
  348. }
  349. void CMarkupPadView::OnMakeShapeGreen(CXTPMarkupObject* /*pSender*/, CXTPMarkupMouseEventArgs* pArgs)
  350. {
  351. if (pArgs->GetSource()->IsKindOf(MARKUP_TYPE(CXTPMarkupShape)))
  352. {
  353. ((CXTPMarkupShape*)pArgs->GetSource())->SetFill(new CXTPMarkupSolidColorBrush(RGB(0, 255, 0)));
  354. }
  355. }
  356. void CMarkupPadView::OnMakeTextBold(CXTPMarkupObject* pSender, CXTPMarkupMouseEventArgs* /*pArgs*/)
  357. {
  358. pSender->SetValue(CXTPMarkupTextElement::m_pFontWeightProperty, new CXTPMarkupEnum(FW_BOLD));
  359. }
  360. void CMarkupPadView::OnMakeTextNormal(CXTPMarkupObject* pSender, CXTPMarkupMouseEventArgs* /*pArgs*/)
  361. {
  362. pSender->SetValue(CXTPMarkupTextElement::m_pFontWeightProperty, NULL);
  363. }
  364. void CMarkupPadView::OnMakeTextYellow(CXTPMarkupObject* pSender, CXTPMarkupMouseEventArgs* /*pArgs*/)
  365. {
  366. pSender->SetValue(CXTPMarkupTextElement::m_pBackgroundProperty, new CXTPMarkupSolidColorBrush(RGB(255, 255, 0)));
  367. }
  368. void CMarkupPadView::OnMakeTextGreen(CXTPMarkupObject* pSender, CXTPMarkupMouseEventArgs* /*pArgs*/)
  369. {
  370. pSender->SetValue(CXTPMarkupTextElement::m_pBackgroundProperty, new CXTPMarkupSolidColorBrush(RGB(0, 128, 0)));
  371. }
  372. void CMarkupPadView::OnHideColumn4(CXTPMarkupObject* pSender, CXTPMarkupMouseEventArgs* /*pArgs*/)
  373. {
  374. ((CXTPMarkupFrameworkElement*)pSender)->SetVisibility(xtpMarkupVisibilityCollapsed);
  375. }
  376. void CMarkupPadView::OnShowColumn4(CXTPMarkupObject* pSender, CXTPMarkupMouseEventArgs* /*pArgs*/)
  377. {
  378. CXTPMarkupGrid* pGrid = MARKUP_DYNAMICCAST(CXTPMarkupGrid, ((CXTPMarkupFrameworkElement*)pSender));
  379. if (!pGrid)
  380. return;
  381. pGrid->GetChildren()->GetItem(3)->SetVisibility(xtpMarkupVisibilityVisible);
  382. }
  383. void CMarkupPadView::OnMoveColumn3(CXTPMarkupObject* pSender, CXTPMarkupMouseEventArgs* /*pArgs*/)
  384. {
  385. CXTPMarkupGrid* pGrid = MARKUP_DYNAMICCAST(CXTPMarkupGrid, ((CXTPMarkupFrameworkElement*)pSender)->GetVisualParent()->GetVisualParent());
  386. if (!pGrid)
  387. return;
  388. if (CXTPMarkupGrid::GetColumn(pGrid->GetChildren()->GetItem(2)) == 2)
  389. {
  390. CXTPMarkupGrid::SetColumn(pGrid->GetChildren()->GetItem(2), 3);
  391. CXTPMarkupGrid::SetColumn(pGrid->GetChildren()->GetItem(3), 2);
  392. }
  393. else
  394. {
  395. CXTPMarkupGrid::SetColumn(pGrid->GetChildren()->GetItem(2), 2);
  396. CXTPMarkupGrid::SetColumn(pGrid->GetChildren()->GetItem(3), 3);
  397. }
  398. }
  399. void CMarkupPadView::OnSetText1(CXTPMarkupObject* pSender, CXTPMarkupMouseEventArgs* /*pArgs*/)
  400. {
  401. ((CXTPMarkupTextBlock*)pSender)->SetText(L"New Text");
  402. }
  403. void CMarkupPadView::OnSetText2(CXTPMarkupObject* pSender, CXTPMarkupMouseEventArgs* /*pArgs*/)
  404. {
  405. ((CXTPMarkupTextBlock*)pSender)->SetText(L"Column5");
  406. }
  407. void CMarkupPadView::ToggleNextControl(CXTPMarkupObject* pSender, CXTPMarkupMouseButtonEventArgs* /*pArgs*/)
  408. {
  409. CXTPMarkupUIElement* pElement = MARKUP_DYNAMICCAST(CXTPMarkupUIElement, pSender);
  410. if (!pElement)
  411. return;
  412. CXTPMarkupPanel* pPanel = MARKUP_DYNAMICCAST(CXTPMarkupPanel, pElement->GetVisualParent());
  413. if (!pPanel)
  414. return;
  415. int nIndex = pPanel->GetChildren()->IndexOf(pElement);
  416. CXTPMarkupUIElement* pNextElement = pPanel->GetChildren()->GetItem(nIndex + 1);
  417. if (!pNextElement)
  418. return;
  419. pNextElement->SetVisibility(pNextElement->GetVisibility() == xtpMarkupVisibilityVisible ? 
  420. xtpMarkupVisibilityCollapsed : xtpMarkupVisibilityVisible);
  421. }
  422. void CMarkupPadView::OnFilePrintPreview() 
  423. {
  424. // replace the default print preview with ours!
  425. // In derived classes, implement special window handling here
  426. // Be sure to Unhook Frame Window close if hooked.
  427. // must not create this on the frame.  Must outlive this function
  428. CPrintPreviewState* pState = new CPrintPreviewState;
  429. // DoPrintPreview's return value does not necessarily indicate that
  430. // Print preview succeeded or failed, but rather what actions are necessary
  431. // at this point.  If DoPrintPreview returns TRUE, it means that
  432. // OnEndPrintPreview will be (or has already been) called and the
  433. // pState structure will be/has been deleted.
  434. // If DoPrintPreview returns FALSE, it means that OnEndPrintPreview
  435. // WILL NOT be called and that cleanup, including deleting pState
  436. // must be done here.
  437. if (!DoPrintPreview(XTP_IDD_PREVIEW_DIALOGBAR, this, RUNTIME_CLASS(CXTPPreviewView), pState))
  438. {
  439. // In derived classes, reverse special window handling here for
  440. // Preview failure case
  441. TRACE0("Error: DoPrintPreview failed.n");
  442. AfxMessageBox(AFX_IDP_COMMAND_FAILURE);
  443. delete pState;      // preview failed to initialize, delete State now
  444. pState = NULL;
  445. }
  446. }