home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 December / PCWKCD1296.iso / vjplusb / activex / inetsdk / samples / urlpad / padview.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-29  |  17.7 KB  |  653 lines

  1. //=------------------------------------------------------------------------=
  2. // PadView.Cpp
  3. //=------------------------------------------------------------------------=
  4. // Copyright 1992-1996 Microsoft Corporation.  All Rights Reserved.
  5. //
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  7. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  8. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  9. // PARTICULAR PURPOSE.
  10. //=--------------------------------------------------------------------------=
  11. //
  12. // implementation of the CPadView class
  13. //
  14.  
  15. #include "stdafx.h"
  16. #include "superpad.h"
  17. #include "padview.h"
  18. #include "paditem.h"
  19. #include "linkitem.h"
  20. #include "tabstop.h"
  21. #include <afxpriv.h>
  22. #include <stdlib.h>
  23.  
  24. #ifdef _DEBUG
  25. #undef THIS_FILE
  26. static char BASED_CODE THIS_FILE[] = __FILE__;
  27. #endif
  28.  
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CPadView
  31.  
  32. IMPLEMENT_DYNCREATE(CPadView, CEditView)
  33.  
  34. BEGIN_MESSAGE_MAP(CPadView, CEditView)
  35.     //{{AFX_MSG_MAP(CPadView)
  36.     ON_WM_CREATE()    
  37.     ON_COMMAND(ID_CHOOSE_FONT, OnChooseFont)
  38.     ON_COMMAND(ID_WORD_WRAP, OnWordWrap)
  39.     ON_UPDATE_COMMAND_UI(ID_WORD_WRAP, OnUpdateWordWrap)
  40.     ON_WM_RBUTTONDOWN()
  41.     ON_COMMAND(ID_CHOOSE_PRINT_FONT, OnChoosePrintFont)
  42.     ON_COMMAND(ID_MIRROR_DISPLAY_FONT, OnMirrorDisplayFont)
  43.     ON_UPDATE_COMMAND_UI(ID_MIRROR_DISPLAY_FONT, OnUpdateMirrorDisplayFont)
  44.     ON_UPDATE_COMMAND_UI(ID_CHOOSE_PRINT_FONT, OnUpdateChoosePrintFont)
  45.     ON_WM_SIZE()
  46.     ON_CONTROL_REFLECT(EN_CHANGE, OnEditChange)
  47.     ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
  48.     ON_COMMAND(ID_EDIT_CUT, OnEditCut)
  49.     ON_WM_TIMER()
  50.     //}}AFX_MSG_MAP
  51.     ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
  52.  
  53.     #ifndef _MAC
  54.         ON_COMMAND(ID_SET_TABSTOPS, OnSetTabStops)
  55.     #endif
  56.  
  57. END_MESSAGE_MAP()
  58.  
  59. UINT CPadView::m_nDefTabStops;
  60. UINT CPadView::m_nDefTabStopsOld;
  61. BOOL CPadView::m_bDefWordWrap;
  62. BOOL CPadView::m_bDefWordWrapOld;
  63. LOGFONT NEAR CPadView::m_lfDefFont;
  64. LOGFONT NEAR CPadView::m_lfDefFontOld;
  65. LOGFONT NEAR CPadView::m_lfDefPrintFont;
  66. LOGFONT NEAR CPadView::m_lfDefPrintFontOld;
  67.  
  68. /////////////////////////////////////////////////////////////////////////////
  69. // Static initialization/termination
  70.  
  71. static TCHAR BASED_CODE szSettings[] = _T("Settings");
  72. static TCHAR BASED_CODE szTabStops[] = _T("TabStops");
  73. static TCHAR BASED_CODE szFont[] = _T("Font");
  74. static TCHAR BASED_CODE szPrintFont[] = _T("PrintFont");
  75. static TCHAR BASED_CODE szHeight[] = _T("Height");
  76. static TCHAR BASED_CODE szWeight[] = _T("Weight");
  77. static TCHAR BASED_CODE szItalic[] = _T("Italic");
  78. static TCHAR BASED_CODE szUnderline[] = _T("Underline");
  79. static TCHAR BASED_CODE szPitchAndFamily[] = _T("PitchAndFamily");
  80. static TCHAR BASED_CODE szCharSet[] = _T("CharSet");
  81. static TCHAR BASED_CODE szFaceName[] = _T("FaceName");
  82. static TCHAR BASED_CODE szSystem[] = _T("System");
  83. static TCHAR BASED_CODE szWordWrap[] = _T("WordWrap");
  84.  
  85. static void GetProfileFont(LPCTSTR szSec, LOGFONT* plf)
  86. {
  87.     CWinApp* pApp = AfxGetApp();
  88.     plf->lfHeight = pApp->GetProfileInt(szSec, szHeight, 0);
  89.     if (plf->lfHeight != 0)
  90.     {
  91.         plf->lfWeight = pApp->GetProfileInt(szSec, szWeight, 0);
  92.         plf->lfItalic = (BYTE)pApp->GetProfileInt(szSec, szItalic, 0);
  93.         plf->lfUnderline = (BYTE)pApp->GetProfileInt(szSec, szUnderline, 0);
  94.         plf->lfPitchAndFamily = (BYTE)pApp->GetProfileInt(szSec, szPitchAndFamily, 0);
  95.         plf->lfCharSet = (BYTE)pApp->GetProfileInt(szSec, szCharSet, DEFAULT_CHARSET);
  96.         CString strFont = pApp->GetProfileString(szSec, szFaceName, szSystem);
  97.         lstrcpyn((TCHAR*)plf->lfFaceName, strFont, sizeof plf->lfFaceName);
  98.         plf->lfFaceName[sizeof plf->lfFaceName-1] = 0;
  99.     }
  100. }
  101.  
  102. static void WriteProfileFont(LPCTSTR szSec, const LOGFONT* plf, LOGFONT* plfOld)
  103. {
  104.     CWinApp* pApp = AfxGetApp();
  105.  
  106.     if (plf->lfHeight != plfOld->lfHeight)
  107.         pApp->WriteProfileInt(szSec, szHeight, plf->lfHeight);
  108.     if (plf->lfHeight != 0)
  109.     {
  110.         if (plf->lfHeight != plfOld->lfHeight)
  111.             pApp->WriteProfileInt(szSec, szHeight, plf->lfHeight);
  112.         if (plf->lfWeight != plfOld->lfWeight)
  113.             pApp->WriteProfileInt(szSec, szWeight, plf->lfWeight);
  114.         if (plf->lfItalic != plfOld->lfItalic)
  115.             pApp->WriteProfileInt(szSec, szItalic, plf->lfItalic);
  116.         if (plf->lfUnderline != plfOld->lfUnderline)
  117.             pApp->WriteProfileInt(szSec, szUnderline, plf->lfUnderline);
  118.         if (plf->lfPitchAndFamily != plfOld->lfPitchAndFamily)
  119.             pApp->WriteProfileInt(szSec, szPitchAndFamily, plf->lfPitchAndFamily);
  120.         if (plf->lfCharSet != plfOld->lfCharSet)
  121.             pApp->WriteProfileInt(szSec, szCharSet, plf->lfCharSet);
  122.         if (_tcscmp(plf->lfFaceName, plfOld->lfFaceName) != 0)
  123.             pApp->WriteProfileString(szSec, szFaceName, (LPCTSTR)plf->lfFaceName);
  124.     }
  125.     *plfOld = *plf;
  126. }
  127.  
  128. void CPadView::Initialize()
  129. {
  130.     CWinApp* pApp = AfxGetApp();
  131.     m_bDefWordWrap = pApp->GetProfileInt(szSettings, szWordWrap, 0);
  132.     m_bDefWordWrapOld = m_bDefWordWrap;
  133.     m_nDefTabStops = pApp->GetProfileInt(szSettings, szTabStops, 8*4);
  134.     m_nDefTabStopsOld = m_nDefTabStops;
  135.     GetProfileFont(szFont, &m_lfDefFont);
  136.     m_lfDefFontOld = m_lfDefFont;
  137.     GetProfileFont(szPrintFont, &m_lfDefPrintFont);
  138.     m_lfDefPrintFontOld = m_lfDefPrintFont;
  139. }
  140.  
  141. void CPadView::Terminate()
  142. {
  143.     CWinApp* pApp = AfxGetApp();
  144.     if (m_nDefTabStops != m_nDefTabStopsOld)
  145.         pApp->WriteProfileInt(szSettings, szTabStops, m_nDefTabStops);
  146.     if (m_bDefWordWrap != m_bDefWordWrapOld)
  147.         pApp->WriteProfileInt(szSettings, szWordWrap, m_bDefWordWrap);
  148.     WriteProfileFont(szFont, &m_lfDefFont, &m_lfDefFontOld);
  149.     WriteProfileFont(szPrintFont, &m_lfDefPrintFont, &m_lfDefPrintFontOld);
  150. }
  151.  
  152. /////////////////////////////////////////////////////////////////////////////
  153. // CPadView construction/destruction
  154.  
  155. CPadView::CPadView()
  156. {
  157.     #ifndef _MAC
  158.         m_nTabStops = m_nDefTabStops;
  159.     #endif
  160.  
  161.     m_uTimerID = 0;
  162. }
  163.  
  164. BOOL CPadView::PreCreateWindow(CREATESTRUCT& cs)
  165. {
  166.     if (!CEditView::PreCreateWindow(cs))
  167.         return FALSE;
  168.  
  169.     if (m_bDefWordWrap)
  170.         cs.style &= ~(WS_HSCROLL|ES_AUTOHSCROLL);
  171.  
  172.     return TRUE;
  173. }
  174.  
  175. int CPadView::OnCreate(LPCREATESTRUCT lpcs)
  176. {
  177.     if (CEditView::OnCreate(lpcs) != 0)
  178.         return -1;
  179.     if (m_lfDefFont.lfHeight != 0)
  180.     {
  181.         m_font.CreateFontIndirect(&m_lfDefFont);
  182.         SetFont(&m_font);
  183.     }
  184.     if (m_lfDefPrintFont.lfHeight != 0)
  185.     {
  186.         m_fontPrint.CreateFontIndirect(&m_lfDefPrintFont);
  187.         SetPrinterFont(&m_fontPrint);
  188.     }
  189.     return 0;
  190. }
  191.  
  192. /////////////////////////////////////////////////////////////////////////////
  193. // CPadView Word Wrap support
  194.  
  195. BOOL CPadView::IsWordWrap() const
  196. {
  197.     return (GetStyle() & ES_AUTOHSCROLL) == 0;
  198. }
  199.  
  200. BOOL CPadView::SetWordWrap(BOOL bWordWrap)
  201. {
  202.     bWordWrap = !!bWordWrap;    // make sure ==TRUE || ==FALSE
  203.     if (IsWordWrap() == bWordWrap)
  204.         return FALSE;
  205.  
  206.     // preserve original control's state.
  207.     CFont* pFont = GetFont();
  208.     int nLen = GetBufferLength();
  209.     TCHAR* pSaveText = new TCHAR[GetBufferLength()+1];
  210.     GetWindowText(pSaveText, nLen+1);
  211.  
  212.     // create new edit control with appropriate style and size.
  213.     DWORD dwStyle = dwStyleDefault & ~(ES_AUTOHSCROLL|WS_HSCROLL|WS_VISIBLE);
  214.     if (!bWordWrap)
  215.         dwStyle |= ES_AUTOHSCROLL|WS_HSCROLL;
  216.  
  217.     CWnd* pParent = GetParent();
  218.     CRect rect;
  219.     GetWindowRect(rect);
  220.     pParent->ScreenToClient(rect);
  221.     CWnd* pFocus = GetFocus();
  222.  
  223.     UINT nID = GetDlgCtrlID();
  224.  
  225.     HWND hWnd = ::CreateWindow(_T("edit"), NULL, dwStyle,
  226.         rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,
  227.         pParent->m_hWnd, (HMENU)nID, AfxGetInstanceHandle(), NULL);
  228.  
  229.     if (hWnd == NULL)
  230.     {
  231.         delete[] pSaveText;
  232.         return FALSE;
  233.     }
  234.  
  235.     // set the window text to nothing to make sure following set doesn't fail
  236.     SetWindowText(NULL);
  237.  
  238.     // restore visual state
  239.     ::SetWindowText(hWnd, pSaveText);
  240.     delete[] pSaveText;
  241.     if (pFont != NULL)
  242.     {
  243.         ASSERT(pFont->m_hObject != NULL);
  244.         ::SendMessage(hWnd, WM_SETFONT, (WPARAM)pFont->m_hObject, 0);
  245.     }
  246.  
  247.     // detach old window, attach new
  248.     SetDlgCtrlID(nID+1);
  249.     HWND hWndOld = Detach();
  250.     ::SetWindowLong(hWndOld, GWL_WNDPROC, (LONG)*GetSuperWndProcAddr());
  251.     ASSERT(m_hWnd == NULL);
  252.     SubclassWindow(hWnd);
  253.     ASSERT(m_hWnd == hWnd);
  254.     GetParentFrame()->SendMessage(WM_RECALCPARENT);
  255.     
  256.     #ifndef _MAC
  257.         UINT nTabStops = m_nTabStops;
  258.         GetEditCtrl().SetTabStops(nTabStops);
  259.     #endif
  260.     
  261.     GetClientRect(&rect);
  262.     SetWindowPos(NULL, 0, 0, 0, 0,
  263.         SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOZORDER|SWP_SHOWWINDOW);
  264.     SetWindowPos(NULL, 0, 0, 0, 0,
  265.         SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|SWP_NOZORDER|SWP_DRAWFRAME);
  266.     SetWindowPos(NULL, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE);
  267.     UpdateWindow();
  268.  
  269.     // destroy old
  270.     ::SetWindowPos(hWndOld, NULL, 0, 0, 0, 0,
  271.         SWP_HIDEWINDOW|SWP_NOREDRAW|SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE|
  272.         SWP_NOZORDER);
  273.     ::DestroyWindow(hWndOld);
  274.  
  275.     // restore rest of state...
  276.     GetEditCtrl().LimitText(nMaxSize);
  277.     if (pFocus == this)
  278.         SetFocus();
  279.  
  280.     // notify container that doc changed
  281.     GetDocument()->UpdateAllItems(NULL);
  282.  
  283.     ASSERT_VALID(this);
  284.     return TRUE;
  285. }
  286.  
  287. /////////////////////////////////////////////////////////////////////////////
  288. // CPadView Printing support
  289.  
  290. void CPadView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
  291. {
  292.     CEditView::OnBeginPrinting(pDC, pInfo);
  293.  
  294.     LPCTSTR pszFileName = GetDocument()->GetPathName();
  295.     BOOL bForceSysTime = _tcschr(pszFileName, '.') == NULL;
  296.     CTime timeSys = CTime::GetCurrentTime();
  297.     CFileStatus status;
  298.     CFile::GetStatus(pszFileName, status);
  299.  
  300.     if (dlgPageSetup.m_iHeaderTime != 0 || bForceSysTime)
  301.         m_timeHeader = timeSys;
  302.     else
  303.         m_timeHeader = status.m_mtime;
  304.  
  305.     if (dlgPageSetup.m_iFooterTime != 0 || bForceSysTime)
  306.         m_timeFooter = timeSys;
  307.     else
  308.         m_timeFooter = status.m_mtime;
  309.  
  310.     if (!pInfo->m_bPreview)
  311.         return;
  312.  
  313.     CWaitCursor wait;
  314.     pInfo->m_nCurPage = 0xFFFF;
  315.     OnPrepareDC(pDC, pInfo);
  316.  
  317.     UINT nIndex = LOWORD(GetEditCtrl().GetSel());
  318.     UINT nCurPage = 1;
  319.     while (nCurPage < (UINT)m_aPageStart.GetSize())
  320.     {
  321.         if (nIndex < m_aPageStart[nCurPage])
  322.             break;
  323.         nCurPage++;
  324.     }
  325.     pInfo->m_nCurPage = nCurPage;
  326.     pInfo->SetMaxPage(m_aPageStart.GetSize());
  327.     m_nPreviewPage = nCurPage;
  328. }
  329.  
  330. void CPadView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
  331. {
  332.     // get string to show as "filename" in header/footer
  333.     LPCTSTR pszFileName = GetDocument()->GetPathName();
  334.     if (pszFileName[0] == 0)
  335.         pszFileName = GetDocument()->GetTitle();
  336.  
  337.     // go thru global CPageSetupDlg to format the header and footer
  338.     CString strHeader;
  339.     dlgPageSetup.FormatHeader(strHeader, m_timeHeader, pszFileName,
  340.         pInfo->m_nCurPage);
  341.     CString strFooter;
  342.     dlgPageSetup.FormatFooter(strFooter, m_timeFooter, pszFileName,
  343.         pInfo->m_nCurPage);
  344.  
  345.     TEXTMETRIC tm;
  346.     pDC->GetTextMetrics(&tm);
  347.     int cyChar = tm.tmHeight;
  348.     CRect rectPage = pInfo->m_rectDraw;
  349.  
  350.     // draw and exclude space for header
  351.     if (!strHeader.IsEmpty())
  352.     {
  353.         pDC->TextOut(rectPage.left, rectPage.top, strHeader);
  354.         rectPage.top += cyChar + cyChar / 4;
  355.         pDC->MoveTo(rectPage.left, rectPage.top);
  356.         pDC->LineTo(rectPage.right, rectPage.top);
  357.         rectPage.top += cyChar / 4;
  358.     }
  359.  
  360.     // allow space for footer
  361.     pInfo->m_rectDraw = rectPage;
  362.     if (!strFooter.IsEmpty())
  363.         pInfo->m_rectDraw.bottom -= cyChar + cyChar/4 + cyChar/4;
  364.  
  365.     // draw body text
  366.     CEditView::OnPrint(pDC, pInfo);
  367.  
  368.     // draw footer
  369.     if (!strFooter.IsEmpty())
  370.     {
  371.         rectPage.bottom -= cyChar;
  372.         pDC->TextOut(rectPage.left, rectPage.bottom, strFooter);
  373.         rectPage.bottom -= cyChar / 4;
  374.         pDC->MoveTo(rectPage.left, rectPage.bottom);
  375.         pDC->LineTo(rectPage.right, rectPage.bottom);
  376.         rectPage.bottom -= cyChar / 4;
  377.     }
  378. }
  379.  
  380. void CPadView::OnScrollTo(CDC*, CPrintInfo* pInfo, POINT)
  381. {
  382.     UINT nPage = pInfo->m_nCurPage;
  383.     ASSERT(nPage < (UINT)m_aPageStart.GetSize());
  384.     if (nPage != m_nPreviewPage)
  385.     {
  386.         UINT nIndex = m_aPageStart[nPage];
  387.         GetEditCtrl().SetSel((int)nIndex, (int)nIndex);
  388.     }
  389. }
  390.  
  391. /////////////////////////////////////////////////////////////////////////////
  392. // CPadView Font Handling
  393.  
  394. void CPadView::OnChooseFont()
  395. {
  396.    // get current font description
  397.    CFont* pFont = GetFont();
  398.    LOGFONT lf;
  399.    if (pFont != NULL)
  400.        pFont->GetObject(sizeof(LOGFONT), &lf);
  401.    else
  402.        ::GetObject(GetStockObject(SYSTEM_FONT), sizeof(LOGFONT), &lf);
  403.  
  404.     CFontDialog dlg(&lf, CF_SCREENFONTS|CF_INITTOLOGFONTSTRUCT);
  405.     if (dlg.DoModal() == IDOK)
  406.     {
  407.         // switch to new font.
  408.         m_font.DeleteObject();
  409.         if (m_font.CreateFontIndirect(&lf))
  410.         {
  411.             CWaitCursor wait;
  412.             SetFont(&m_font);
  413.             m_lfDefFont = lf;
  414.  
  415.             if (GetPrinterFont() == NULL)
  416.             {
  417.                 // notify container that content has changed
  418.                 GetDocument()->UpdateAllItems(NULL);
  419.             }
  420.         }
  421.     }
  422. }
  423.  
  424. static void ScaleLogFont(LPLOGFONT plf, const CDC& dcFrom, const CDC& dcTo)
  425.     // helper to scale log font member from one DC to another!
  426. {
  427.     plf->lfHeight = MulDiv(plf->lfHeight,
  428.         dcTo.GetDeviceCaps(LOGPIXELSY), dcFrom.GetDeviceCaps(LOGPIXELSY));
  429.     plf->lfWidth = MulDiv(plf->lfWidth,
  430.         dcTo.GetDeviceCaps(LOGPIXELSX), dcFrom.GetDeviceCaps(LOGPIXELSX));
  431. }
  432.  
  433. void CPadView::OnChoosePrintFont()
  434. {
  435.     CWaitCursor wait;
  436.     CFont* pFont = GetPrinterFont();
  437.     LOGFONT lf;
  438.     LPLOGFONT plf = NULL;
  439.     if (pFont != NULL)
  440.     {
  441.         pFont->GetObject(sizeof(LOGFONT), &lf);
  442.         plf = &lf;
  443.     }
  444.  
  445.     // magic to get printer dialog that would be used if we were printing!
  446.     CPrintDialog dlgPrint(FALSE);
  447.     if (!AfxGetApp()->GetPrinterDeviceDefaults(&dlgPrint.m_pd))
  448.     {
  449.         AfxMessageBox(IDP_ERR_GET_DEVICE_DEFAULTS);
  450.         return;
  451.     }
  452.     wait.Restore();
  453.     HDC hdcPrint = dlgPrint.CreatePrinterDC();
  454.     if (hdcPrint == NULL)
  455.     {
  456.         AfxMessageBox(IDP_ERR_GET_PRINTER_DC);
  457.         return;
  458.     }
  459.  
  460.     CDC dcScreen;
  461.     dcScreen.Attach(::GetDC(NULL));
  462.     CDC dcPrint;
  463.     dcPrint.Attach(hdcPrint);
  464.  
  465.     if (plf != NULL)
  466.     {
  467.         // need to map initial logfont to screen metrics.
  468.         ::ScaleLogFont(plf, dcPrint, dcScreen);
  469.     }
  470.  
  471.     // now bring up the dialog since we know the printer DC
  472.     CFontDialog dlg(plf, CF_PRINTERFONTS, &dcPrint);
  473.     if (dlg.DoModal() == IDOK)
  474.     {
  475.         // map the resulting logfont back to printer metrics.
  476.         lf = dlg.m_lf;
  477.         ::ScaleLogFont(&lf, dcScreen, dcPrint);
  478.  
  479.         m_fontPrint.DeleteObject();
  480.         if (m_fontPrint.CreateFontIndirect(&lf))
  481.         {
  482.             SetPrinterFont(&m_fontPrint);
  483.             m_lfDefPrintFont = lf;
  484.  
  485.             // notify container that content has changed
  486.             GetDocument()->UpdateAllItems(NULL);
  487.         }
  488.     }
  489.     //NOTE: destructor will call dcPrint.DeleteDC
  490.  
  491.     ::ReleaseDC(NULL, dcScreen.Detach());
  492. }
  493.  
  494. void CPadView::OnMirrorDisplayFont()
  495. {
  496.     if (GetPrinterFont() != NULL)
  497.     {
  498.         SetPrinterFont(NULL);
  499.         m_lfDefPrintFont.lfHeight = 0;
  500.  
  501.         // notify container that content changed
  502.         GetDocument()->UpdateAllItems(NULL);
  503.     }
  504. }
  505.  
  506. void CPadView::OnUpdateChoosePrintFont(CCmdUI* pCmdUI)
  507. {
  508.     pCmdUI->SetCheck(GetPrinterFont() != NULL);
  509. }
  510.  
  511. void CPadView::OnUpdateMirrorDisplayFont(CCmdUI* pCmdUI)
  512. {
  513.     pCmdUI->SetCheck(GetPrinterFont() == NULL);
  514. }
  515.  
  516. /////////////////////////////////////////////////////////////////////////////
  517. // CPadView Tab Stops
  518.  
  519. #ifndef _MAC // CEditView::SetTabStops is not supported on the MAC
  520. void CPadView::OnSetTabStops()
  521. {
  522.     CSetTabStops dlg;
  523.     dlg.m_nTabStops = m_nTabStops/4;
  524.     if (dlg.DoModal() == IDOK)
  525.     {
  526.         CWaitCursor wait;
  527.         SetTabStops(dlg.m_nTabStops*4);
  528.         m_nDefTabStops = m_nTabStops;
  529.  
  530.         // notify container that content changed
  531.         GetDocument()->UpdateAllItems(NULL);
  532.     }
  533. }
  534. #endif 
  535.  
  536. /////////////////////////////////////////////////////////////////////////////
  537. // CPadView Word Wrap
  538.  
  539. void CPadView::OnUpdateWordWrap(CCmdUI* pCmdUI)
  540. {
  541.     pCmdUI->SetCheck(IsWordWrap());
  542. }
  543.  
  544. void CPadView::OnWordWrap()
  545. {
  546.     CWaitCursor wait;
  547.     SetWordWrap(!IsWordWrap());
  548.     m_bDefWordWrap = IsWordWrap();
  549. }
  550.  
  551. /////////////////////////////////////////////////////////////////////////////
  552. // CPadView commands
  553.  
  554. void CPadView::OnRButtonDown(UINT, CPoint)
  555. {
  556.     GetParentFrame()->BringWindowToTop();
  557. }
  558.  
  559. void CPadView::OnSize(UINT nType, int cx, int cy)
  560. {
  561.     CWaitCursor wait;
  562.     CEditView::OnSize(nType, cx, cy);
  563.  
  564.     CFrameWnd* pFrameWnd = GetParentFrame();
  565.     ASSERT_VALID(pFrameWnd);
  566.  
  567.     if ((pFrameWnd->GetStyle() & WS_VISIBLE) &&
  568.         pFrameWnd->IsKindOf(RUNTIME_CLASS(COleIPFrameWnd)))
  569.     {
  570.         // update the cx part of the extent to the width of the control
  571.         COleServerItem* pItem = GetDocument()->GetEmbeddedItem();
  572.  
  573.         // only update if it has actually changed
  574.         if ((int)pItem->m_sizeExtent.cx != cx)
  575.         {
  576.             pItem->m_sizeExtent.cx = cx;
  577.             OnEditChange();
  578.         }
  579.     }
  580. }
  581.  
  582. /////////////////////////////////////////////////////////////////////////////
  583. // CPadView OLE support
  584.  
  585. void CPadView::OnEditChange()
  586. {
  587.     CEditView::OnEditChange();
  588.  
  589.     if (m_uTimerID != 0) // if outstanding timer kill it
  590.         KillTimer(m_uTimerID);
  591.     m_uTimerID = SetTimer(1, 200, NULL); //set a timer for 200 milliseconds
  592.     if (m_uTimerID == 0) // no timer available so force update now
  593.         GetDocument()->UpdateAllItems(NULL);
  594. }
  595.  
  596. void CPadView::OnEditCopy()
  597. {
  598.     CWaitCursor wait;
  599.  
  600.     // get the current selection
  601.     UINT nFrom, nTo;
  602.     GetEditCtrl().GetSel((int&)nFrom, (int&)nTo);
  603.  
  604.     // what gets copied depends on partial vs. full selection
  605.     if ((nFrom == 0 && nTo == (UINT)GetWindowTextLength()))
  606.     {
  607.         // copy entire document to the clipboard
  608.         GetDocument()->GetEmbeddedItem()->CopyToClipboard(TRUE);
  609.     }
  610.     else
  611.     {
  612.         // copy linked item to clipboard
  613.         CPadLinkItem item(GetDocument(), nFrom, nTo);
  614.         item.CopyToClipboard(TRUE);
  615.     }
  616. }
  617.  
  618. void CPadView::OnEditCut()
  619. {
  620.     OnEditCopy();
  621.     CEditView::OnEditCut();
  622. }
  623.  
  624. void CPadView::OnTimer(UINT nIDEvent)
  625. {
  626.     if (m_uTimerID != nIDEvent) // not our timer
  627.     {
  628.         CEditView::OnTimer(nIDEvent);
  629.         return;
  630.     }
  631.  
  632.     KillTimer(m_uTimerID); // kill one-shot timer
  633.     m_uTimerID = 0;
  634.     GetDocument()->UpdateAllItems(NULL);
  635. }
  636.  
  637. /////////////////////////////////////////////////////////////////////////////
  638. // CPadView diagnostics
  639.  
  640. #ifdef _DEBUG
  641. void CPadView::AssertValid() const
  642. {
  643.     CEditView::AssertValid();
  644. }
  645.  
  646. void CPadView::Dump(CDumpContext& dc) const
  647. {
  648.     CEditView::Dump(dc);
  649. }
  650. #endif //_DEBUG
  651.  
  652. /////////////////////////////////////////////////////////////////////////////
  653.