home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / APPEXPRT.PAK / TEDITVIE.OWL < prev    next >
Encoding:
Text File  |  1997-05-06  |  5.2 KB  |  178 lines

  1. <<[H]TEditView [[TEditView]]
  2. ##{hheader.snp}
  3. #include <owl/editview.h>
  4.  
  5. ##<<TApplication QUERY_FILENAME_CPP [[Filename]]
  6. #include "[[Filename]].rh"          // Definition of all resources.
  7.  
  8.  
  9. //{{TEditView = [[TEditView]]}}
  10. class [[TEditView]] : public TEditView {
  11.   public:
  12.     [[TEditView]](TDocument& doc, TWindow* parent = 0);
  13.     virtual ~[[TEditView]]();
  14. ##--BEGIN-- @OPT_APPL_PRINTING
  15.  
  16. //{{[[TEditView]]VIRTUAL_BEGIN}}
  17.   public:
  18.     virtual void Paint(TDC& dc, bool erase, TRect& rect);
  19. ##:DBVirtual(\\"[[TEditView]]", "Paint")
  20. //{{[[TEditView]]VIRTUAL_END}}
  21. //{{[[TEditView]]RSP_TBL_BEGIN}}
  22.   protected:
  23.     void EvGetMinMaxInfo(MINMAXINFO far& minmaxinfo);
  24. //{{[[TEditView]]RSP_TBL_END}}
  25. DECLARE_RESPONSE_TABLE([[TEditView]]);
  26. ##--END-- @OPT_APPL_PRINTING
  27. };    //{{[[TEditView]]}}
  28. ##{hfooter.snp}
  29. >>[H]TEditView [[TEditView]]
  30.  
  31.  
  32. <<[CPP]TEditView [[TEditView]]
  33. ##{cheader.snp}
  34. #include <owl/pch.h>
  35.  
  36. ##<<TApplication QUERY_FILE_H [[FileName]]
  37. #include "[[FileName]]"
  38. ##QUERY_FILE_H [[FileName]]
  39. #include "[[FileName]]"
  40.  
  41. #include <stdio.h>
  42.  
  43.  
  44. //{{[[TEditView]] Implementation}}
  45.  
  46.  
  47. ##--BEGIN-- @OPT_APPL_PRINTING
  48. ##@QUERY_APPL_COMMENT == VALUE_VERBOSE 4
  49. //
  50. // Build a response table for all messages/commands handled
  51. // by [[TEditView]] derived from TEditView.
  52. //
  53. DEFINE_RESPONSE_TABLE1([[TEditView]], TEditView)
  54. //{{[[TEditView]]RSP_TBL_BEGIN}}
  55. ##:DBResponse(\\"[[TEditView]]", "", "", "WM_GETMINMAXINFO", "")
  56.   EV_WM_GETMINMAXINFO,
  57. //{{[[TEditView]]RSP_TBL_END}}
  58. END_RESPONSE_TABLE;
  59.  
  60.  
  61. ##--END-- @OPT_APPL_PRINTING
  62. ##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  63. //--------------------------------------------------------
  64. // [[TEditView]]
  65. // ~~~~~~~~~~
  66. // Construction/Destruction handling.
  67. //
  68. ##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  69. [[TEditView]]::[[TEditView]](TDocument& doc, TWindow* parent)
  70. :
  71.   TEditView(doc, parent)
  72. {
  73. ##QUERY_WIND_STYLE [[StyleAttributes]]
  74. ##StyleAttributes != "" 3
  75.   // Override the default window style for TEditView.
  76. [[StyleAttributes]]
  77.  
  78. ##{wndbkgd.snp}
  79.   // INSERT>> Your constructor code here.
  80.  
  81. }
  82.  
  83.  
  84. [[TEditView]]::~[[TEditView]]()
  85. {
  86.   // INSERT>> Your destructor code here.
  87.  
  88. }
  89. ##--BEGIN-- @OPT_APPL_PRINTING == TRUE
  90.  
  91.  
  92. ##@QUERY_APPL_COMMENT == VALUE_VERBOSE 3
  93. //
  94. // Paint routine for Window, Printer, and PrintPreview for a TEditView client.
  95. //
  96. void [[TEditView]]::Paint(TDC& dc, bool, TRect& rect)
  97. {
  98. ##<<TApplication QUERY_CLASS_NAME [[TApplication]]
  99.   [[TApplication]]* theApp = TYPESAFE_DOWNCAST(GetApplication(), [[TApplication]]);
  100.   if (theApp) {
  101. ##:@QUERY_APPL_COMMENT == VALUE_VERBOSE 2
  102.     // Only paint if we're printing and we have something to paint, otherwise do nothing.
  103.     //
  104.     if (theApp->Printing && theApp->Printer && !rect.IsEmpty()) {
  105. ##:@QUERY_APPL_COMMENT == VALUE_VERBOSE 2
  106.       // Use pageSize to get the size of the window to render into.  For a Window it's the client area,
  107.       // for a printer it's the printer DC dimensions and for print preview it's the layout window.
  108.       TSize   pageSize(rect.right - rect.left, rect.bottom - rect.top);
  109.  
  110.       HFONT   hFont = (HFONT)GetWindowFont();
  111.       TFont   font("Arial", -12);
  112.       if (!hFont)
  113.         dc.SelectObject(font);
  114.       else
  115.         dc.SelectObject(TFont(hFont));
  116.  
  117.       TEXTMETRIC  tm;
  118.       int fHeight = dc.GetTextMetrics(tm) ? tm.tmHeight + tm.tmExternalLeading : 10;
  119.  
  120. ##:@QUERY_APPL_COMMENT == VALUE_VERBOSE 2
  121.       // How many lines of this font can we fit on a page.
  122.       //
  123.       int linesPerPage = MulDiv(pageSize.cy, 1, fHeight);
  124.       if (linesPerPage) {
  125.         TPrintDialog::TData& printerData = theApp->Printer->GetSetup();
  126.  
  127.         int maxPg = ((GetNumLines() / linesPerPage) + 1.0);
  128.  
  129. ##:@QUERY_APPL_COMMENT == VALUE_VERBOSE 2
  130.         // Compute the number of pages to print.
  131.         //
  132.         printerData.MinPage = 1;
  133.         printerData.MaxPage = maxPg;
  134.  
  135. ##:@QUERY_APPL_COMMENT == VALUE_VERBOSE 2
  136.         // Do the text stuff:
  137.         //
  138.         int   fromPage = printerData.FromPage == -1 ? 1 : printerData.FromPage;
  139.         int   toPage = printerData.ToPage == -1 ? 1 : printerData.ToPage;
  140.         int   currentPage = fromPage;
  141.         TAPointer<char> buffer = new char[255];
  142.  
  143.         while (currentPage <= toPage) {
  144.           int startLine = (currentPage - 1) * linesPerPage;
  145.           int lineIdx = 0;
  146.           while (lineIdx < linesPerPage) {
  147. ##:@QUERY_APPL_COMMENT == VALUE_VERBOSE 2
  148.             // If the string is no longer valid then there's nothing more to display.
  149.             //
  150.             if (!GetLine(buffer, 255, startLine + lineIdx))
  151.               break;
  152.             dc.TabbedTextOut(TPoint(0, lineIdx * fHeight), buffer, strlen(buffer), 0, 0, 0);
  153.             lineIdx++;
  154.           }
  155.           currentPage++;
  156.         }
  157.       }
  158.     }
  159.   }
  160. }
  161.  
  162.  
  163. void [[TEditView]]::EvGetMinMaxInfo(MINMAXINFO far& minmaxinfo)
  164. {
  165. ##<<TApplication QUERY_CLASS_NAME [[TApplication]]
  166.   [[TApplication]]* theApp = TYPESAFE_DOWNCAST(GetApplication(), [[TApplication]]);
  167.   if (theApp) {
  168.     if (theApp->Printing) {
  169.       minmaxinfo.ptMaxSize = TPoint(32000, 32000);
  170.       minmaxinfo.ptMaxTrackSize = TPoint(32000, 32000);
  171.       return;
  172.     }
  173.   }
  174.   TEditView::EvGetMinMaxInfo(minmaxinfo);
  175. }
  176. ##--END-- @OPT_APPL_PRINTING == TRUE
  177. >>[CPP]TEditView [[TEditView]]
  178.