PPageOverrides.cpp

00001 /* 
00002  *      Copyright (C) 2003-2005 Gabest
00003  *      http://www.gabest.org
00004  *
00005  *  This Program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2, or (at your option)
00008  *  any later version.
00009  *   
00010  *  This Program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00013  *  GNU General Public License for more details.
00014  *   
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with GNU Make; see the file COPYING.  If not, write to
00017  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
00018  *  http://www.gnu.org/copyleft/gpl.html
00019  *
00020  */
00021 
00022 // PPageOverrides.cpp : implementation file
00023 //
00024 
00025 #include "stdafx.h"
00026 #include "mplayerc.h"
00027 #include "PPageOverrides.h"
00028 #include "ComPropertySheet.h"
00029 #include "RegFilterChooserDlg.h"
00030 #include "SelectMediaType.h"
00031 #include "GraphBuilder.h"
00032 #include "..\..\..\include\moreuuids.h"
00033 
00034 #include <initguid.h>
00035 #include <Dmoreg.h>
00036 
00037 // CPPageOverrides dialog
00038 
00039 IMPLEMENT_DYNAMIC(CPPageOverrides, CPPageBase)
00040 CPPageOverrides::CPPageOverrides()
00041         : CPPageBase(CPPageOverrides::IDD, CPPageOverrides::IDD)
00042         , m_iLoadType(Filter::PREFERRED)
00043         , m_pLastSelFilter(NULL)
00044 {
00045 }
00046 
00047 CPPageOverrides::~CPPageOverrides()
00048 {
00049 }
00050 
00051 void CPPageOverrides::DoDataExchange(CDataExchange* pDX)
00052 {
00053         __super::DoDataExchange(pDX);
00054         DDX_Control(pDX, IDC_LIST1, m_filters);
00055         DDX_Radio(pDX, IDC_RADIO1, m_iLoadType);
00056         DDX_Control(pDX, IDC_EDIT1, m_dwMerit);
00057         DDX_Control(pDX, IDC_TREE2, m_tree);
00058 }
00059 
00060 void CPPageOverrides::StepUp(CCheckListBox& list)
00061 {
00062         int i = list.GetCurSel();
00063         if(i < 1) return;
00064 
00065         CString str;
00066         list.GetText(i, str);
00067         DWORD_PTR dwItemData = list.GetItemData(i);
00068         int nCheck = list.GetCheck(i);
00069         list.DeleteString(i);
00070         i--;
00071         list.InsertString(i, str);
00072         list.SetItemData(i, dwItemData);
00073         list.SetCheck(i, nCheck);
00074         list.SetCurSel(i);
00075 }
00076 
00077 void CPPageOverrides::StepDown(CCheckListBox& list)
00078 {
00079         int i = list.GetCurSel();
00080         if(i < 0 || i >= list.GetCount()-1) return;
00081 
00082         CString str;
00083         list.GetText(i, str);
00084         DWORD_PTR dwItemData = list.GetItemData(i);
00085         int nCheck = list.GetCheck(i);
00086         list.DeleteString(i);
00087         i++;
00088         list.InsertString(i, str);
00089         list.SetItemData(i, dwItemData);
00090         list.SetCheck(i, nCheck);
00091         list.SetCurSel(i);
00092 }
00093 
00094 Filter* CPPageOverrides::GetCurFilter()
00095 {
00096         int i = m_filters.GetCurSel();
00097         return i >= 0 ? (Filter*)m_pFilters.GetAt((POSITION)m_filters.GetItemDataPtr(i)) : (Filter*)NULL;
00098 }
00099 
00100 void CPPageOverrides::SetupMajorTypes(CArray<GUID>& guids)
00101 {
00102         guids.RemoveAll();
00103         guids.Add(MEDIATYPE_NULL);
00104         guids.Add(MEDIATYPE_Video);
00105         guids.Add(MEDIATYPE_Audio);
00106         guids.Add(MEDIATYPE_Text);
00107         guids.Add(MEDIATYPE_Midi);
00108         guids.Add(MEDIATYPE_Stream);
00109         guids.Add(MEDIATYPE_Interleaved);
00110         guids.Add(MEDIATYPE_File);
00111         guids.Add(MEDIATYPE_ScriptCommand);
00112         guids.Add(MEDIATYPE_AUXLine21Data);
00113         guids.Add(MEDIATYPE_VBI);
00114         guids.Add(MEDIATYPE_Timecode);
00115         guids.Add(MEDIATYPE_LMRT);
00116         guids.Add(MEDIATYPE_URL_STREAM);
00117         guids.Add(MEDIATYPE_MPEG1SystemStream);
00118         guids.Add(MEDIATYPE_AnalogVideo);
00119         guids.Add(MEDIATYPE_AnalogAudio);
00120         guids.Add(MEDIATYPE_MPEG2_PACK);
00121         guids.Add(MEDIATYPE_MPEG2_PES);
00122         guids.Add(MEDIATYPE_MPEG2_SECTIONS);
00123         guids.Add(MEDIATYPE_DVD_ENCRYPTED_PACK);
00124         guids.Add(MEDIATYPE_DVD_NAVIGATION);
00125 }
00126 
00127 void CPPageOverrides::SetupSubTypes(CArray<GUID>& guids)
00128 {
00129         guids.RemoveAll();
00130         guids.Add(MEDIASUBTYPE_None);
00131         guids.Add(MEDIASUBTYPE_CLPL);
00132         guids.Add(MEDIASUBTYPE_YUYV);
00133         guids.Add(MEDIASUBTYPE_IYUV);
00134         guids.Add(MEDIASUBTYPE_YVU9);
00135         guids.Add(MEDIASUBTYPE_Y411);
00136         guids.Add(MEDIASUBTYPE_Y41P);
00137         guids.Add(MEDIASUBTYPE_YUY2);
00138         guids.Add(MEDIASUBTYPE_YVYU);
00139         guids.Add(MEDIASUBTYPE_UYVY);
00140         guids.Add(MEDIASUBTYPE_Y211);
00141         guids.Add(MEDIASUBTYPE_CLJR);
00142         guids.Add(MEDIASUBTYPE_IF09);
00143         guids.Add(MEDIASUBTYPE_CPLA);
00144         guids.Add(MEDIASUBTYPE_MJPG);
00145         guids.Add(MEDIASUBTYPE_TVMJ);
00146         guids.Add(MEDIASUBTYPE_WAKE);
00147         guids.Add(MEDIASUBTYPE_CFCC);
00148         guids.Add(MEDIASUBTYPE_IJPG);
00149         guids.Add(MEDIASUBTYPE_Plum);
00150         guids.Add(MEDIASUBTYPE_DVCS);
00151         guids.Add(MEDIASUBTYPE_DVSD);
00152         guids.Add(MEDIASUBTYPE_MDVF);
00153         guids.Add(MEDIASUBTYPE_RGB1);
00154         guids.Add(MEDIASUBTYPE_RGB4);
00155         guids.Add(MEDIASUBTYPE_RGB8);
00156         guids.Add(MEDIASUBTYPE_RGB565);
00157         guids.Add(MEDIASUBTYPE_RGB555);
00158         guids.Add(MEDIASUBTYPE_RGB24);
00159         guids.Add(MEDIASUBTYPE_RGB32);
00160         guids.Add(MEDIASUBTYPE_ARGB1555);
00161         guids.Add(MEDIASUBTYPE_ARGB4444);
00162         guids.Add(MEDIASUBTYPE_ARGB32);
00163         guids.Add(MEDIASUBTYPE_A2R10G10B10);
00164         guids.Add(MEDIASUBTYPE_A2B10G10R10);
00165         guids.Add(MEDIASUBTYPE_AYUV);
00166         guids.Add(MEDIASUBTYPE_AI44);
00167         guids.Add(MEDIASUBTYPE_IA44);
00168         guids.Add(MEDIASUBTYPE_RGB32_D3D_DX7_RT);
00169         guids.Add(MEDIASUBTYPE_RGB16_D3D_DX7_RT);
00170         guids.Add(MEDIASUBTYPE_ARGB32_D3D_DX7_RT);
00171         guids.Add(MEDIASUBTYPE_ARGB4444_D3D_DX7_RT);
00172         guids.Add(MEDIASUBTYPE_ARGB1555_D3D_DX7_RT);
00173         guids.Add(MEDIASUBTYPE_RGB32_D3D_DX9_RT);
00174         guids.Add(MEDIASUBTYPE_RGB16_D3D_DX9_RT);
00175         guids.Add(MEDIASUBTYPE_ARGB32_D3D_DX9_RT);
00176         guids.Add(MEDIASUBTYPE_ARGB4444_D3D_DX9_RT);
00177         guids.Add(MEDIASUBTYPE_ARGB1555_D3D_DX9_RT);
00178         guids.Add(MEDIASUBTYPE_YV12);
00179         guids.Add(MEDIASUBTYPE_NV12);
00180         guids.Add(MEDIASUBTYPE_IMC1);
00181         guids.Add(MEDIASUBTYPE_IMC2);
00182         guids.Add(MEDIASUBTYPE_IMC3);
00183         guids.Add(MEDIASUBTYPE_IMC4);
00184         guids.Add(MEDIASUBTYPE_S340);
00185         guids.Add(MEDIASUBTYPE_S342);
00186         guids.Add(MEDIASUBTYPE_Overlay);
00187         guids.Add(MEDIASUBTYPE_MPEG1Packet);
00188         guids.Add(MEDIASUBTYPE_MPEG1Payload);
00189         guids.Add(MEDIASUBTYPE_MPEG1AudioPayload);
00190         guids.Add(MEDIASUBTYPE_MPEG1System);
00191         guids.Add(MEDIASUBTYPE_MPEG1VideoCD);
00192         guids.Add(MEDIASUBTYPE_MPEG1Video);
00193         guids.Add(MEDIASUBTYPE_MPEG1Audio);
00194         guids.Add(MEDIASUBTYPE_Avi);
00195         guids.Add(MEDIASUBTYPE_Asf);
00196         guids.Add(MEDIASUBTYPE_QTMovie);
00197         guids.Add(MEDIASUBTYPE_QTRpza);
00198         guids.Add(MEDIASUBTYPE_QTSmc);
00199         guids.Add(MEDIASUBTYPE_QTRle);
00200         guids.Add(MEDIASUBTYPE_QTJpeg);
00201         guids.Add(MEDIASUBTYPE_PCMAudio_Obsolete);
00202         guids.Add(MEDIASUBTYPE_PCM);
00203         guids.Add(MEDIASUBTYPE_WAVE);
00204         guids.Add(MEDIASUBTYPE_AU);
00205         guids.Add(MEDIASUBTYPE_AIFF);
00206         guids.Add(MEDIASUBTYPE_dvsd);
00207         guids.Add(MEDIASUBTYPE_dvhd);
00208         guids.Add(MEDIASUBTYPE_dvsl);
00209         guids.Add(MEDIASUBTYPE_dv25);
00210         guids.Add(MEDIASUBTYPE_dv50);
00211         guids.Add(MEDIASUBTYPE_dvh1);
00212         guids.Add(MEDIASUBTYPE_Line21_BytePair);
00213         guids.Add(MEDIASUBTYPE_Line21_GOPPacket);
00214         guids.Add(MEDIASUBTYPE_Line21_VBIRawData);
00215         guids.Add(MEDIASUBTYPE_TELETEXT);
00216         guids.Add(MEDIASUBTYPE_DRM_Audio);
00217         guids.Add(MEDIASUBTYPE_IEEE_FLOAT);
00218         guids.Add(MEDIASUBTYPE_DOLBY_AC3_SPDIF);
00219         guids.Add(MEDIASUBTYPE_RAW_SPORT);
00220         guids.Add(MEDIASUBTYPE_SPDIF_TAG_241h);
00221         guids.Add(MEDIASUBTYPE_DssVideo);
00222         guids.Add(MEDIASUBTYPE_DssAudio);
00223         guids.Add(MEDIASUBTYPE_VPVideo);
00224         guids.Add(MEDIASUBTYPE_VPVBI);
00225         guids.Add(MEDIASUBTYPE_ATSC_SI);
00226         guids.Add(MEDIASUBTYPE_DVB_SI);
00227         guids.Add(MEDIASUBTYPE_MPEG2DATA);
00228         guids.Add(MEDIASUBTYPE_MPEG2_VIDEO);
00229         guids.Add(MEDIASUBTYPE_MPEG2_PROGRAM);
00230         guids.Add(MEDIASUBTYPE_MPEG2_TRANSPORT);
00231         guids.Add(MEDIASUBTYPE_MPEG2_TRANSPORT_STRIDE);
00232         guids.Add(MEDIASUBTYPE_MPEG2_AUDIO);
00233         guids.Add(MEDIASUBTYPE_DOLBY_AC3);
00234         guids.Add(MEDIASUBTYPE_DVD_SUBPICTURE);
00235         guids.Add(MEDIASUBTYPE_DVD_LPCM_AUDIO);
00236         guids.Add(MEDIASUBTYPE_DTS);
00237         guids.Add(MEDIASUBTYPE_SDDS);
00238         guids.Add(MEDIASUBTYPE_DVD_NAVIGATION_PCI);
00239         guids.Add(MEDIASUBTYPE_DVD_NAVIGATION_DSI);
00240         guids.Add(MEDIASUBTYPE_DVD_NAVIGATION_PROVIDER);
00241         guids.Add(MEDIASUBTYPE_I420);
00242         guids.Add(MEDIASUBTYPE_WAVE_DOLBY_AC3);
00243         guids.Add(MEDIASUBTYPE_WAVE_DTS);
00244 }
00245 
00246 BEGIN_MESSAGE_MAP(CPPageOverrides, CPPageBase)
00247         ON_UPDATE_COMMAND_UI(IDC_BUTTON2, OnUpdateFilter)
00248         ON_UPDATE_COMMAND_UI(IDC_RADIO1, OnUpdateFilter)
00249         ON_UPDATE_COMMAND_UI(IDC_RADIO2, OnUpdateFilter)
00250         ON_UPDATE_COMMAND_UI(IDC_RADIO3, OnUpdateFilter)
00251         ON_UPDATE_COMMAND_UI(IDC_BUTTON11, OnUpdateFilterUp)
00252         ON_UPDATE_COMMAND_UI(IDC_BUTTON6, OnUpdateFilterDown)
00253         ON_UPDATE_COMMAND_UI(IDC_EDIT1, OnUpdateFilterMerit)
00254         ON_UPDATE_COMMAND_UI(IDC_BUTTON13, OnUpdateFilter)
00255         ON_UPDATE_COMMAND_UI(IDC_BUTTON14, OnUpdateSubType)
00256         ON_UPDATE_COMMAND_UI(IDC_BUTTON9, OnUpdateDeleteType)
00257         ON_UPDATE_COMMAND_UI(IDC_BUTTON10, OnUpdateFilter)
00258         ON_BN_CLICKED(IDC_BUTTON1, OnAddRegistered)
00259         ON_BN_CLICKED(IDC_BUTTON2, OnRemoveFilter)
00260         ON_BN_CLICKED(IDC_BUTTON11, OnMoveFilterUp)
00261         ON_BN_CLICKED(IDC_BUTTON6, OnMoveFilterDown)
00262         ON_LBN_DBLCLK(IDC_LIST1, OnLbnDblclkFilter)
00263         ON_BN_CLICKED(IDC_BUTTON13, OnAddMajorType)
00264         ON_BN_CLICKED(IDC_BUTTON14, OnAddSubType)
00265         ON_BN_CLICKED(IDC_BUTTON9, OnDeleteType)
00266         ON_BN_CLICKED(IDC_BUTTON10, OnResetTypes)
00267         ON_LBN_SELCHANGE(IDC_LIST1, OnLbnSelchangeList1)
00268         ON_BN_CLICKED(IDC_RADIO1, OnBnClickedRadio)
00269         ON_BN_CLICKED(IDC_RADIO2, OnBnClickedRadio)
00270         ON_BN_CLICKED(IDC_RADIO3, OnBnClickedRadio)
00271         ON_EN_CHANGE(IDC_EDIT1, OnEnChangeEdit1)
00272         ON_NOTIFY(NM_DBLCLK, IDC_TREE2, OnNMDblclkTree2)
00273         ON_WM_DROPFILES()
00274 END_MESSAGE_MAP()
00275 
00276 
00277 // CPPageOverrides message handlers
00278 
00279 BOOL CPPageOverrides::OnInitDialog()
00280 {
00281         __super::OnInitDialog();
00282         
00283         DragAcceptFiles(TRUE);
00284 
00285         AppSettings& s = AfxGetAppSettings();
00286 
00287         m_pFilters.RemoveAll();
00288 
00289         POSITION pos = s.filters.GetHeadPosition();
00290         while(pos)
00291         {
00292                 CAutoPtr<Filter> f(new Filter(s.filters.GetNext(pos)));
00293 
00294                 CString name(_T("<unknown>"));
00295 
00296                 if(f->type == Filter::REGISTERED)
00297                 {
00298                         name = CGraphRegFilter(f->dispname).GetName();
00299                         if(name.IsEmpty()) name = f->name + _T(" <not registered>");
00300                 }
00301                 else if(f->type == Filter::EXTERNAL)
00302                 {
00303                         name = f->name;
00304                         if(f->fTemporary) name += _T(" <temporary>");
00305                         if(!CPath(MakeFullPath(f->path)).FileExists()) name += _T(" <not found!>");
00306                 }
00307 
00308                 int i = m_filters.AddString(name);
00309                 m_filters.SetCheck(i, f->fDisabled ? 0 : 1);
00310                 m_filters.SetItemDataPtr(i, m_pFilters.AddTail(f));
00311         }
00312 
00313         UpdateData(FALSE);
00314 
00315         return TRUE;  // return TRUE unless you set the focus to a control
00316         // EXCEPTION: OCX Property Pages should return FALSE
00317 }
00318 
00319 BOOL CPPageOverrides::OnApply()
00320 {
00321         UpdateData();
00322 
00323         AppSettings& s = AfxGetAppSettings();
00324 
00325         s.filters.RemoveAll();
00326 
00327         for(int i = 0; i < m_filters.GetCount(); i++)
00328         {
00329                 if(POSITION pos = (POSITION)m_filters.GetItemData(i))
00330                 {
00331                         CAutoPtr<Filter> f(new Filter(m_pFilters.GetAt(pos)));
00332                         f->fDisabled = !m_filters.GetCheck(i);
00333                         s.filters.AddTail(f);
00334                 }
00335         }
00336 
00337         return __super::OnApply();
00338 }
00339 
00340 void CPPageOverrides::OnUpdateFilter(CCmdUI* pCmdUI)
00341 {
00342         if(Filter* f = GetCurFilter())
00343         {
00344                 pCmdUI->Enable(!(pCmdUI->m_nID == IDC_RADIO2 && f->type == Filter::EXTERNAL));
00345         }
00346         else
00347         {
00348                 pCmdUI->Enable(FALSE);
00349         }
00350 }
00351 
00352 void CPPageOverrides::OnUpdateFilterUp(CCmdUI* pCmdUI)
00353 {
00354         pCmdUI->Enable(m_filters.GetCurSel() > 0);
00355 }
00356 
00357 void CPPageOverrides::OnUpdateFilterDown(CCmdUI* pCmdUI)
00358 {
00359         pCmdUI->Enable(m_filters.GetCurSel() >= 0 && m_filters.GetCurSel() < m_filters.GetCount()-1);
00360 }
00361 
00362 void CPPageOverrides::OnUpdateFilterMerit(CCmdUI* pCmdUI)
00363 {
00364         UpdateData();
00365         pCmdUI->Enable(m_iLoadType == Filter::MERIT);
00366 }
00367 
00368 void CPPageOverrides::OnUpdateSubType(CCmdUI* pCmdUI)
00369 {
00370         HTREEITEM node = m_tree.GetSelectedItem();
00371         pCmdUI->Enable(node != NULL && m_tree.GetItemData(node) == NULL);
00372 }
00373 
00374 void CPPageOverrides::OnUpdateDeleteType(CCmdUI* pCmdUI)
00375 {
00376         pCmdUI->Enable(!!m_tree.GetSelectedItem());
00377 }
00378 
00379 void CPPageOverrides::OnAddRegistered()
00380 {
00381         CRegFilterChooserDlg dlg(this);
00382         if(dlg.DoModal() == IDOK)
00383         {
00384                 while(!dlg.m_filters.IsEmpty())
00385                 {
00386                         if(Filter* f = dlg.m_filters.RemoveHead())
00387                         {
00388                                 CAutoPtr<Filter> p(f);
00389 
00390                                 CString name = f->name;
00391 
00392                                 if(f->type == Filter::EXTERNAL)
00393                                 {
00394                                         if(!CPath(MakeFullPath(f->path)).FileExists()) name += _T(" <not found!>");
00395                                 }
00396 
00397                                 int i = m_filters.AddString(name);
00398                                 m_filters.SetItemDataPtr(i, m_pFilters.AddTail(p));
00399                                 m_filters.SetCheck(i, 1);
00400 
00401                                 if(dlg.m_filters.IsEmpty())
00402                                 {
00403                                         m_filters.SetCurSel(i);
00404                                         OnLbnSelchangeList1();
00405                                 }
00406                         }
00407                 }
00408         }
00409 }
00410 
00411 void CPPageOverrides::OnRemoveFilter()
00412 {
00413         int i = m_filters.GetCurSel();
00414         m_pFilters.RemoveAt((POSITION)m_filters.GetItemDataPtr(i));
00415         m_filters.DeleteString(i);
00416         if(i >= m_filters.GetCount()) i--;
00417         m_filters.SetCurSel(i);
00418         OnLbnSelchangeList1();
00419 }
00420 
00421 void CPPageOverrides::OnMoveFilterUp()
00422 {
00423         StepUp(m_filters);
00424 }
00425 
00426 void CPPageOverrides::OnMoveFilterDown()
00427 {
00428         StepDown(m_filters);
00429 }
00430 
00431 void CPPageOverrides::OnLbnDblclkFilter()
00432 {
00433         if(Filter* f = GetCurFilter())
00434         {
00435                 CComPtr<IBaseFilter> pBF;
00436                 CString name;
00437 
00438                 if(f->type == Filter::REGISTERED)
00439                 {
00440                         CStringW namew;
00441                         if(CreateFilter(f->dispname, &pBF, namew))
00442                                 name = namew;
00443                 }
00444                 else if(f->type == Filter::EXTERNAL)
00445                 {
00446                         if(SUCCEEDED(LoadExternalFilter(f->path, f->clsid, &pBF)))
00447                                 name = f->name;
00448                 }
00449 
00450                 if(CComQIPtr<ISpecifyPropertyPages> pSPP = pBF)
00451                 {
00452                         CComPropertySheet ps(name, this);
00453                         if(ps.AddPages(pSPP) > 0)
00454                         {
00455                                 CComPtr<IFilterGraph> pFG;
00456                                 if(SUCCEEDED(pFG.CoCreateInstance(CLSID_FilterGraph)))
00457                                         pFG->AddFilter(pBF, L"");
00458 
00459                                 ps.DoModal();
00460                         }
00461                 }
00462         }
00463 }
00464 
00465 void CPPageOverrides::OnAddMajorType()
00466 {
00467         Filter* f = GetCurFilter();
00468         if(!f) return;
00469 
00470         CArray<GUID> guids;
00471         SetupMajorTypes(guids);
00472         
00473         CSelectMediaType dlg(guids, MEDIATYPE_NULL, this);
00474         if(dlg.DoModal() == IDOK)
00475         {
00476                 POSITION pos = f->guids.GetHeadPosition();
00477                 while(pos)
00478                 {
00479                         if(f->guids.GetNext(pos) == dlg.m_guid) {AfxMessageBox(_T("Already on the list!")); return;}
00480                         f->guids.GetNext(pos);
00481                 }
00482 
00483                 f->guids.AddTail(dlg.m_guid);
00484                 pos = f->guids.GetTailPosition();
00485                 f->guids.AddTail(GUID_NULL);
00486 
00487                 CString major = GetMediaTypeName(dlg.m_guid);
00488                 CString sub = GetMediaTypeName(GUID_NULL);
00489 
00490                 HTREEITEM node = m_tree.InsertItem(major);
00491                 m_tree.SetItemData(node, NULL);
00492 
00493                 node = m_tree.InsertItem(sub, node);
00494                 m_tree.SetItemData(node, (DWORD_PTR)pos);
00495         }
00496 }
00497 
00498 void CPPageOverrides::OnAddSubType()
00499 {
00500         Filter* f = GetCurFilter();
00501         if(!f) return;
00502 
00503         HTREEITEM node = m_tree.GetSelectedItem();
00504         if(!node) return;
00505 
00506         HTREEITEM child = m_tree.GetChildItem(node);
00507         if(!child) return;
00508 
00509         POSITION pos = (POSITION)m_tree.GetItemData(child);
00510         GUID major = f->guids.GetAt(pos);
00511 
00512         CArray<GUID> guids;
00513         SetupSubTypes(guids);
00514         
00515         CSelectMediaType dlg(guids, MEDIASUBTYPE_NULL, this);
00516         if(dlg.DoModal() == IDOK)
00517         {
00518                 for(child = m_tree.GetChildItem(node); child; child = m_tree.GetNextSiblingItem(child))
00519                 {
00520                         pos = (POSITION)m_tree.GetItemData(child);
00521                         f->guids.GetNext(pos);
00522                         if(f->guids.GetAt(pos) == dlg.m_guid) {AfxMessageBox(_T("Already on the list!")); return;}
00523                 }
00524 
00525                 f->guids.AddTail(major);
00526                 pos = f->guids.GetTailPosition();
00527                 f->guids.AddTail(dlg.m_guid);
00528 
00529                 CString sub = GetMediaTypeName(dlg.m_guid);
00530 
00531                 node = m_tree.InsertItem(sub, node);
00532                 m_tree.SetItemData(node, (DWORD_PTR)pos);
00533         }
00534 }
00535 
00536 void CPPageOverrides::OnDeleteType()
00537 {
00538         if(Filter* f = GetCurFilter())
00539         {
00540                 HTREEITEM node = m_tree.GetSelectedItem();
00541                 if(!node) return;
00542 
00543                 POSITION pos = (POSITION)m_tree.GetItemData(node);
00544 
00545                 if(pos == NULL)
00546                 {
00547                         for(HTREEITEM child = m_tree.GetChildItem(node); child; child = m_tree.GetNextSiblingItem(child))
00548                         {
00549                                 pos = (POSITION)m_tree.GetItemData(child);
00550 
00551                                 POSITION pos1 = pos;
00552                                 f->guids.GetNext(pos);
00553                                 POSITION pos2 = pos;
00554                                 f->guids.GetNext(pos);
00555 
00556                                 f->guids.RemoveAt(pos1);
00557                                 f->guids.RemoveAt(pos2);
00558                         }
00559 
00560                         m_tree.DeleteItem(node);
00561                 }
00562                 else
00563                 {
00564                         HTREEITEM parent = m_tree.GetParentItem(node);
00565 
00566                         POSITION pos1 = pos;
00567                         f->guids.GetNext(pos);
00568                         POSITION pos2 = pos;
00569                         f->guids.GetNext(pos);
00570 
00571                         m_tree.DeleteItem(node);
00572 
00573                         if(!m_tree.ItemHasChildren(parent))
00574                         {
00575                                 f->guids.SetAt(pos2, GUID_NULL);
00576                                 node = m_tree.InsertItem(GetMediaTypeName(GUID_NULL), parent);
00577                                 m_tree.SetItemData(node, (DWORD_PTR)pos1);
00578                         }
00579                         else
00580                         {
00581                                 f->guids.RemoveAt(pos1);
00582                                 f->guids.RemoveAt(pos2);
00583                         }
00584                 }
00585         }
00586 }
00587 
00588 void CPPageOverrides::OnResetTypes()
00589 {
00590         if(Filter* f = GetCurFilter())
00591         {
00592                 f->guids.RemoveAll();
00593                 f->guids.AddTail(&f->backup);
00594 
00595                 m_pLastSelFilter = NULL;
00596                 OnLbnSelchangeList1();
00597         }
00598 }
00599 
00600 void CPPageOverrides::OnLbnSelchangeList1()
00601 {
00602         if(Filter* f = GetCurFilter())
00603         {
00604                 if(m_pLastSelFilter == f) return;
00605                 m_pLastSelFilter = f;
00606 
00607                 m_iLoadType = f->iLoadType;
00608                 UpdateData(FALSE);
00609                 m_dwMerit = f->dwMerit;
00610 
00611                 HTREEITEM dummy_item = m_tree.InsertItem(_T(""), 0,0, NULL, TVI_FIRST);
00612                 if(dummy_item)
00613                         for(HTREEITEM item = m_tree.GetNextVisibleItem(dummy_item); item; item = m_tree.GetNextVisibleItem(dummy_item)) 
00614                                 m_tree.DeleteItem(item);
00615 
00616                 CMapStringToPtr map;
00617 
00618                 POSITION pos = f->guids.GetHeadPosition();
00619                 while(pos)
00620                 {
00621                         POSITION tmp = pos;
00622                         CString major = GetMediaTypeName(f->guids.GetNext(pos));
00623                         CString sub = GetMediaTypeName(f->guids.GetNext(pos));
00624 
00625                         HTREEITEM node = NULL;
00626 
00627                         void* val = NULL;
00628                         if(map.Lookup(major, val)) node = (HTREEITEM)val;
00629                         else map[major] = node = m_tree.InsertItem(major);
00630                         m_tree.SetItemData(node, NULL);
00631 
00632                         node = m_tree.InsertItem(sub, node);
00633                         m_tree.SetItemData(node, (DWORD_PTR)tmp);
00634                 }
00635 
00636                 m_tree.DeleteItem(dummy_item);
00637 
00638                 for(HTREEITEM item = m_tree.GetFirstVisibleItem(); item; item = m_tree.GetNextVisibleItem(item)) 
00639                         m_tree.Expand(item, TVE_EXPAND);
00640 
00641                 m_tree.EnsureVisible(m_tree.GetRootItem());
00642         }
00643         else
00644         {
00645                 m_pLastSelFilter = NULL;
00646 
00647                 m_iLoadType = Filter::PREFERRED;
00648                 UpdateData(FALSE);
00649                 m_dwMerit = 0;
00650 
00651                 m_tree.DeleteAllItems();
00652         }
00653 }
00654 
00655 void CPPageOverrides::OnBnClickedRadio()
00656 {
00657         UpdateData();
00658         if(Filter* f = GetCurFilter())
00659                 f->iLoadType = m_iLoadType;
00660 }
00661 
00662 void CPPageOverrides::OnEnChangeEdit1()
00663 {
00664         UpdateData();
00665         if(Filter* f = GetCurFilter())
00666         {
00667                 DWORD dw;
00668                 if(m_dwMerit.GetDWORD(dw))
00669                         f->dwMerit = dw;
00670         }
00671 }
00672 
00673 void CPPageOverrides::OnNMDblclkTree2(NMHDR *pNMHDR, LRESULT *pResult)
00674 {
00675         *pResult = 0;
00676 
00677         if(Filter* f = GetCurFilter())
00678         {
00679                 HTREEITEM node = m_tree.GetSelectedItem();
00680                 if(!node) return;
00681 
00682                 POSITION pos = (POSITION)m_tree.GetItemData(node);
00683                 if(!pos) return;
00684 
00685                 f->guids.GetNext(pos);
00686                 if(!pos) return;
00687 
00688                 CArray<GUID> guids;
00689                 SetupSubTypes(guids);
00690 
00691                 CSelectMediaType dlg(guids, f->guids.GetAt(pos), this);
00692                 if(dlg.DoModal() == IDOK)
00693                 {
00694                         f->guids.SetAt(pos, dlg.m_guid);
00695                         m_tree.SetItemText(node, GetMediaTypeName(dlg.m_guid));
00696                 }
00697         }
00698 }
00699 
00700 void CPPageOverrides::OnDropFiles(HDROP hDropInfo)
00701 {
00702         SetActiveWindow();
00703 
00704         UINT nFiles = ::DragQueryFile(hDropInfo, (UINT)-1, NULL, 0);
00705         for(UINT iFile = 0; iFile < nFiles; iFile++)
00706         {
00707                 TCHAR szFileName[_MAX_PATH];
00708                 ::DragQueryFile(hDropInfo, iFile, szFileName, _MAX_PATH);
00709 
00710                 CFilterMapper2 fm2(false);
00711                 fm2.Register(szFileName);
00712 
00713                 while(!fm2.m_filters.IsEmpty())
00714                 {
00715                         if(Filter* f = fm2.m_filters.RemoveHead())
00716                         {
00717                                 CAutoPtr<Filter> p(f);
00718                                 int i = m_filters.AddString(f->name);
00719                                 m_filters.SetItemDataPtr(i, m_pFilters.AddTail(p));
00720                                 m_filters.SetCheck(i, 1);
00721 
00722                                 if(fm2.m_filters.IsEmpty())
00723                                 {
00724                                         m_filters.SetCurSel(i);
00725                                         OnLbnSelchangeList1();
00726                                 }
00727                         }
00728                 }
00729         }
00730         ::DragFinish(hDropInfo);
00731 }

Generated on Tue Dec 13 14:47:01 2005 for guliverkli by  doxygen 1.4.5