//---------------------------------------------------------------------------- // Project Bug // // Copyright © 1996. All Rights Reserved. // // SUBSYSTEM: Bug Application // FILE: bugapp.cpp // AUTHOR: // // OVERVIEW // ~~~~~~~~ // Source file for implementation of TBugApp (TApplication). // //---------------------------------------------------------------------------- #include #include #include #include #include #include #include #include "bugapp.h" #include "bgmdicln.h" #include "bgmdichl.h" #include "bugedtvw.h" #include "bgabtdlg.h" // Definition of about dialog. //{{TBugApp Implementation}} //{{DOC_VIEW}} DEFINE_DOC_TEMPLATE_CLASS(TFileDocument, TBugEditView, DocType1); //{{DOC_VIEW_END}} //{{DOC_MANAGER}} DocType1 __dvt1("All Files", "*.*", 0, "txt", dtAutoDelete | dtUpdateDir | dtOverwritePrompt); //{{DOC_MANAGER_END}} // // Build a response table for all messages/commands handled by the application. // DEFINE_RESPONSE_TABLE2(TBugApp, TRecentFiles, TApplication) //{{TBugAppRSP_TBL_BEGIN}} EV_OWLVIEW(dnCreate, EvNewView), EV_OWLVIEW(dnClose, EvCloseView), EV_COMMAND(CM_FILESEND, CmFileSend), EV_COMMAND_ENABLE(CM_FILESEND, CeFileSend), EV_COMMAND(CM_HELPABOUT, CmHelpAbout), EV_WM_DROPFILES, EV_WM_WININICHANGE, EV_OWLDOCUMENT(dnCreate, EvOwlDocument), EV_OWLDOCUMENT(dnRename, EvOwlDocument), EV_REGISTERED(MruFileMessage, CmFileSelected), //{{TBugAppRSP_TBL_END}} END_RESPONSE_TABLE; //-------------------------------------------------------- // TBugApp // ~~~~~ // void test(const char *title="Press OK") { char obuf[100],ibuf[100] = "62.5 22"; istrstream is(ibuf); double dx,dy; is >> dx; is >> dy; sprintf(obuf,"x=%5.2lf y=%5.2lf",dx,dy); MessageBox(NULL,obuf,title,MB_OK); } TBugApp::TBugApp() : TApplication("Bug"), TRecentFiles(".\\Bug.ini", 4) { Printer = 0; Printing = 0; SetDocManager(new TDocManager(dmMDI, this)); test("test 1"); ApxMail = new TMailer(); test("test 2"); // INSERT>> Your constructor code here. } TBugApp::~TBugApp() { delete Printer; delete ApxMail; // INSERT>> Your destructor code here. } void TBugApp::CreateGadgets(TDockableControlBar* 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 caption and fly-over help hints. // cb->SetCaption("Toolbar"); cb->SetHintMode(TGadgetWindow::EnterHints); } void TBugApp::SetupSpeedBar(TDecoratedMDIFrame* frame) { ApxHarbor = new THarbor(*frame); // Create default toolbar New and associate toolbar buttons with commands. // TDockableControlBar* cb = new TDockableControlBar(frame); CreateGadgets(cb); // Setup the toolbar ID used by OLE 2 for toolbar negotiation. // cb->Attr.Id = IDW_TOOLBAR; ApxHarbor->Insert(*cb, alTop); } //-------------------------------------------------------- // TBugApp // ~~~~~ // Application main window construction & intialization. // void TBugApp::InitMainWindow() { if (nCmdShow != SW_HIDE) nCmdShow = (nCmdShow != SW_SHOWMINNOACTIVE) ? SW_SHOWNORMAL : nCmdShow; MdiClient = new TBugMDIClient(this); TDecoratedMDIFrame* frame = new TDecoratedMDIFrame(Name, IDM_MDI, *MdiClient, true, this); // Enable acceptance of dropped files // frame->Attr.ExStyle |= WS_EX_ACCEPTFILES; nCmdShow = (nCmdShow != SW_SHOWMINNOACTIVE) ? SW_SHOWNORMAL : nCmdShow; // Assign icons for this application. // frame->SetIcon(this, IDI_MDIAPPLICATION); frame->SetIconSm(this, IDI_MDIAPPLICATION); // Associate with the accelerator table. // frame->Attr.AccelTable = IDM_MDI; TStatusBar* sb = new TStatusBar(frame, TGadget::Recessed, TStatusBar::CapsLock | TStatusBar::NumLock | TStatusBar::ScrollLock); frame->Insert(*sb, TDecoratedFrame::Bottom); SetupSpeedBar(frame); SetMainWindow(frame); frame->SetMenuDescr(TMenuDescr(IDM_MDI)); } //-------------------------------------------------------- // TBugApp // ~~~~~ // Application instance initialization. // void TBugApp::InitInstance() { TApplication::InitInstance(); ProcessCmdLine(lpCmdLine); } //-------------------------------------------------------- // TBugApp // ~~~~~ // Process command line parameters. // void TBugApp::ProcessCmdLine(char * CmdLine) { TCmdLine cmd(CmdLine); while (cmd.Kind != TCmdLine::Done) { if (cmd.Kind == TCmdLine::Option) { if (strnicmp(cmd.Token, "unregister", cmd.TokenLen) == 0) { UnRegisterInfo(); return; } } cmd.NextToken(); } RegisterInfo(); } //-------------------------------------------------------- // TBugApp // ~~~~~ // Register application info. // void TBugApp::RegisterInfo() { TAPointer buffer = new char[_MAX_PATH]; GetModuleFileName(buffer, _MAX_PATH); TRegKey(TRegKey::ClassesRoot, "Bug.Application\\DefaultIcon").SetDefValue(0, REG_SZ, buffer, strlen(buffer)); strcat(buffer, ",1"); TRegKey(TRegKey::ClassesRoot, "Bug.Document.1\\DefaultIcon").SetDefValue(0, REG_SZ, buffer, strlen(buffer)); strcpy(buffer, "Bug.Document.1"); TRegKey(TRegKey::ClassesRoot, ".txt").SetDefValue(0, REG_SZ, buffer, strlen(buffer)); } //-------------------------------------------------------- // TBugApp // ~~~~~ // Unregister application info. // void TBugApp::UnRegisterInfo() { TAPointer buffer = new char[_MAX_PATH]; GetModuleFileName(buffer, _MAX_PATH); TRegKey(TRegKey::ClassesRoot, "Bug.Application").DeleteKey("DefaultIcon"); TRegKey(TRegKey::ClassesRoot, "Bug.Document.1").DeleteKey("DefaultIcon"); TRegKey::ClassesRoot.DeleteKey("Bug.Application"); TRegKey::ClassesRoot.DeleteKey("Bug.Document.1"); TRegKey::ClassesRoot.DeleteKey(".txt"); } //-------------------------------------------------------- // TBugApp // ~~~~~ // Response Table handlers: // void TBugApp::EvNewView(TView& view) { TMDIClient* mdiClient = TYPESAFE_DOWNCAST(GetMainWindow()->GetClientWindow(), TMDIClient); if (mdiClient) { TBugMDIChild* child = new TBugMDIChild(*mdiClient, 0, view.GetWindow()); // Set the menu descriptor for this view. // if (view.GetViewMenu()) child->SetMenuDescr(*view.GetViewMenu()); // Assign icons with this child window. // child->SetIcon(this, IDI_DOC); child->SetIconSm(this, IDI_DOC); child->Create(); } } void TBugApp::EvCloseView(TView&) { } void TBugApp::CeFileSend(TCommandEnabler& ce) { ce.Enable((GetDocManager()->GetCurrentDoc() != 0) && ApxMail->IsMAPIAvailable()); } void TBugApp::CmFileSend () { // Check to see if a document exists // TDocument* currentDoc = GetDocManager()->GetCurrentDoc(); if (currentDoc) { TAPointer savedPath = new char[_MAX_PATH]; TAPointer docName = new char[_MAX_PATH]; bool dirtyState = currentDoc->IsDirty(); if (currentDoc->GetDocPath()) strcpy(savedPath, currentDoc->GetDocPath()); else strcpy(savedPath, ""); if (currentDoc->GetTitle()) strcpy(docName, currentDoc->GetTitle()); else strcpy(docName, "Document"); TFileName tempFile(TFileName::TempFile); currentDoc->SetDocPath(tempFile.Canonical().c_str()); currentDoc->Commit(true); currentDoc->SetDocPath(savedPath); currentDoc->SetDirty(dirtyState); ApxMail->SendDocuments(GetMainWindow(), tempFile.Canonical().c_str(), docName, false); tempFile.Remove(); } } //-------------------------------------------------------- // TBugApp // ~~~~~~~~~~~ // Menu Help About Bug command void TBugApp::CmHelpAbout() { // Show the modal dialog. // // TBugAboutDlg(GetMainWindow()).Execute(); test("test 3"); } void TBugApp::EvDropFiles(TDropInfo drop) { TFileDropletList files; // Iterate thru the entries in drop and create FileDrops objects for each // one. // int fileCount = drop.DragQueryFileCount(); // Number of files dropped. for (int i = 0; i < fileCount; i++) files.Add(new TFileDroplet(drop, i)); // Open the files that were dropped. // AddFiles(files); // Release the memory allocated for this handle with DragFinish. // drop.DragFinish(); } void TBugApp::AddFiles(TFileDropletList& files) { // Open all files dragged in. // for (TFileDropletListIter fileIter(files); fileIter; fileIter++) { TDocTemplate* tpl = GetDocManager()->MatchTemplate(fileIter.Current()->GetName()); if (tpl) GetDocManager()->CreateDoc(tpl, fileIter.Current()->GetName()); } } void TBugApp::EvOwlDocument(TDocument& doc) { if (doc.GetDocPath()) SaveMenuChoice(doc.GetDocPath()); } int32 TBugApp::CmFileSelected(uint wp, int32) { TAPointer text = new char[_MAX_PATH]; GetMenuText(wp, text, _MAX_PATH); TDocTemplate* tpl = GetDocManager()->MatchTemplate(text); if (tpl) GetDocManager()->CreateDoc(tpl, text); return 0; } void TBugApp::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) { const int bufferSize = 255; char printDBuffer[bufferSize]; LPSTR printDevice = printDBuffer; LPSTR devName; LPSTR driverName = 0; LPSTR outputName = 0; if (::GetProfileString("windows", "device", "", printDevice, bufferSize)) { // 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* []) { TBugApp app; return app.Run(); }