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

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