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

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