home *** CD-ROM | disk | FTP | other *** search
- /* Project emedit
- Early Morning Software
- Copyright ⌐ 1994. All Rights Reserved.
-
- SUBSYSTEM: emedit.exe Application
- FILE: mdtmdich.cpp
- AUTHOR: Ted Stockwell
-
-
- OVERVIEW
- ========
- Source file for implementation of emeditMDIChild (TMDIChild).
- */
-
-
- #include <owl\owlpch.h>
- #include <stdio.h>
- #ifndef __EMEDIT_H
- #include <emedit.h>
- #define __EMEDIT_H
- #endif
- #pragma hdrstop
-
- #include "emedtapp.h"
- #include "mdtmdich.h"
- #include "mdtchldc.h"
-
-
- //{{emeditMDIChild Implementation}}
-
-
- //
- // Build a response table for all messages/commands handled
- // by emeditMDIChild derived from TMDIChild.
- //
- DEFINE_RESPONSE_TABLE1(emeditMDIChild, TMDIChild)
- //{{emeditMDIChildRSP_TBL_BEGIN}}
- EV_WM_GETMINMAXINFO,
- EV_WM_NCACTIVATE,
- //{{emeditMDIChildRSP_TBL_END}}
- END_RESPONSE_TABLE;
-
-
- //////////////////////////////////////////////////////////
- // emeditMDIChild
- // ==========
- // Construction/Destruction handling.
- emeditMDIChild::emeditMDIChild (
- TMDIClient &parent,
- const char far *title,
- TWindow *clientWnd,
- BOOL shrinkToClient,
- TModule *module
- ) :
- TMDIChild (
- parent, title,
- (clientWnd == 0) ? new emeditChildClient( 0 ) : clientWnd,
- shrinkToClient, module
- )
- {
- // INSERT>> Your constructor code here.
-
- }
-
-
- emeditMDIChild::~emeditMDIChild ()
- {
- Destroy();
- // INSERT>> Your destructor code here.
- }
-
-
- //
- // Paint routine for Window, Printer, and PrintPreview for an TEdit client.
- //
- void emeditMDIChild::Paint (TDC& dc, BOOL, TRect& rect)
- {
- emeditApp *theApp = TYPESAFE_DOWNCAST(GetApplication(), emeditApp);
- if (theApp) {
- // Only paint if we're printing and we have something to paint, otherwise do nothing.
- if (theApp->Printing && theApp->Printer && !rect.IsEmpty()) {
- emeditChildClient* cclient = TYPESAFE_DOWNCAST(GetClientWindow(), emeditChildClient);
-
- // Use pageSize to get the size of the window to render into. For a Window it's the client area,
- // for a printer it's the printer DC dimensions and for print preview it's the layout window.
- TSize pageSize(rect.right - rect.left, rect.bottom - rect.top);
- HFONT hFont;
- cclient->editor->GetProphFont( (int)hFont );
- dc.SelectObject( hFont );
-
- TEXTMETRIC tm;
- int fHeight = (dc.GetTextMetrics(tm) == TRUE) ? tm.tmHeight + tm.tmExternalLeading : 10;
-
- // How many lines of this font can we fit on a page.
- int linesPerPage = MulDiv(pageSize.cy, 1, fHeight);
- if (linesPerPage) {
- TPrintDialog::TData &printerData = theApp->Printer->GetSetup();
-
- // Compute the number of pages to print.
- printerData.MinPage = 1;
- printerData.MaxPage = ((cclient->editor->Count() / linesPerPage) + 1.0);
-
- // Do the text stuff:
- int fromPage = printerData.FromPage == -1 ? 1 : printerData.FromPage;
- int toPage = printerData.ToPage == -1 ? 1 : printerData.ToPage;
- char buffer[255];
- int currentPage = fromPage;
-
- while (currentPage <= toPage) {
- int startLine = (currentPage - 1) * linesPerPage;
- int lineIdx = 0;
- while (lineIdx < linesPerPage) {
- // If the string is no longer valid then there's nothing more to display.
- if (!cclient->editor->GetLine(buffer, sizeof(buffer), startLine + lineIdx))
- break;
- dc.TabbedTextOut(TPoint(0, lineIdx * fHeight), buffer, lstrlen(buffer), 0, NULL, 0);
- lineIdx++;
- }
- currentPage++;
- }
- }
- }
- }
- }
-
-
- void emeditMDIChild::EvGetMinMaxInfo (MINMAXINFO far& minmaxinfo)
- {
- emeditApp *theApp = TYPESAFE_DOWNCAST(GetApplication(), emeditApp);
- if (theApp) {
- if (theApp->Printing) {
- minmaxinfo.ptMaxSize = TPoint(32000, 32000);
- minmaxinfo.ptMaxTrackSize = TPoint(32000, 32000);
- return;
- }
- }
- TMDIChild::EvGetMinMaxInfo(minmaxinfo);
- }
-
-
-
-
-
- void emeditMDIChild::SetupWindow ()
- {
- TMDIChild::SetupWindow();
-
- // INSERT>> Your code here.
- emeditApp* App= (emeditApp*)GetApplication();
- emeditChildClient* cclient = TYPESAFE_DOWNCAST(GetClientWindow(), emeditChildClient);
-
- // set the default block mode to the current default
- cclient->editor->SetPropSelDefaultType( App->GetDefaultBlockType() );
-
- // set the insert mode to the current default
- const BOOL insertmode= App->StatusBar()->GetInsertIndicator();
- cclient->editor->SetPropInsertMode( insertmode );
-
- // set the caret width to match the insert mode
- if (!insertmode) {
- int W;
- cclient->editor->GetPropCaretWidth( W );
- cclient->editor->SetPropCaretWidth( W << 1 );
- }
-
- // set the caption
- string untitled(*GetModule(), IDS_UNTITLED);
- const char far* p = cclient->editor->FileName ? cclient->editor->FileName : untitled.c_str();
- if (!Title || !*Title) {
- SetWindowText(p);
- } else {
- const char frmt[] = "%s - %s";
- char* newCaption = new char[strlen(Title)+3+strlen(p)+1];
- wsprintf(newCaption, frmt, p, Title);
- SetWindowText(newCaption);
- delete newCaption;
- }
- }
-
-
- BOOL emeditMDIChild::EvNCActivate (BOOL active)
- {
- BOOL result= TMDIChild::EvNCActivate(active);
-
- // INSERT>> Your code here.
- if (result) // if the change in active state should be allowed
- if (active) { // if the child window is becoming active
- emeditChildClient* cclient = TYPESAFE_DOWNCAST(GetClientWindow(), emeditChildClient);
- cclient->UpdateStatusBar(); // refresh the applications status bar
- } else { // otherwise clear modify and position info from status bar
- emeditMessageBar* StatusBar= ((emeditApp*)GetApplication())->StatusBar();
- StatusBar->SetPositionIndicator();
- StatusBar->SetModifyIndicator();
- }
-
- return result;
- }
-
-