home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / expert.pak / TEDITFIL.OWL < prev    next >
Text File  |  1997-07-23  |  7KB  |  212 lines

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