home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c016 / 3.ddi / MEDIADIB.PAK / DIBAPP.CPP next >
Encoding:
C/C++ Source or Header  |  1993-12-07  |  4.3 KB  |  149 lines

  1. //---------------------------------------------------------
  2. //     DIBVIEW Sample Application
  3. //---------------------------------------------------------
  4. #include <owl\owlpch.h>
  5. #include <owl\applicat.h>
  6. #include <owl\statusba.h>
  7. #include <owl\controlb.h>
  8. #include <owl\buttonga.h>
  9. #define KNIFE_DATA
  10. #include "dibdoc.h"
  11. #include "dibview.h"
  12. #include "dibapp.rc"
  13.  
  14. //---------------------------------------------------------
  15. // A variant of TMDIChild that can parent vbx controls directly
  16. //---------------------------------------------------------
  17. class TVbxMDIChild : public TMDIChild, public TVbxEventHandler {
  18.   public:
  19.     TVbxMDIChild(TMDIClient& parent, const char far* title, TWindow* client)
  20.       : TMDIChild(parent, title, client, FALSE) {}
  21.   DECLARE_RESPONSE_TABLE(TVbxMDIChild);
  22. };
  23.  
  24. DEFINE_RESPONSE_TABLE2(TVbxMDIChild, TMDIChild, TVbxEventHandler)
  25. END_RESPONSE_TABLE;
  26.  
  27. //---------------------------------------------------------
  28. //     TDIBApp Class
  29. //---------------------------------------------------------
  30. class TDIBApp : public TApplication {
  31.   public:
  32.      TDIBApp();
  33.  
  34.   protected:
  35.      // Override methods of TApplication
  36.      void InitInstance();
  37.      void InitMainWindow();
  38.  
  39.      // Event handlers
  40.      void EvNewView  (TView& view);
  41.      void EvCloseView(TView& view);
  42.      void CmCopyDib();
  43.      void CmAbout();
  44.  
  45.      TMDIClient* Client;
  46.   DECLARE_RESPONSE_TABLE(TDIBApp);
  47. };
  48.  
  49. ///////////////////////////////////////
  50.  
  51. DEFINE_RESPONSE_TABLE1(TDIBApp, TApplication)
  52.   EV_OWLVIEW(dnCreate, EvNewView),
  53.   EV_OWLVIEW(dnClose,  EvCloseView),
  54.   EV_COMMAND(CM_COPYDIB, CmCopyDib),
  55.   EV_COMMAND(CM_ABOUT, CmAbout),
  56. END_RESPONSE_TABLE;
  57.  
  58. ///////////////////////////////////////
  59. TDIBApp::TDIBApp() : TApplication("Dib View")
  60. {
  61. }
  62.  
  63. ///////////////////////////////////////
  64. void TDIBApp::InitMainWindow()
  65. {
  66.   // Construct the decorated frame window
  67.   TDecoratedMDIFrame* frame = new TDecoratedMDIFrame(GetName(), 0,
  68.                                  *(Client = new TMDIClient), TRUE);
  69.   // Construct a status bar
  70.   TStatusBar* sb = new TStatusBar(frame, TGadget::Recessed);
  71.  
  72.   // Construct a control bar
  73.   TControlBar *cb = new TControlBar(frame);
  74.   cb->Insert(*new TButtonGadget(CM_FILEOPEN, CM_FILEOPEN, TButtonGadget::Command));
  75.   cb->Insert(*new TButtonGadget(CM_FILESAVE, CM_FILESAVE, TButtonGadget::Command));
  76.   cb->Insert(*new TButtonGadget(CM_FILESAVEAS, CM_FILESAVEAS, TButtonGadget::Command));
  77.   cb->Insert(*new TButtonGadget(CM_COPYDIB, CM_COPYDIB, TButtonGadget::Command));
  78.   cb->Insert(*new TSeparatorGadget);
  79.   cb->Insert(*new TButtonGadget(CM_ABOUT, CM_ABOUT, TButtonGadget::Command));
  80.   cb->SetHintMode(TGadgetWindow::EnterHints);
  81.  
  82.   // Insert the status bar and control bar into the frame
  83.   frame->Insert(*sb, TDecoratedFrame::Bottom);
  84.   frame->Insert(*cb, TDecoratedFrame::Top);
  85.  
  86.   // Install the document manager
  87.   SetDocManager(new TDocManager(dmMDI));
  88.  
  89.   // Set the main window and its menu
  90.   frame->SetMenuDescr(TMenuDescr("COMMANDS",1,0,0,0,1,1));
  91.   SetMainWindow(frame);
  92. }
  93.  
  94. ///////////////////////////////////////
  95.  
  96. void TDIBApp::InitInstance()
  97. {
  98.   TApplication::InitInstance();
  99.   EnableCtl3d();
  100. }
  101.  
  102. ///////////////////////////////////////
  103.  
  104. void TDIBApp::EvNewView(TView& view)
  105. {
  106.   TMDIChild* child = new TVbxMDIChild(*Client, view.GetDocument().GetTitle(),
  107.                                       view.GetWindow());
  108.   if (view.GetViewMenu())
  109.     child->SetMenuDescr(*view.GetViewMenu());
  110.   child->Create();
  111. }
  112.  
  113. ///////////////////////////////////////
  114.  
  115. void TDIBApp::EvCloseView(TView& /*view*/)
  116. {  // nothing needs to be done here for MDI
  117. }
  118.  
  119. void TDIBApp::CmCopyDib()
  120. {
  121.   // Could add code to create a new Doc&View, or a new view on current doc
  122. }
  123.  
  124. void TDIBApp::CmAbout()
  125. {
  126.   TDialog(GetMainWindow(), IDD_ABOUT).Execute();
  127. }
  128.  
  129. //---------------------------------------------------------
  130. //     TIMKLibrary Class
  131. //---------------------------------------------------------
  132. class TIMKLibrary
  133. {
  134.   public:
  135.     TIMKLibrary() { imkBegin(); }
  136.    ~TIMKLibrary() { imkEnd();  }
  137. };
  138.  
  139. //---------------------------------------------------------
  140. //     OWLMAIN
  141. //---------------------------------------------------------
  142. int OwlMain(int /*argc*/, char* /*argv*/ [])
  143. {
  144.   TBIVbxLibrary vbxLib;
  145.   TIMKLibrary imkLib;
  146.  
  147.   return TDIBApp().Run();
  148. }
  149.