home *** CD-ROM | disk | FTP | other *** search
- /* Project xped3
-
- Copyright ⌐ 1993. All Rights Reserved.
-
- SUBSYSTEM: xped3.exe Application
- FILE: xpd3mdic.cpp
- AUTHOR:
-
-
- OVERVIEW
- ========
- Source file for implementation of xped3MDIClient (TMDIClient).
- */
-
-
- #include <owl\owlpch.h>
- #pragma hdrstop
-
- #include <dir.h>
-
- #include "xped3app.h"
- #include "xpd3mdic.h"
- #include "xpd3mdi1.h"
-
-
- //{{xped3MDIClient Implementation}}
-
-
- //
- // Build a response table for all messages/commands handled
- // by xped3MDIClient derived from TMDIClient.
- //
- DEFINE_RESPONSE_TABLE1(xped3MDIClient, TMDIClient)
- //{{xped3MDIClientRSP_TBL_BEGIN}}
- EV_COMMAND(CM_MDIFILENEW, CmFileNew),
- EV_COMMAND(CM_MDIFILEOPEN, CmFileOpen),
- //{{xped3MDIClientRSP_TBL_END}}
- END_RESPONSE_TABLE;
-
-
- //////////////////////////////////////////////////////////
- // xped3MDIClient
- // ===========
- // Construction/Destruction handling.
- xped3MDIClient::xped3MDIClient ()
- : TMDIClient ()
- {
- ChildCount = 0;
-
- // INSERT>> Your constructor code here.
-
- }
-
-
- xped3MDIClient::~xped3MDIClient ()
- {
- Destroy();
-
- // INSERT>> Your destructor code here.
-
- }
-
-
- //////////////////////////////////////////////////////////
- // xped3MDIClient
- // ===========
- // MDIClient site initialization.
- void xped3MDIClient::SetupWindow ()
- {
- // Default SetUpWindow processing.
- TMDIClient::SetupWindow ();
-
- // Common file file flags and filters for Open/Save As dialogs. Filename and directory are
- // computed in the member functions CmFileOpen, and CmFileSaveAs.
- FileData.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
- FileData.SetFilter("All Files (*.*)|*.*|");
-
- }
-
-
- //////////////////////////////////////////////////////////
- // xped3MDIClient
- // ===========
- // Menu File New command
- void xped3MDIClient::CmFileNew ()
- {
- char title[255];
-
- // Generate a title for the MDI child window.
- wsprintf(title, "%d", ChildCount++);
-
- xped3MDIChild* child = new xped3MDIChild(*this, title, 0);
-
- // Associate ICON w/ this child window.
- child->SetIcon(GetApplication(), IDI_DOC);
-
- // If the current active MDI child is maximize then this one should be also.
- xped3MDIChild *curChild = (xped3MDIChild *)GetActiveMDIChild();
- if (curChild && (curChild->GetWindowLong(GWL_STYLE) & WS_MAXIMIZE))
- child->Attr.Style |= WS_MAXIMIZE;
-
- child->Create();
- }
-
-
- void xped3MDIClient::OpenFile (const char *fileName)
- {
- if (fileName)
- lstrcpy(FileData.FileName, fileName);
-
- //
- // Create a MDIChild window whose client is TEditFile.
- //
- xped3MDIChild* child = new xped3MDIChild(*this, "", new TEditFile(0, 0, 0, 0, 0, 0, 0, FileData.FileName));
-
- // Associate ICON w/ this child window.
- child->SetIcon(GetApplication(), IDI_DOC);
-
- // If the current active MDI child is maximize then this one should be also.
- xped3MDIChild *curChild = (xped3MDIChild *)GetActiveMDIChild();
- if (curChild && (curChild->GetWindowLong(GWL_STYLE) & WS_MAXIMIZE))
- child->Attr.Style |= WS_MAXIMIZE;
-
- child->Create();
-
- LoadTextFile();
- }
-
-
- //////////////////////////////////////////////////////////
- // xped3MDIClient
- // ===========
- // Menu File Open command
- void xped3MDIClient::CmFileOpen ()
- {
- //
- // Display standard Open dialog box to select a file name.
- //
- *FileData.FileName = 0;
- if (TFileOpenDialog(this, FileData).Execute() == IDOK)
- OpenFile();
- }
-
-
- // Used by ListBox client to read a text file into the list box.
- void xped3MDIClient::LoadTextFile ()
- {
- char buf[255+1];
- ifstream *inStream;
-
- xped3MDIChild *curChild = (xped3MDIChild *)GetActiveMDIChild();
- TListBox *client = TYPESAFE_DOWNCAST(curChild->GetClientWindow(), TListBox);
-
- // Only work if the client class is a TListBox.
- if (client) {
- client->ClearList();
- inStream = new ifstream(FileData.FileName);
- while (inStream->good()) {
- inStream->getline(buf, sizeof(buf) - 1);
- if (inStream->good())
- client->AddString(buf);
- }
-
- // 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(), *FileData.FileName);
- MessageBox(msg, GetApplication()->GetName(), MB_ICONEXCLAMATION | MB_OK);
- delete msg;
- }
-
- delete inStream;
- }
- }
-
-
-