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

  1. /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  2.  
  3.   msgview.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\imake.h>
  15. #include <ideaddon\iproj.h>
  16. #include <ideaddon\iide.h>
  17. #include <windowsx.h>
  18.  
  19. #include "msgview.h"
  20.  
  21. extern HINSTANCE ghInst;
  22.  
  23. #define MV_FOREGROUND "Foreground"
  24.  
  25. struct INotificationMonitor : public IProjectClient
  26.                             , public IMakeClient {
  27. };
  28.  
  29. class NotificationMonitor : public IUnknownImp<INotificationMonitor> {
  30. public:
  31.   NotificationMonitor();
  32.   ~NotificationMonitor();
  33.  
  34.   //.... IProjectClient methods ....
  35.    virtual void OpenNotify( IPolyString * projectName );
  36.    virtual void CloseNotify();
  37.    virtual void NodeDeleteNotify( ProjectNode node );
  38.    virtual void NodeAddNotify( ProjectNode node );
  39.    virtual void NodeCopyNotify( ProjectNode, ProjectNode, BOOL ) {}
  40.    virtual void NodeMoveNotify( ProjectNode, ProjectNode ) {}
  41.    virtual void NodeChangeNotify( ProjectNode ) {}
  42.    virtual void DependencyQueryResponder( ProjectNode node, 
  43.                                           IPolyString * outputName );
  44.    virtual BOOL HandleAddNodeUI() { return FALSE; }
  45.                                           
  46.  
  47.    // IMakeClient
  48.    virtual void MakeBeginNotify();
  49.    virtual void MakeEndNotify();
  50.  
  51.  
  52.            void SetHwnd(HWND hwnd);
  53.            void Stop();
  54. protected:
  55.   // private variables
  56.   IProjectServer* d_projectServer;
  57.   IMakeServer*    d_makeServer;
  58.  
  59.   HWND            d_hwndList;
  60.  
  61.   int            d_projectOpened;
  62. };
  63.  
  64.  
  65. NotificationMonitor::NotificationMonitor() 
  66.                     : IUnknownImp<INotificationMonitor>(IID_IUnknown) {
  67.   d_projectServer = GET_INTERFACE( IProjectServer );
  68.   d_makeServer  = GET_INTERFACE(IMakeServer);
  69.  
  70.   AddRef();
  71.   d_projectServer->RegisterProjectClient( this );
  72.  
  73.   AddRef();
  74.   d_makeServer->RegisterMakeClient( this );
  75.  
  76. };
  77.  
  78. void NotificationMonitor::Stop() {
  79.   AddRef();
  80.   d_makeServer->UnRegisterMakeClient( this );
  81.  
  82.   AddRef();
  83.   d_projectServer->UnregisterProjectClient(this);
  84. };
  85.  
  86. NotificationMonitor::~NotificationMonitor() {
  87.  
  88.   d_projectServer->Release();
  89.   d_makeServer->Release();
  90. };
  91.  
  92.  
  93. void NotificationMonitor::SetHwnd(HWND hwnd) {
  94.   d_hwndList = hwnd;
  95.   if ( d_projectOpened ) {
  96.     OpenNotify(0);
  97.   }
  98.  
  99. };
  100.  
  101. //
  102. // IProjectClient methods
  103. //
  104. void NotificationMonitor::OpenNotify( IPolyString * projectName ) {
  105.   d_projectOpened = 1;
  106.   if ( !IsWindow(d_hwndList) ) return;
  107.  
  108.   ListBox_AddString(d_hwndList, "OpenNotify");
  109.   if (projectName)
  110.     projectName->Release();
  111.   d_projectOpened = 0;
  112. }
  113. //.............................................................................
  114. void NotificationMonitor::CloseNotify() {
  115.   if ( !IsWindow(d_hwndList) ) return;
  116.  
  117.   ListBox_AddString(d_hwndList, "CloseNotify");
  118. }
  119.  
  120. void NotificationMonitor::NodeDeleteNotify( ProjectNode ) {
  121.   if ( !IsWindow(d_hwndList) ) return;
  122.  
  123.   ListBox_AddString(d_hwndList, "NodeDeleteNotify");
  124. }
  125. //.............................................................................
  126. void NotificationMonitor::NodeAddNotify( ProjectNode ) {
  127.   if ( !IsWindow(d_hwndList) ) return;
  128.  
  129.   ListBox_AddString(d_hwndList, "NodeAddNotify");
  130. }
  131. //.............................................................................
  132. void NotificationMonitor::DependencyQueryResponder( ProjectNode,
  133.                           IPolyString *) {
  134. }
  135.  
  136. void NotificationMonitor::MakeBeginNotify() {
  137.   if ( !IsWindow(d_hwndList) ) return;
  138.  
  139.   ListBox_AddString(d_hwndList, "MakeBeginNotify");
  140. };
  141.  
  142. void NotificationMonitor::MakeEndNotify() {
  143.   if ( !IsWindow(d_hwndList) ) return;
  144.  
  145.   ListBox_AddString(d_hwndList, "MakeEndNotify");
  146. };
  147.  
  148.  
  149. /******************************************************************************
  150. *
  151. *
  152. * MonitorViewClient
  153. *
  154. *
  155. ******************************************************************************/
  156.  
  157. class MonitorViewClient : public IViewClient {
  158. public:
  159.   MonitorViewClient();
  160.   ~MonitorViewClient();
  161.  
  162.   //IUnknown members
  163.   STDMETHODIMP QueryInterface (THIS_ REFIID, LPVOID FAR *);
  164.   STDMETHODIMP_(ULONG) AddRef (THIS) { return m_RefCount++; }
  165.   STDMETHODIMP_(ULONG) Release (THIS)
  166.       {return --m_RefCount == 0 ? (delete this, 0) : m_RefCount; }
  167.  
  168.   virtual HWND      GetHwnd();
  169.   virtual long      GetRestoreDataLen();
  170.   virtual void*    GetRestoreData();
  171.   virtual BOOL      CanClose();
  172.   virtual unsigned  CommandSupported( IPolyString* );
  173.   virtual void      ExecuteCommand( IPolyString* );
  174.   virtual HWND      Create(IViewParentWnd* wndServer, void * restoreData);
  175.   virtual void      PropertyChangeNotify();
  176.  
  177. protected:
  178.   HWND                  d_hwnd;
  179.   IViewParentWnd*      d_viewParent;
  180.   NotificationMonitor*  d_monitor;
  181. protected:
  182.   // private variables
  183.   ULONG                m_RefCount;
  184. };
  185.  
  186. MonitorViewClient::MonitorViewClient() {
  187.   m_RefCount = 1;
  188.   d_hwnd = 0;
  189.   d_viewParent = 0;
  190.   d_monitor = 0;
  191. };
  192.  
  193. MonitorViewClient::~MonitorViewClient() {
  194.   if (d_viewParent) {
  195.     d_viewParent->Release();
  196.   }
  197.   if ( IsWindow(d_hwnd) )
  198.     DestroyWindow(d_hwnd);
  199.   if (d_monitor) {
  200.     d_monitor->Stop();
  201.     d_monitor->Release();
  202.   }
  203. };
  204.  
  205.  
  206. STDMETHODIMP
  207. MonitorViewClient::QueryInterface (REFIID riid, LPVOID FAR* ppobj)
  208. {
  209.   if ((riid == IID_IUnknown)/* || (riid == IID_PUBLIC_)*/)
  210.   {
  211.     *ppobj = (LPVOID)this;
  212.     AddRef();
  213.    return NOERROR;
  214.   }
  215.  
  216.   *ppobj = NULL;
  217.   return ResultFromScode(E_NOINTERFACE);
  218. }
  219.  
  220. HWND MonitorViewClient::Create(IViewParentWnd* wndServer, void * /*restoreData*/) {
  221.  
  222.   d_viewParent = wndServer;
  223.   HWND hwndParent = wndServer->GetHwnd();
  224.   //
  225.   // just create a window listbox control
  226.   //
  227.   d_hwnd = CreateWindowEx(
  228.                             0,                      /* no extended styles         */
  229.                             "LISTBOX",              /* class name                 */
  230.                             "",                    /* window name                */
  231.                             WS_CHILDWINDOW |        /* overlapped window           */
  232.                             WS_VISIBLE  |
  233.                             WS_HSCROLL |            /* horizontal scroll bar       */
  234.                             WS_VSCROLL,            /* vertical scroll bar        */
  235.                             CW_USEDEFAULT,          /* default horizontal position */
  236.                             CW_USEDEFAULT,          /* default vertical position   */
  237.                             CW_USEDEFAULT,          /* default width               */
  238.                             CW_USEDEFAULT,          /* default height             */
  239.                             (HWND) hwndParent,      /* no parent or owner window   */
  240.                             (HMENU) NULL,          /* class menu used            */
  241.                             NULL/*hinstance*/,      /* instance handle             */
  242.                             NULL);                  /* no window creation data     */
  243.  
  244.   d_monitor = new NotificationMonitor;
  245.   d_monitor->SetHwnd(d_hwnd);
  246.   return d_hwnd;
  247.  
  248. };
  249.  
  250. HWND MonitorViewClient::GetHwnd()
  251. {
  252.   return d_hwnd;
  253. };
  254.  
  255. long  MonitorViewClient::GetRestoreDataLen()
  256. {
  257.   //
  258.   // there is nothing to save.
  259.   //
  260.   return 0; 
  261. };
  262.  
  263. //
  264. // Save the data user entered to the destop file
  265. //
  266. void* MonitorViewClient::GetRestoreData()
  267. {
  268.   //
  269.   // there is nothing to save.
  270.   //
  271.   return NULL;
  272. };
  273.  
  274. BOOL  MonitorViewClient::CanClose()
  275. {
  276.   return 1;
  277. };
  278.  
  279. unsigned MonitorViewClient::CommandSupported(IPolyString* cmdStr)
  280. {
  281.   cmdStr->Release();
  282.   return CMD_UNKNOWN;
  283. }
  284.  
  285.  
  286. void MonitorViewClient::ExecuteCommand(IPolyString* cmdStr)
  287. {
  288.   cmdStr->Release();
  289. }
  290.  
  291. void MonitorViewClient::PropertyChangeNotify() {
  292.  
  293. };
  294. /************************************************************************************************************************/
  295.  
  296. MonitorViewFactory::MonitorViewFactory(IViewType* MonitorView) {
  297.   m_RefCount = 1;
  298.  
  299.   MonitorView->Init(this
  300.                     , MakePolyString("AddOnMonitorView")
  301.                     , /* message region */ 0, 358, 813, 538);
  302.   MonitorView->Release();
  303. };
  304.  
  305. STDMETHODIMP
  306. MonitorViewFactory::QueryInterface (REFIID riid, LPVOID FAR* ppobj)
  307. {
  308.   if ((riid == IID_IUnknown)/* || (riid == IID_PUBLIC_)*/)
  309.   {
  310.     *ppobj = (LPVOID)this;
  311.     AddRef();
  312.     return NOERROR;
  313.   }
  314.  
  315.   *ppobj = NULL;
  316.   return ResultFromScode(E_NOINTERFACE);
  317. }
  318.  
  319. IViewClient* MonitorViewFactory::CreateView(IViewParentWnd* wndServer, void * restoreData) {
  320.   MonitorViewClient* viewClient = new MonitorViewClient;
  321.   viewClient->Create(wndServer, restoreData);
  322.   return viewClient;
  323. };
  324.  
  325. void MonitorViewFactory::InitializeProperty(IViewType* viewType) {
  326.   viewType->Release();
  327. }
  328.  
  329.  
  330. //.............................................................................
  331.