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

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