home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / mac / SiteBldr / AMOVIE / SDK / _SETUP / COMMON.Z / contprop.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-17  |  6.0 KB  |  256 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. //contprop.cpp
  13. //
  14. // Contents:
  15. //
  16. //     CContrastProperties class. This class implements the property page
  17. //     for the contrast filter and exposes the IPropertyPage interface
  18. //     which is defined by OLE2.
  19. //
  20.  
  21. #include <streams.h>
  22. #include <commctrl.h>
  23. #include <olectl.h>
  24. #include <memory.h>
  25.  
  26. #include "resource.h"
  27. #include "contuids.h"
  28. #include "icontrst.h"
  29. #include "contrast.h"
  30. #include "contprop.h"
  31.  
  32. // *
  33. // * CContrastProperties
  34. // *
  35.  
  36.  
  37. //
  38. // CreateInstance
  39. //
  40. CUnknown *CContrastProperties::CreateInstance(LPUNKNOWN lpunk, HRESULT *phr) {
  41.  
  42.     CUnknown *punk = new CContrastProperties(lpunk, phr);
  43.     if (punk == NULL) {
  44.     *phr = E_OUTOFMEMORY;
  45.     }
  46.  
  47.     return punk;
  48. }
  49.  
  50.  
  51. //
  52. // CContrastProperties::Constructor
  53. //
  54. CContrastProperties::CContrastProperties(LPUNKNOWN pUnk, HRESULT *phr)
  55.     : CBasePropertyPage(NAME("Contrast Property Page"),pUnk,phr,
  56.         IDD_CONTRASTPROP, IDS_TITLE)
  57.     , m_pContrast(NULL)
  58. {
  59.  
  60.     InitCommonControls();
  61.  
  62. }
  63.  
  64. // SetDirty
  65. //
  66. // Sets m_bDirty and notifies the property page site of the change
  67. //
  68. void CContrastProperties::SetDirty()
  69. {
  70.     m_bDirty = TRUE;
  71.     if (m_pPageSite)
  72.     {
  73.         m_pPageSite->OnStatusChange(PROPPAGESTATUS_DIRTY);
  74.     }
  75. }
  76.  
  77.  
  78. BOOL CContrastProperties::OnReceiveMessage(HWND hwnd,
  79.                                         UINT uMsg,
  80.                                         WPARAM wParam,
  81.                                         LPARAM lParam)
  82. {
  83.     switch (uMsg)
  84.     {
  85.         case WM_INITDIALOG:
  86.         {
  87.             m_hwndSlider = CreateSlider(hwnd);
  88.             ASSERT(m_hwndSlider);
  89.             return (LRESULT) 1;
  90.         }
  91.         case WM_VSCROLL:
  92.         {
  93.             ASSERT(m_hwndSlider);
  94.             OnSliderNotification(wParam);
  95.             return (LRESULT) 1;
  96.         }
  97.  
  98.         case WM_COMMAND:
  99.         {
  100.             if (LOWORD(wParam) == IDB_DEFAULT)
  101.             {
  102.                 pIContrast()->put_DefaultContrastLevel();
  103.                 SendMessage(m_hwndSlider, TBM_SETPOS, TRUE, 0L);
  104.                 SetDirty();
  105.             }
  106.             return (LRESULT) 1;
  107.         }
  108.  
  109.         case WM_DESTROY:
  110.         {
  111.             DestroyWindow(m_hwndSlider);
  112.             return (LRESULT) 1;
  113.         }
  114.  
  115.     }
  116.     return CBasePropertyPage::OnReceiveMessage(hwnd,uMsg,wParam,lParam);
  117. }
  118.  
  119.  
  120. HRESULT CContrastProperties::OnConnect(IUnknown *pUnknown)
  121. {
  122.  
  123.     ASSERT(m_pContrast == NULL);
  124.  
  125.     HRESULT hr = pUnknown->QueryInterface(IID_IContrast, (void **) &m_pContrast);
  126.     if (FAILED(hr))
  127.     {
  128.         return E_NOINTERFACE;
  129.     }
  130.  
  131.     ASSERT(m_pContrast);
  132.  
  133.     // Get the initial contrast value
  134.     m_pContrast->get_ContrastLevel(&m_cContrastLevel);
  135.     m_cContrastOnExit = m_cContrastLevel;
  136.     return NOERROR;
  137. }
  138.  
  139. HRESULT CContrastProperties::OnDisconnect()
  140. {
  141.     // Release of Interface after setting the appropriate contrast value
  142.  
  143.     if (m_pContrast == NULL)
  144.     {
  145.         return E_UNEXPECTED;
  146.     }
  147.  
  148.     m_pContrast->put_ContrastLevel(m_cContrastOnExit, 0);
  149.     m_pContrast->Release();
  150.     m_pContrast = NULL;
  151.     return NOERROR;
  152. }
  153.  
  154. // We are being deactivated
  155.  
  156. HRESULT CContrastProperties::OnDeactivate(void)
  157. {
  158.     // Remember the present contrast level for the next activate
  159.  
  160.     pIContrast()->get_ContrastLevel(&m_cContrastLevel);
  161.  
  162.     return NOERROR;
  163. }
  164.  
  165. //
  166. // Apply
  167. //
  168. // Changes made should be kept. Change the m_cContrastOnExit variable.
  169. // The contrast level will be changed to its value
  170. //  on CContrastProperties::Deactivate.
  171. //
  172.  
  173. HRESULT CContrastProperties::OnApplyChanges()
  174. {
  175.     pIContrast()->get_ContrastLevel(&m_cContrastOnExit);
  176.     m_bDirty  = FALSE; // the page is now clean
  177.     return(NOERROR);
  178.  
  179. }
  180.  
  181.  
  182. //
  183. // CreateSlider
  184. //
  185. // Create the slider (common control) to allow the user to
  186. // adjust the contrast
  187. HWND CContrastProperties::CreateSlider(HWND hwndParent) {
  188.  
  189.     HWND hwndSlider = CreateWindow( TRACKBAR_CLASS
  190.                   , TEXT("")
  191.                   , WS_CHILD | WS_VISIBLE | WS_TABSTOP | TBS_VERT | TBS_BOTH | WS_GROUP
  192.                   , 120, 0
  193.                   , 50, 100
  194.                   , hwndParent
  195.                   , NULL
  196.                   , g_hInst
  197.                   , NULL
  198.                   );
  199.     if (hwndSlider == NULL) {
  200.     DWORD dwErr = GetLastError();
  201.     DbgLog((LOG_ERROR, 1, TEXT("Could not create window: 0x%x"), dwErr));
  202.     return NULL;
  203.     }
  204.  
  205.     // Set the Range
  206.     SendMessage(hwndSlider, TBM_SETRANGE, TRUE, MAKELONG(MinContrastLevel, MaxContrastLevel) );
  207.  
  208.     // Set a tick at zero
  209.     SendMessage(hwndSlider, TBM_SETTIC, 0, 0L);
  210.  
  211.     //
  212.     // Set the slider position according to the value we obtained during
  213.     // initialisation or the last IPropertyPage::Deactivate call
  214.     //
  215.     SendMessage(hwndSlider, TBM_SETPOS, TRUE, m_cContrastLevel);
  216.  
  217.     return hwndSlider;
  218. }
  219.  
  220.  
  221. //
  222. // OnSliderNotification
  223. //
  224. // Handle the notification meesages from the slider control
  225. void CContrastProperties::OnSliderNotification(WPARAM wParam) {
  226.  
  227.     switch (wParam) {
  228.     case TB_BOTTOM:
  229.         SetDirty();
  230.     SendMessage(m_hwndSlider, TBM_SETPOS, TRUE, (LPARAM) MinContrastLevel);
  231.     break;
  232.  
  233.     case TB_TOP:
  234.         SetDirty();
  235.     SendMessage(m_hwndSlider, TBM_SETPOS, TRUE, (LPARAM) MaxContrastLevel);
  236.     break;
  237.  
  238.     case TB_PAGEDOWN:
  239.     case TB_PAGEUP:
  240.     break;
  241.  
  242.     case TB_THUMBPOSITION:
  243.     case TB_ENDTRACK: {
  244.             SetDirty();
  245.             signed char Level = (signed char) SendMessage(m_hwndSlider, TBM_GETPOS, 0, 0L);
  246.         pIContrast()->put_ContrastLevel(Level, 0);
  247.         }
  248.     break;
  249.  
  250.     case TB_THUMBTRACK: // default handling of these messages is ok.
  251.     case TB_LINEDOWN:
  252.     case TB_LINEUP:
  253.     break;
  254.     }
  255. }
  256.