home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / VISUAL_B / PROGRAMS / EM_EDIT / MDTMDICH.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-04  |  6.2 KB  |  199 lines

  1. /*  Project emedit
  2.     Early Morning Software
  3.     Copyright ⌐ 1994. All Rights Reserved.
  4.  
  5.     SUBSYSTEM:    emedit.exe Application
  6.     FILE:         mdtmdich.cpp
  7.     AUTHOR:       Ted Stockwell
  8.  
  9.  
  10.     OVERVIEW
  11.     ========
  12.     Source file for implementation of emeditMDIChild (TMDIChild).
  13. */
  14.  
  15.  
  16. #include <owl\owlpch.h>
  17. #include <stdio.h>
  18. #ifndef __EMEDIT_H
  19.   #include <emedit.h>
  20.   #define __EMEDIT_H
  21. #endif
  22. #pragma hdrstop
  23.  
  24. #include "emedtapp.h"
  25. #include "mdtmdich.h"
  26. #include "mdtchldc.h"
  27.  
  28.  
  29. //{{emeditMDIChild Implementation}}
  30.  
  31.  
  32. //
  33. // Build a response table for all messages/commands handled
  34. // by emeditMDIChild derived from TMDIChild.
  35. //
  36. DEFINE_RESPONSE_TABLE1(emeditMDIChild, TMDIChild)
  37. //{{emeditMDIChildRSP_TBL_BEGIN}}
  38.     EV_WM_GETMINMAXINFO,
  39.     EV_WM_NCACTIVATE,
  40. //{{emeditMDIChildRSP_TBL_END}}
  41. END_RESPONSE_TABLE;
  42.  
  43.  
  44. //////////////////////////////////////////////////////////
  45. // emeditMDIChild
  46. // ==========
  47. // Construction/Destruction handling.
  48. emeditMDIChild::emeditMDIChild (
  49.   TMDIClient &parent,
  50.   const char far *title,
  51.   TWindow *clientWnd,
  52.   BOOL shrinkToClient,
  53.   TModule *module
  54. ) :
  55.   TMDIChild (
  56.     parent, title,
  57.     (clientWnd == 0) ? new emeditChildClient( 0 ) : clientWnd,
  58.     shrinkToClient, module
  59.   )
  60. {
  61.     // INSERT>> Your constructor code here.
  62.  
  63. }
  64.  
  65.  
  66. emeditMDIChild::~emeditMDIChild ()
  67. {
  68.     Destroy();
  69.     // INSERT>> Your destructor code here.
  70. }
  71.  
  72.  
  73. //
  74. // Paint routine for Window, Printer, and PrintPreview for an TEdit client.
  75. //
  76. void emeditMDIChild::Paint (TDC& dc, BOOL, TRect& rect)
  77. {
  78.     emeditApp *theApp = TYPESAFE_DOWNCAST(GetApplication(), emeditApp);
  79.     if (theApp) {
  80.         // Only paint if we're printing and we have something to paint, otherwise do nothing.
  81.         if (theApp->Printing && theApp->Printer && !rect.IsEmpty()) {
  82.             emeditChildClient* cclient = TYPESAFE_DOWNCAST(GetClientWindow(), emeditChildClient);
  83.  
  84.             // Use pageSize to get the size of the window to render into.  For a Window it's the client area,
  85.             // for a printer it's the printer DC dimensions and for print preview it's the layout window.
  86.             TSize   pageSize(rect.right - rect.left, rect.bottom - rect.top);
  87.             HFONT   hFont;
  88.             cclient->editor->GetProphFont( (int)hFont );
  89.             dc.SelectObject( hFont );
  90.  
  91.             TEXTMETRIC  tm;
  92.             int fHeight = (dc.GetTextMetrics(tm) == TRUE) ? tm.tmHeight + tm.tmExternalLeading : 10;
  93.  
  94.             // How many lines of this font can we fit on a page.
  95.             int linesPerPage = MulDiv(pageSize.cy, 1, fHeight);
  96.             if (linesPerPage) {
  97.                 TPrintDialog::TData &printerData = theApp->Printer->GetSetup();
  98.  
  99.                 // Compute the number of pages to print.
  100.                 printerData.MinPage = 1;
  101.                 printerData.MaxPage = ((cclient->editor->Count() / linesPerPage) + 1.0);
  102.  
  103.                 // Do the text stuff:
  104.                 int     fromPage = printerData.FromPage == -1 ? 1 : printerData.FromPage;
  105.                 int     toPage = printerData.ToPage == -1 ? 1 : printerData.ToPage;
  106.                 char    buffer[255];
  107.                 int     currentPage = fromPage;
  108.  
  109.                 while (currentPage <= toPage) {
  110.                     int startLine = (currentPage - 1) * linesPerPage;
  111.                     int lineIdx = 0;
  112.                     while (lineIdx < linesPerPage) {
  113.                         // If the string is no longer valid then there's nothing more to display.
  114.                         if (!cclient->editor->GetLine(buffer, sizeof(buffer), startLine + lineIdx))
  115.                             break;
  116.                         dc.TabbedTextOut(TPoint(0, lineIdx * fHeight), buffer, lstrlen(buffer), 0, NULL, 0);
  117.                         lineIdx++;
  118.                     }
  119.                     currentPage++;
  120.                 }
  121.             }
  122.         }
  123.     }
  124. }
  125.  
  126.  
  127. void emeditMDIChild::EvGetMinMaxInfo (MINMAXINFO far& minmaxinfo)
  128. {
  129.     emeditApp *theApp = TYPESAFE_DOWNCAST(GetApplication(), emeditApp);
  130.     if (theApp) {
  131.         if (theApp->Printing) {
  132.             minmaxinfo.ptMaxSize = TPoint(32000, 32000);
  133.             minmaxinfo.ptMaxTrackSize = TPoint(32000, 32000);
  134.             return;
  135.         }
  136.     }
  137.     TMDIChild::EvGetMinMaxInfo(minmaxinfo);
  138. }
  139.  
  140.  
  141.  
  142.  
  143.  
  144. void emeditMDIChild::SetupWindow ()
  145. {
  146.     TMDIChild::SetupWindow();
  147.  
  148.     // INSERT>> Your code here.
  149.     emeditApp* App= (emeditApp*)GetApplication();
  150.     emeditChildClient* cclient = TYPESAFE_DOWNCAST(GetClientWindow(), emeditChildClient);
  151.  
  152.     // set the default block mode to the current default
  153.     cclient->editor->SetPropSelDefaultType( App->GetDefaultBlockType() );
  154.  
  155.     // set the insert mode to the current default
  156.     const BOOL insertmode= App->StatusBar()->GetInsertIndicator();
  157.     cclient->editor->SetPropInsertMode( insertmode );
  158.  
  159.     // set the caret width to match the insert mode
  160.     if (!insertmode) {
  161.       int W;
  162.       cclient->editor->GetPropCaretWidth( W );
  163.       cclient->editor->SetPropCaretWidth( W << 1 );
  164.     }
  165.  
  166.     // set the caption
  167.     string untitled(*GetModule(), IDS_UNTITLED);
  168.     const char far* p = cclient->editor->FileName ? cclient->editor->FileName : untitled.c_str();
  169.     if (!Title || !*Title) {
  170.       SetWindowText(p);
  171.     } else {
  172.       const char frmt[] = "%s - %s";
  173.       char* newCaption = new char[strlen(Title)+3+strlen(p)+1];
  174.       wsprintf(newCaption, frmt, p, Title);
  175.       SetWindowText(newCaption);
  176.       delete newCaption;
  177.     }
  178. }
  179.  
  180.  
  181. BOOL emeditMDIChild::EvNCActivate (BOOL active)
  182. {
  183.     BOOL result= TMDIChild::EvNCActivate(active);
  184.  
  185.     // INSERT>> Your code here.
  186.     if (result) // if the change in active state should be allowed
  187.       if (active) { // if the child window is becoming active
  188.         emeditChildClient* cclient = TYPESAFE_DOWNCAST(GetClientWindow(), emeditChildClient);
  189.         cclient->UpdateStatusBar(); // refresh the applications status bar
  190.       } else { // otherwise clear modify and position info from status bar
  191.         emeditMessageBar* StatusBar= ((emeditApp*)GetApplication())->StatusBar();
  192.         StatusBar->SetPositionIndicator();
  193.         StatusBar->SetModifyIndicator();
  194.       }
  195.  
  196.     return result;
  197. }
  198.  
  199.