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

  1. /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  2.  
  3.   mpdenv.cpp
  4.   Created: 10/24/95
  5.   Copyright (c) 1995, Borland International
  6.   $Revision:   1.16  $
  7.     
  8. :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/ 
  9.  
  10. #ifndef __AOEXPCH_H
  11.   #include "aoexpch.h"
  12. #endif
  13.  
  14. #pragma hdrstop
  15.  
  16. #include <owl\window.h>
  17. #include <ideaddon\impd.h>
  18. #include <ideaddon\iproj.h>
  19. #include <windowsx.h> // this must come after iproj.h to avoid error
  20.  
  21. #include "tests.hrc"
  22. #include "addonpg.h"
  23.  
  24. /******************************************************************************
  25. *  This file contains 3 MPD page implementations.
  26. *
  27. *     AddonPageBase: The minimal page implementation.
  28. *
  29. *     CWindowPage:   A page that demonstrates how to implement
  30. *                    various features of a MPD page
  31. *
  32. *     SubclassWindowPage: Demonstrates how to subclass a page.
  33. *
  34. ******************************************************************************/
  35.  
  36. extern HINSTANCE ghInst;
  37.  
  38. /******************************************************************************
  39. *
  40. * AddonPageBase is the minimal implementation of a addon MPD page
  41. *
  42. ******************************************************************************/
  43.  
  44. AddonPageBase::AddonPageBase()
  45.                   :  IUnknownImp<IMpdPage> (IID_IUnknown) {
  46.   d_modified = 0;
  47. };
  48.  
  49.  
  50. VOID AddonPageBase::Init(HWND hDlg, IStatusBar* isb) {
  51.   d_statusBar = isb;
  52.   d_hDlg = hDlg;
  53.   d_modified = 0;
  54. };
  55.  
  56. void AddonPageBase::SetStatusText(char* t) {
  57.   IPolyString* pstr = MakePolyString(t);
  58.   //
  59.   // display the status text in MPD and IDE status bar
  60.   //
  61.   d_statusBar->Display(pstr);
  62. };
  63.  
  64. BOOL AddonPageBase::IsModified() {
  65.   return d_modified;
  66. };
  67.  
  68. HINSTANCE AddonPageBase::GetHInstance() {
  69.   return ghInst;
  70. }
  71.  
  72. UINT AddonPageBase::GetResourceId() {
  73.   return d_pageResource;
  74. };
  75.  
  76. IPolyString*  AddonPageBase::GetPageTitle() {
  77.   return MakePolyString(d_pageTitle);
  78. };
  79.  
  80. UINT AddonPageBase::GetPageStyle() {
  81.   return d_pageStyle;
  82. };
  83.  
  84. void AddonPageBase::SetInfo(UINT pStyle, UINT pid, char* title) {
  85.   d_pageResource = pid;
  86.   d_pageStyle = pStyle;
  87.   d_pageTitle = title;
  88. };
  89.  
  90. void AddonPageBase::Help(BOOL fF1Key) {
  91.   if (fF1Key) {
  92.     ::MessageBox(NULL, "Help on example page", "F1 Help", MB_OK);
  93.   } else {
  94.     ::MessageBox(NULL, "Help on example page", "Help", MB_OK);
  95.   }
  96. };
  97.  
  98. void AddonPageBase::DisplayPageStatus() {
  99.   SetStatusText("Addon Page");
  100. };
  101.  
  102. VOID AddonPageBase::Undo() {
  103.   SetDlgItems();
  104.   d_modified = 0;
  105. };
  106.  
  107. /******************************************************************************
  108. *
  109. * CWindowPage show how to implement an full-feature addon page.
  110. *
  111. ******************************************************************************/
  112.  
  113. struct PageData {
  114.   int d_okToClose;
  115.   int d_checked;
  116.   int d_listCurrent;
  117.   int d_comboCurrent;
  118.   char d_comment[256];
  119. };
  120.  
  121. class CWindowPage : public AddonPageBase {
  122. public:
  123.   //
  124.   // IMpdPage interface
  125.   //
  126.   virtual BOOL CanClose();
  127.   virtual void SetDlgItems();
  128.   virtual void GetDlgItems();
  129.   virtual VOID Init(HWND hDlg, IStatusBar* isb);
  130.   virtual LRESULT OnCommand(UINT id, HWND hWndCtl, UINT notifyCode);
  131. protected:
  132.   PageData* d_pageData;
  133. };
  134.  
  135.  
  136. VOID CWindowPage::Init(HWND hDlg, IStatusBar* isb) {
  137.  
  138.   //
  139.   // define a static variable to store data
  140.   //
  141.   static PageData pageData;
  142.  
  143.   d_pageData = &pageData;
  144.   AddonPageBase::Init(hDlg, isb);
  145.   SetDlgItemText(hDlg, IDC_PAGE_TYPE, "C Window");
  146. };
  147.  
  148. //
  149. // OnCommand()
  150. //    Sets the modify state based on user input.
  151. //    Displays status text when focus changed between controls in the page
  152. //
  153. LRESULT CWindowPage::OnCommand(UINT wID, HWND /*hWndCtl*/, UINT wNotifyCode) {
  154.   char* statusText = 0;
  155.   switch (wID)
  156.   {
  157.     case IDC_LIST1:
  158.       switch (wNotifyCode)
  159.       {
  160.         case LBN_SELCHANGE:
  161.           SetModified(1);
  162.           break;
  163.         case LBN_SETFOCUS:
  164.           statusText = "Listbox";
  165.           break;
  166.         case LBN_KILLFOCUS:
  167.           break;
  168.       }
  169.       break;
  170.     //
  171.     //  Special note for button with BS_NOTIFY style:
  172.     //
  173.     //      Button with BS_NOTIFY style will send BN_SETFOCUS and BN_KILLFOCUS
  174.     //      message to its parent, so we must check the notify code to
  175.     //      make sure the button is clicked.
  176.     //
  177.     case IDC_MESSAGE:
  178.       switch (wNotifyCode)
  179.       {
  180.         case BN_SETFOCUS:
  181.           statusText = "Click me to display a message box";
  182.           break;
  183.         case BN_KILLFOCUS:
  184.           break;
  185.         case BN_CLICKED:
  186.           MessageBox(d_hDlg, "This is a message box","Addon", MB_OK);
  187.           break;
  188.       }
  189.       break;
  190.     case IDC_RADIO1:
  191.       switch (wNotifyCode)
  192.       {
  193.         case BN_SETFOCUS:
  194.           statusText = "RadioButton 1";
  195.           break;
  196.         case BN_KILLFOCUS:
  197.           break;
  198.         case BN_CLICKED:
  199.           SetModified(1);
  200.           break;
  201.       }
  202.       break;
  203.     case IDC_RADIO2:
  204.       switch (wNotifyCode)
  205.       {
  206.         case BN_SETFOCUS:
  207.           statusText = "RadioButton 2";
  208.           break;
  209.         case BN_KILLFOCUS:
  210.           break;
  211.         case BN_CLICKED:
  212.           SetModified(1);
  213.           break;
  214.       }
  215.       break;
  216.     case IDC_CHECK1:
  217.       switch (wNotifyCode)
  218.       {
  219.         case BN_SETFOCUS:
  220.           statusText = "CheckButton 1";
  221.           break;
  222.         case BN_KILLFOCUS:
  223.           break;
  224.         case BN_CLICKED:
  225.           SetModified(1);
  226.           break;
  227.       }
  228.       break;
  229.     case IDC_EDIT1:
  230.       switch (wNotifyCode)
  231.       {
  232.         case EN_CHANGE:
  233.           SetModified(1);
  234.           break;
  235.         case EN_SETFOCUS:
  236.           statusText = "Edit";
  237.           break;
  238.         case EN_KILLFOCUS:
  239.           break;
  240.       }
  241.       break;
  242.     case IDC_COMBO1:
  243.     {
  244.       switch (wNotifyCode)
  245.       {
  246.         case CBN_EDITCHANGE:
  247.         case CBN_SELCHANGE:
  248.           SetModified(1);
  249.           break;
  250.         case CBN_SETFOCUS:
  251.           statusText = "Combo";
  252.           break;
  253.         case CBN_KILLFOCUS:
  254.           break;
  255.       }
  256.     }
  257.   };
  258.   if (statusText) {
  259.     SetStatusText(statusText);
  260.   }
  261.   //
  262.   // we must return 0 to tell addon that we have processed this message
  263.   //  any further processing is not necessary
  264.   //
  265.   switch (wID)
  266.   {
  267.     case IDC_LIST1:
  268.     case IDC_MESSAGE:
  269.     case IDC_RADIO1:
  270.     case IDC_RADIO2:
  271.     case IDC_CHECK1:
  272.     case IDC_EDIT1:
  273.     case IDC_COMBO1:
  274.       return 0;
  275.   };
  276.   return 0;
  277. };
  278.  
  279. //
  280. //  SetDlgItems()
  281. //    Set the controls the correct state. This method is called
  282. //    when the page is displayed and when the "Undo Page" button
  283. //    is clicked.
  284. //
  285. void CWindowPage::SetDlgItems() {
  286.  
  287.   CheckRadioButton(d_hDlg
  288.             , IDC_RADIO1
  289.             , IDC_RADIO2
  290.             , IDC_RADIO1 + (d_pageData->d_okToClose ? 0 : 1));
  291.  
  292.   CheckDlgButton(d_hDlg, IDC_CHECK1, d_pageData->d_checked);
  293.   SetDlgItemText(d_hDlg, IDC_EDIT1, d_pageData->d_comment);
  294.  
  295.   HWND hwndCtl = GetDlgItem(d_hDlg, IDC_LIST1);
  296.  
  297.   //
  298.   // This can be called multiple times
  299.   //
  300.   if (!ListBox_GetCount(hwndCtl)) {
  301.     ListBox_AddString(hwndCtl, "C");
  302.     ListBox_AddString(hwndCtl, "C++");
  303.     ListBox_AddString(hwndCtl, "Pascal");
  304.   }
  305.   ListBox_SetCurSel(hwndCtl, d_pageData->d_listCurrent);
  306.  
  307.   hwndCtl = GetDlgItem(d_hDlg, IDC_COMBO1);
  308.   if (!ComboBox_GetCount(hwndCtl)) {
  309.     ComboBox_AddString(hwndCtl, "Dos");
  310.     ComboBox_AddString(hwndCtl, "Windows");
  311.     ComboBox_AddString(hwndCtl, "Windows95");
  312.     ComboBox_AddString(hwndCtl, "NT");
  313.   }
  314.   ComboBox_SetCurSel(hwndCtl, d_pageData->d_comboCurrent);
  315.  
  316. };
  317.  
  318. //
  319. //  GetDlgItems()
  320. //    Get the user change. This is callled when user select the OK button.
  321. //
  322. void CWindowPage::GetDlgItems() {
  323.  
  324.   d_pageData->d_checked = IsDlgButtonChecked(d_hDlg, IDC_CHECK1);
  325.   GetDlgItemText(d_hDlg, IDC_EDIT1, d_pageData->d_comment, sizeof(d_pageData->d_comment));
  326.  
  327.  
  328.   HWND hwndCtl = GetDlgItem(d_hDlg, IDC_LIST1);
  329.   d_pageData->d_listCurrent = ListBox_GetCurSel(hwndCtl);
  330.  
  331.   hwndCtl = GetDlgItem(d_hDlg, IDC_COMBO1);
  332.   d_pageData->d_comboCurrent= ComboBox_GetCurSel(hwndCtl);
  333.  
  334.   d_pageData->d_okToClose = 0;
  335. };
  336.  
  337. //
  338. // CanClose()
  339. //    This method is called to determined if it is ok to close the page.
  340. //
  341. BOOL CWindowPage::CanClose() {
  342.   //
  343.   // This page can not be closed unless IDC_RADIO1 is checked.
  344.   //
  345.   int canClose = IsDlgButtonChecked(d_hDlg, IDC_RADIO1);
  346.   if (!canClose) {
  347.      MessageBox(d_hDlg, "This page can not be closed, because the \"Ok to close page\" radion button is not checked ","Addon", MB_OK);
  348.   };
  349.   return canClose;
  350. };
  351.  
  352. //*****************************************************************************
  353. //
  354. // SubclassWindowPage is an example that subclass a dialog
  355. // A program can do this when it needs to respond to other dialog messages.
  356. //
  357. //*****************************************************************************
  358.  
  359. class SubclassWindowPage : public CWindowPage {
  360. public:
  361.   //
  362.   // IMpdPage interface
  363.   //
  364.   virtual VOID Init(HWND hDlg, IStatusBar* isb);
  365.   virtual LRESULT OnCommand(UINT id, HWND hWndCtl, UINT notifyCode);
  366. protected:
  367. };
  368.  
  369. static DLGPROC oldDlgWinProc;
  370. static CWindowPage* cTester;
  371.  
  372. BOOL CALLBACK DlgWinProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
  373.   switch (msg) {
  374.     case WM_COMMAND:
  375.     {
  376.       WORD wID = LOWORD(wParam);
  377.       WORD wNotifyCode = HIWORD(wParam);
  378.       HWND hWndCtl = (HWND) lParam;
  379.       return cTester->CWindowPage::OnCommand(wID, hWndCtl, wNotifyCode);
  380.     }
  381.   }
  382.   return oldDlgWinProc(hwnd, msg, wParam, lParam);
  383. }
  384.  
  385.  
  386. VOID SubclassWindowPage::Init(HWND hDlg, IStatusBar* isb) {
  387.  
  388.   CWindowPage::Init(hDlg, isb);
  389.  
  390.   SetDlgItemText(hDlg, IDC_PAGE_TYPE, "Subclass Dialog page");
  391.   oldDlgWinProc = SubclassDialog(hDlg, DlgWinProc);
  392.   cTester = this;
  393. };
  394.  
  395. //
  396. // WM_COMMAND is processed in DlgWinProc, do nothing in OnCommand() here.
  397. //
  398. LRESULT SubclassWindowPage::OnCommand(UINT id, HWND hWndCtl, UINT notifyCode) {
  399.   id, hWndCtl, notifyCode;
  400.   //
  401.   // must return 1 here in order for DlgWinProc to get WM_COMMAND message
  402.   //
  403.   return 1;
  404. };
  405.  
  406. /******************************************************************************
  407. *
  408. * IMpdChapterAddon
  409. *  A simple chapter implementation. It displays 3 different pages
  410. *     AddonPageBase: The minimal page implementation.
  411. *
  412. *     CWindowPage:   A page that demonstrates how to implement
  413. *                    various features of a MPD page
  414. *
  415. *     SubclassWindowPage: Demonstrates how to subclass a page.
  416. *                      (not working yet)
  417. *
  418. ******************************************************************************/
  419. IMpdChapterAddon::IMpdChapterAddon()
  420.                   :  IUnknownImp<IMpdChapter> (IID_IUnknown) {
  421.  
  422.   d_nPages = 0;
  423. };
  424.  
  425. IMpdChapterAddon::~IMpdChapterAddon() {
  426.  
  427.   unsigned i;
  428.   for (i = 0; i < d_nPages; ++i ) {
  429.     d_pages[i]->Release();
  430.   }
  431. };
  432.  
  433. void IMpdChapterAddon::Init() {
  434.  
  435.   d_pages[0] = new AddonPageBase;
  436.   d_pages[0]->SetInfo(MPD_OPENSUMMARY, IDD_MPD_PAGE1, "Addon Summary");
  437.  
  438.   d_pages[1] = new CWindowPage;
  439.   d_pages[1]->SetInfo(MPD_CLOSEPAGE,   IDD_MPD_PAGE2, "Page1");
  440.  
  441.   d_pages[2] = new SubclassWindowPage;
  442.   d_pages[2]->SetInfo(MPD_CLOSEPAGE,   IDD_MPD_PAGE3, "Page2");
  443.  
  444.   d_nPages = 3;
  445. };
  446.  
  447. UINT IMpdChapterAddon::GetPageCount() {
  448.   return d_nPages;
  449. };
  450.  
  451. IMpdPage* IMpdChapterAddon::GetPage(UINT iPage) {
  452.   if (iPage && iPage <= d_nPages) {
  453.     IMpdPage* page = d_pages[iPage-1];
  454.     page->AddRef();
  455.     return page;
  456.   }
  457.   return 0;
  458. };
  459.  
  460. void IMpdChapterAddon::SetEditNode(ProjectNode) {
  461. };
  462.  
  463.  
  464. IMpdPage* IMpdChapterAddon::OpenPage(UINT pid, ProjectNode /*node*/) {
  465.  
  466.   IMpdPage* page;
  467.   switch (pid) {
  468.     case IDD_MPD_PAGE1:
  469.       page = d_pages[0];
  470.       break;
  471.     case IDD_MPD_PAGE2:
  472.       page = d_pages[1];
  473.       break;
  474.     case IDD_MPD_PAGE3:
  475.       page = d_pages[2];
  476.       break;
  477.     default:
  478.       return 0;
  479.   }
  480.   page->AddRef();
  481.   return page;
  482. }
  483.  
  484. void IMpdChapterAddon::Close(UINT /*fOk*/) {
  485. };
  486.