home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / expert.pak / TOLEVIEW.OWL < prev    next >
Text File  |  1997-07-23  |  7KB  |  229 lines

  1. <<[H]TOleView [[TOleView]]
  2. ##{hheader.snp}
  3. #include <owl\owlpch.h>
  4. #pragma hdrstop
  5.  
  6.  
  7. ##<<TApplication QUERY_FILENAME_CPP [[Filename]]
  8. #include "[[Filename]].rh"            // Definition of all resources.
  9.  
  10.  
  11. //{{TOleView = [[TOleView]]}}
  12. class [[TOleView]] : public TOleView {
  13. public:
  14.     [[TOleView]] (TDocument& doc, TWindow* parent = 0);
  15.     virtual ~[[TOleView]] ();
  16. ##--BEGIN-- @OPT_APPL_TOOLBAR
  17.  
  18. private:
  19.     TControlBar *ToolBar;
  20. ##--END-- @OPT_APPL_TOOLBAR
  21. ##--BEGIN-- @OPT_APPL_PRINTING
  22.  
  23. //{{[[TOleView]]VIRTUAL_BEGIN}}
  24. public:
  25.     virtual void Paint (TDC& dc, bool erase, TRect& rect);
  26. ##:DBVirtual(\\"[[TOleView]]", "Paint")
  27. //{{[[TOleView]]VIRTUAL_END}}
  28. ##--END-- @OPT_APPL_PRINTING
  29. ##--BEGIN-- @OPT_APPL_PRINTING || @OPT_APPL_TOOLBAR
  30. //{{[[TOleView]]RSP_TBL_BEGIN}}
  31. protected:
  32. ##@OPT_APPL_PRINTING
  33.     void EvGetMinMaxInfo (MINMAXINFO far& minmaxinfo);
  34. ##@OPT_APPL_TOOLBAR
  35.     bool EvOcViewShowTools (TOcToolBarInfo far& tbi);
  36. //{{[[TOleView]]RSP_TBL_END}}
  37. DECLARE_RESPONSE_TABLE([[TOleView]]);
  38. ##--END-- @OPT_APPL_PRINTING || @OPT_APPL_TOOLBAR
  39. };    //{{[[TOleView]]}}
  40. ##{hfooter.snp}
  41. >>[H]TOleView [[TOleView]]
  42.  
  43.  
  44. <<[CPP]TOleView [[TOleView]]
  45. ##{cheader.snp}
  46. #include <owl\owlpch.h>
  47. #pragma hdrstop
  48.  
  49. ##<<TApplication QUERY_FILE_H [[FileName]]
  50. #include "[[FileName]]"
  51. ##QUERY_FILE_H [[FileName]]
  52. #include "[[FileName]]"
  53.  
  54. #include <stdio.h>
  55.  
  56.  
  57. //{{[[TOleView]] Implementation}}
  58.  
  59. ##--BEGIN-- @OPT_APPL_PRINTING || @OPT_APPL_TOOLBAR
  60. ##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  61. //
  62. // Build a response table for all messages/commands handled
  63. // by [[TOleView]] derived from TOleView.
  64. //
  65. ##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  66. DEFINE_RESPONSE_TABLE1([[TOleView]], TOleView)
  67. //{{[[TOleView]]RSP_TBL_BEGIN}}
  68. ##      @OPT_APPL_PRINTING
  69. ##          :DBResponse(\\"[[TOleView]]", "", "", "WM_GETMINMAXINFO", "")
  70.     EV_WM_GETMINMAXINFO,
  71. ##      @OPT_APPL_TOOLBAR
  72. ##          :DBResponse(\\"[[TOleView]]", "", "", "OC_VIEWSHOWTOOLS", "")
  73.     EV_OC_VIEWSHOWTOOLS,
  74. //{{[[TOleView]]RSP_TBL_END}}
  75. END_RESPONSE_TABLE;
  76.  
  77.  
  78. ##--END-- @OPT_APPL_PRINTING || @OPT_APPL_TOOLBAR
  79. ##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  80. //////////////////////////////////////////////////////////
  81. // [[TOleView]]
  82. // ==========
  83. // Construction/Destruction handling.
  84. ##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  85. [[TOleView]]::[[TOleView]] (TDocument& doc, TWindow* parent)
  86.     : TOleView(doc, parent)
  87. {
  88. ##QUERY_WIND_STYLE [[StyleAttributes]]
  89. ##StyleAttributes != "" 3
  90.     // Override the default window style for TOleView.
  91. [[StyleAttributes]]
  92.  
  93. ##QUERY_WIND_BACKGRND [[BackgroundColor]]
  94. ##BackgroundColor != "" 3
  95.     // Change the window's background color
  96.     SetBkgndColor([[BackgroundColor]]);
  97.  
  98. ##@OPT_APPL_TOOLBAR 2
  99.     ToolBar = 0;
  100.  
  101.     // INSERT>> Your constructor code here.
  102.  
  103. }
  104.  
  105.  
  106. [[TOleView]]::~[[TOleView]] ()
  107. {
  108.     // INSERT>> Your destructor code here.
  109.  
  110. }
  111. ##--BEGIN-- @OPT_APPL_PRINTING == TRUE
  112.  
  113.  
  114. ##--BEGIN-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  115. //
  116. // Paint routine for Window, Printer, and PrintPreview for a TOleView client.
  117. //
  118. ##--END-- @QUERY_APPL_COMMENT == VALUE_VERBOSE
  119. void [[TOleView]]::Paint (TDC& dc, bool erase, TRect& rect)
  120. {
  121. ##<<TApplication QUERY_CLASS_NAME [[TApplication]]
  122.     [[TApplication]] *theApp = TYPESAFE_DOWNCAST(GetApplication(), [[TApplication]]);
  123.     if (theApp) {
  124. ##:@QUERY_APPL_COMMENT == VALUE_VERBOSE
  125.         // Only paint if we're printing and we have something to paint, otherwise do nothing.
  126.         if (theApp->Printing && theApp->Printer && !rect.IsEmpty()) {
  127. ##:@QUERY_APPL_COMMENT == VALUE_VERBOSE 2
  128.             // Use pageSize to get the size of the window to render into.  For a Window it's the client area,
  129.             // for a printer it's the printer DC dimensions and for print preview it's the layout window.
  130.             TSize   pageSize(rect.right - rect.left, rect.bottom - rect.top);
  131.  
  132.             TPrintDialog::TData &printerData = theApp->Printer->GetSetup();
  133.  
  134. ##:@QUERY_APPL_COMMENT == VALUE_VERBOSE
  135.             // Compute the number of pages to print.
  136.             printerData.MinPage = 1;
  137.             printerData.MaxPage = 1;
  138.  
  139.             TOcView     *ocView = GetOcView();
  140.  
  141. ##:@QUERY_APPL_COMMENT == VALUE_VERBOSE 3
  142.             //
  143.             // Default TOcPart painting
  144.             //
  145.             TRect clientRect = GetClientRect();
  146.             TRect logicalRect = clientRect + (TSize&)ocView->GetOrigin();
  147.     
  148.             for (TOcPartCollectionIter i(GetOcDoc()->GetParts()); i; i++) {
  149.                 TOcPart& p = *i.Current();
  150.                 if (p.IsVisible(logicalRect)) {
  151.                     TRect r = p.GetRect();
  152.                     r -= ocView->GetOrigin();
  153.                     p.Draw(dc, r, clientRect);        // Draw the embedded object.
  154.                     if (p.IsSelected()) {
  155.                         TUIHandle handle(r,
  156.                                          TUIHandle::HandlesIn       |
  157.                                          TUIHandle::Grapples        |
  158.                                          TUIHandle::HatchBorder,
  159.                                          5);
  160.                         handle.Paint(dc);
  161.                     } else {
  162.                         TUIHandle handle(r, TUIHandle::HatchBorder, 5);
  163.                         handle.Paint(dc);
  164.                     }
  165.                 }
  166.             }
  167.  
  168.             // INSERT>> Special printing code goes here.
  169.  
  170.         } else {
  171.             TOleView::Paint(dc, erase, rect);
  172.  
  173.             // INSERT>> Normal painting code goes here.
  174.  
  175.         }
  176. ##--BEGIN-- @QUERY_APPL_OLE == VALUE_SERVER
  177. ##@QUERY_PRJ_NAME [[Title]]
  178.         dc.TextOut(0, 30, "[[Title]] OLE Server");
  179. ##--END-- @QUERY_APPL_OLE == VALUE_SERVER
  180.     }
  181. }
  182.  
  183.  
  184. void [[TOleView]]::EvGetMinMaxInfo (MINMAXINFO far& minmaxinfo)
  185. {
  186. ##<<TApplication QUERY_CLASS_NAME [[TApplication]]
  187.     [[TApplication]] *theApp = TYPESAFE_DOWNCAST(GetApplication(), [[TApplication]]);
  188.     if (theApp) {
  189.         if (theApp->Printing) {
  190.             minmaxinfo.ptMaxSize = TPoint(32000, 32000);
  191.             minmaxinfo.ptMaxTrackSize = TPoint(32000, 32000);
  192.             return;
  193.         }
  194.     }
  195.     TOleView::EvGetMinMaxInfo(minmaxinfo);
  196. }
  197. ##--END-- @OPT_APPL_PRINTING == TRUE
  198. ##--BEGIN-- @OPT_APPL_TOOLBAR
  199.  
  200.  
  201. bool [[TOleView]]::EvOcViewShowTools (TOcToolBarInfo far& tbi)
  202. {
  203.     // Construct & create a control bar for show, destroy our bar for hide
  204.     if (tbi.Show) {
  205.         if (!ToolBar) {
  206.             ToolBar = new TControlBar(this);
  207.  
  208. ##<<TApplication QUERY_CLASS_NAME [[TApplication]]
  209.             [[TApplication]] *theApp = TYPESAFE_DOWNCAST(GetApplication(), [[TApplication]]);
  210.             CHECK(theApp);
  211.  
  212.             theApp->CreateGadgets(ToolBar, true);
  213.         }
  214.  
  215.         ToolBar->Create();
  216.         tbi.HTopTB = (HWND)*ToolBar;
  217.     } else {
  218.         if (ToolBar) {
  219.             ToolBar->Destroy();
  220.             delete ToolBar;
  221.             ToolBar = 0;
  222.         }
  223.     }
  224.  
  225.     return true;
  226. }
  227. ##--END-- @OPT_APPL_TOOLBAR
  228. >>[CPP]TOleView [[TOleView]]
  229.