home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / APXDLGDV.PAK / APXDLGDA.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  6.8 KB  |  295 lines

  1. //----------------------------------------------------------------------------
  2. //  Project ApxDlgDv
  3. //  Borland International
  4. //  Copyright ⌐ 1996. All Rights Reserved.
  5. //
  6. //  SUBSYSTEM:    ApxDlgDv Application
  7. //  FILE:         apxdlgda.cpp
  8. //  AUTHOR:
  9. //
  10. //  OVERVIEW
  11. //  ~~~~~~~~
  12. //  Source file for implementation of TApxDlgDvApp (TApplication).
  13. //
  14. //----------------------------------------------------------------------------
  15.  
  16. #include <owl/pch.h>
  17.  
  18. #include <owl/buttonga.h>
  19. #include <owl/docmanag.h>
  20. #include <owl/statusba.h>
  21. #include <owl/filedoc.h>
  22.  
  23. #include <classlib/cmdline.h>
  24. #include <classlib/filename.h>
  25.  
  26. #include "apxdlgda.h"
  27. #include "apxdlddc.h"                        // Definition of client class.
  28.  
  29.  
  30. //{{TApxDlgDvApp Implementation}}
  31.  
  32.  
  33.  
  34. DEFINE_DOC_TEMPLATE_CLASS(TFileDocument, TApxDlgDvDlgClient, DlgDTPL);
  35. DlgDTPL __dlogClnt("All Files", "*.*", 0, "TXT", dtAutoDelete | dtUpdateDir);
  36.  
  37. //{{DOC_VIEW}}
  38. //{{DOC_VIEW_END}}
  39.  
  40. //{{DOC_MANAGER}}
  41. //{{DOC_MANAGER_END}}
  42.  
  43.  
  44. //
  45. // Build a response table for all messages/commands handled by the application.
  46. //
  47. DEFINE_RESPONSE_TABLE2(TApxDlgDvApp, TRecentFiles, TApplication)
  48. //{{TApxDlgDvAppRSP_TBL_BEGIN}}
  49.   EV_OWLVIEW(dnCreate, EvNewView),
  50.   EV_OWLVIEW(dnClose,  EvCloseView),
  51.   EV_COMMAND(CM_FILESEND, CmFileSend),
  52.   EV_COMMAND_ENABLE(CM_FILESEND, CeFileSend),
  53.   EV_COMMAND(CM_HELPABOUT, CmHelpAbout),
  54.   EV_OWLDOCUMENT(dnCreate, EvOwlDocument),
  55.   EV_OWLDOCUMENT(dnRename, EvOwlDocument),
  56.   EV_REGISTERED(MruFileMessage, CmFileSelected),
  57. //{{TApxDlgDvAppRSP_TBL_END}}
  58. END_RESPONSE_TABLE;
  59.  
  60.  
  61. //--------------------------------------------------------
  62. // TApxDlgDvApp
  63. // ~~~~~
  64. //
  65. TApxDlgDvApp::TApxDlgDvApp() : TApplication("AppExpert Dialog Client DocView Example"), TRecentFiles(".\\ApxDlgDv.ini", 4)
  66. {
  67.   SetDocManager(new TDocManager(dmSDI, this));
  68.  
  69.   ApxMail = new TMailer();
  70.  
  71.   // INSERT>> Your constructor code here.
  72. }
  73.  
  74.  
  75. TApxDlgDvApp::~TApxDlgDvApp()
  76. {
  77.   delete ApxMail;
  78.  
  79.   // INSERT>> Your destructor code here.
  80. }
  81.  
  82.  
  83. //--------------------------------------------------------
  84. // TApxDlgDvApp
  85. // ~~~~~
  86. // Application main window construction & intialization.
  87. //
  88. void TApxDlgDvApp::InitMainWindow()
  89. {
  90.   if (nCmdShow != SW_HIDE)
  91.     nCmdShow = (nCmdShow != SW_SHOWMINNOACTIVE) ? SW_SHOWNORMAL : nCmdShow;
  92.  
  93.   TSDIDecFrame* frame = new TSDIDecFrame(0, GetName(), 0, true, this);
  94.  
  95.   // Assign icons for this application.
  96.   //
  97.   frame->SetIcon(this, IDI_SDIAPPLICATION);
  98.   frame->SetIconSm(this, IDI_SDIAPPLICATION);
  99.  
  100.   SetMainWindow(frame);
  101.  
  102. }
  103.  
  104.  
  105. //--------------------------------------------------------
  106. // TApxDlgDvApp
  107. // ~~~~~
  108. // Application instance initialization.
  109. //
  110. void TApxDlgDvApp::InitInstance()
  111. {
  112.   TApplication::InitInstance();
  113.   GetDocManager()->CreateAnyDoc(0, dtNewDoc);
  114.   ProcessCmdLine(lpCmdLine);
  115. }
  116.  
  117.  
  118. //--------------------------------------------------------
  119. // TApxDlgDvApp
  120. // ~~~~~
  121. // Process command line parameters.
  122. //
  123. void TApxDlgDvApp::ProcessCmdLine(char * CmdLine)
  124. {
  125.   TCmdLine cmd(CmdLine);
  126.  
  127.   while (cmd.Kind != TCmdLine::Done) {
  128.     if (cmd.Kind == TCmdLine::Option) {
  129.       if (strnicmp(cmd.Token, "unregister", cmd.TokenLen) == 0) {
  130.         UnRegisterInfo();
  131.         return;
  132.       }
  133.     }
  134.     cmd.NextToken();
  135.   }
  136.  
  137.   RegisterInfo();
  138. }
  139.  
  140.  
  141. //--------------------------------------------------------
  142. // TApxDlgDvApp
  143. // ~~~~~
  144. // Register application info.
  145. //
  146. void TApxDlgDvApp::RegisterInfo()
  147. {
  148.   TAPointer<char> buffer = new char[_MAX_PATH];
  149.  
  150.   GetModuleFileName(buffer, _MAX_PATH);
  151.  
  152.   TRegKey(TRegKey::ClassesRoot, "ApxDlgDv.Application\\DefaultIcon").SetDefValue(0, REG_SZ, buffer, strlen(buffer));
  153.   strcat(buffer, ",1");
  154. }
  155.  
  156.  
  157. //--------------------------------------------------------
  158. // TApxDlgDvApp
  159. // ~~~~~
  160. // Unregister application info.
  161. //
  162. void TApxDlgDvApp::UnRegisterInfo()
  163. {
  164.   TAPointer<char> buffer = new char[_MAX_PATH];
  165.  
  166.   GetModuleFileName(buffer, _MAX_PATH);
  167.  
  168.   TRegKey(TRegKey::ClassesRoot, "ApxDlgDv.Application").DeleteKey("DefaultIcon");
  169.   TRegKey(TRegKey::ClassesRoot, "ApxDlgDv.Document.1").DeleteKey("DefaultIcon");
  170.  
  171.   TRegKey::ClassesRoot.DeleteKey("ApxDlgDv.Application");
  172. }
  173.  
  174.  
  175.  
  176. //--------------------------------------------------------
  177. // TApxDlgDvApp
  178. // ~~~~~
  179. // Response Table handlers:
  180. //
  181. void TApxDlgDvApp::EvNewView(TView& view)
  182. {
  183.   GetMainWindow()->SetClientWindow(view.GetWindow());
  184.   if (!view.IsOK())
  185.     GetMainWindow()->SetClientWindow(0);
  186.   else if (view.GetViewMenu())
  187.     GetMainWindow()->MergeMenu(*view.GetViewMenu());
  188. }
  189.  
  190.  
  191. void TApxDlgDvApp::EvCloseView(TView&)
  192. {
  193.   GetMainWindow()->SetClientWindow(0);
  194.   GetMainWindow()->SetCaption("AppExpert Dialog Client DocView Example");
  195. }
  196.  
  197.  
  198. //{{TSDIDecFrame Implementation}}
  199.  
  200.  
  201. TSDIDecFrame::TSDIDecFrame(TWindow* parent, const char far* title, TWindow* clientWnd, bool trackMenuSelection, TModule* module)
  202. :
  203.   TDecoratedFrame(parent, title, clientWnd, trackMenuSelection, module)
  204. {
  205.   // INSERT>> Your constructor code here.
  206.  
  207. }
  208.  
  209.  
  210. TSDIDecFrame::~TSDIDecFrame()
  211. {
  212.   // INSERT>> Your destructor code here.
  213.  
  214. }
  215.  
  216.  
  217. void TApxDlgDvApp::CeFileSend(TCommandEnabler& ce)
  218. {
  219.   ce.Enable((GetDocManager()->GetCurrentDoc() != 0)
  220.             && ApxMail->IsMAPIAvailable());
  221. }
  222.  
  223.  
  224. void TApxDlgDvApp::CmFileSend ()
  225. {
  226.   // Check to see if a document exists
  227.   //
  228.   TDocument* currentDoc = GetDocManager()->GetCurrentDoc();
  229.  
  230.   if (currentDoc) {
  231.     TAPointer<char> savedPath = new char[_MAX_PATH];
  232.     TAPointer<char> docName = new char[_MAX_PATH];
  233.  
  234.     bool dirtyState = currentDoc->IsDirty();
  235.  
  236.     if (currentDoc->GetDocPath())
  237.       strcpy(savedPath, currentDoc->GetDocPath());
  238.     else
  239.       strcpy(savedPath, "");
  240.  
  241.     if (currentDoc->GetTitle())
  242.       strcpy(docName, currentDoc->GetTitle());
  243.     else
  244.       strcpy(docName, "Document");
  245.  
  246.     TFileName tempFile(TFileName::TempFile);
  247.  
  248.     currentDoc->SetDocPath(tempFile.Canonical().c_str());
  249.     currentDoc->Commit(true);
  250.  
  251.     currentDoc->SetDocPath(savedPath);
  252.     currentDoc->SetDirty(dirtyState);
  253.  
  254.     ApxMail->SendDocuments(GetMainWindow(), tempFile.Canonical().c_str(), docName, false);
  255.  
  256.     tempFile.Remove();
  257.   }
  258. }
  259.  
  260.  
  261. //--------------------------------------------------------
  262. // TApxDlgDvApp
  263. // ~~~~~~~~~~~
  264. //
  265. // Menu Help About ApxDlgDv command
  266. void TApxDlgDvApp::CmHelpAbout()
  267. {
  268. }
  269.  
  270.  
  271. void TApxDlgDvApp::EvOwlDocument(TDocument& doc)
  272. {
  273.   if (doc.GetDocPath())
  274.     SaveMenuChoice(doc.GetDocPath());
  275. }
  276.  
  277.  
  278. int32 TApxDlgDvApp::CmFileSelected(uint wp, int32)
  279. {
  280.   TAPointer<char> text = new char[_MAX_PATH];
  281.  
  282.   GetMenuText(wp, text, _MAX_PATH);
  283.   TDocTemplate* tpl = GetDocManager()->MatchTemplate(text);
  284.   if (tpl)
  285.     GetDocManager()->CreateDoc(tpl, text);
  286.   return 0;
  287. }
  288.  
  289.  
  290. int OwlMain(int , char* [])
  291. {
  292.   TApxDlgDvApp   app;
  293.   return app.Run();
  294. }
  295.