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

  1. <<[H]TListView [[TListView]]
  2. ##{hheader.snp}
  3. #include <owl/listview.h>
  4.  
  5. ##<<TApplication QUERY_FILENAME_CPP [[Filename]]
  6. #include "[[Filename]].rh"            // Definition of all resources.
  7.  
  8.  
  9. //{{TListView = [[TListView]]}}
  10. class [[TListView]] : public TListView {
  11.   public:
  12.     [[TListView]](TDocument& doc, TWindow* parent = 0);
  13.     virtual ~[[TListView]]();
  14. ##--BEGIN-- @OPT_APPL_PRINTING
  15.  
  16. //{{[[TListView]]VIRTUAL_BEGIN}}
  17.   public:
  18.     virtual void Paint(TDC& dc, bool erase, TRect& rect);
  19. ##:DBVirtual(\\"[[TListView]]", "Paint")
  20. //{{[[TListView]]VIRTUAL_END}}
  21. //{{[[TListView]]RSP_TBL_BEGIN}}
  22.   protected:
  23.     void EvGetMinMaxInfo(MINMAXINFO far& minmaxinfo);
  24. //{{[[TListView]]RSP_TBL_END}}
  25. DECLARE_RESPONSE_TABLE([[TListView]]);
  26. ##--END-- @OPT_APPL_PRINTING
  27. };    //{{[[TListView]]}}
  28. ##{hfooter.snp}
  29. >>[H]TListView [[TListView]]
  30.  
  31.  
  32. <<[CPP]TListView [[TListView]]
  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. //{{[[TListView]] 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 [[TListView]] derived from TListView.
  52. //
  53. DEFINE_RESPONSE_TABLE1([[TListView]], TListView)
  54. //{{[[TListView]]RSP_TBL_BEGIN}}
  55. ##:DBResponse(\\"[[TListView]]", "", "", "WM_GETMINMAXINFO", "")
  56.   EV_WM_GETMINMAXINFO,
  57. //{{[[TListView]]RSP_TBL_END}}
  58. END_RESPONSE_TABLE;
  59.  
  60.  
  61. ##--END-- @OPT_APPL_PRINTING
  62. ##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  63. //--------------------------------------------------------
  64. // [[TListView]]
  65. // ~~~~~~~~~~
  66. // Construction/Destruction handling.
  67. //
  68. ##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  69. [[TListView]]::[[TListView]](TDocument& doc, TWindow* parent)
  70. :
  71.   TListView(doc, parent)
  72. {
  73. ##QUERY_WIND_STYLE [[StyleAttributes]]
  74. ##StyleAttributes != "" 3
  75.   // Override the default window style for TListView.
  76.   [[StyleAttributes]]
  77.  
  78. ##{wndbkgd.snp}
  79.   // INSERT>> Your constructor code here.
  80.  
  81. }
  82.  
  83.  
  84. [[TListView]]::~[[TListView]]()
  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 TListView client.
  95. //
  96. void [[TListView]]::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) {                  TPrintDialog::TData& printerData = theApp->Printer->GetSetup();
  125.  
  126.         int maxPg = ((GetCount() / linesPerPage) + 1.0);
  127.  
  128. ##:@QUERY_APPL_COMMENT == VALUE_VERBOSE
  129.         // Compute the number of pages to print.
  130.         printerData.MinPage = 1;
  131.         printerData.MaxPage = maxPg;
  132.  
  133. ##:@QUERY_APPL_COMMENT == VALUE_VERBOSE 2
  134.         // Do the text stuff:
  135.         //
  136.         int     fromPage = printerData.FromPage == -1 ? 1 : printerData.FromPage;
  137.         int     toPage = printerData.ToPage == -1 ? 1 : printerData.ToPage;
  138.         int     currentPage = fromPage;
  139.         TAPointer<char> buffer = new char[255];
  140.  
  141.         while (currentPage <= toPage) {
  142.           int startLine = (currentPage - 1) * linesPerPage;
  143.           int lineIdx = 0;
  144.           while (lineIdx < linesPerPage) {
  145. ##:@QUERY_APPL_COMMENT == VALUE_VERBOSE 2
  146.             // If the string is no longer valid then there's nothing more to display.
  147.             //
  148.             if (GetString(buffer, startLine + lineIdx) < 0)
  149.                 break;
  150.               dc.TabbedTextOut(TPoint(0, lineIdx * fHeight), buffer, strlen(buffer), 0, 0, 0);
  151.               lineIdx++;
  152.           }
  153.           currentPage++;
  154.         }
  155.       }
  156.     }
  157.   }
  158. }
  159.  
  160.  
  161. void [[TListView]]::EvGetMinMaxInfo(MINMAXINFO far& minmaxinfo)
  162. {
  163. ##<<TApplication QUERY_CLASS_NAME [[TApplication]]
  164.   [[TApplication]]* theApp = TYPESAFE_DOWNCAST(GetApplication(), [[TApplication]]);
  165.   if (theApp) {
  166.     if (theApp->Printing) {
  167.       minmaxinfo.ptMaxSize = TPoint(32000, 32000);
  168.       minmaxinfo.ptMaxTrackSize = TPoint(32000, 32000);
  169.       return;
  170.     }
  171.   }
  172.   TListView::EvGetMinMaxInfo(minmaxinfo);
  173. }
  174. ##--END-- @OPT_APPL_PRINTING == TRUE
  175. >>[CPP]TListView [[TListView]]
  176.