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

对话框与窗口

开发平台:

Visual C++

  1. // wordpvw.cpp : implementation of the CWordPadView class
  2. //
  3. // This file is a part of the XTREME TOOLKIT PRO MFC class library.
  4. // (c)1998-2008 Codejock Software, All Rights Reserved.
  5. //
  6. // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
  7. // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
  8. // CONSENT OF CODEJOCK SOFTWARE.
  9. //
  10. // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
  11. // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
  12. // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
  13. // SINGLE COMPUTER.
  14. //
  15. // CONTACT INFORMATION:
  16. // support@codejock.com
  17. // http://www.codejock.com
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "wordpad.h"
  22. #include "cntritem.h"
  23. #include "srvritem.h"
  24. #include "wordpdoc.h"
  25. #include "wordpvw.h"
  26. #include "formatta.h"
  27. #include "datedial.h"
  28. #include "formatpa.h"
  29. #include "ruler.h"
  30. #include "strings.h"
  31. #include "colorlis.h"
  32. #include "pageset.h"
  33. #include <penwin.h>
  34. #include "ControlSelector.h"
  35. extern CLIPFORMAT cfEmbeddedObject;
  36. extern CLIPFORMAT cfRTO;
  37. #ifdef _DEBUG
  38. #undef THIS_FILE
  39. static char BASED_CODE THIS_FILE[] = __FILE__;
  40. #endif
  41. BOOL CCharFormat::operator==(CCharFormat& cf)
  42. {
  43. return
  44. dwMask == cf.dwMask
  45. && dwEffects == cf.dwEffects
  46. && yHeight == cf.yHeight
  47. && yOffset == cf.yOffset
  48. && crTextColor == cf.crTextColor
  49. && bPitchAndFamily == cf.bPitchAndFamily
  50. #if (_MSC_VER < 1300)
  51. && (lstrcmpA(szFaceName, cf.szFaceName) == 0);
  52. #else
  53. && (lstrcmp(szFaceName, cf.szFaceName) == 0);
  54. #endif
  55. }
  56. BOOL CParaFormat::operator==(PARAFORMAT& pf)
  57. {
  58. if(
  59. dwMask != pf.dwMask
  60. || wNumbering != pf.wNumbering
  61. || dxStartIndent != pf.dxStartIndent
  62. || dxRightIndent != pf.dxRightIndent
  63. || dxOffset != pf.dxOffset
  64. || cTabCount != pf.cTabCount
  65. )
  66. {
  67. return FALSE;
  68. }
  69. for (int i=0;i<pf.cTabCount;i++)
  70. {
  71. if (rgxTabs[i] != pf.rgxTabs[i])
  72. return FALSE;
  73. }
  74. return TRUE;
  75. }
  76. /////////////////////////////////////////////////////////////////////////////
  77. // CWordPadView
  78. IMPLEMENT_DYNCREATE(CWordPadView, CRichEditView)
  79. //WM_SETTINGCHANGE -- default printer might have changed
  80. //WM_FONTCHANGE -- pool of fonts changed
  81. //WM_DEVMODECHANGE -- printer settings changes
  82. BEGIN_MESSAGE_MAP(CWordPadView, CRichEditView)
  83. ON_COMMAND(ID_CANCEL_EDIT_CNTR, OnCancelEditCntr)
  84. ON_COMMAND(ID_CANCEL_EDIT_SRVR, OnCancelEditSrvr)
  85. //{{AFX_MSG_MAP(CWordPadView)
  86. ON_COMMAND(ID_PAGE_SETUP, OnPageSetup)
  87. ON_COMMAND(ID_CHAR_BOLD, OnCharBold)
  88. ON_UPDATE_COMMAND_UI(ID_CHAR_BOLD, OnUpdateCharBold)
  89. ON_COMMAND(ID_CHAR_ITALIC, OnCharItalic)
  90. ON_UPDATE_COMMAND_UI(ID_CHAR_ITALIC, OnUpdateCharItalic)
  91. ON_COMMAND(ID_CHAR_UNDERLINE, OnCharUnderline)
  92. ON_UPDATE_COMMAND_UI(ID_CHAR_UNDERLINE, OnUpdateCharUnderline)
  93. ON_COMMAND(ID_PARA_CENTER, OnParaCenter)
  94. ON_UPDATE_COMMAND_UI(ID_PARA_CENTER, OnUpdateParaCenter)
  95. ON_COMMAND(ID_PARA_LEFT, OnParaLeft)
  96. ON_UPDATE_COMMAND_UI(ID_PARA_LEFT, OnUpdateParaLeft)
  97. ON_COMMAND(ID_PARA_RIGHT, OnParaRight)
  98. ON_UPDATE_COMMAND_UI(ID_PARA_RIGHT, OnUpdateParaRight)
  99. ON_WM_CREATE()
  100. ON_COMMAND(ID_INSERT_DATE_TIME, OnInsertDateTime)
  101. ON_COMMAND(ID_FORMAT_PARAGRAPH, OnFormatParagraph)
  102. ON_COMMAND(ID_FORMAT_TABS, OnFormatTabs)
  103. ON_COMMAND(ID_COLOR16, OnColorDefault)
  104. ON_WM_TIMER()
  105. ON_WM_DESTROY()
  106. ON_WM_MEASUREITEM()
  107. ON_COMMAND(ID_PEN_BACKSPACE, OnPenBackspace)
  108. ON_COMMAND(ID_PEN_NEWLINE, OnPenNewline)
  109. ON_COMMAND(ID_PEN_PERIOD, OnPenPeriod)
  110. ON_COMMAND(ID_PEN_SPACE, OnPenSpace)
  111. ON_WM_SIZE()
  112. ON_WM_KEYDOWN()
  113. ON_COMMAND(ID_FILE_PRINT, OnFilePrint)
  114. ON_COMMAND(ID_FILE_PRINT_DIRECT, OnFilePrint)
  115. ON_WM_DROPFILES()
  116. ON_COMMAND(ID_PEN_LENS, OnPenLens)
  117. ON_COMMAND(ID_PEN_TAB, OnPenTab)
  118. ON_WM_PALETTECHANGED()
  119. ON_WM_QUERYNEWPALETTE()
  120. ON_WM_SETTINGCHANGE()
  121. //}}AFX_MSG_MAP
  122. // Standard printing commands
  123. ON_COMMAND(ID_INSERT_BULLET, CRichEditView::OnBullet)
  124. ON_UPDATE_COMMAND_UI(ID_INSERT_BULLET, CRichEditView::OnUpdateBullet)
  125. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CRichEditView::OnFilePrintPreview)
  126. ON_COMMAND_RANGE(ID_COLOR0, ID_COLOR16, OnColorPick)
  127. ON_EN_CHANGE(AFX_IDW_PANE_FIRST, OnEditChange)
  128. ON_WM_MOUSEACTIVATE()
  129. ON_REGISTERED_MESSAGE(CWordPadApp::m_nPrinterChangedMsg, OnPrinterChangedMsg)
  130. ON_WM_CONTEXTMENU()
  131. ON_WM_RBUTTONDOWN()
  132. ON_NOTIFY(XTP_FN_GETFORMAT, ID_COMBO_SIZE, OnGetCharFormat)
  133. ON_NOTIFY(XTP_FN_SETFORMAT, ID_COMBO_SIZE, OnSetCharFormat)
  134. ON_UPDATE_COMMAND_UI(ID_COMBO_SIZE, OnUpdateComboSize)
  135. ON_NOTIFY(XTP_FN_SETFORMAT, ID_COMBO_FONT, OnSetCharFormat)
  136. ON_UPDATE_COMMAND_UI(ID_COMBO_FONT, OnUpdateComboFont)
  137. ON_XTP_EXECUTE(ID_SELECTOR_TEXT, OnSelectorText)
  138. ON_UPDATE_COMMAND_UI(ID_SELECTOR_TEXT, OnUpdateSelectorText)
  139. ON_COMMAND(ID_BUTTON_TEXT, OnButtonText)
  140. ON_UPDATE_COMMAND_UI(ID_BUTTON_TEXT, OnUpdateText)
  141. ON_COMMAND(XTP_IDS_AUTOMATIC, OnTextAuto)
  142. ON_UPDATE_COMMAND_UI(XTP_IDS_AUTOMATIC, OnUpdateTextAuto)
  143. ON_COMMAND(XTP_IDS_MORE_COLORS, OnTextMore)
  144. ON_XTP_EXECUTE(ID_EDIT_UNDO, OnEditUndo)
  145. ON_NOTIFY(XTP_LBN_SELCHANGE, ID_EDIT_UNDO, OnListBoxControlSelChange)
  146. ON_NOTIFY(XTP_LBN_POPUP, ID_EDIT_UNDO, OnListBoxControlPoup)
  147. ON_NOTIFY(XTP_SLN_SELCHANGE, ID_INSERT_COLUMNS, OnColumnsSelChange)
  148. ON_NOTIFY(XTP_SLN_SELCHANGE, ID_INSERT_TABLE, OnTableSelChange)
  149. ON_XTP_EXECUTE(ID_INSERT_TABLE, OnInsertTable)
  150. ON_XTP_EXECUTE(ID_INSERT_COLUMNS, OnInsertColumns)
  151. END_MESSAGE_MAP()
  152. /////////////////////////////////////////////////////////////////////////////
  153. // CWordPadView construction/destruction
  154. CWordPadView::CWordPadView()
  155. {
  156. m_bSyncCharFormat = m_bSyncParaFormat = TRUE;
  157. m_uTimerID = 0;
  158. m_bDelayUpdateItems = FALSE;
  159. m_bOnBar = FALSE;
  160. m_bInPrint = FALSE;
  161. m_nPasteType = 0;
  162. m_rectMargin = theApp.m_rectPageMargin;
  163. m_clr = RGB(0, 0, 0);
  164. }
  165. BOOL CWordPadView::PreCreateWindow(CREATESTRUCT& cs)
  166. {
  167. BOOL bRes = CRichEditView::PreCreateWindow(cs);
  168. cs.style |= ES_SELECTIONBAR;
  169. return bRes;
  170. }
  171. /////////////////////////////////////////////////////////////////////////////
  172. // CWordPadView attributes
  173. BOOL CWordPadView::IsFormatText()
  174. {
  175. // this function checks to see if any formatting is not default text
  176. BOOL bRes = FALSE;
  177. CHARRANGE cr;
  178. CCharFormat cf;
  179. CParaFormat pf;
  180. GetRichEditCtrl().GetSel(cr);
  181. GetRichEditCtrl().HideSelection(TRUE, FALSE);
  182. GetRichEditCtrl().SetSel(0,-1);
  183. if (!(GetRichEditCtrl().GetSelectionType() & (SEL_OBJECT|SEL_MULTIOBJECT)))
  184. {
  185. GetRichEditCtrl().GetSelectionCharFormat(cf);
  186. if (cf == m_defTextCharFormat)
  187. {
  188. GetRichEditCtrl().GetParaFormat(pf);
  189. if (pf == m_defParaFormat) //compared using CParaFormat::operator==
  190. bRes = TRUE;
  191. }
  192. }
  193. GetRichEditCtrl().SetSel(cr);
  194. GetRichEditCtrl().HideSelection(FALSE, FALSE);
  195. return bRes;
  196. }
  197. HMENU CWordPadView::GetContextMenu(WORD, LPOLEOBJECT, CHARRANGE* )
  198. {
  199. return NULL;
  200. }
  201. /////////////////////////////////////////////////////////////////////////////
  202. // CWordPadView operations
  203. void CWordPadView::WrapChanged()
  204. {
  205. CWaitCursor wait;
  206. CFrameWnd* pFrameWnd = GetParentFrame();
  207. ASSERT(pFrameWnd != NULL);
  208. pFrameWnd->SetMessageText(IDS_FORMATTING);
  209. CWnd* pBarWnd = pFrameWnd->GetMessageBar();
  210. if (pBarWnd != NULL)
  211. pBarWnd->UpdateWindow();
  212. CRichEditView::WrapChanged();
  213. pFrameWnd->SetMessageText(AFX_IDS_IDLEMESSAGE);
  214. if (pBarWnd != NULL)
  215. pBarWnd->UpdateWindow();
  216. }
  217. void CWordPadView::SetUpdateTimer()
  218. {
  219. if (m_uTimerID != 0) // if outstanding timer kill it
  220. KillTimer(m_uTimerID);
  221. m_uTimerID = (UINT)SetTimer(1, 1000, NULL); //set a timer for 1000 milliseconds
  222. if (m_uTimerID == 0) // no timer available so force update now
  223. GetDocument()->UpdateAllItems(NULL);
  224. else
  225. m_bDelayUpdateItems = TRUE;
  226. }
  227. void CWordPadView::DeleteContents()
  228. {
  229. ASSERT_VALID(this);
  230. ASSERT(m_hWnd != NULL);
  231. CRichEditView::DeleteContents();
  232. SetDefaultFont(IsTextType(GetDocument()->m_nNewDocType));
  233. }
  234. void CWordPadView::SetDefaultFont(BOOL bText)
  235. {
  236. ASSERT_VALID(this);
  237. ASSERT(m_hWnd != NULL);
  238. m_bSyncCharFormat = m_bSyncParaFormat = TRUE;
  239. CHARFORMAT* pCharFormat = bText ? &m_defTextCharFormat : &m_defCharFormat;
  240. // set the default character format -- the FALSE makes it the default
  241. GetRichEditCtrl().SetSel(0,-1);
  242. GetRichEditCtrl().SetDefaultCharFormat(*pCharFormat);
  243. GetRichEditCtrl().SetSelectionCharFormat(*pCharFormat);
  244. GetRichEditCtrl().SetParaFormat(m_defParaFormat);
  245. GetRichEditCtrl().SetSel(0,0);
  246. GetRichEditCtrl().EmptyUndoBuffer();
  247. GetRichEditCtrl().SetModify(FALSE);
  248. ASSERT_VALID(this);
  249. }
  250. /////////////////////////////////////////////////////////////////////////////
  251. // CWordPadView drawing
  252. /////////////////////////////////////////////////////////////////////////////
  253. // CWordPadView printing
  254. void CWordPadView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
  255. {
  256. CRichEditView::OnPrint(pDC, pInfo);
  257. if (pInfo != NULL && pInfo->m_bPreview)
  258. DrawMargins(pDC);
  259. }
  260. void CWordPadView::DrawMargins(CDC* pDC)
  261. {
  262. if (pDC->m_hAttribDC != NULL)
  263. {
  264. CRect rect;
  265. rect.left = m_rectMargin.left;
  266. rect.right = m_sizePaper.cx - m_rectMargin.right;
  267. rect.top = m_rectMargin.top;
  268. rect.bottom = m_sizePaper.cy - m_rectMargin.bottom;
  269. //rect in twips
  270. int logx = ::GetDeviceCaps(pDC->m_hDC, LOGPIXELSX);
  271. int logy = ::GetDeviceCaps(pDC->m_hDC, LOGPIXELSY);
  272. rect.left = MulDiv(rect.left, logx, 1440);
  273. rect.right = MulDiv(rect.right, logx, 1440);
  274. rect.top = MulDiv(rect.top, logy, 1440);
  275. rect.bottom = MulDiv(rect.bottom, logy, 1440);
  276. CPen pen(PS_DOT, 0, pDC->GetTextColor());
  277. CPen* ppen = pDC->SelectObject(&pen);
  278. pDC->MoveTo(0, rect.top);
  279. pDC->LineTo(10000, rect.top);
  280. pDC->MoveTo(rect.left, 0);
  281. pDC->LineTo(rect.left, 10000);
  282. pDC->MoveTo(0, rect.bottom);
  283. pDC->LineTo(10000, rect.bottom);
  284. pDC->MoveTo(rect.right, 0);
  285. pDC->LineTo(rect.right, 10000);
  286. pDC->SelectObject(ppen);
  287. }
  288. }
  289. BOOL CWordPadView::OnPreparePrinting(CPrintInfo* pInfo)
  290. {
  291. return DoPreparePrinting(pInfo);
  292. }
  293. /////////////////////////////////////////////////////////////////////////////
  294. // OLE Client support and commands
  295. inline int roundleast(int n)
  296. {
  297. int mod = n%10;
  298. n -= mod;
  299. if (mod >= 5)
  300. n += 10;
  301. else if (mod <= -5)
  302. n -= 10;
  303. return n;
  304. }
  305. static void RoundRect(LPRECT r1)
  306. {
  307. r1->left = roundleast(r1->left);
  308. r1->right = roundleast(r1->right);
  309. r1->top = roundleast(r1->top);
  310. r1->bottom = roundleast(r1->bottom);
  311. }
  312. static void MulDivRect(LPRECT r1, LPRECT r2, int num, int div)
  313. {
  314. r1->left = MulDiv(r2->left, num, div);
  315. r1->top = MulDiv(r2->top, num, div);
  316. r1->right = MulDiv(r2->right, num, div);
  317. r1->bottom = MulDiv(r2->bottom, num, div);
  318. }
  319. void CWordPadView::OnPageSetup()
  320. {
  321. CPageSetupDialog dlg;
  322. PAGESETUPDLG& psd = dlg.m_psd;
  323. BOOL bMetric = theApp.GetUnits() == 1; //centimeters
  324. psd.Flags |= PSD_MARGINS | (bMetric ? PSD_INHUNDREDTHSOFMILLIMETERS :
  325. PSD_INTHOUSANDTHSOFINCHES);
  326. int nUnitsPerInch = bMetric ? 2540 : 1000;
  327. MulDivRect(&psd.rtMargin, m_rectMargin, nUnitsPerInch, 1440);
  328. RoundRect(&psd.rtMargin);
  329. // get the current device from the app
  330. PRINTDLG pd;
  331. pd.hDevNames = NULL;
  332. pd.hDevMode = NULL;
  333. theApp.GetPrinterDeviceDefaults(&pd);
  334. psd.hDevNames = pd.hDevNames;
  335. psd.hDevMode = pd.hDevMode;
  336. if (dlg.DoModal() == IDOK)
  337. {
  338. RoundRect(&psd.rtMargin);
  339. MulDivRect(m_rectMargin, &psd.rtMargin, 1440, nUnitsPerInch);
  340. theApp.m_rectPageMargin = m_rectMargin;
  341. theApp.SelectPrinter(psd.hDevNames, psd.hDevMode);
  342. theApp.NotifyPrinterChanged();
  343. }
  344. // PageSetupDlg failed
  345. if (CommDlgExtendedError() != 0)
  346. {
  347. CPageSetupDlg dlg;
  348. dlg.m_nBottomMargin = m_rectMargin.bottom;
  349. dlg.m_nLeftMargin = m_rectMargin.left;
  350. dlg.m_nRightMargin = m_rectMargin.right;
  351. dlg.m_nTopMargin = m_rectMargin.top;
  352. if (dlg.DoModal() == IDOK)
  353. {
  354. m_rectMargin.SetRect(dlg.m_nLeftMargin, dlg.m_nTopMargin,
  355. dlg.m_nRightMargin, dlg.m_nBottomMargin);
  356. // m_page will be changed at this point
  357. theApp.m_rectPageMargin = m_rectMargin;
  358. theApp.NotifyPrinterChanged();
  359. }
  360. }
  361. }
  362. /////////////////////////////////////////////////////////////////////////////
  363. // OLE Server support
  364. // The following command handler provides the standard keyboard
  365. //  user interface to cancel an in-place editing session.  Here,
  366. //  the server (not the container) causes the deactivation.
  367. void CWordPadView::OnCancelEditSrvr()
  368. {
  369. GetDocument()->OnDeactivateUI(FALSE);
  370. }
  371. /////////////////////////////////////////////////////////////////////////////
  372. // CWordPadView diagnostics
  373. #ifdef _DEBUG
  374. void CWordPadView::AssertValid() const
  375. {
  376. CRichEditView::AssertValid();
  377. }
  378. void CWordPadView::Dump(CDumpContext& dc) const
  379. {
  380. CRichEditView::Dump(dc);
  381. }
  382. CWordPadDoc* CWordPadView::GetDocument() // non-debug version is inline
  383. {
  384. return (CWordPadDoc*)m_pDocument;
  385. }
  386. #endif //_DEBUG
  387. /////////////////////////////////////////////////////////////////////////////
  388. // CWordPadView message helpers
  389. /////////////////////////////////////////////////////////////////////////////
  390. // CWordPadView message handlers
  391. int CWordPadView::OnCreate(LPCREATESTRUCT lpCreateStruct)
  392. {
  393. if (CRichEditView::OnCreate(lpCreateStruct) == -1)
  394. return -1;
  395. theApp.m_listPrinterNotify.AddTail(m_hWnd);
  396. if (theApp.m_bWordSel)
  397. GetRichEditCtrl().SetOptions(ECOOP_OR, ECO_AUTOWORDSELECTION);
  398. else
  399. GetRichEditCtrl().SetOptions(ECOOP_AND, ~(DWORD)ECO_AUTOWORDSELECTION);
  400. //  GetRichEditCtrl().SetOptions(ECOOP_OR, ECO_SELECTIONBAR);
  401. GetDefaultFont(m_defTextCharFormat, IDS_DEFAULTTEXTFONT);
  402. GetDefaultFont(m_defCharFormat, IDS_DEFAULTFONT);
  403. GetRichEditCtrl().GetParaFormat(m_defParaFormat);
  404. m_defParaFormat.cTabCount = 0;
  405. return 0;
  406. }
  407. void CWordPadView::GetDefaultFont(CCharFormat& cf, UINT nFontNameID)
  408. {
  409. USES_CONVERSION;
  410. CString strDefFont;
  411. VERIFY(strDefFont.LoadString(nFontNameID));
  412. ASSERT(cf.cbSize == sizeof(CHARFORMAT));
  413. cf.dwMask = CFM_BOLD|CFM_ITALIC|CFM_UNDERLINE|CFM_STRIKEOUT|CFM_SIZE|
  414. CFM_COLOR|CFM_OFFSET|CFM_PROTECTED;
  415. cf.dwEffects = CFE_AUTOCOLOR;
  416. cf.yHeight = 200; //10pt
  417. cf.yOffset = 0;
  418. cf.crTextColor = RGB(0, 0, 0);
  419. cf.bCharSet = 0;
  420. cf.bPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
  421. ASSERT(strDefFont.GetLength() < LF_FACESIZE);
  422. #if (_RICHEDIT_VER >= 0x0200)
  423. lstrcpyn(cf.szFaceName, strDefFont, LF_FACESIZE);
  424. #else
  425. lstrcpynA(cf.szFaceName, T2A((LPTSTR) (LPCTSTR) strDefFont), LF_FACESIZE);
  426. #endif
  427. cf.dwMask |= CFM_FACE;
  428. }
  429. void CWordPadView::OnInsertDateTime()
  430. {
  431. CDateDialog dlg;
  432. if (dlg.DoModal() == IDOK)
  433. GetRichEditCtrl().ReplaceSel(dlg.m_strSel);;
  434. }
  435. void CWordPadView::OnFormatParagraph()
  436. {
  437. CFormatParaDlg dlg(GetParaFormatSelection());
  438. dlg.m_nWordWrap = m_nWordWrap;
  439. if (dlg.DoModal() == IDOK)
  440. SetParaFormat(dlg.m_pf);
  441. }
  442. void CWordPadView::OnFormatTabs()
  443. {
  444. CFormatTabDlg dlg(GetParaFormatSelection());
  445. if (dlg.DoModal() == IDOK)
  446. SetParaFormat(dlg.m_pf);
  447. }
  448. void CWordPadView::OnTextNotFound(LPCTSTR lpStr)
  449. {
  450. ASSERT_VALID(this);
  451. MessageBeep(0);
  452. AfxMessageBox(IDS_FINISHED_SEARCH,MB_OK|MB_ICONINFORMATION);
  453. CRichEditView::OnTextNotFound(lpStr);
  454. }
  455. void CWordPadView::OnColorPick(UINT nID)
  456. {
  457. CRichEditView::OnColorPick(CColorMenu::GetColor(nID));
  458. }
  459. void CWordPadView::OnTimer(UINT_PTR nIDEvent)
  460. {
  461. if (m_uTimerID != nIDEvent) // not our timer
  462. CRichEditView::OnTimer(nIDEvent);
  463. else
  464. {
  465. KillTimer(m_uTimerID); // kill one-shot timer
  466. m_uTimerID = 0;
  467. if (m_bDelayUpdateItems)
  468. GetDocument()->UpdateAllItems(NULL);
  469. m_bDelayUpdateItems = FALSE;
  470. }
  471. }
  472. void CWordPadView::OnEditChange()
  473. {
  474. SetUpdateTimer();
  475. }
  476. void CWordPadView::OnDestroy()
  477. {
  478. POSITION pos = theApp.m_listPrinterNotify.Find(m_hWnd);
  479. ASSERT(pos != NULL);
  480. theApp.m_listPrinterNotify.RemoveAt(pos);
  481. CRichEditView::OnDestroy();
  482. if (m_uTimerID != 0) // if outstanding timer kill it
  483. OnTimer(m_uTimerID);
  484. ASSERT(m_uTimerID == 0);
  485. }
  486. void CWordPadView::CalcWindowRect(LPRECT lpClientRect, UINT nAdjustType)
  487. {
  488. CRichEditView::CalcWindowRect(lpClientRect, nAdjustType);
  489. if (theApp.m_bWin4 && nAdjustType != 0 && (GetStyle() & WS_VSCROLL))
  490. lpClientRect->right--;
  491. // if the ruler is visible then slide the view up under the ruler to avoid
  492. // showing the top border of the view
  493. if (GetExStyle() & WS_EX_CLIENTEDGE)
  494. {
  495. CFrameWnd* pFrame = GetParentFrame();
  496. if (pFrame != NULL)
  497. {
  498. CRulerBar* pBar = (CRulerBar*)pFrame->GetControlBar(ID_VIEW_RULER);
  499. if (pBar != NULL)
  500. {
  501. BOOL bVis = pBar->IsVisible();
  502. if (pBar->m_bDeferInProgress)
  503. bVis = !bVis;
  504. if (bVis)
  505. lpClientRect->top -= 2;
  506. }
  507. }
  508. }
  509. }
  510. void CWordPadView::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMIS)
  511. {
  512. lpMIS->itemID = (UINT)(WORD)lpMIS->itemID;
  513. CRichEditView::OnMeasureItem(nIDCtl, lpMIS);
  514. }
  515. void CWordPadView::OnPenBackspace()
  516. {
  517. SendMessage(WM_KEYDOWN, VK_BACK, 0);
  518. SendMessage(WM_KEYUP, VK_BACK, 0);
  519. }
  520. void CWordPadView::OnPenNewline()
  521. {
  522. SendMessage(WM_CHAR, 'n', 0);
  523. }
  524. void CWordPadView::OnPenPeriod()
  525. {
  526. SendMessage(WM_CHAR, '.', 0);
  527. }
  528. void CWordPadView::OnPenSpace()
  529. {
  530. SendMessage(WM_CHAR, ' ', 0);
  531. }
  532. void CWordPadView::OnPenTab()
  533. {
  534. SendMessage(WM_CHAR, VK_TAB, 0);
  535. }
  536. void CWordPadView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
  537. {
  538. if (nChar == VK_F10 && GetKeyState(VK_SHIFT) < 0)
  539. {
  540. long nStart, nEnd;
  541. GetRichEditCtrl().GetSel(nStart, nEnd);
  542. CPoint pt = GetRichEditCtrl().GetCharPos(nEnd);
  543. SendMessage(WM_CONTEXTMENU, (WPARAM)m_hWnd, MAKELPARAM(pt.x, pt.y));
  544. }
  545. CRichEditView::OnKeyDown(nChar, nRepCnt, nFlags);
  546. }
  547. HRESULT CWordPadView::GetClipboardData(CHARRANGE* lpchrg, DWORD /*reco*/,
  548. LPDATAOBJECT lpRichDataObj, LPDATAOBJECT* lplpdataobj)
  549. {
  550. CHARRANGE& cr = *lpchrg;
  551. if ((cr.cpMax - cr.cpMin == 1) &&
  552. GetRichEditCtrl().GetSelectionType() == SEL_OBJECT)
  553. {
  554. return E_NOTIMPL;
  555. }
  556. BeginWaitCursor();
  557. //create the data source
  558. COleDataSource* pDataSource = new COleDataSource;
  559. // put the formats into the data source
  560. LPENUMFORMATETC lpEnumFormatEtc;
  561. lpRichDataObj->EnumFormatEtc(DATADIR_SET, &lpEnumFormatEtc);
  562. if (lpEnumFormatEtc != NULL)
  563. {
  564. FORMATETC etc;
  565. while (lpEnumFormatEtc->Next(1, &etc, NULL) == S_OK)
  566. {
  567. STGMEDIUM stgMedium;
  568. lpRichDataObj->GetData(&etc, &stgMedium);
  569. pDataSource->CacheData(etc.cfFormat, &stgMedium, &etc);
  570. }
  571. lpEnumFormatEtc->Release();
  572. }
  573. CEmbeddedItem item(GetDocument(), cr.cpMin, cr.cpMax);
  574. item.m_lpRichDataObj = lpRichDataObj;
  575. // get wordpad formats
  576. item.GetClipboardData(pDataSource);
  577. // get the IDataObject from the data source
  578. *lplpdataobj =  (LPDATAOBJECT)pDataSource->GetInterface(&IID_IDataObject);
  579. EndWaitCursor();
  580. return S_OK;
  581. }
  582. HRESULT CWordPadView::QueryAcceptData(LPDATAOBJECT lpdataobj,
  583. CLIPFORMAT* lpcfFormat, DWORD reco, BOOL bReally,
  584. HGLOBAL hMetaPict)
  585. {
  586. if (bReally && *lpcfFormat == 0 && (m_nPasteType == 0))
  587. {
  588. COleDataObject dataobj;
  589. dataobj.Attach(lpdataobj, FALSE);
  590. if (!dataobj.IsDataAvailable(cfRTO)) // native avail, let richedit do as it wants
  591. {
  592. if (dataobj.IsDataAvailable(cfEmbeddedObject))
  593. {
  594. if (PasteNative(lpdataobj))
  595. return S_FALSE;
  596. }
  597. }
  598. }
  599. return CRichEditView::QueryAcceptData(lpdataobj, lpcfFormat, reco, bReally,
  600. hMetaPict);
  601. }
  602. BOOL CWordPadView::PasteNative(LPDATAOBJECT lpdataobj)
  603. {
  604. // check data object for wordpad object
  605. // if true, suck out RTF directly
  606. FORMATETC etc = {NULL, NULL, DVASPECT_CONTENT, -1, TYMED_ISTORAGE};
  607. etc.cfFormat = (CLIPFORMAT)cfEmbeddedObject;
  608. STGMEDIUM stgMedium = {TYMED_ISTORAGE, 0, NULL};
  609. // create an IStorage to transfer the data in
  610. LPLOCKBYTES lpLockBytes;
  611. if (FAILED(::CreateILockBytesOnHGlobal(NULL, TRUE, &lpLockBytes)))
  612. return FALSE;
  613. ASSERT(lpLockBytes != NULL);
  614. HRESULT hr = ::StgCreateDocfileOnILockBytes(lpLockBytes,
  615. STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, &stgMedium.pstg);
  616. lpLockBytes->Release(); //storage addref'd
  617. if (FAILED(hr))
  618. return FALSE;
  619. ASSERT(stgMedium.pstg != NULL);
  620. CLSID clsid;
  621. BOOL bRes = FALSE; //let richedit do what it wants
  622. if (SUCCEEDED(lpdataobj->GetDataHere(&etc, &stgMedium)) &&
  623. SUCCEEDED(ReadClassStg(stgMedium.pstg, &clsid)) &&
  624. clsid == GetDocument()->GetClassID())
  625. {
  626. //suck out RTF now
  627. // open Contents stream
  628. COleStreamFile file;
  629. CFileException fe;
  630. if (file.OpenStream(stgMedium.pstg, szContents,
  631. CFile::modeReadWrite|CFile::shareExclusive, &fe))
  632. {
  633. // load it with CArchive (loads from Contents stream)
  634. CArchive loadArchive(&file, CArchive::load |
  635. CArchive::bNoFlushOnDelete);
  636. Stream(loadArchive, TRUE); //stream in selection
  637. hr = TRUE; // don't let richedit do anything
  638. }
  639. }
  640. ::ReleaseStgMedium(&stgMedium);
  641. return bRes;
  642. }
  643. // things to fix
  644. // if format==0 we are doing a straight EM_PASTE
  645. //  look for native formats
  646. //      richedit specific -- allow richedit to handle (these will be first)
  647. //      look for RTF, CF_TEXT.  If there paste special as these
  648. //  Do standard OLE scenario
  649. // if pasting a particular format (format != 0)
  650. //  if richedit specific, allow through
  651. //  if RTF, CF_TEXT. paste special
  652. //  if OLE format, do standard OLE scenario
  653. void CWordPadView::OnFilePrint()
  654. {
  655. // don't allow winini changes to occur while printing
  656. m_bInPrint = TRUE;
  657. CRichEditView::OnFilePrint();
  658. // printer may have changed
  659. theApp.NotifyPrinterChanged(); // this will cause a GetDocument()->PrinterChanged();
  660. m_bInPrint = FALSE;
  661. }
  662. int CWordPadView::OnMouseActivate(CWnd* pWnd, UINT nHitTest, UINT message)
  663. {
  664. if (m_bOnBar)
  665. {
  666. SetFocus();
  667. return MA_ACTIVATEANDEAT;
  668. }
  669. else
  670. return CRichEditView::OnMouseActivate(pWnd, nHitTest, message);
  671. }
  672. typedef BOOL (WINAPI *PCWPROC)(HWND, LPSTR, UINT, LPVOID, DWORD, DWORD);
  673. void CWordPadView::OnPenLens()
  674. {
  675. USES_CONVERSION;
  676. HINSTANCE hLib = LoadLibrary(_T("PENWIN32.DLL"));
  677. if (hLib == NULL)
  678. return;
  679. PCWPROC pCorrectWriting = (PCWPROC)GetProcAddress(hLib, "CorrectWriting");
  680. ASSERT(pCorrectWriting != NULL);
  681. if (pCorrectWriting != NULL)
  682. {
  683. CHARRANGE cr;
  684. GetRichEditCtrl().GetSel(cr);
  685. int nCnt = 2*(cr.cpMax-cr.cpMin);
  686. BOOL bSel = (nCnt != 0);
  687. nCnt = max(1024, nCnt);
  688. char* pBuf = new char[nCnt];
  689. pBuf[0] = NULL;
  690. if (bSel)
  691. {
  692. #if (_MSC_VER > 1310) // VS2005
  693. CString strSelText = GetRichEditCtrl().GetSelText();
  694. strcpy_s(pBuf, nCnt, T2A((LPTSTR)(LPCTSTR)strSelText));
  695. #else
  696. GetRichEditCtrl().GetSelText(pBuf);
  697. #endif
  698. }
  699. if (pCorrectWriting(m_hWnd, pBuf, nCnt, 0, bSel ? 0 : CWR_INSERT, 0))
  700. GetRichEditCtrl().ReplaceSel(A2T(pBuf));
  701. delete [] pBuf;
  702. }
  703. FreeLibrary(hLib);
  704. }
  705. LRESULT CWordPadView::OnPrinterChangedMsg(WPARAM, LPARAM)
  706. {
  707. CDC dc;
  708. AfxGetApp()->CreatePrinterDC(dc);
  709. OnPrinterChanged(dc);
  710. return 0;
  711. }
  712. static void ForwardPaletteChanged(HWND hWndParent, HWND hWndFocus)
  713. {
  714. // this is a quick and dirty hack to send the WM_QUERYNEWPALETTE to a window that is interested
  715. HWND hWnd = NULL;
  716. for (hWnd = ::GetWindow(hWndParent, GW_CHILD); hWnd != NULL; hWnd = ::GetWindow(hWnd, GW_HWNDNEXT))
  717. {
  718. if (hWnd != hWndFocus)
  719. {
  720. ::SendMessage(hWnd, WM_PALETTECHANGED, (WPARAM)hWndFocus, 0L);
  721. ForwardPaletteChanged(hWnd, hWndFocus);
  722. }
  723. }
  724. }
  725. void CWordPadView::OnPaletteChanged(CWnd* pFocusWnd)
  726. {
  727. ForwardPaletteChanged(m_hWnd, pFocusWnd->GetSafeHwnd());
  728. // allow the richedit control to realize its palette
  729. // remove this if if richedit fixes their code so that
  730. // they don't realize their palette into foreground
  731. if (::GetWindow(m_hWnd, GW_CHILD) == NULL)
  732. CRichEditView::OnPaletteChanged(pFocusWnd);
  733. }
  734. static BOOL FindQueryPalette(HWND hWndParent)
  735. {
  736. // this is a quick and dirty hack to send the WM_QUERYNEWPALETTE to a window that is interested
  737. HWND hWnd = NULL;
  738. for (hWnd = ::GetWindow(hWndParent, GW_CHILD); hWnd != NULL; hWnd = ::GetWindow(hWnd, GW_HWNDNEXT))
  739. {
  740. if (::SendMessage(hWnd, WM_QUERYNEWPALETTE, 0, 0L))
  741. return TRUE;
  742. else if (FindQueryPalette(hWnd))
  743. return TRUE;
  744. }
  745. return FALSE;
  746. }
  747. BOOL CWordPadView::OnQueryNewPalette()
  748. {
  749. if(FindQueryPalette(m_hWnd))
  750. return TRUE;
  751. return CRichEditView::OnQueryNewPalette();
  752. }
  753. void CWordPadView::OnSettingChange(UINT uFlags, LPCTSTR lpszSection)
  754. {
  755. CRichEditView::OnSettingChange(uFlags, lpszSection);
  756. //printer might have changed
  757. if (!m_bInPrint)
  758. {
  759. if (lstrcmpi(lpszSection, _T("windows")) == 0)
  760. theApp.NotifyPrinterChanged(TRUE); // force update to defaults
  761. }
  762. }
  763. void CWordPadView::OnSize(UINT nType, int cx, int cy)
  764. {
  765. CRichEditView::OnSize(nType, cx, cy);
  766. CRect rect(HORZ_TEXTOFFSET, VERT_TEXTOFFSET, cx, cy);
  767. GetRichEditCtrl().SetRect(rect);
  768. }
  769. void CWordPadView::OnGetCharFormat(NMHDR* pNMHDR, LRESULT* pRes)
  770. {
  771. ASSERT(pNMHDR != NULL);
  772. ASSERT(pRes != NULL);
  773. ((NMXTPCHARHDR*)pNMHDR)->cf = GetCharFormatSelection();
  774. *pRes = 1;
  775. }
  776. void CWordPadView::OnSetCharFormat(NMHDR* pNMHDR, LRESULT* pRes)
  777. {
  778. ASSERT(pNMHDR != NULL);
  779. ASSERT(pRes != NULL);
  780. #if (_MSC_VER < 1300)
  781. CHARFORMAT& cf = ((NMXTPCHARHDR*)pNMHDR)->cf;
  782. #else
  783. CHARFORMAT2 cf;
  784. MEMCPY_S(&cf, &((NMXTPCHARHDR*)pNMHDR)->cf, sizeof(((NMXTPCHARHDR*)pNMHDR)->cf));
  785. #endif
  786. SetCharFormat(cf);
  787. *pRes = 1;
  788. }
  789. void CWordPadView::OnUpdateComboFont(CCmdUI* pCmd)
  790. {
  791. CXTPCommandBar* pToolBar = (CXTPToolBar*)pCmd->m_pOther;
  792. if (pToolBar)
  793. {
  794. CXTPControlFontComboBox* pFontCombo = (CXTPControlFontComboBox*)pToolBar->GetControls()->GetAt(pCmd->m_nIndex);
  795. if (pFontCombo->GetType() == xtpControlComboBox)
  796. {
  797. pFontCombo->SetCharFormat((CHARFORMAT&)GetCharFormatSelection());
  798. }
  799. }
  800. pCmd->Enable(TRUE);
  801. }
  802. void CWordPadView::OnUpdateComboSize(CCmdUI* pCmd)
  803. {
  804. CXTPCommandBar* pToolBar = (CXTPToolBar*)pCmd->m_pOther;
  805. if (pToolBar)
  806. {
  807. CXTPControlSizeComboBox* pSizeCombo = (CXTPControlSizeComboBox*)pToolBar->GetControls()->GetAt(pCmd->m_nIndex);
  808. if (pSizeCombo->GetType() == xtpControlComboBox)
  809. {
  810. CHARFORMAT& cf = GetCharFormatSelection();
  811. pSizeCombo->SetTwipSize( (cf.dwMask & CFM_SIZE) ? cf.yHeight : -1);
  812. }
  813. }
  814. pCmd->Enable(TRUE);
  815. }
  816. void CWordPadView::OnUpdateSelectorText(CCmdUI* pCmd)
  817. {
  818. CXTPCommandBar* pToolBar = (CXTPToolBar*)pCmd->m_pOther;
  819. if (pToolBar)
  820. {
  821. CHARFORMAT& cfm = GetCharFormatSelection( );
  822. CXTPControlColorSelector* pSelector = (CXTPControlColorSelector*)pToolBar->GetControls()->GetAt(pCmd->m_nIndex);
  823. pSelector->SetColor(cfm.dwEffects & CFE_AUTOCOLOR? -1: cfm.crTextColor);
  824. }
  825. pCmd->Enable(TRUE);
  826. }
  827. void CWordPadView::OnButtonText()
  828. {
  829. CHARFORMAT& cfm = GetCharFormatSelection( );
  830. cfm.dwMask |= CFM_COLOR;
  831. cfm.dwEffects &= ~CFE_AUTOCOLOR ;
  832. cfm.crTextColor = m_clr;
  833. GetRichEditCtrl().SetSelectionCharFormat(cfm);
  834. }
  835. void CWordPadView::OnSelectorText(NMHDR* pNMHDR, LRESULT* pResult)
  836. {
  837. NMXTPCONTROL* tagNMCONTROL = (NMXTPCONTROL*)pNMHDR;
  838. CXTPControlColorSelector* pControl = (CXTPControlColorSelector*)tagNMCONTROL->pControl;
  839. m_clr = pControl->GetColor();
  840. OnButtonText();
  841. *pResult = 1;
  842. }
  843. void CWordPadView::OnUpdateText(CCmdUI* pCmd)
  844. {
  845. CXTPCommandBar* pToolBar = (CXTPToolBar*)pCmd->m_pOther;
  846. if (pToolBar)
  847. {
  848. CXTPControlPopupColor* pPopup = (CXTPControlPopupColor*)pToolBar->GetControls()->GetAt(pCmd->m_nIndex);
  849. pPopup->SetColor(m_clr);
  850. }
  851. pCmd->Enable(TRUE);
  852. }
  853. void CWordPadView::OnTextAuto()
  854. {
  855. CHARFORMAT& cfm = GetCharFormatSelection( );
  856. cfm.dwMask |= CFM_COLOR;
  857. cfm.dwEffects |= CFE_AUTOCOLOR ;
  858. GetRichEditCtrl().SetSelectionCharFormat(cfm);
  859. m_clr = GetSysColor(COLOR_BTNTEXT);
  860. }
  861. void CWordPadView::OnUpdateTextAuto(CCmdUI* pCmd)
  862. {
  863. CHARFORMAT& cfm = GetCharFormatSelection( );
  864. pCmd->SetCheck(cfm.dwEffects & CFE_AUTOCOLOR? TRUE: FALSE);
  865. }
  866. void CWordPadView::OnTextMore()
  867. {
  868. CColorDialog cd(m_clr);
  869. if (cd.DoModal())
  870. {
  871. m_clr = cd.GetColor();
  872. OnButtonText();
  873. }
  874. }
  875. void CWordPadView::OnEditUndo(NMHDR* pNMHDR, LRESULT* pResult)
  876. {
  877. if (((NMXTPCONTROL*)pNMHDR)->pControl->GetType() == xtpControlSplitButtonPopup)
  878. {
  879. CRichEditView::OnEditUndo();
  880. *pResult = 1; // Handled;
  881. }
  882. CXTPControlListBox* pControlListBox = DYNAMIC_DOWNCAST(CXTPControlListBox, ((NMXTPCONTROL*)pNMHDR)->pControl);
  883. if (pControlListBox)
  884. {
  885. CString str;
  886. str.Format(_T("Undo last %i actions"), pControlListBox->GetListCtrl()->GetSelCount());
  887. AfxMessageBox(str);
  888. *pResult = 1; // Handled;
  889. }
  890. }
  891. CXTPControlStatic* CWordPadView::FindInfoControl(CXTPControl* pControl)
  892. {
  893. CXTPCommandBar* pCommandBar = pControl->GetParent();
  894. for (int i = 0; i < pCommandBar->GetControls()->GetCount(); i++)
  895. {
  896. CXTPControlStatic* pControlStatic = DYNAMIC_DOWNCAST(CXTPControlStatic, pCommandBar->GetControl(i));
  897. if (pControlStatic && pControlStatic->GetID() == pControl->GetID())
  898. {
  899. return pControlStatic;
  900. }
  901. }
  902. return NULL;
  903. }
  904. void CWordPadView::OnListBoxControlSelChange(NMHDR* pNMHDR, LRESULT* pRes)
  905. {
  906. ASSERT(pNMHDR != NULL);
  907. ASSERT(pRes != NULL);
  908. CXTPControlListBox* pControlListBox = DYNAMIC_DOWNCAST(CXTPControlListBox, ((NMXTPCONTROL*)pNMHDR)->pControl);
  909. if (pControlListBox)
  910. {
  911. CXTPControlStatic* pInfo = FindInfoControl(pControlListBox);
  912. if (pInfo)
  913. {
  914. CString str;
  915. str.Format(_T("Undo %i Actions"), pControlListBox->GetListCtrl()->GetSelCount());
  916. pInfo->SetCaption(str);
  917. pInfo->DelayRedrawParent();
  918. }
  919. *pRes = 1;
  920. }
  921. }
  922. void CWordPadView::OnListBoxControlPoup(NMHDR* pNMHDR, LRESULT* pRes)
  923. {
  924. ASSERT(pNMHDR != NULL);
  925. ASSERT(pRes != NULL);
  926. CXTPControlListBox* pControlListBox = DYNAMIC_DOWNCAST(CXTPControlListBox, ((NMXTPCONTROL*)pNMHDR)->pControl);
  927. if (pControlListBox)
  928. {
  929. CListBox* pListBox = pControlListBox->GetListCtrl();
  930. pListBox->ResetContent();
  931. int nCount = RAND_S() % 20 + 3;
  932. for (int i = 0; i < nCount; i++)
  933. {
  934. CString str;
  935. str.Format(_T("Undo String %i"), i + 1);
  936. pListBox->AddString(str);
  937. }
  938. CXTPControlStatic* pInfo = FindInfoControl(pControlListBox);
  939. if (pInfo)
  940. {
  941. CString str;
  942. pInfo->SetCaption(_T("Undo 0 Actions"));
  943. pInfo->DelayRedrawParent();
  944. }
  945. *pRes = 1;
  946. }
  947. }
  948. void CWordPadView::OnColumnsSelChange(NMHDR* pNMHDR, LRESULT* pRes)
  949. {
  950. ASSERT(pNMHDR != NULL);
  951. ASSERT(pRes != NULL);
  952. CControlColumns* pControlColumns = DYNAMIC_DOWNCAST(CControlColumns, ((NMXTPCONTROL*)pNMHDR)->pControl);
  953. if (pControlColumns)
  954. {
  955. CXTPControlStatic* pInfo = FindInfoControl(pControlColumns);
  956. if (pInfo)
  957. {
  958. int nCount = pControlColumns->m_szItemsActive.cx;
  959. CString str = _T("Cancel");
  960. if (nCount != 0)
  961. {
  962. str.Format(_T("%i Columns"), nCount);
  963. }
  964. pInfo->SetWidth(pControlColumns->m_szItem.cx * pControlColumns->m_szItemsVisible.cx);
  965. pInfo->SetCaption(str);
  966. pInfo->DelayRedrawParent();
  967. }
  968. *pRes = 1;
  969. }
  970. }
  971. void CWordPadView::OnInsertTable(NMHDR* pNMHDR, LRESULT* pResult)
  972. {
  973. CControlTable* pControlTable = DYNAMIC_DOWNCAST(CControlTable, ((NMXTPCONTROL*)pNMHDR)->pControl);
  974. if (pControlTable)
  975. {
  976. CSize szActive = pControlTable->m_szResult;
  977. CString str;
  978. str.Format(_T("<%i x %i Table>"), szActive.cx, szActive.cy);
  979. GetRichEditCtrl().ReplaceSel(str);
  980. *pResult = 1; // Handled;
  981. }
  982. }
  983. void CWordPadView::OnInsertColumns(NMHDR* pNMHDR, LRESULT* pResult)
  984. {
  985. CControlColumns* pControlColumns = DYNAMIC_DOWNCAST(CControlColumns, ((NMXTPCONTROL*)pNMHDR)->pControl);
  986. if (pControlColumns)
  987. {
  988. int nCount = pControlColumns->m_szResult.cx;
  989. CString str;
  990. str.Format(_T("<%i Columns>"), nCount);
  991. GetRichEditCtrl().ReplaceSel(str);
  992. *pResult = 1; // Handled;
  993. }
  994. }
  995. void CWordPadView::OnTableSelChange(NMHDR* pNMHDR, LRESULT* pRes)
  996. {
  997. ASSERT(pNMHDR != NULL);
  998. ASSERT(pRes != NULL);
  999. CControlTable* pControlTable = DYNAMIC_DOWNCAST(CControlTable, ((NMXTPCONTROL*)pNMHDR)->pControl);
  1000. if (pControlTable)
  1001. {
  1002. CXTPControlStatic* pInfo = FindInfoControl(pControlTable);
  1003. if (pInfo)
  1004. {
  1005. CSize szActive = pControlTable->m_szItemsActive;
  1006. CString str = _T("Cancel");
  1007. if (szActive != CSize(0))
  1008. {
  1009. str.Format(_T("%i x %i Table"), szActive.cx, szActive.cy);
  1010. }
  1011. pInfo->SetWidth(pControlTable->m_szItem.cx * pControlTable->m_szItemsVisible.cx);
  1012. pInfo->SetCaption(str);
  1013. pInfo->DelayRedrawParent();
  1014. }
  1015. *pRes = 1;
  1016. }
  1017. }
  1018. void CWordPadView::ShowContextMenu(CPoint point)
  1019. {
  1020. ClientToScreen(&point);
  1021. ((CXTPFrameWnd*)AfxGetMainWnd())->GetCommandBars()->
  1022. TrackPopupMenu(IDR_TEXT_POPUP, TPM_RIGHTBUTTON, point.x, point.y);
  1023. }
  1024. void CWordPadView::OnRButtonDown(UINT /*nFlags*/, CPoint point)
  1025. {
  1026. ShowContextMenu(point);
  1027. }
  1028. void CWordPadView::OnContextMenu(CWnd* /*pWnd*/, CPoint point)
  1029. {
  1030. ShowContextMenu(point);
  1031. }