/***************************************************************************** * * Copyright (c) 1999, KL GROUP INC. All Rights Reserved. * http://www.klgroup.com * * This file is provided for demonstration and educational uses only. * Permission to use, copy, modify and distribute this file for * any purpose and without fee is hereby granted, provided that the * above copyright notice and this permission notice appear in all * copies, and that the name of KL Group not be used in advertising * or publicity pertaining to this material without the specific, * prior written permission of an authorized representative of * KL Group. * * KL GROUP MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY * OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * PURPOSE, OR NON-INFRINGEMENT. KL GROUP SHALL NOT BE LIABLE FOR ANY * DAMAGES SUFFERED BY USERS AS A RESULT OF USING, MODIFYING OR * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. */ /* Project oc3owl OVERVIEW ======== Source file for implementation of oc3owlApp (TApplication). */ #include #pragma hdrstop #include #include "och3dowl.h" #include "oc3wlapp.h" #include "oc3dmdif.h" #include "oc3wmdic.h" #include "oc3wmdi1.h" #include "oc3wlwnv.h" #include "oc3wlabd.h" // Definition of about dialog. // Drag / Drop support: TFileDrop::TFileDrop (char* fileName, TPoint& p, bool inClient, TModule*) { char exePath[MAXPATH]; exePath[0] = 0; FileName = strcpy(new char[strlen(fileName) + 1], fileName); Point = p; InClientArea = inClient; } TFileDrop::~TFileDrop () { delete FileName; } const char *TFileDrop::WhoAmI () { return FileName; } //{{oc3owlApp Implementation}} //{{DOC_VIEW}} DEFINE_DOC_TEMPLATE_CLASS(TFileDocument, oc3owlWindowView, DocType1); //{{DOC_VIEW_END}} //{{DOC_MANAGER}} DocType1 __dvt1("All Files (*.*)", "*.*", 0, "TXT", dtAutoDelete | dtUpdateDir); //{{DOC_MANAGER_END}} // // Build a response table for all messages/commands handled // by the application. // DEFINE_RESPONSE_TABLE1(oc3owlApp, TApplication) //{{oc3owlAppRSP_TBL_BEGIN}} EV_OWLVIEW(dnCreate, EvNewView), EV_OWLVIEW(dnClose, EvCloseView), EV_COMMAND(CM_HELPABOUT, CmHelpAbout), EV_WM_DROPFILES, EV_WM_WININICHANGE, //{{oc3owlAppRSP_TBL_END}} END_RESPONSE_TABLE; ////////////////////////////////////////////////////////// // oc3owlApp // ===== // oc3owlApp::oc3owlApp () : TApplication("Olectra Chart 3D - OWL Wrapper Demo") { Printer = 0; Printing = 0; SetDocManager(new TDocManager(dmMDI, this)); // INSERT>> Your constructor code here. } oc3owlApp::~oc3owlApp () { if (Printer) delete Printer; // INSERT>> Your destructor code here. } void oc3owlApp::CreateGadgets (TControlBar *cb, bool server) { if (!server) { cb->Insert(*new TButtonGadget(CM_MDIFILENEW, CM_MDIFILENEW)); cb->Insert(*new TButtonGadget(CM_MDIFILEOPEN, CM_MDIFILEOPEN)); cb->Insert(*new TButtonGadget(CM_FILESAVE, CM_FILESAVE)); cb->Insert(*new TSeparatorGadget(6)); } cb->Insert(*new TButtonGadget(CM_EDITCUT, CM_EDITCUT)); cb->Insert(*new TButtonGadget(CM_EDITCOPY, CM_EDITCOPY)); cb->Insert(*new TButtonGadget(CM_EDITPASTE, CM_EDITPASTE)); cb->Insert(*new TSeparatorGadget(6)); cb->Insert(*new TButtonGadget(CM_EDITUNDO, CM_EDITUNDO)); cb->Insert(*new TSeparatorGadget(6)); cb->Insert(*new TButtonGadget(CM_EDITFIND, CM_EDITFIND)); cb->Insert(*new TButtonGadget(CM_EDITFINDNEXT, CM_EDITFINDNEXT)); if (!server) { cb->Insert(*new TSeparatorGadget(6)); cb->Insert(*new TButtonGadget(CM_FILEPRINT, CM_FILEPRINT)); cb->Insert(*new TButtonGadget(CM_FILEPRINTPREVIEW, CM_FILEPRINTPREVIEW)); } // Add fly-over help hints. cb->SetHintMode(TGadgetWindow::EnterHints); } void oc3owlApp::SetupSpeedBar (TDecoratedMDIFrame *frame) { // // Create default toolbar New and associate toolbar buttons with commands. // TControlBar* cb = new TControlBar(frame); CreateGadgets(cb); // Setup the toolbar ID used by OLE 2 for toolbar negotiation. cb->Attr.Id = IDW_TOOLBAR; frame->Insert(*cb, TDecoratedFrame::Top); } ////////////////////////////////////////////////////////// // oc3owlApp // ===== // Application intialization. // void oc3owlApp::InitMainWindow () { if (nCmdShow != SW_HIDE) nCmdShow = (nCmdShow != SW_SHOWMINNOACTIVE) ? SW_SHOWNORMAL : nCmdShow; mdiClient = new oc3owlMDIClient(this); oc3owlDecoratedMDIFrame* frame = new oc3owlDecoratedMDIFrame(Name, MDI_MENU, *mdiClient, true, this); nCmdShow = (nCmdShow != SW_SHOWMINNOACTIVE) ? SW_SHOWNORMAL : nCmdShow; // // Assign ICON w/ this application. // frame->SetIcon(this, IDI_MDIAPPLICATION); // // Menu associated with window and accelerator table associated with table. // frame->AssignMenu(MDI_MENU); // // Associate with the accelerator table. // frame->Attr.AccelTable = MDI_MENU; SetupSpeedBar(frame); TStatusBar *sb = new TStatusBar(frame, TGadget::Recessed, TStatusBar::CapsLock | TStatusBar::NumLock | TStatusBar::ScrollLock | TStatusBar::Overtype); frame->Insert(*sb, TDecoratedFrame::Bottom); SetMainWindow(frame); frame->SetMenuDescr(TMenuDescr(MDI_MENU)); } ////////////////////////////////////////////////////////// // oc3owlApp // ===== // Response Table handlers: // void oc3owlApp::EvNewView (TView& view) { TMDIClient *mdiClient = TYPESAFE_DOWNCAST(GetMainWindow()->GetClientWindow(), TMDIClient); if (mdiClient) { oc3owlMDIChild* child = new oc3owlMDIChild(*mdiClient, 0, view.GetWindow()); // Associate ICON w/ this child window. child->SetIcon(this, IDI_DOC); child->Create(); } } void oc3owlApp::EvCloseView (TView&) { } ////////////////////////////////////////////////////////// // oc3owlApp // =========== // Menu Help About oc3owl.exe command void oc3owlApp::CmHelpAbout () { // // Show the modal dialog. // oc3owlAboutDlg(GetMainWindow()).Execute(); } void oc3owlApp::InitInstance () { TApplication::InitInstance(); // Accept files via drag/drop in the frame window. GetMainWindow()->DragAcceptFiles(true); } void oc3owlApp::EvDropFiles (TDropInfo drop) { // Number of files dropped. int totalNumberOfFiles = drop.DragQueryFileCount(); TFileList* files = new TFileList; for (int i = 0; i < totalNumberOfFiles; i++) { // Tell DragQueryFile the file interested in (i) and the length of your buffer. int fileLength = drop.DragQueryFileNameLen(i) + 1; char *fileName = new char[fileLength]; drop.DragQueryFile(i, fileName, fileLength); // Getting the file dropped. The location is relative to your client coordinates, // and will have negative values if dropped in the non client parts of the window. // // DragQueryPoint copies that point where the file was dropped and returns whether // or not the point is in the client area. Regardless of whether or not the file // is dropped in the client or non-client area of the window, you will still receive // the file name. TPoint point; bool inClientArea = drop.DragQueryPoint(point); files->Add(new TFileDrop(fileName, point, inClientArea, this)); } // Open the files that were dropped. AddFiles(files); // Release the memory allocated for this handle with DragFinish. drop.DragFinish(); } void oc3owlApp::AddFiles (TFileList* files) { // Open all files dragged in. TFileListIter fileIter(*files); while (fileIter) { TDocTemplate* tpl = GetDocManager()->MatchTemplate(fileIter.Current()->WhoAmI()); if (tpl) tpl->CreateDoc(fileIter.Current()->WhoAmI()); fileIter++; } } void oc3owlApp::EvWinIniChange (char far* section) { if (strcmp(section, "windows") == 0) { // If the device changed in the WIN.INI file then the printer // might have changed. If we have a TPrinter (Printer) then // check and make sure it's identical to the current device // entry in WIN.INI. if (Printer) { char printDBuffer[255]; LPSTR printDevice = printDBuffer; LPSTR devName; LPSTR driverName = 0; LPSTR outputName = 0; if (::GetProfileString("windows", "device", "", printDevice, sizeof(printDevice))) { // The string which should come back is something like: // // HP LaserJet III,hppcl5a,LPT1: // // Where the format is: // // devName,driverName,outputName // devName = printDevice; while (*printDevice) { if (*printDevice == ',') { *printDevice++ = 0; if (!driverName) driverName = printDevice; else outputName = printDevice; } else printDevice = ::AnsiNext(printDevice); } if ((Printer->GetSetup().Error != 0) || (strcmp(devName, Printer->GetSetup().GetDeviceName()) != 0) || (strcmp(driverName, Printer->GetSetup().GetDriverName()) != 0) || (strcmp(outputName, Printer->GetSetup().GetOutputName()) != 0)) { // New printer installed so get the new printer device now. delete Printer; Printer = new TPrinter(this); } } else { // No printer installed (GetProfileString failed). delete Printer; Printer = new TPrinter(this); } } } } int OwlMain (int , char* []) { try { oc3owlApp app; return app.Run(); } catch (xmsg& x) { ::MessageBox(0, x.why().c_str(), "Exception", MB_OK); } return -1; }