home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1998 May
/
Pcwk5b98.iso
/
Borland
/
Cplus45
/
BC45
/
EXPERT.PAK
/
TMDICLIE.OWL
< prev
next >
Wrap
Text File
|
1995-08-29
|
17KB
|
504 lines
'////////////////////////////////////////////////////////////////////////////////////
' Expert PROJECT
' Expert - (C) Copyright 1993 by Borland International, Inc. All Rights Reserved.
'
' SUBSYSTEM: OWL code template
' FILE: TMDIClient.OWL
'
'
' OVERVIEW
' ========
' Definition of all OWL classes when can be generated by the CODEGEN phase of
' AppGen and ClassExpert. AppGen generates when all options have been selected
' and multiple classes are generated. ClassExpert uses the CODEGEN phase when
' a new class is generated.
'////////////////////////////////////////////////////////////////////////////////////
<<[H]TMDIClient [[TMDIClient]]
##{hheader.snp}
#include <owl\owlpch.h>
#pragma hdrstop
##<<TApplication QUERY_FILENAME_CPP [[FileName]]
#include "[[FileName]].rh" // Definition of all resources.
//{{TMDIClient = [[TMDIClient]]}}
class [[TMDIClient]] : public TMDIClient {
public:
int ChildCount; // Number of child window created.
[[TMDIClient]](TModule* module = 0);
virtual ~[[TMDIClient]] ();
void OpenFile (const char *fileName = 0);
private:
void LoadTextFile ();
//{{[[TMDIClient]]VIRTUAL_BEGIN}}
protected:
##:DBVirtual(\\"[[TMDIClient]]", "SetupWindow")
virtual void SetupWindow ();
//{{[[TMDIClient]]VIRTUAL_END}}
//{{[[TMDIClient]]RSP_TBL_BEGIN}}
protected:
##!@OPT_APPL_DOCVIEW 2
void CmFileNew ();
void CmFileOpen ();
##@OPT_APPL_PRINTING 4
void CmFilePrint ();
void CmFilePrintSetup ();
void CmFilePrintPreview ();
void CmPrintEnable (TCommandEnabler &tce);
##@OPT_APPL_DRAGDROP
void EvDropFiles (TDropInfo);
//{{[[TMDIClient]]RSP_TBL_END}}
DECLARE_RESPONSE_TABLE([[TMDIClient]]);
}; //{{[[TMDIClient]]}}
##{hfooter.snp}
>>[H]TMDIClient
'
' TMDIClient CPP file.
'
<<[CPP]TMDIClient [[TMDIClient]]
##{cheader.snp}
#include <owl\owlpch.h>
#pragma hdrstop
##@OPT_APPL_DRAGDROP 2
#include <dir.h>
##!@OPT_APPL_DRAGDROP 2
##: !@OPT_APPL_DOCVIEW
#include <dir.h>
##<<TApplication QUERY_FILE_H [[FileName]]
#include "[[FileName]]"
##--BEGIN-- !@OPT_APPL_DOCVIEW
## --BEGIN-- @QUERY_APPL_MODEL == VALUE_MDI
##: <<TMDIChild QUERY_WIND_CLIENT [[Client]]
##: <<*Client QUERY_FILE_H [[FileName]]
#include "[[FileName]]"
## --END-- @QUERY_APPL_MODEL == VALUE_MDI
## --BEGIN-- @QUERY_APPL_MODEL == VALUE_SDI
## --END-- @QUERY_APPL_MODEL == VALUE_SDI
##--END-- !@OPT_APPL_DOCVIEW
##<<TMDIChild QUERY_FILE_H [[FileName]]
#include "[[FileName]]"
##QUERY_FILE_H [[FileName]]
#include "[[FileName]]"
##@OPT_APPL_PRINTING 2
#include "apxprint.h"
#include "apxprev.h"
//{{[[TMDIClient]] Implementation}}
##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
//
// Build a response table for all messages/commands handled
// by [[TMDIClient]] derived from TMDIClient.
//
##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
DEFINE_RESPONSE_TABLE1([[TMDIClient]], TMDIClient)
//{{[[TMDIClient]]RSP_TBL_BEGIN}}
##!@OPT_APPL_DOCVIEW 2
##:DBResponse(\\"[[TMDIClient]]", "CM_MDIFILENEW", "CmFileNew", "", "COMMAND")
##:DBResponse(\\"[[TMDIClient]]", "CM_MDIFILEOPEN", "CmFileOpen", "", "COMMAND")
EV_COMMAND(CM_MDIFILENEW, CmFileNew),
EV_COMMAND(CM_MDIFILEOPEN, CmFileOpen),
##@OPT_APPL_PRINTING 6
##:DBResponse(\\"[[TMDIClient]]", "CM_FILEPRINT", "CmFilePrint", "", "COMMAND")
##:DBResponse(\\"[[TMDIClient]]", "CM_FILEPRINTERSETUP", "CmFilePrintSetup", "", "COMMAND")
##:DBResponse(\\"[[TMDIClient]]", "CM_FILEPRINTPREVIEW", "CmFilePrintPreview", "", "COMMAND")
##:DBResponse(\\"[[TMDIClient]]", "CM_FILEPRINT", "CmPrintEnable", "", "ENABLER")
##:DBResponse(\\"[[TMDIClient]]", "CM_FILEPRINTERSETUP", "CmPrintEnable", "", "ENABLER")
##:DBResponse(\\"[[TMDIClient]]", "CM_FILEPRINTPREVIEW", "CmPrintEnable", "", "ENABLER")
EV_COMMAND(CM_FILEPRINT, CmFilePrint),
EV_COMMAND(CM_FILEPRINTERSETUP, CmFilePrintSetup),
EV_COMMAND(CM_FILEPRINTPREVIEW, CmFilePrintPreview),
EV_COMMAND_ENABLE(CM_FILEPRINT, CmPrintEnable),
EV_COMMAND_ENABLE(CM_FILEPRINTERSETUP, CmPrintEnable),
EV_COMMAND_ENABLE(CM_FILEPRINTPREVIEW, CmPrintEnable),
##@OPT_APPL_DRAGDROP
##:DBResponse(\\"[[TMDIClient]]", "", "", "WM_DROPFILES", "")
EV_WM_DROPFILES,
//{{[[TMDIClient]]RSP_TBL_END}}
END_RESPONSE_TABLE;
##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
//////////////////////////////////////////////////////////
// [[TMDIClient]]
// ===========
// Construction/Destruction handling.
##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
[[TMDIClient]]::[[TMDIClient]] (TModule* module)
: TMDIClient (module)
{
##QUERY_WIND_STYLE [[StyleAttributes]]
##StyleAttributes != "" 3
// Override the default window style for TMDIClient.
[[StyleAttributes]]
##QUERY_WIND_BACKGRND [[BackgroundColor]]
##BackgroundColor != "" 3
// Change the window's background color
SetBkgndColor([[BackgroundColor]]);
ChildCount = 0;
// INSERT>> Your constructor code here.
}
[[TMDIClient]]::~[[TMDIClient]] ()
{
Destroy();
// INSERT>> Your destructor code here.
}
##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
//////////////////////////////////////////////////////////
// [[TMDIClient]]
// ===========
// MDIClient site initialization.
##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
void [[TMDIClient]]::SetupWindow ()
{
// Default SetUpWindow processing.
TMDIClient::SetupWindow ();
##--BEGIN-- !@OPT_APPL_DOCVIEW
##<<TApplication QUERY_CLASS_NAME [[TApplication]]
[[TApplication]] *theApp = TYPESAFE_DOWNCAST(GetApplication(), [[TApplication]]);
##@QUERY_APPL_COMMENT == VALUE_VERBOSE 2
// Common file file flags and filters for Open/Save As dialogs. Filename and directory are
// computed in the member functions CmFileOpen, and CmFileSaveAs.
theApp->FileData.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
##OPT_DV_RESET
##OPT_DV_NEXT
##QUERY_DV_DESCR [[Descr]]
##--BEGIN-- QUERY_DV_FILTER [[Filter]]
##(Filter != "*.*") && (Descr != "All Files (*.*)"
theApp->FileData.SetFilter("[[Descr]]|[[Filter]]|All Files (*.*)|*.*|");
##(Filter == "*.*") && (Descr == "All Files (*.*)"
theApp->FileData.SetFilter("All Files (*.*)|*.*|");
##--END-- QUERY_DV_FILTER [[Filter]]
##--END-- !@OPT_APPL_DOCVIEW
##@OPT_APPL_DRAGDROP 2
// Accept files via drag/drop in the client window.
DragAcceptFiles(true);
}
##--BEGIN-- !@OPT_APPL_DOCVIEW
##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
//////////////////////////////////////////////////////////
// [[TMDIClient]]
// ===========
// Menu File New command
##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
void [[TMDIClient]]::CmFileNew ()
{
##<<TMDIChild QUERY_WIND_CLIENT [[ClientClass]]
##--BEGIN-- <<*ClientClass QUERY_BASE_NAME [[BaseClient]]
##--BEGIN-- BaseClient != "TEditFile"
char title[255];
char numberStr[16];
##:@QUERY_APPL_COMMENT == VALUE_VERBOSE
// Generate a title for the MDI child window.
if (GetModule()->LoadString(IDS_UNTITLED, title, sizeof(title))) {
wsprintf(numberStr, " - %d", ChildCount++);
strcat(title, numberStr);
} else
title[0] = '\0';
##--END-- BaseClient != "TEditFile"
##--BEGIN-- BaseClient == "TEditFile"
char title[255];
##:@QUERY_APPL_COMMENT == VALUE_VERBOSE
// Generate a title for the MDI child window.
wsprintf(title, "%d", ChildCount++);
##--END-- BaseClient "TEditFile"
##--BEGIN-- <<TMDIChild QUERY_CLASS_NAME [[TMDIChild]]
##BaseClient == "TEditFile"
[[TMDIChild]]* child = new [[TMDIChild]](*this, title, 0);
##BaseClient == "TListBox"
[[TMDIChild]]* child = new [[TMDIChild]](*this, title, 0);
##BaseClient == "TWindow"
[[TMDIChild]]* child = new [[TMDIChild]](*this, title, 0);
##--END-- <<TMDIChild QUERY_CLASS_NAME [[TMDIChild]]
##--END-- <<*ClientClass QUERY_BASE_NAME [[BaseClient]]
##:@QUERY_APPL_COMMENT == VALUE_VERBOSE
// Associate ICON w/ this child window.
child->SetIcon(GetApplication(), IDI_DOC);
##:@QUERY_APPL_COMMENT == VALUE_VERBOSE
// If the current active MDI child is maximize then this one should be also.
##<<TMDIChild QUERY_CLASS_NAME [[TMDIChild]]
[[TMDIChild]] *curChild = ([[TMDIChild]] *)GetActiveMDIChild();
if (curChild && (curChild->GetWindowLong(GWL_STYLE) & WS_MAXIMIZE))
child->Attr.Style |= WS_MAXIMIZE;
child->Create();
}
void [[TMDIClient]]::OpenFile (const char *fileName)
{
##<<TApplication QUERY_CLASS_NAME [[TApplication]]
[[TApplication]] *theApp = TYPESAFE_DOWNCAST(GetApplication(), [[TApplication]]);
if (fileName)
strcpy(theApp->FileData.FileName, fileName);
//
##<<TMDIChild QUERY_WIND_CLIENT [[TMDIChildClient]]
// Create a MDIChild window whose client is [[TMDIChildClient]].
//
##<<TMDIChild QUERY_CLASS_NAME [[TMDIChild]]
##<<TMDIChild QUERY_WIND_CLIENT [[ClientClass]]
##<<*ClientClass QUERY_BASE_NAME [[BaseClient]]
##--BEGIN-- TRUE
##BaseClient == "TEditFile"
[[TMDIChild]]* child = new [[TMDIChild]](*this, "", new [[ClientClass]](0, 0, 0, 0, 0, 0, 0, theApp->FileData.FileName));
##BaseClient == "TListBox" 2
[[ClientClass]] far *client = new [[ClientClass]](0, 0, 0, 0, 100, 100);
[[TMDIChild]]* child = new [[TMDIChild]](*this, theApp->FileData.FileName, client);
##BaseClient == "TWindow"
[[TMDIChild]]* child = new [[TMDIChild]](*this, theApp->FileData.FileName, new [[ClientClass]](0));
##--END-- TRUE
##:@QUERY_APPL_COMMENT == VALUE_VERBOSE
// Associate ICON w/ this child window.
child->SetIcon(GetApplication(), IDI_DOC);
##:@QUERY_APPL_COMMENT == VALUE_VERBOSE
// If the current active MDI child is maximize then this one should be also.
##<<TMDIChild QUERY_CLASS_NAME [[TMDIChild]]
[[TMDIChild]] *curChild = ([[TMDIChild]] *)GetActiveMDIChild();
if (curChild && (curChild->GetWindowLong(GWL_STYLE) & WS_MAXIMIZE))
child->Attr.Style |= WS_MAXIMIZE;
child->Create();
LoadTextFile();
}
##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
//////////////////////////////////////////////////////////
// [[TMDIClient]]
// ===========
// Menu File Open command
##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
void [[TMDIClient]]::CmFileOpen ()
{
##<<TApplication QUERY_CLASS_NAME [[TApplication]]
[[TApplication]] *theApp = TYPESAFE_DOWNCAST(GetApplication(), [[TApplication]]);
##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
//
// Display standard Open dialog box to select a file name.
//
##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
*(theApp->FileData.FileName) = 0;
if (TFileOpenDialog(this, theApp->FileData).Execute() == IDOK)
OpenFile();
}
##:@QUERY_APPL_COMMENT == VALUE_VERBOSE
// Used by ListBox client to read a text file into the list box.
void [[TMDIClient]]::LoadTextFile ()
{
char buf[255+1];
ifstream *inStream;
##<<TApplication QUERY_CLASS_NAME [[TApplication]]
[[TApplication]] *theApp = TYPESAFE_DOWNCAST(GetApplication(), [[TApplication]]);
##<<TMDIChild QUERY_CLASS_NAME [[TMDIChild]]
[[TMDIChild]] *curChild = ([[TMDIChild]] *)GetActiveMDIChild();
TListBox *client = TYPESAFE_DOWNCAST(curChild->GetClientWindow(), TListBox);
##:@QUERY_APPL_COMMENT == VALUE_VERBOSE
// Only work if the client class is a TListBox.
if (client) {
client->ClearList();
inStream = new ifstream(theApp->FileData.FileName);
while (inStream->good()) {
inStream->getline(buf, sizeof(buf) - 1);
if (inStream->good())
client->AddString(buf);
}
##:@QUERY_APPL_COMMENT == VALUE_VERBOSE
// Return an error message if we had a stream error and it wasn't the eof.
if (inStream->bad() && !inStream->eof()) {
string msgTemplate(*GetModule(), IDS_UNABLEREAD);
char* msg = new char[MAXPATH + msgTemplate.length()];
wsprintf(msg, msgTemplate.c_str(), *(theApp->FileData.FileName));
MessageBox(msg, GetApplication()->GetName(), MB_ICONEXCLAMATION | MB_OK);
delete msg;
}
delete inStream;
}
}
##--END-- !@OPT_APPL_DOCVIEW
##--BEGIN-- @OPT_APPL_PRINTING
##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
//////////////////////////////////////////////////////////
// [[TMDIClient]]
// ==========
// Menu File Print command
##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
void [[TMDIClient]]::CmFilePrint ()
{
##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
//
// Create Printer object if not already created.
//
##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
##<<TApplication QUERY_CLASS_NAME [[TApplication]]
[[TApplication]] *theApp = TYPESAFE_DOWNCAST(GetApplication(), [[TApplication]]);
if (theApp) {
if (!theApp->Printer)
theApp->Printer = new TPrinter(GetApplication());
##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
//
// Create Printout window and set characteristics.
//
##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
APXPrintOut printout(theApp->Printer, Title, GetActiveMDIChild()->GetClientWindow(), true);
theApp->Printing++;
##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
//
// Bring up the Print dialog and print the document.
//
##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
theApp->Printer->Print(GetWindowPtr(GetActiveWindow()), printout, true);
theApp->Printing--;
}
}
##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
//////////////////////////////////////////////////////////
// [[TMDIClient]]
// ==========
// Menu File Print Setup command
##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
void [[TMDIClient]]::CmFilePrintSetup ()
{
##<<TApplication QUERY_CLASS_NAME [[TApplication]]
[[TApplication]] *theApp = TYPESAFE_DOWNCAST(GetApplication(), [[TApplication]]);
if (theApp) {
if (!theApp->Printer)
theApp->Printer = new TPrinter(GetApplication());
##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
//
// Bring up the Print Setup dialog.
//
##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
theApp->Printer->Setup(this);
}
}
##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
//////////////////////////////////////////////////////////
// [[TMDIClient]]
// ==========
// Menu File Print Preview command
##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
void [[TMDIClient]]::CmFilePrintPreview ()
{
##<<TApplication QUERY_CLASS_NAME [[TApplication]]
[[TApplication]] *theApp = TYPESAFE_DOWNCAST(GetApplication(), [[TApplication]]);
if (theApp) {
if (!theApp->Printer)
theApp->Printer = new TPrinter(GetApplication());
theApp->Printing++;
PreviewWindow *prevW = new PreviewWindow(Parent, theApp->Printer, GetActiveMDIChild()->GetClientWindow(), "Print Preview", new TLayoutWindow(0));
prevW->Create();
GetApplication()->BeginModal(GetApplication()->GetMainWindow());
##:@QUERY_APPL_COMMENT == VALUE_VERBOSE 2
// We must destroy the preview window explicitly. Otherwise, the window will not be destroyed until
// it's parent the MainWindow is destroyed.
prevW->Destroy();
delete prevW;
theApp->Printing--;
}
}
##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
//////////////////////////////////////////////////////////
// [[TMDIClient]]
// ==========
// Menu enabler used by Print, Print Setup and Print Preview.
##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
void [[TMDIClient]]::CmPrintEnable (TCommandEnabler &tce)
{
if (GetActiveMDIChild()) {
##<<TApplication QUERY_CLASS_NAME [[TApplication]]
[[TApplication]] *theApp = TYPESAFE_DOWNCAST(GetApplication(), [[TApplication]]);
if (theApp) {
##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
// If we have a Printer already created just test if all is okay.
// Otherwise create a Printer object and make sure the printer
// really exists and then delete the Printer object.
##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
if (!theApp->Printer) {
theApp->Printer = new TPrinter(GetApplication());
tce.Enable(theApp->Printer->GetSetup().Error == 0);
} else
tce.Enable(theApp->Printer->GetSetup().Error == 0);
}
} else
tce.Enable(false);
}
##--END-- @OPT_APPL_PRINTING
##--BEGIN-- @OPT_APPL_DRAGDROP
void [[TMDIClient]]::EvDropFiles (TDropInfo)
{
Parent->ForwardMessage();
}
##--END-- @OPT_APPL_DRAGDROP
>>[CPP]TMDIClient