A Fast Bresenham Type Algorithm For Drawing Ellipses by John Kennedy
[xy_vsfilter.git] / src / apps / mplayerc / PPageInternalFilters.cpp
blobb31147f2d8c64178254126cab62a6e9387728293
3 /*
4 * Copyright (C) 2003-2006 Gabest
5 * http://www.gabest.org
7 * This Program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
10 * any later version.
12 * This Program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Make; see the file COPYING. If not, write to
19 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20 * http://www.gnu.org/copyleft/gpl.html
24 // PPageInternalFilters.cpp : implementation file
27 #include "stdafx.h"
28 #include "mplayerc.h"
29 #include "PPageInternalFilters.h"
30 #include "ComPropertySheet.h"
31 #include "..\..\filters\filters.h"
33 static struct filter_t
35 LPCTSTR label;
36 int type;
37 int flag;
38 UINT nHintID;
39 CUnknown* (WINAPI * CreateInstance)(LPUNKNOWN lpunk, HRESULT* phr);
41 s_filters[] =
43 {_T("AVI"), 0, SRC_AVI, IDS_SRC_AVI, NULL},
44 {_T("CDDA (Audio CD)"), 0, SRC_CDDA, IDS_SRC_CDDA, NULL},
45 {_T("CDXA (VCD/SVCD/XCD)"), 0, SRC_CDXA, IDS_SRC_CDXA, NULL},
46 __if_exists(CDiracSplitterFilter) {{_T("Dirac"), 0, SRC_DIRAC, IDS_SRC_DIRAC, NULL},}
47 {_T("DirectShow Media"), 0, SRC_DSM, IDS_SRC_DSM, NULL},
48 {_T("DTS/AC3"), 0, SRC_DTSAC3, IDS_SRC_DTSAC3, NULL},
49 {_T("DVD Video Title Set"), 0, SRC_VTS, IDS_SRC_VTS, NULL},
50 {_T("DVD2AVI Project File"), 0, SRC_D2V, IDS_SRC_D2V, NULL},
51 {_T("FLI/FLC"), 0, SRC_FLIC, IDS_SRC_FLIC, NULL},
52 {_T("FLV"), 0, SRC_FLV, IDS_SRC_FLV, NULL},
53 {_T("Matroska"), 0, SRC_MATROSKA, IDS_SRC_MATROSKA, NULL},
54 {_T("MP4/MOV"), 0, SRC_MP4, IDS_SRC_MP4, NULL},
55 {_T("MPEG Audio"), 0, SRC_MPA, IDS_SRC_MPA, NULL},
56 {_T("MPEG PS/TS/PVA"), 0, SRC_MPEG, 0, NULL},
57 __if_exists(CNutSplitterFilter) {{_T("Nut"), 0, SRC_NUT, IDS_SRC_NUT, NULL},}
58 {_T("Ogg"), 0, SRC_OGG, IDS_SRC_OGG, NULL},
59 {_T("RealMedia"), 0, SRC_REALMEDIA, IDS_SRC_REALMEDIA, NULL},
60 {_T("RoQ"), 0, SRC_ROQ, IDS_SRC_ROQ, NULL},
61 {_T("SHOUTcast"), 0, SRC_SHOUTCAST, IDS_SRC_SHOUTCAST, NULL},
62 __if_exists(CRadGtSplitterFilter) {{_T("Smacker/Bink"), 0, SRC_RADGT, IDS_SRC_RADGT, NULL},}
63 {_T("AAC"), 1, TRA_AAC, IDS_TRA_AAC, CreateInstance<CMpaDecFilter>},
64 {_T("AC3"), 1, TRA_AC3, IDS_TRA_AC3, CreateInstance<CMpaDecFilter>},
65 {_T("DTS"), 1, TRA_DTS, IDS_TRA_DTS, CreateInstance<CMpaDecFilter>},
66 __if_exists(CDiracVideoDecoder) {{_T("Dirac"), 1, TRA_DIRAC, IDS_TRA_DIRAC, NULL},}
67 //{_T("FLV4"), 1, TRA_FLV4, 0, NULL},
68 {_T("LPCM"), 1, TRA_LPCM, IDS_TRA_LPCM, CreateInstance<CMpaDecFilter>},
69 {_T("MPEG Audio"), 1, TRA_MPA, IDS_TRA_MPA, CreateInstance<CMpaDecFilter>},
70 {_T("MPEG-1 Video"), 1, TRA_MPEG1, IDS_TRA_MPEG1, CreateInstance<CMpeg2DecFilter>},
71 {_T("MPEG-2 Video"), 1, TRA_MPEG2, IDS_TRA_MPEG2, CreateInstance<CMpeg2DecFilter>},
72 {_T("PS2 Audio (PCM/ADPCM)"), 1, TRA_PS2AUD, IDS_TRA_PS2AUD, CreateInstance<CMpaDecFilter>},
73 {_T("RealVideo"), 1, TRA_RV, IDS_TRA_RV, NULL},
74 {_T("RealAudio"), 1, TRA_RA, IDS_TRA_RA, NULL},
75 {_T("Vorbis"), 1, TRA_VORBIS, 0, NULL /* TODO: CreateInstance<CMpaDecFilter>*/},
76 //{_T("VP62"), 1, TRA_VP62, 0, NULL},
79 IMPLEMENT_DYNAMIC(CPPageInternalFiltersListBox, CCheckListBox)
80 CPPageInternalFiltersListBox::CPPageInternalFiltersListBox()
81 : CCheckListBox()
85 void CPPageInternalFiltersListBox::PreSubclassWindow()
87 __super::PreSubclassWindow();
88 EnableToolTips(TRUE);
91 INT_PTR CPPageInternalFiltersListBox::OnToolHitTest(CPoint point, TOOLINFO* pTI) const
93 BOOL b = FALSE;
94 int row = ItemFromPoint(point, b);
95 if(row < 0) return -1;
97 CRect r;
98 GetItemRect(row, r);
99 pTI->rect = r;
100 pTI->hwnd = m_hWnd;
101 pTI->uId = (UINT)row;
102 pTI->lpszText = LPSTR_TEXTCALLBACK;
103 pTI->uFlags |= TTF_ALWAYSTIP;
105 return pTI->uId;
108 BEGIN_MESSAGE_MAP(CPPageInternalFiltersListBox, CCheckListBox)
109 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipNotify)
110 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipNotify)
111 END_MESSAGE_MAP()
113 BOOL CPPageInternalFiltersListBox::OnToolTipNotify(UINT id, NMHDR* pNMHDR, LRESULT* pResult)
115 TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
116 TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
118 filter_t* f = (filter_t*)GetItemDataPtr(pNMHDR->idFrom);
119 if(f->nHintID == 0) return FALSE;
121 ::SendMessage(pNMHDR->hwndFrom, TTM_SETMAXTIPWIDTH, 0, (LPARAM)(INT)1000);
123 static CStringA m_strTipTextA;
124 static CStringW m_strTipTextW;
126 m_strTipTextA = CString(MAKEINTRESOURCE(f->nHintID));
127 m_strTipTextW = CString(MAKEINTRESOURCE(f->nHintID));
129 if(pNMHDR->code == TTN_NEEDTEXTA) pTTTA->lpszText = (LPSTR)(LPCSTR)m_strTipTextA;
130 else pTTTW->lpszText = (LPWSTR)(LPCWSTR)m_strTipTextW;
132 *pResult = 0;
134 return TRUE; // message was handled
137 void CPPageInternalFiltersListBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
139 CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
141 CFont* pOldFont = NULL;
143 if(((filter_t*)lpDrawItemStruct->itemData)->CreateInstance)
145 if(!(HFONT)m_bold)
147 CFont* pFont = pDC->GetCurrentFont();
149 LOGFONT lf;
150 pFont->GetLogFont(&lf);
151 lf.lfWeight = FW_BOLD;
153 m_bold.CreateFontIndirect(&lf);
156 if((HFONT)m_bold)
158 pOldFont = pDC->SelectObject(&m_bold);
162 __super::DrawItem(lpDrawItemStruct);
164 if(pOldFont)
166 pDC->SelectObject(pOldFont);
170 // CPPageInternalFilters dialog
172 IMPLEMENT_DYNAMIC(CPPageInternalFilters, CPPageBase)
173 CPPageInternalFilters::CPPageInternalFilters()
174 : CPPageBase(CPPageInternalFilters::IDD, CPPageInternalFilters::IDD)
178 CPPageInternalFilters::~CPPageInternalFilters()
183 void CPPageInternalFilters::DoDataExchange(CDataExchange* pDX)
185 __super::DoDataExchange(pDX);
186 DDX_Control(pDX, IDC_LIST1, m_listSrc);
187 DDX_Control(pDX, IDC_LIST2, m_listTra);
190 BEGIN_MESSAGE_MAP(CPPageInternalFilters, CPPageBase)
191 ON_LBN_DBLCLK(IDC_LIST1, &CPPageInternalFilters::OnLbnDblclkList1)
192 ON_LBN_DBLCLK(IDC_LIST2, &CPPageInternalFilters::OnLbnDblclkList2)
193 END_MESSAGE_MAP()
195 // CPPageInternalFilters message handlers
197 BOOL CPPageInternalFilters::OnInitDialog()
199 __super::OnInitDialog();
201 AppSettings& s = AfxGetAppSettings();
203 for(int i = 0; i < countof(s_filters); i++)
205 CCheckListBox* l =
206 s_filters[i].type == 0 ? &m_listSrc :
207 s_filters[i].type == 1 ? &m_listTra :
208 NULL;
210 UINT* pflags =
211 s_filters[i].type == 0 ? &s.SrcFilters :
212 s_filters[i].type == 1 ? &s.TraFilters :
213 NULL;
215 if(l && pflags)
217 int Index = l->AddString(s_filters[i].label);
218 l->SetCheck(Index, !!(*pflags & s_filters[i].flag));
219 l->SetItemDataPtr(Index, &s_filters[i]);
223 UpdateData(FALSE);
225 return TRUE; // return TRUE unless you set the focus to a control
226 // EXCEPTION: OCX Property Pages should return FALSE
229 BOOL CPPageInternalFilters::OnApply()
231 UpdateData();
233 AppSettings& s = AfxGetAppSettings();
235 s.SrcFilters = s.TraFilters = 0;
237 CList<filter_t*> fl;
238 for(int i = 0; i < m_listSrc.GetCount(); i++)
239 if(m_listSrc.GetCheck(i))
240 fl.AddTail((filter_t*)m_listSrc.GetItemDataPtr(i));
241 for(int i = 0; i < m_listTra.GetCount(); i++)
242 if(m_listTra.GetCheck(i))
243 fl.AddTail((filter_t*)m_listTra.GetItemDataPtr(i));
245 POSITION pos = fl.GetHeadPosition();
246 while(pos)
248 filter_t* f = fl.GetNext(pos);
250 UINT* pflags =
251 f->type == 0 ? &s.SrcFilters :
252 f->type == 1 ? &s.TraFilters :
253 NULL;
255 if(pflags)
256 *pflags |= f->flag;
259 return __super::OnApply();
262 void CPPageInternalFilters::ShowPPage(CPPageInternalFiltersListBox& l)
264 int i = l.GetCurSel();
265 if(i < 0) return;
267 filter_t* f = (filter_t*)l.GetItemDataPtr(i);
268 if(!f || !f->CreateInstance) return;
270 HRESULT hr;
271 CUnknown* pObj = f->CreateInstance(NULL, &hr);
272 if(!pObj) return;
274 CComPtr<IUnknown> pUnk = (IUnknown*)(INonDelegatingUnknown*)pObj;
276 if(SUCCEEDED(hr))
278 if(CComQIPtr<ISpecifyPropertyPages> pSPP = pUnk)
280 CComPropertySheet ps(ResStr(IDS_PROPSHEET_PROPERTIES), this);
281 ps.AddPages(pSPP);
282 ps.DoModal();
287 void CPPageInternalFilters::OnLbnDblclkList1()
289 ShowPPage(m_listSrc);
292 void CPPageInternalFilters::OnLbnDblclkList2()
294 ShowPPage(m_listTra);