home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / tybc4 / xped4 / xpd4mdi1.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-13  |  5.0 KB  |  149 lines

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