www.pudn.com > DS4050src.zip > divxfilterproperties.cpp


/************************************************************************** 
 *                                                                        * 
 * This code has been developed by Andrea Graziani. Those intending to    * 
 * use this software module in hardware or software products are advised  * 
 * that its use may infringe existing patents or copyrights, and any such *  
 * use would be at such party's own risk. The original developer of this  * 
 * software module and his/her company, and subsequent editors and their  * 
 * companies (including Project Mayo), will have no liability for use of  * 
 * this software or modifications or derivatives thereof.                 * 
 *                                                                        * 
 * Project Mayo gives users of the Codec and Filter a license to this     * 
 * software  module or modifications thereof for use in hardware or       * 
 * software products claiming conformance to the MPEG-4 Video Standard    * 
 * as described in the Open DivX license.                                 * 
 *                                                                        * 
 * The complete Open DivX license can be found at                         * 
 * http://www.projectmayo.com/opendivx/license.php                        * 
 *                                                                        * 
 **************************************************************************/ 
/** 
*  Copyright (C) 2001 - Project Mayo 
 * 
 * Andrea Graziani 
 * 
 * DivX Advanced Research Center  
* 
**/ 
// divxfilterproperties.cpp // 
 
#include  
#include  
 
#include "resource.h" 
#include "divxuid.h" 
#include "divxfilterproperties.h" 
 
// 
// CreateInstance 
// 
CUnknown * WINAPI DivXFilterProperties::CreateInstance(LPUNKNOWN lpunk, HRESULT * phr) 
{ 
	CUnknown *punk = new DivXFilterProperties(lpunk, phr); 
	if (punk == NULL) { 
		*phr = E_OUTOFMEMORY; 
	} 
	return punk; 
} // CreateInstance 
 
 
/** 
 *	constructor/denstructor 
**/ 
 
DivXFilterProperties::DivXFilterProperties(LPUNKNOWN lpunk, HRESULT * phr) : 
	CBasePropertyPage(NAME("DivX Deux Filter Properties Page"), lpunk, IDD_PROPPAGE, IDS_NAME), 
	m_pDivXFilterInterface(NULL) 
{ 
	ASSERT(phr); 
 
	InitCommonControls(); 
} // DivXFilterProperties 
 
 
DivXFilterProperties::~DivXFilterProperties() 
{ 
} // ~DivXFilterProperties 
 
 
/** 
 * 
**/ 
 
