home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / APXSDI.PAK / APXSDEDF.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  4.4 KB  |  158 lines

  1. //----------------------------------------------------------------------------
  2. //  Project ApxSdi
  3. //  Borland International
  4. //  Copyright ⌐ 1996. All Rights Reserved.
  5. //
  6. //  SUBSYSTEM:    ApxSdi Application
  7. //  FILE:         apxsdedf.cpp
  8. //  AUTHOR:       
  9. //
  10. //  OVERVIEW
  11. //  ~~~~~~~~
  12. //  Source file for implementation of TApxSdiEditFile (TEditFile).
  13. //
  14. //----------------------------------------------------------------------------
  15.  
  16. #include <owl/pch.h>
  17.  
  18. #include "apxsdapp.h"
  19. #include "apxsdedf.h"
  20.  
  21. #include <stdio.h>
  22.  
  23.  
  24. //{{TApxSdiEditFile Implementation}}
  25.  
  26.  
  27. //
  28. // Build a response table for all messages/commands handled
  29. // by TApxSdiEditFile derived from TEditFile.
  30. //
  31. DEFINE_RESPONSE_TABLE1(TApxSdiEditFile, TEditFile)
  32. //{{TApxSdiEditFileRSP_TBL_BEGIN}}
  33.   EV_WM_GETMINMAXINFO,
  34. //{{TApxSdiEditFileRSP_TBL_END}}
  35. END_RESPONSE_TABLE;
  36.  
  37.  
  38. //--------------------------------------------------------
  39. // TApxSdiEditFile
  40. // ~~~~~~~~~~
  41. // Construction/Destruction handling.
  42. //
  43. TApxSdiEditFile::TApxSdiEditFile(TWindow* parent, int id, const char far* text, int x, int y, int w, int h, const char far* fileName, TModule* module)
  44. :
  45.   TEditFile(parent, id, text, x, y, w, h, fileName, module)
  46. {
  47.   // INSERT>> Your constructor code here.
  48.  
  49. }
  50.  
  51.  
  52. TApxSdiEditFile::~TApxSdiEditFile()
  53. {
  54.   Destroy();
  55.  
  56.   // INSERT>> Your destructor code here.
  57.  
  58. }
  59.  
  60.  
  61. void TApxSdiEditFile::SetupWindow()
  62. {
  63.   TEditFile::SetupWindow();
  64.  
  65.   TApxSdiApp* theApp = TYPESAFE_DOWNCAST(GetApplication(), TApxSdiApp);
  66.   FileData = theApp->FileData;
  67. }
  68.  
  69.  
  70. //
  71. // Paint routine for Window, Printer, and PrintPreview for an TEdit client.
  72. //
  73. void TApxSdiEditFile::Paint(TDC& dc, bool, TRect& rect)
  74. {
  75.   TApxSdiApp* theApp = TYPESAFE_DOWNCAST(GetApplication(), TApxSdiApp);
  76.   if (theApp) {
  77.     // Only paint if we're printing and we have something to paint, otherwise do nothing.
  78.     //
  79.     if (theApp->Printing && theApp->Printer && !rect.IsEmpty()) {
  80.       // Use pageSize to get the size of the window to render into.  For a Window it's the client area,
  81.       // for a printer it's the printer DC dimensions and for print preview it's the layout window.
  82.       //
  83.       TSize   pageSize(rect.right - rect.left, rect.bottom - rect.top);
  84.  
  85.       HFONT   hFont = (HFONT)GetWindowFont();
  86.       TFont   font("Arial", -12);
  87.       if (!hFont)
  88.         dc.SelectObject(font);
  89.       else
  90.         dc.SelectObject(TFont(hFont));
  91.  
  92.       TEXTMETRIC  tm;
  93.       int fHeight = dc.GetTextMetrics(tm) ? tm.tmHeight + tm.tmExternalLeading : 10;
  94.  
  95.       // How many lines of this font can we fit on a page.
  96.       //
  97.       int linesPerPage = MulDiv(pageSize.cy, 1, fHeight);
  98.       if (linesPerPage) {        TPrintDialog::TData& printerData = theApp->Printer->GetSetup();
  99.  
  100.         int maxPg = ((GetNumLines() / linesPerPage) + 1.0);
  101.  
  102.         // Compute the number of pages to print.
  103.         //
  104.         printerData.MinPage = 1;
  105.         printerData.MaxPage = maxPg;
  106.  
  107.         // Do the text stuff:
  108.         //
  109.         int   fromPage = printerData.FromPage == -1 ? 1 : printerData.FromPage;
  110.         int   toPage = printerData.ToPage == -1 ? 1 : printerData.ToPage;
  111.         int   currentPage = fromPage;
  112.         TAPointer<char> buffer = new char[255];
  113.  
  114.         while (currentPage <= toPage) {
  115.           int startLine = (currentPage - 1) * linesPerPage;
  116.           int lineIdx = 0;
  117.           while (lineIdx < linesPerPage) {
  118.             // If the string is no longer valid then there's nothing more to display.
  119.             //
  120.             if (!GetLine(buffer, 255, startLine + lineIdx))
  121.               break;
  122.             dc.TabbedTextOut(TPoint(0, lineIdx * fHeight), buffer, strlen(buffer), 0, 0, 0);
  123.             lineIdx++;
  124.           }
  125.           currentPage++;
  126.         }
  127.       }
  128.     }
  129.   }
  130. }
  131.  
  132.  
  133. void TApxSdiEditFile::EvGetMinMaxInfo(MINMAXINFO far& minmaxinfo)
  134. {
  135.   TApxSdiApp* theApp = TYPESAFE_DOWNCAST(GetApplication(), TApxSdiApp);
  136.   if (theApp) {
  137.     if (theApp->Printing) {
  138.       minmaxinfo.ptMaxSize = TPoint(32000, 32000);
  139.       minmaxinfo.ptMaxTrackSize = TPoint(32000, 32000);
  140.       return;
  141.     }
  142.   }
  143.   TEditFile::EvGetMinMaxInfo(minmaxinfo);
  144. }
  145.  
  146.  
  147. // Override SaveAs to store the menu choice.
  148. //
  149. bool TApxSdiEditFile::SaveAs()
  150. {
  151.   if (TEditFile::SaveAs()) {
  152.     TApxSdiApp* theApp = TYPESAFE_DOWNCAST(GetApplication(), TApxSdiApp);
  153.     theApp->SaveMenuChoice(GetFileName());
  154.     return true;
  155.   }
  156.   return false;
  157. }
  158.