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

  1. /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  2.  
  3.   mpdprj.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 <owl\window.h>
  15. #include <ideaddon\impd.h>
  16. #include <ideaddon\ioption.h>
  17. #include <ideaddon\imake.h>
  18. #include <ideaddon\iproj.h>
  19. #include <windowsx.h> // this must come after iproj.h to avoid error
  20. #include <commctrl.h>
  21. #include "tests.hrc"
  22. #include "addonpg.h"
  23.  
  24. /******************************************************************************
  25. *  This file contains 3 MPD page implementations.
  26. *
  27. *  AddonSummaryPage displays the selected node information
  28. *
  29. *  ProjectPage       lets user set, add and remove named project proerty
  30. *
  31. *  OptionPage       shows IOptionSetServer usage.
  32. *
  33. ******************************************************************************/
  34.  
  35. class AddonProjectPageBase : public AddonPageBase {
  36. public:
  37.   void SetNode(ProjectNode node);
  38. protected:
  39.   ProjectNode     d_node;
  40. };
  41.  
  42. void AddonProjectPageBase::SetNode(ProjectNode node) {
  43.   d_node = node;
  44. }
  45.  
  46. /******************************************************************************
  47. *
  48. * AddonSummaryPage displays node information 
  49. *
  50. ******************************************************************************/
  51.  
  52. class AddonSummaryPage : public AddonProjectPageBase {
  53. public:
  54.   AddonSummaryPage(IProjectServer * projectServer);
  55.   ~AddonSummaryPage();
  56.   //
  57.   // IMpdPage interface
  58.   //
  59.   virtual BOOL    CanClose();
  60.   virtual void    SetDlgItems();
  61.   virtual void    GetDlgItems();
  62.   virtual LRESULT OnCommand(UINT id, HWND hWndCtl, UINT notifyCode);
  63. protected:
  64.   IProjectServer* d_projectServer;
  65. };
  66.  
  67. AddonSummaryPage::AddonSummaryPage(IProjectServer * projectServer) {
  68.   d_projectServer = projectServer;
  69. };
  70.  
  71. AddonSummaryPage::~AddonSummaryPage() {
  72.   d_projectServer->Release();
  73. };
  74.  
  75. #define NUM_ITEMS sizeof(headers)/sizeof(headers[0])
  76.  
  77. void AddonSummaryPage::SetDlgItems() {
  78.  
  79.   IProjectNodeInfo* pni = d_projectServer->QueryNodeInfo( d_node );
  80.   if (!pni)
  81.     return;
  82.  
  83.   //
  84.   // This page is read only, so we will initialize it only once.
  85.   //
  86.   if ( GetDlgItem(d_hDlg, IDC_NODEVIEW) ) {
  87.     return;
  88.   }
  89.  
  90.   IMakeServer*     makeServer = GET_INTERFACE(IMakeServer);
  91.   long inputAge;
  92.   long outputAge;
  93.   if (makeServer) {
  94.     inputAge = makeServer->NodeInputAge( d_node );
  95.     outputAge = makeServer->NodeOutputAge( d_node );
  96.     makeServer->Release();
  97.   } else {
  98.     inputAge = 0;
  99.     outputAge = 0;
  100.   }
  101.   char* itemNames[] = {
  102.      "Name",
  103.      "Type",
  104.      "Description",
  105.      "Input Location",
  106.      "Input Age",
  107.      "Output Location",
  108.      "Output Age",
  109.   };
  110.  
  111.   char items[10][256];
  112.   int i = 0;
  113.  
  114.   IPolyString* name = pni->GetName();
  115.   if (name) {
  116.     strcpy(items[i++], name->GetCstr());
  117.     name->Release();
  118.   }
  119.   IPolyString* nodeType = pni->GetNodeType();
  120.   if (nodeType) {
  121.     strcpy(items[i++], nodeType->GetCstr());
  122.     nodeType->Release();
  123.   }
  124.   IPolyString* nodeDesc = pni->GetDescription();
  125.   if (nodeDesc) {
  126.     strcpy(items[i++], nodeDesc->GetCstr());
  127.     nodeDesc->Release();
  128.   }
  129.   IPolyString* nodeInput = pni->GetInputLocation();
  130.   if (nodeInput) {
  131.     strcpy(items[i++], nodeInput->GetCstr());
  132.     nodeInput->Release();
  133.   }
  134.  
  135.   wsprintf(items[i++], "0x%x", inputAge);
  136.  
  137.   IPolyString* nodeOutput = pni->GetOutputLocation();
  138.   if (nodeOutput) {
  139.     strcpy(items[i++], nodeOutput->GetCstr());
  140.     nodeOutput->Release();
  141.   }
  142.  
  143.   wsprintf(items[i++], "0x%x", outputAge);
  144.   pni->Release();
  145.  
  146.   // Ensure that the common control DLL is loaded.
  147.   InitCommonControls();
  148.  
  149.   HWND hWndList;      // Handle to the list view window
  150.  
  151.   // Get the size and position of the parent window
  152.   RECT rcl;          // Rectangle for setting the size of the window
  153.   GetClientRect(d_hDlg, &rcl);
  154.  
  155.   // Create the list view window that starts out in report view
  156.  
  157.   extern HINSTANCE ghInst;
  158.  
  159.   hWndList = CreateWindowEx(WS_EX_NOPARENTNOTIFY,
  160.                             WC_LISTVIEW,                // list view class
  161.                             "",                        // no default text
  162.                             WS_VISIBLE | WS_CHILD | WS_BORDER
  163.                             | LVS_REPORT |WS_EX_CLIENTEDGE,
  164.                             0, 0,
  165.                             rcl.right - rcl.left, rcl.bottom - rcl.top,
  166.                             d_hDlg,
  167.                             (HMENU)IDC_NODEVIEW,
  168.                             ghInst,
  169.                             NULL );
  170.  
  171.   if (hWndList == NULL )
  172.     return;
  173.  
  174.  
  175.   // Now initialize the columns we will need
  176.   // Initialize the LV_COLUMN structure
  177.   // the mask specifies that the .fmt, .ex, width, and .subitem members 
  178.   // of the structure are valid,
  179.   LV_COLUMN lvC;      // List View Column structure
  180.   lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  181.   lvC.fmt = LVCFMT_LEFT;  // left align the column
  182.   lvC.cx = 75;            // width of the column, in pixels
  183.  
  184.  
  185.    static char* headers[] = { "Information", "Value" };
  186.  
  187.   // Add the columns.
  188.   int index;          // Index used in for loops
  189.    for ( index = 0; index < NUM_ITEMS; ++index ) {
  190.      lvC.iSubItem = index;
  191.       lvC.pszText = headers[index];
  192.      if (ListView_InsertColumn(hWndList, index, &lvC) == -1)
  193.        return;
  194.    };
  195.  
  196.   LV_ITEM lvI;        // List view item structure
  197.   lvI.mask = LVIF_TEXT | LVIF_STATE;
  198.   lvI.state = 0;      //
  199.   lvI.stateMask = 0;  //
  200.  
  201.   for (index = 0; index < sizeof(itemNames)/sizeof(itemNames[0]); index++)
  202.   {
  203.     lvI.iItem = index;
  204.     lvI.iSubItem = 0;
  205.     lvI.pszText = itemNames[index]; 
  206.     lvI.cchTextMax = strlen(items[index])+1;
  207.  
  208.     if (ListView_InsertItem(hWndList, &lvI) == -1)
  209.       return;
  210.  
  211.     int iSubItem;      // Index for inserting sub items
  212.     for (iSubItem = 1; iSubItem < NUM_ITEMS; iSubItem++)
  213.     {
  214.       ListView_SetItemText( hWndList,
  215.                             index,
  216.                             iSubItem,
  217.                             items[index]);
  218.     }
  219.   }
  220. };
  221.  
  222. void AddonSummaryPage::GetDlgItems() {};
  223.  
  224. BOOL AddonSummaryPage::CanClose() { return 1; };
  225.  
  226.  
  227. LRESULT AddonSummaryPage::OnCommand(UINT wID, HWND /*hWndCtl*/, UINT /*notifyCode*/) {
  228.   switch (wID)
  229.   {
  230.       default:
  231.       break;
  232.   }
  233.   return 0;
  234. }
  235.  
  236. /******************************************************************************
  237. *
  238. *  AddonSummaryPage displays the selected node information
  239. *
  240. ******************************************************************************/
  241.  
  242. class ProjectPage : public AddonProjectPageBase {
  243. public:
  244.   ProjectPage(IProjectServer * projectServer);
  245.   ~ProjectPage();
  246.   //
  247.   // IMpdPage interface
  248.   //
  249.   virtual BOOL    CanClose();
  250.   virtual void    SetDlgItems();
  251.   virtual void    GetDlgItems();
  252.   virtual LRESULT OnCommand(UINT id, HWND hWndCtl, UINT notifyCode);
  253. protected:
  254.           void          PFind();
  255.           void          PSet();
  256.           void          PRemove();
  257.  
  258.           IPolyString*  GetName();
  259.  
  260.   IProjectServer *  d_projectServer;
  261. };
  262.  
  263. ProjectPage::ProjectPage(IProjectServer * projectServer) {
  264.   d_projectServer = projectServer;
  265. };
  266.  
  267. ProjectPage::~ProjectPage() {
  268.   d_projectServer->Release();
  269. };
  270.  
  271. void ProjectPage::SetDlgItems() {};
  272.  
  273. void ProjectPage::GetDlgItems() {};
  274.  
  275. BOOL ProjectPage::CanClose() { return 1; };
  276.  
  277. IPolyString* ProjectPage::GetName() {
  278.   char bufName[256];
  279.   GetDlgItemText(d_hDlg, IDC_PROPERTY_LABEL, bufName, sizeof(bufName));
  280.   return MakePolyString(bufName);
  281.  
  282. }
  283.  
  284. void ProjectPage::PFind() {
  285.   UINT dataSize;
  286.   char* text;
  287.   text = (char *) d_projectServer->NodePropertyFind(d_node,
  288.                                           GetName(),
  289.                                           &dataSize);                                         
  290.   if (dataSize == 0)
  291.    text = "";
  292.  
  293.   SetDlgItemText(d_hDlg, IDC_PROPERTY, text);
  294.  
  295. };
  296.  
  297. void ProjectPage::PSet() {
  298.  
  299.   char buf[256];
  300.   GetDlgItemText(d_hDlg, IDC_PROPERTY, buf, sizeof(buf));
  301.   d_projectServer->NodePropertySet(d_node, 
  302.                                     GetName(),
  303.                                     buf,
  304.                                     strlen(buf)+1);
  305.   PFind();
  306. };
  307.  
  308. void ProjectPage::PRemove() {
  309.  
  310.   d_projectServer->NodePropertyRemove(d_node, GetName());
  311.   PFind();
  312. }
  313.  
  314.  
  315. LRESULT ProjectPage::OnCommand(UINT wID, HWND /*hWndCtl*/, UINT /*notifyCode*/) {
  316.   switch (wID)
  317.   {
  318.     case IDC_FIND:
  319.       PFind();
  320.       break;
  321.     case IDC_SET:
  322.       PSet();
  323.       break;
  324.     case IDC_REMOVE:
  325.       PRemove();
  326.       break;
  327.   }
  328.   return 0;
  329. }
  330.  
  331. /******************************************************************************
  332. *  OptionPage       shows IOptionSetServer usage.
  333. ******************************************************************************/
  334.  
  335. class OptionPage : public AddonProjectPageBase {
  336. public:
  337.   OptionPage(IOptionSetServer* optionSetServer);
  338.   ~OptionPage();
  339.   //
  340.   // IMpdPage interface
  341.   //
  342.   virtual BOOL    CanClose();
  343.   virtual void    SetDlgItems();
  344.   virtual void    GetDlgItems();
  345.   virtual VOID    Init(HWND hDlg, IStatusBar* isb);
  346.   virtual LRESULT OnCommand(UINT id, HWND hWndCtl, UINT notifyCode);
  347. protected:
  348.           void Remove();
  349.  
  350.   IOptionSetServer* d_optionSetServer;
  351. };
  352.  
  353. OptionPage::OptionPage(IOptionSetServer* optionSetServer) {
  354.   d_optionSetServer = optionSetServer;
  355.   //
  356.   // always modified
  357.   //
  358.   d_modified = 1;
  359. };
  360.  
  361. OptionPage::~OptionPage() {
  362.   d_optionSetServer->Release();
  363. };
  364.  
  365. VOID OptionPage::Init(HWND hDlg, IStatusBar* isb) {
  366.  
  367.   AddonPageBase::Init(hDlg, isb);
  368. };
  369.  
  370. BOOL OptionPage::CanClose() { return 1; };
  371.  
  372. int ids[] = {
  373.             IDC_INCLUDE    ,
  374.             IDC_LIBRARY    ,
  375.         IDC_SOURCE      ,
  376.             IDC_INTERMEDIATE,
  377.             IDC_FINAL      ,
  378.             IDC_DEFINES    ,
  379.             IDC_CMDOVERRIDE ,
  380. };
  381.  
  382. OptionsStringIds oids[] = {
  383.          OID_Include,
  384.              OID_Library,
  385.              OID_Source,
  386.              OID_Intermediate,
  387.              OID_Final,
  388.              OID_Defines,
  389.              OID_CmdlineOverride,
  390. };
  391.  
  392. void OptionPage::SetDlgItems() {
  393.  
  394.    int i;
  395.  
  396.    for (i = 0; i< sizeof(ids)/sizeof(ids[0]); ++i ) {
  397.     IPolyString* pps = d_optionSetServer->OptionGet(d_node, oids[i]);
  398.       if (pps) {
  399.          SetDlgItemText(d_hDlg, ids[i], pps->GetCstr());
  400.       pps->Release();
  401.       } else
  402.          SetDlgItemText(d_hDlg, ids[i], "");
  403.  
  404.       char buf[256];
  405.       IPolyString *val;
  406.       GetDlgItemText(d_hDlg, ids[i], buf, sizeof(buf));
  407.       val = MakePolyString(buf);
  408.       d_optionSetServer->OptionApply(d_node, oids[i], val);
  409.    }
  410.  
  411. };
  412.  
  413. void OptionPage::GetDlgItems() {
  414.    int i;
  415.  
  416.    for (i = 0; i< sizeof(ids)/sizeof(ids[0]); ++i ) {
  417.       char buf[256];
  418.     IPolyString *val;
  419.       GetDlgItemText(d_hDlg, ids[i], buf, sizeof(buf));
  420.       val = MakePolyString(buf);
  421.       d_optionSetServer->OptionApply(d_node, oids[i], val);
  422.    }
  423.  
  424. };
  425.  
  426. void OptionPage::Remove() {
  427.   d_optionSetServer->OptionRemove(d_node, OID_RemoveAll);
  428.   SetDlgItems();
  429. };
  430.  
  431.  
  432. LRESULT OptionPage::OnCommand(UINT wID, HWND /*hWndCtl*/, UINT /*notifyCode*/) {
  433.   switch (wID)
  434.   {
  435.       case IDC_REMOVE:
  436.         Remove();
  437.         break;
  438.       default:
  439.         break;
  440.   }
  441.   return 0;
  442. }
  443.  
  444.  
  445. /******************************************************************************
  446. * IMpdProjectChapterAddon: a simple project chapter
  447. ******************************************************************************/
  448.  
  449. IMpdProjectChapterAddon::IMpdProjectChapterAddon() {
  450.   d_projectServer = GET_INTERFACE( IProjectServer );
  451.   d_optionSetServer = GET_INTERFACE( IOptionSetServer );
  452. };
  453.  
  454. IMpdProjectChapterAddon::~IMpdProjectChapterAddon() {
  455.   d_projectServer->Release();
  456.   d_optionSetServer->Release();
  457. };
  458.  
  459. void IMpdProjectChapterAddon::Init() {
  460.  
  461.   d_projectServer->AddRef();
  462.   d_pages[0] = new  AddonSummaryPage(d_projectServer);
  463.   d_pages[0]->SetInfo(MPD_OPENSUMMARY, IDD_MPD_PAGE1, "Addon Summary");
  464.  
  465.   d_projectServer->AddRef();
  466.   d_pages[1] = new ProjectPage(d_projectServer);
  467.   d_pages[1]->SetInfo(MPD_CLOSEPAGE, IDD_MPD_PAGE4, "Set Named Option");
  468.  
  469.   d_optionSetServer->AddRef();
  470.   d_pages[2] = new OptionPage(d_optionSetServer);
  471.   d_pages[2]->SetInfo(MPD_CLOSEPAGE, IDD_MPD_PAGE5, "Set Options");
  472.  
  473.   d_nPages = 3;
  474. };
  475.  
  476.  
  477. UINT IMpdProjectChapterAddon::GetResourceId() {return ID_MPD_PROJECT_CHAPTER;};
  478.  
  479.  
  480. IMpdPage* IMpdProjectChapterAddon::OpenPage(UINT pid, ProjectNode node) {
  481.   IMpdPage* page;
  482.  
  483.   switch (pid) {
  484.     case IDD_MPD_PAGE1:
  485.       page = d_pages[0];
  486.       break;
  487.     case IDD_MPD_PAGE4:
  488.       page = d_pages[1];
  489.       break;
  490.     case IDD_MPD_PAGE5:
  491.       page = d_pages[2];
  492.       break;
  493.     default:
  494.       return 0;
  495.   }
  496.   ((AddonProjectPageBase*)page)->SetNode(node);
  497.  
  498.   page->AddRef();
  499.   return page;
  500. };
  501.  
  502. 
  503.