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

  1. /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  2.  
  3.   prjview.cpp
  4.   Created: 10/24/95
  5.   Copyright (c) 1995, Borland International
  6.   $Revision:   1.16  $
  7.  
  8. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
  9. #ifndef __AOEXPCH_H
  10.   #include "aoexpch.h"
  11. #endif
  12. #pragma hdrstop
  13.  
  14. #include <ideaddon\iproj.h>
  15. #include <ideaddon\iide.h>
  16. #include "prjview.h"
  17. #include "prjwin.h"
  18.  
  19. extern HINSTANCE ghInst;
  20.  
  21. /******************************************************************************
  22. *
  23. * ProjectViewClient:  Demonstrates the implementations and uses of various
  24. *                    Addon interfaces
  25. *
  26. * Interfaces implemented
  27. *
  28. *  IUserViewFactory
  29. *  IViewClient
  30. *
  31. * Interfaces used
  32. *  IProjectServer
  33. *  IMakeServer
  34. *  IToolServer
  35. *  IProjectServer
  36. *  IProjectClient
  37. *
  38. ******************************************************************************/
  39.  
  40. class ProjectViewClient : public IUnknownImp<IProjectViewClient> {
  41. public:
  42.   ProjectViewClient();
  43.   ~ProjectViewClient();
  44.  
  45.   //.... IProjectClient methods ....
  46.    virtual void OpenNotify( IPolyString * projectName );
  47.    virtual void CloseNotify();
  48.    virtual void NodeDeleteNotify( ProjectNode node );
  49.    virtual void NodeAddNotify( ProjectNode node );
  50.    virtual void NodeCopyNotify( ProjectNode, ProjectNode, BOOL ) {}
  51.    virtual void NodeMoveNotify( ProjectNode, ProjectNode ) {}
  52.    virtual void NodeChangeNotify( ProjectNode ) {}
  53.    virtual void DependencyQueryResponder( ProjectNode node, 
  54.                                           IPolyString * outputName );
  55.    virtual BOOL HandleAddNodeUI() { return FALSE; }
  56.  
  57.   //
  58.   // IViewClient methods
  59.   //
  60.   virtual HWND      GetHwnd();
  61.   virtual long      GetRestoreDataLen();
  62.   virtual void*    GetRestoreData();
  63.   virtual BOOL      CanClose();
  64.   virtual unsigned  CommandSupported( IPolyString* );
  65.   virtual void      ExecuteCommand( IPolyString* );
  66.   virtual HWND      Create(IViewParentWnd* wndServer, void * restoreData);
  67.   virtual void      PropertyChangeNotify();
  68.  
  69.   virtual void      Stop();
  70.   IViewParentWnd *  GetIViewParentWnd() { return d_viewParent; }
  71. protected:
  72.   HWND            d_hwnd;
  73.   IViewParentWnd* d_viewParent;
  74.  
  75. protected:
  76.   ProjectNode    d_node;
  77.   IProjectServer* d_projectServer;
  78.  
  79.   TreeModel*      d_tm;
  80. };
  81.  
  82. ProjectViewClient::ProjectViewClient()
  83.                   : IUnknownImp<IProjectViewClient>(IID_IUnknown) {
  84.   d_hwnd = 0;
  85.   d_viewParent = 0;
  86.   d_projectServer = GET_INTERFACE( IProjectServer );
  87.  
  88.   AddRef();
  89.   d_projectServer->RegisterProjectClient( this );
  90. };
  91.  
  92. void ProjectViewClient::Stop() {
  93.   AddRef();
  94.   d_projectServer->UnregisterProjectClient( this );
  95. }
  96.  
  97. ProjectViewClient::~ProjectViewClient() {
  98.   if (d_viewParent) {
  99.     d_viewParent->Release();
  100.   }
  101.   d_projectServer->Release();
  102. };
  103.  
  104.  
  105. HWND ProjectViewClient::Create(IViewParentWnd* wndServer, void * restoreData) {
  106.   d_viewParent = wndServer;
  107.   //
  108.   // create our window
  109.   //
  110.   d_hwnd = CreateTreeWindow(ghInst, wndServer->GetHwnd());
  111.   
  112.   d_tm = GetTreeModelFromHWND(d_hwnd);
  113.   if (restoreData) {
  114.     //
  115.     // If there is a valid restoreData, initialize the tree using the data as
  116.     // the top node
  117.     //
  118.     d_node = *(ProjectNode*)restoreData;
  119.   } else {
  120.     //
  121.     // Default the top node to project top node by setting d_node to 0.
  122.     //
  123.     d_node = 0;
  124.   }
  125.   d_tm->SetTopNode(d_node);
  126.   AddRef();
  127.   d_tm->SetProjectViewClient(this);
  128.  
  129.   return d_hwnd;
  130.  
  131. };
  132.  
  133. HWND ProjectViewClient::GetHwnd()
  134. {
  135.   return d_hwnd;
  136. };
  137.  
  138. long  ProjectViewClient::GetRestoreDataLen()
  139. {
  140.   //
  141.   // return the size of the data that is to be stored in destop file
  142.   //
  143.   return sizeof(d_node);
  144. };
  145.  
  146. void* ProjectViewClient::GetRestoreData()
  147. {
  148.   //
  149.   // The data saved here is the same as the restoreData argument
  150.   // in IViewClient::Create(IViewParentWnd* wndServer, void * restoreData).
  151.   //
  152.  
  153.   //
  154.   // have to keep the return pointer valid, so we copy it here
  155.   //
  156.   d_node = d_tm->GetTopNode();
  157.   //
  158.   // return a valid pointer
  159.   //
  160.   return &d_node;
  161.   
  162. };
  163.  
  164. BOOL ProjectViewClient::CanClose()
  165. {
  166.   //
  167.   // It is ok to close this window.
  168.   //
  169.   return 1;
  170. };
  171.  
  172. unsigned ProjectViewClient::CommandSupported(IPolyString* cmdStr)
  173. {
  174.   cmdStr->Release();
  175.   return CMD_UNKNOWN;
  176. }
  177.  
  178.  
  179. void ProjectViewClient::ExecuteCommand(IPolyString* cmdStr)
  180. {
  181.   cmdStr->Release();
  182. }
  183.  
  184.  
  185. void ProjectViewClient::PropertyChangeNotify() {
  186. };
  187.  
  188.  
  189. //
  190. // IProjectClient methods
  191. //
  192. void ProjectViewClient::OpenNotify( IPolyString * projectName ) {
  193.   projectName->Release();
  194. }
  195. //.............................................................................
  196. void ProjectViewClient::CloseNotify() {
  197. }
  198.  
  199. //
  200. //  process node delete/add notification here.
  201. //
  202. //  NOTE: We do not get node change or node movement notifications
  203. //
  204. void ProjectViewClient::NodeDeleteNotify( ProjectNode node ) {
  205.   d_tm->OnNodeDeleted(node);
  206. }
  207. //.............................................................................
  208. void ProjectViewClient::NodeAddNotify( ProjectNode node ) {
  209.   d_tm->OnNodeAdd(node);
  210. }
  211. //.............................................................................
  212. void ProjectViewClient::DependencyQueryResponder( ProjectNode /*node*/, 
  213.                                        IPolyString * /*outputName*/ ) {}
  214.  
  215.  
  216. /******************************************************************************
  217. *
  218. *
  219. * ProjectViewFactory
  220. *
  221. *
  222. ******************************************************************************/
  223.  
  224. ProjectViewFactory::ProjectViewFactory(IViewType* projectViewType) 
  225.                   : IUnknownImp<IUserViewFactory>(IID_IUnknown)
  226. {
  227.   //
  228.   // View type is "AddOnProjectView" and this view
  229.   //  will stay in the project region
  230.   //
  231.   IPolyString* viewType = MakePolyString("AddOnProjectView");
  232.   projectViewType->Init(this, viewType, /* project region */ 0, 358, 813, 538);
  233.   
  234.   IViewType2 * vt2 = QUERY_INTERFACE( projectViewType, IViewType2 );
  235.   if ( vt2 ) {
  236.     vt2->SetDisplayName( ::MakePolyString( "AddonProject" ) );
  237.     vt2->SetFamilyName( ::MakePolyString( "AddonTestbedViews" ) );
  238.     vt2->SetDisplayFamilyName( ::MakePolyString( "AddonTestbed" ) );
  239.   }
  240.  
  241.   projectViewType->Release();
  242. };
  243.  
  244. void ProjectViewFactory::InitializeProperty(IViewType* projectViewType) {
  245.   projectViewType->Release();
  246. };
  247.  
  248. IViewClient* ProjectViewFactory::CreateView(IViewParentWnd* wndServer, void * restoreData) {
  249.   ProjectViewClient* viewClient = new ProjectViewClient;
  250.   viewClient->Create(wndServer, restoreData);
  251.   viewClient->GetIViewParentWnd()->SetTitle( ::MakePolyString( "AddOnProject View Caption" ) );
  252.   return viewClient;
  253. };
  254.