home *** CD-ROM | disk | FTP | other *** search
/ The Best of Select: Windows 95 Special 1 / WINDOWS95_1.bin / internet / vogon / textdlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-29  |  5.2 KB  |  176 lines

  1. // textdlg.cpp : implementation file
  2. //
  3.  
  4. #include "StdAfx.h"
  5. #include "Vogon.h"
  6.  
  7. #include "CntrInfo.h"
  8. #include "CntrItem.h"
  9. #include "TextDlg.h"
  10.  
  11. #ifdef _DEBUG
  12. #undef THIS_FILE
  13. static char BASED_CODE THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CTextRetrievalDlg dialog
  18.  
  19.  
  20. CTextRetrievalDlg::CTextRetrievalDlg(_DWebster* pWebsterDispatch, CWnd* pParent /*=NULL*/)
  21.     : CDialog(CTextRetrievalDlg::IDD, pParent)
  22. {
  23.     //{{AFX_DATA_INIT(CTextRetrievalDlg)
  24.         // NOTE: the ClassWizard will add member initialization here
  25.     //}}AFX_DATA_INIT
  26.  
  27.    // Stash the Webster OCX dispatch pointer
  28.    m_pWebsterDispatch = pWebsterDispatch;
  29. }
  30.  
  31.  
  32. void CTextRetrievalDlg::DoDataExchange(CDataExchange* pDX)
  33. {
  34.     CDialog::DoDataExchange(pDX);
  35.     //{{AFX_DATA_MAP(CTextRetrievalDlg)
  36.     DDX_Control(pDX, IDC_STATIC_TITLE, m_staticTitle);
  37.     DDX_Control(pDX, IDC_STATIC_SOURCE_BYTES, m_staticSourceBytes);
  38.     DDX_Control(pDX, IDC_STATIC_PURE_BYTES, m_staticPureBytes);
  39.     DDX_Control(pDX, IDC_EDIT_TEXT, m_editText);
  40.     //}}AFX_DATA_MAP
  41. }
  42.  
  43.  
  44. BEGIN_MESSAGE_MAP(CTextRetrievalDlg, CDialog)
  45.     //{{AFX_MSG_MAP(CTextRetrievalDlg)
  46.     ON_BN_CLICKED(IDC_BUTTON_SOURCE, OnButtonSource)
  47.     ON_BN_CLICKED(IDC_BUTTON_PURE, OnButtonPure)
  48.     ON_BN_CLICKED(IDC_BUTTON_COPY, OnButtonCopy)
  49.     //}}AFX_MSG_MAP
  50. END_MESSAGE_MAP()
  51.  
  52.  
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CTextRetrievalDlg message handlers
  55.  
  56. /////////////////////////////////////////////////////////////////////////////
  57. //
  58. BOOL CTextRetrievalDlg::OnInitDialog() 
  59. {
  60.    CDialog::OnInitDialog();
  61.  
  62.    // Show the HTML source for the current page
  63.    UpdateFromText(FALSE);
  64.  
  65.    // TODO: Add extra initialization here
  66.  
  67.    return TRUE;  // return TRUE unless you set the focus to a control
  68.                  // EXCEPTION: OCX Property Pages should return FALSE
  69. }
  70.  
  71. /////////////////////////////////////////////////////////////////////////////
  72. //
  73. void CTextRetrievalDlg::OnButtonSource() 
  74. {  // Show the HTML source for the current page
  75.    UpdateFromText(FALSE);
  76. }
  77.  
  78. /////////////////////////////////////////////////////////////////////////////
  79. //
  80. void CTextRetrievalDlg::OnButtonPure() 
  81. {  // Show the pure text for the current page
  82.    UpdateFromText(TRUE);
  83. }
  84.  
  85. /////////////////////////////////////////////////////////////////////////////
  86. //
  87. void CTextRetrievalDlg::OnButtonCopy() 
  88. {  // Copy the edit box selection (or everything if no selection) to the clipboard:
  89.    int selStart;
  90.    int selEnd;
  91.    
  92.    // Stash the scroll position - select may cause scroll
  93.    int saveLoc = m_editText.GetFirstVisibleLine();
  94.    // Was anything selected ?
  95.    m_editText.GetSel(selStart, selEnd);
  96.  
  97.    if (selEnd <= selStart)
  98.    {  // No selection: select everything
  99.       m_editText.SetSel(0, -1);
  100.    }
  101.  
  102.    m_editText.Copy();
  103.  
  104.    if (selEnd <= selStart)
  105.    {  // Was selected - deselect, restore to original state
  106.       m_editText.SetSel(-1, -1);
  107.    }
  108.  
  109.    // Restore the scroll position
  110.    m_editText.LineScroll(saveLoc - m_editText.GetFirstVisibleLine());
  111. }
  112.  
  113. /////////////////////////////////////////////////////////////////////////////
  114. // CTextRetrievalDlg helper functions
  115.  
  116. /////////////////////////////////////////////////////////////////////////////
  117. //
  118. void CTextRetrievalDlg::UpdateFromText(BOOL bPure) 
  119. {  // Show the source or pure text for the current page
  120.    CString stringText;
  121.  
  122.    // Get the current page URL
  123.    CString stringURL(m_pWebsterDispatch->GetPageURL());
  124.  
  125.    // Get the pure text length
  126.    long pureLength   = m_pWebsterDispatch->GetTextSize(stringURL);
  127.    // Get the source length
  128.    long sourceLength = m_pWebsterDispatch->GetContentSizeRead(stringURL);
  129.  
  130.    // Get the text, from start to end (** 16-bit version restricted to 32KB per GetContent() **)
  131.    if (bPure)
  132.    {  // Pure text
  133.       m_staticTitle.SetWindowText(CString(_T("Pure Text: ")) + stringURL);
  134.       stringText = m_pWebsterDispatch->GetText(stringURL, 0, pureLength);
  135.    }
  136.    else
  137.    {  // Source HTML text
  138.       m_staticTitle.SetWindowText(CString(_T("Source Text: ")) + stringURL);
  139.       stringText = m_pWebsterDispatch->GetContent(stringURL, 0, sourceLength);
  140.    }
  141.  
  142.    // Convert all stand-alone newline characters to CR-LF for the edit control ...
  143.    int index;
  144.    CString stringTranslated;
  145.  
  146.    while ((index = stringText.Find(TCHAR('\n'))) >= 0)
  147.    {  // Found an NL (== LF): translate to CR-LF
  148.       if (index && stringText[index - 1] == TCHAR('\r'))
  149.       {  // CR-LF present, so just use it as-is
  150.          stringTranslated += stringText.Left(index + 1);
  151.       }
  152.       else
  153.       {  // NL (== LF), no CR: translate to CR-LF
  154.          stringTranslated += stringText.Left(index);
  155.          stringTranslated += _T("\r\n");
  156.       }
  157.  
  158.       // Subtract the string we just added to stringTranslated
  159.       stringText = stringText.Mid(index + 1);
  160.    }
  161.  
  162.    // Acquire the remaining text
  163.    stringTranslated += stringText;
  164.  
  165.  
  166.    // Display the text in the edit control:
  167.    m_editText.SetWindowText(stringTranslated);
  168.  
  169.    // Display sizes:
  170.    TCHAR fmtBuf[64];
  171.    m_staticPureBytes.SetWindowText(CString(ltoa(pureLength, fmtBuf, 10)));
  172.    m_staticSourceBytes.SetWindowText(CString(ltoa(sourceLength, fmtBuf, 10)));
  173. }
  174.  
  175.  
  176.