home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / Borland / Cplus45 / BC45 / STEP13.PAK / STEP13.CPP next >
C/C++ Source or Header  |  1995-08-29  |  4KB  |  126 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows - (C) Copyright 1991, 1994 by Borland International
  3. //   Tutorial application -- step13.cpp
  4. //----------------------------------------------------------------------------
  5. #include <owl/owlpch.h>
  6. #include <owl/applicat.h>
  7. #include <owl/decmdifr.h>
  8. #include <owl/dialog.h>
  9. #include <owl/controlb.h>
  10. #include <owl/buttonga.h>
  11. #include <owl/statusba.h>
  12. #include <owl/docmanag.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include "step13.rc"
  16.  
  17. class TDrawApp : public TApplication {
  18.   public:
  19.     TDrawApp() : TApplication() {}
  20.  
  21.   protected:
  22.     // Override methods of TApplication
  23.     void InitInstance();
  24.     void InitMainWindow();
  25.  
  26.     // Event handlers
  27.     void EvNewView  (TView& view);
  28.     void EvCloseView(TView& view);
  29.     void EvDropFiles(TDropInfo dropInfo);
  30.     void CmAbout();
  31.  
  32.     TMDIClient* Client;
  33.   DECLARE_RESPONSE_TABLE(TDrawApp);
  34. };
  35.  
  36. DEFINE_RESPONSE_TABLE1(TDrawApp, TApplication)
  37.   EV_OWLVIEW(dnCreate, EvNewView),
  38.   EV_OWLVIEW(dnClose,  EvCloseView),
  39.   EV_WM_DROPFILES,
  40.   EV_COMMAND(CM_ABOUT, CmAbout),
  41. END_RESPONSE_TABLE;
  42.  
  43. void
  44. TDrawApp::InitMainWindow()
  45. {
  46.   // Construct the decorated frame window
  47.   TDecoratedMDIFrame* frame = new TDecoratedMDIFrame("Drawing Pad", 0,
  48.                                     *(Client = new TMDIClient), true);
  49.   // Construct a status bar
  50.   TStatusBar* sb = new TStatusBar(frame, TGadget::Recessed);
  51.  
  52.   // Construct a control bar
  53.   TControlBar* cb = new TControlBar(frame);
  54.   cb->Insert(*new TButtonGadget(CM_FILENEW, CM_FILENEW, TButtonGadget::Command));
  55.   cb->Insert(*new TButtonGadget(CM_FILEOPEN, CM_FILEOPEN, TButtonGadget::Command));
  56.   cb->Insert(*new TButtonGadget(CM_FILESAVE, CM_FILESAVE, TButtonGadget::Command));
  57.   cb->Insert(*new TButtonGadget(CM_FILESAVEAS, CM_FILESAVEAS, TButtonGadget::Command));
  58.   cb->Insert(*new TSeparatorGadget);
  59.   cb->Insert(*new TButtonGadget(CM_PENSIZE, CM_PENSIZE, TButtonGadget::Command));
  60.   cb->Insert(*new TButtonGadget(CM_PENCOLOR, CM_PENCOLOR, TButtonGadget::Command));
  61.   cb->Insert(*new TSeparatorGadget);
  62.   cb->Insert(*new TButtonGadget(CM_ABOUT, CM_ABOUT, TButtonGadget::Command));
  63.   cb->SetHintMode(TGadgetWindow::EnterHints);
  64.  
  65.   // Insert the status bar and control bar into the frame
  66.   frame->Insert(*sb, TDecoratedFrame::Bottom);
  67.   frame->Insert(*cb, TDecoratedFrame::Top);
  68.  
  69.   // Set the main window and its menu
  70.   SetMainWindow(frame);
  71.   GetMainWindow()->SetMenuDescr(TMenuDescr("COMMANDS",1,1,0,0,1,1));
  72.  
  73.   // Install the document manager
  74.   SetDocManager(new TDocManager(dmMDI | dmMenu));
  75. }
  76.  
  77. void
  78. TDrawApp::InitInstance()
  79. {
  80.   TApplication::InitInstance();
  81.   GetMainWindow()->DragAcceptFiles(true);
  82. }
  83.  
  84. void
  85. TDrawApp::EvDropFiles(TDropInfo dropInfo)
  86. {
  87.   int fileCount = dropInfo.DragQueryFileCount();
  88.   for (int index = 0; index < fileCount; index++) {
  89.     int fileLength = dropInfo.DragQueryFileNameLen(index)+1;
  90.     char* filePath = new char [fileLength];
  91.     dropInfo.DragQueryFile(index, filePath, fileLength);
  92.     TDocTemplate* tpl = GetDocManager()->MatchTemplate(filePath);
  93.     if (tpl)
  94.       tpl->CreateDoc(filePath);
  95.     delete filePath;
  96.   }
  97.   dropInfo.DragFinish();
  98. }
  99.  
  100. void
  101. TDrawApp::EvNewView(TView& view)
  102. {
  103.   TMDIChild* child = new TMDIChild(*Client, 0, view.GetWindow());
  104.   if (view.GetViewMenu())
  105.     child->SetMenuDescr(*view.GetViewMenu());
  106.   child->Create();
  107. }
  108.  
  109. void
  110. TDrawApp::EvCloseView(TView& /*view*/)
  111. {
  112.   // Nothing needs to be done here for MDI
  113. }
  114.  
  115. void
  116. TDrawApp::CmAbout()
  117. {
  118.   TDialog(GetMainWindow(), IDD_ABOUT).Execute();
  119. }
  120.  
  121. int
  122. OwlMain(int /*argc*/, char* /*argv*/ [])
  123. {
  124.   return TDrawApp().Run();
  125. }
  126.