// virtual method called by base class with Window messages 
// 
BOOL DivXFilterProperties::OnReceiveMessage(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 
{ 
  switch (uMsg) 
  { 
	case WM_INITDIALOG: 
		{ 
			m_hwndSlider = CreateSlider(hwnd); 
			ASSERT(m_hwndSlider); 
			return (LRESULT) 1; 
		} 
	case WM_HSCROLL: 
		{ 
			ASSERT(m_hwndSlider); 
			OnSliderNotification(wParam); 
			return (LRESULT) 1; 
		} 
	case WM_COMMAND: 
		{ 
			if (LOWORD(wParam) == IDC_BUTTON) 
			{ 
				pIDivXFilter()->put_DefaultPPLevel(); 
				SendMessage(m_hwndSlider, TBM_SETPOS, TRUE, 0L); 
				SetDirty(); 
			} 
			return (LRESULT) 1; 
		} 
	case WM_DESTROY: 
		{ 
			DestroyWindow(m_hwndSlider); 
			m_hwndSlider = NULL; 
			return (LRESULT) 1; 
		} 
  } 
  return CBasePropertyPage::OnReceiveMessage(hwnd,uMsg,wParam,lParam); 
} // OnReceiveMessage 
 
 
// create the slider (common control) to allow the user to adjust postprocessing level 
// 
HWND DivXFilterProperties::CreateSlider(HWND hwndParent) 
{ 
	ULONG Styles = WS_CHILD | WS_VISIBLE | WS_TABSTOP | TBS_HORZ | TBS_BOTH | WS_GROUP | TBS_AUTOTICKS; 
	HWND hwndSlider = CreateWindow(TRACKBAR_CLASS, 
		TEXT(""), 
		Styles, 
		10, 35, 
		290, 35, 
		hwndParent, 
		NULL, 
		g_hInst, 
		NULL); 
	if (hwndSlider == NULL) { 
		DWORD dwErr = GetLastError(); 
		return NULL; 
	} 
 
	SendMessage(hwndSlider, TBM_SETTICFREQ, 10, 0); 
	SendMessage(hwndSlider, TBM_SETRANGE, TRUE, MAKELONG(MinPPLevel, MaxPPLevel)); // initial range for the slider 
	SendMessage(hwndSlider, TBM_SETTIC, 0, 0L); // tick at zero 
	SendMessage(hwndSlider, TBM_SETPOS, TRUE, m_ciPPLevel); // initial slider position 
	 
	return hwndSlider; 
} // CreateSlider 
 
 
// notification messages from the slider control 
// 
void DivXFilterProperties::OnSliderNotification(WPARAM wParam) 
{ 
  switch (wParam)  
	{ 
	case TB_BOTTOM: 
		SetDirty(); 
		SendMessage(m_hwndSlider, TBM_SETPOS, TRUE, (LPARAM) MinPPLevel); 
		break; 
		 
	case TB_TOP: 
		SetDirty(); 
		SendMessage(m_hwndSlider, TBM_SETPOS, TRUE, (LPARAM) MaxPPLevel); 
		break; 
		 
	case TB_PAGEDOWN: 
	case TB_PAGEUP: 
	case TB_THUMBTRACK: 
	case TB_ENDTRACK: 
		{ 
			SetDirty(); 
			int Level = (int) SendMessage(m_hwndSlider, TBM_GETPOS, 0, 0L); 
			pIDivXFilter()->put_PPLevel(Level); 
		} 
		break; 
  } 
} // OnSliderNotification 
 
 
// set m_bDirty and notifies the property page of the change 
// 
void DivXFilterProperties::SetDirty() 
{ 
  m_bDirty = TRUE; 
 
  if (m_pPageSite) { 
      m_pPageSite->OnStatusChange(PROPPAGESTATUS_DIRTY); 
  } 
} // SetDirty 
 
 
// called when the property page connects to a filter 
// 
HRESULT DivXFilterProperties::OnConnect(IUnknown *pUnknown) 
{ 
  ASSERT(m_pDivXFilterInterface == NULL); 
 
  HRESULT hr = pUnknown->QueryInterface(IID_IDivXFilterInterface, (void **) &m_pDivXFilterInterface); 
  if (FAILED(hr)) { 
		return E_NOINTERFACE; 
  } 
 
  ASSERT(m_pDivXFilterInterface); 
 
  // Get the initial postprocessing value 
  m_pDivXFilterInterface->get_PPLevel(&m_ciPPLevel); 
  m_ciPPOnExit = m_ciPPLevel; 
 
  return S_OK; 
} // OnConnect 
 
 
HRESULT DivXFilterProperties::OnDisconnect() 
{ 
	if (m_pDivXFilterInterface == NULL) { 
		return E_UNEXPECTED; 
	} 
	 
	// release the interface after setting the appropriate postprocessing value 
	m_pDivXFilterInterface->put_PPLevel(m_ciPPOnExit); 
	m_pDivXFilterInterface->Release(); 
	m_pDivXFilterInterface = NULL; 
 
	return S_OK; 
} // OnDisconnect 
 
 
HRESULT DivXFilterProperties::OnDeactivate() 
{ 
	// remember the current value for next activate 
	pIDivXFilter()->get_PPLevel(&m_ciPPLevel); 
 
	return S_OK; 
} // OnDeactivate 
 
 
// keep changes made 
// 
HRESULT DivXFilterProperties::OnApplyChanges() 
{ 
  pIDivXFilter()->get_PPLevel(&m_ciPPOnExit); 
  m_bDirty = FALSE; 
 
  return S_OK; 
} // OnApplyChanges