home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / mac / SiteBldr / AMOVIE / SDK / _SETUP / COMMON.Z / nullprop.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-17  |  8.8 KB  |  307 lines

  1. //==========================================================================;
  2. //
  3. //  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  4. //  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  5. //  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  6. //  PURPOSE.
  7. //
  8. //  Copyright (c) 1992 - 1996  Microsoft Corporation.  All Rights Reserved.
  9. //
  10. //--------------------------------------------------------------------------;
  11. //----------------------------------------------------------------------------
  12. //INullIPProperty
  13. //----------------------------------------------------------------------------
  14.  
  15. #include <streams.h>
  16. #include <windowsx.h>
  17. #include <commctrl.h>
  18. #include <olectl.h>
  19. #include <memory.h>
  20. #include <stdlib.h>
  21. #include <stdio.h>
  22. #include <tchar.h>
  23.  
  24. #include "resource.h"
  25. #include "nulluids.h"
  26. #include "inull.h"
  27. #include "nullprop.h"
  28. #include "nullip.h"
  29. #include "texttype.h"
  30.  
  31. //----------------------------------------------------------------------------
  32. // INullIPProperties
  33. //----------------------------------------------------------------------------
  34.  
  35. //----------------------------------------------------------------------------
  36. // CreateInstance
  37. //----------------------------------------------------------------------------
  38. CUnknown *NullIPProperties::CreateInstance(LPUNKNOWN lpunk, HRESULT *phr)
  39. {
  40.  
  41.     CUnknown *punk = new NullIPProperties(lpunk, phr);
  42.     if (punk == NULL) {
  43.     *phr = E_OUTOFMEMORY;
  44.     }
  45.     return punk;
  46. }
  47. //----------------------------------------------------------------------------
  48. //
  49. // NullIPProperties::Constructor
  50. //----------------------------------------------------------------------------
  51. NullIPProperties::NullIPProperties(LPUNKNOWN pUnk, HRESULT *phr)
  52.     : CBasePropertyPage(NAME("NullIP Property Page"),pUnk,phr,
  53.         IDD_DIALOG1, IDS_TITLE)
  54.     , m_pPin(NULL)
  55.     , m_nIndex(0)
  56.     , m_pINullIPP(NULL)
  57. {
  58.     ASSERT(phr);
  59. }
  60.  
  61. //----------------------------------------------------------------------------
  62. //
  63. // SetDirty
  64. //
  65. // Sets m_hrDirtyFlag and notifies the property page site of the change
  66. //----------------------------------------------------------------------------
  67. void NullIPProperties::SetDirty()
  68. {
  69.     m_bDirty = TRUE;
  70.     if (m_pPageSite)
  71.     {
  72.         m_pPageSite->OnStatusChange(PROPPAGESTATUS_DIRTY);
  73.     }
  74. }
  75.  
  76. //----------------------------------------------------------------------------
  77. //
  78. // OnReceiveMessage
  79. //
  80. // Handles the messages for our property window
  81. //----------------------------------------------------------------------------
  82. BOOL NullIPProperties::OnReceiveMessage(HWND hwnd,
  83.                                         UINT uMsg,
  84.                                         WPARAM wParam,
  85.                                         LPARAM lParam)
  86. {
  87.     switch (uMsg)
  88.     {
  89.         case WM_INITDIALOG:
  90.         {
  91.             // get the hWnd of the list box
  92.             m_hwndLB = GetDlgItem (hwnd, IDC_MEDIALIST) ;
  93.             FillListBox();
  94.             return (LRESULT) 1;
  95.         }
  96.  
  97.         case WM_COMMAND:
  98.         {
  99.             if (HIWORD(wParam) == LBN_SELCHANGE)
  100.             {
  101.                 SetDirty();
  102.             }
  103.             return (LRESULT) 1;
  104.         }
  105.  
  106.     }
  107.     return CBasePropertyPage::OnReceiveMessage(hwnd,uMsg,wParam,lParam);
  108. }
  109.  
  110. //----------------------------------------------------------------------------
  111. // OnConnect
  112. //
  113. // Notification of which object this property page should be displayed.
  114. // We query the object for the INullIPP interface.
  115. //
  116. // If cObjects == 0 then we must release the interface.
  117. //----------------------------------------------------------------------------
  118. HRESULT NullIPProperties::OnConnect(IUnknown *pUnknown)
  119. {
  120.     ASSERT(m_pINullIPP == NULL);
  121.  
  122.     HRESULT hr = pUnknown->QueryInterface(IID_INullIPP, (void **) &m_pINullIPP);
  123.     if (FAILED(hr))
  124.     {
  125.         return E_NOINTERFACE;
  126.     }
  127.  
  128.     ASSERT(m_pINullIPP);
  129.  
  130.     ASSERT(!m_pPin);
  131.     m_pINullIPP->get_IPin(&m_pPin);
  132.  
  133.     return NOERROR;
  134. }
  135.  
  136. HRESULT NullIPProperties::OnDisconnect()
  137. {
  138.     // Release of Interface
  139.  
  140.     if (m_pINullIPP == NULL)
  141.         return E_UNEXPECTED;
  142.     m_pINullIPP->Release();
  143.     m_pINullIPP = NULL;
  144.  
  145.     // Release the pin interface that we are holding.
  146.  
  147.     if (m_pPin)
  148.     {
  149.         m_pPin->Release() ;
  150.         m_pPin = NULL ;
  151.     }
  152.     return NOERROR;
  153. }
  154.  
  155. //----------------------------------------------------------------------------
  156. // Activate
  157. //
  158. // We are being activated
  159. //----------------------------------------------------------------------------
  160. HRESULT NullIPProperties::OnActivate()
  161. {
  162.     SendMessage (m_hwndLB, LB_SETCURSEL, m_nIndex, 0) ;
  163.     return NOERROR;
  164. }
  165.  
  166.  
  167. //----------------------------------------------------------------------------
  168. //
  169. // OnApplyChanges
  170. //
  171. // Changes made should be kept.
  172. //----------------------------------------------------------------------------
  173. HRESULT NullIPProperties::OnApplyChanges()
  174. {
  175.  
  176.     ASSERT(m_pINullIPP);
  177.  
  178.     // get the current selection of the media type
  179.     int iIndex = SendMessage (m_hwndLB, LB_GETCURSEL, 0, 0) ;
  180.     if (iIndex <= 0)
  181.         iIndex = 0 ;
  182.  
  183.     m_bDirty = FALSE;            // the page is now clean
  184.     if (iIndex == 0)
  185.     {
  186.         m_pINullIPP->put_MediaType (NULL) ;
  187.         m_nIndex = 0;
  188.         return NOERROR;
  189.     }
  190.  
  191.     IEnumMediaTypes * pMTEnum;
  192.     AM_MEDIA_TYPE *pMediaType;
  193.     ULONG count;
  194.  
  195.     // get the type enumerator from the pin again
  196.  
  197.     HRESULT hr = m_pPin->EnumMediaTypes(&pMTEnum);
  198.     if (FAILED(hr))
  199.     {
  200.         return hr;
  201.     }
  202.  
  203.     // skip to the appropriate type and read it
  204.  
  205.     pMTEnum->Skip(iIndex - 1);
  206.     pMTEnum->Next(1, &pMediaType, &count);
  207.     if (count != 1) {
  208.         pMTEnum->Release();
  209.         return E_UNEXPECTED;
  210.     }
  211.  
  212.     // change the type by calling the filter
  213.  
  214.     CMediaType cmt(*pMediaType);
  215.     DeleteMediaType(pMediaType);
  216.     hr = m_pINullIPP->put_MediaType(&cmt) ;
  217.     if (FAILED(hr))
  218.     {
  219.         pMTEnum->Release();
  220.         return NOERROR;
  221.     }
  222.  
  223.     // update the current selection and release the enumerator
  224.  
  225.     m_nIndex = iIndex;
  226.     pMTEnum->Release();
  227.     return NOERROR;
  228. }
  229.  
  230. //----------------------------------------------------------------------------
  231. // FillListBox
  232. //----------------------------------------------------------------------------
  233. void NullIPProperties::FillListBox()
  234. {
  235.     IEnumMediaTypes * pMTEnum;
  236.     AM_MEDIA_TYPE *pMediaType;
  237.     ULONG count;
  238.     TCHAR szBuffer[100];
  239.     int Loop = 0, wextent = 0 ;
  240.     SIZE extent ;
  241.     FILTER_STATE state ;
  242.     CMediaType *pmtCurrent ;
  243.  
  244.     // get the current media type
  245.     ASSERT(m_pINullIPP);
  246.     m_pINullIPP->get_MediaType (&pmtCurrent);
  247.     m_nIndex = 0 ;
  248.  
  249.     // Fill the first entry of the list box with a choice to select any media.
  250.     LoadString(g_hInst, IDS_ANYTYPE, szBuffer, 100);
  251.     SendMessage (m_hwndLB, LB_ADDSTRING, 0, (LPARAM)szBuffer) ;
  252.  
  253.     // if the filter is not connected on the input, nothing more to fill
  254.     // also return if we haven't gotten any pin interface
  255.     if (m_pPin == NULL)
  256.         return ;
  257.  
  258.     // get a dc for the control. need this to get the extent of the strings
  259.     // that we put in the list box (so that we can get a horiz scroll bar).
  260.     HDC hdc = GetDC (m_hwndLB) ;
  261.  
  262.     // now enumerate the media types from our pin.
  263.     HRESULT hr = m_pPin->EnumMediaTypes(&pMTEnum);
  264.  
  265.     if (SUCCEEDED(hr))
  266.     {
  267.         ASSERT(pMTEnum);
  268.         pMTEnum->Next(1, &pMediaType, &count);
  269.         while (count == 1)
  270.         {
  271.             // increment the loop counter
  272.             Loop++;
  273.  
  274.             // convert the media type to string.
  275.             CTextMediaType(*pMediaType).AsText(szBuffer, 100, TEXT(" - "), TEXT(" - "), TEXT("\0"));
  276.  
  277.             // if the mediatype matches the current one, set m_nIndex to cur index
  278.             if (*pmtCurrent == *pMediaType) {
  279.                 m_nIndex = Loop;
  280.             }
  281.  
  282.             // get the extent of the string and save the max extent
  283.             GetTextExtentPoint (hdc, szBuffer, _tcslen(szBuffer), &extent) ;
  284.             if (extent.cx > wextent)
  285.                 wextent = extent.cx ;
  286.  
  287.             // add the string to the list box.
  288.             SendMessage (m_hwndLB, LB_ADDSTRING, 0, (LPARAM)szBuffer) ;
  289.  
  290.             // enumerate the next media type and loop.
  291.             DeleteMediaType(pMediaType);
  292.             pMTEnum->Next(1, &pMediaType, &count);
  293.         }
  294.         pMTEnum->Release();
  295.         SendMessage (m_hwndLB, LB_SETHORIZONTALEXTENT, wextent, 0) ;
  296.         SendMessage (m_hwndLB, LB_SETCURSEL, m_nIndex, 0) ;
  297.     }
  298.     ASSERT(m_pINullIPP);
  299.  
  300.     // if the filter is in a running state, disable the list box and allow
  301.     // no input.
  302.  
  303.     m_pINullIPP->get_State(&state);
  304.     EnableWindow (m_hwndLB, state != State_Running) ;
  305. }
  306.  
  307.