1 /*******************************************************************************
3 * This file is part of the Ogg Vorbis DirectShow filter collection *
5 * Copyright (c) 2001, Tobias Waldvogel *
6 * All rights reserved. *
8 * Redistribution and use in source and binary forms, with or without *
9 * modification, are permitted provided that the following conditions are met: *
11 * - Redistributions of source code must retain the above copyright notice, *
12 * this list of conditions and the following disclaimer. *
14 * - Redistributions in binary form must reproduce the above copyright notice, *
15 * this list of conditions and the following disclaimer in the documentation *
16 * and/or other materials provided with the distribution. *
18 * - The names of the contributors may not be used to endorse or promote *
19 * products derived from this software without specific prior written *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" *
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE *
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE *
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE *
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR *
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF *
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS *
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN *
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) *
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
32 * POSSIBILITY OF SUCH DAMAGE. *
34 *******************************************************************************/
37 #include "..\resource.h"
43 COggMuxPropPage::COggMuxPropPage(LPUNKNOWN pUnk
, HRESULT
*phr
) :
44 CBasePropertyPage(NAME("Ogg Multiplexer property page"), pUnk
,
45 IDD_PROPPAGE_MUXER
, IDS_PROPPAGE_MUXER_TITLE
),
52 STDMETHODIMP
COggMuxPropPage::NonDelegatingQueryInterface(REFIID riid
, void **ppv
) // For PropertyPages
54 if(riid
== IID_IPropertyBag
)
56 CheckPointer(ppv
, E_POINTER
);
57 return GetInterface((IPropertyBag
*)(this), ppv
);
59 return CBasePropertyPage::NonDelegatingQueryInterface(riid
, ppv
);
62 HRESULT
COggMuxPropPage::OnConnect(IUnknown
*pUnknown
)
64 return pUnknown
->QueryInterface(IID_IBaseFilter
, (void **)&m_pFilter
);
67 HRESULT
COggMuxPropPage::OnDisconnect()
77 HRESULT
COggMuxPropPage::OnActivate()
87 // Load the values for the language combo box
88 SendDlgItemMessage(m_Dlg
, IDC_LANGSELECT
, CB_LIMITTEXT
, (WPARAM
)127, 0);
89 for (int i
=0; i
<SIZEOF_ARRAY(aLCID
); i
++)
90 SendDlgItemMessage(m_Dlg
, IDC_LANGSELECT
, CB_ADDSTRING
, 0, (LPARAM
)aLCID
[i
].caption
);
92 // Walk through all pins ...
93 m_pFilter
->EnumPins(&pEnum
);
94 hr
= pEnum
->Next(1, &pPin
, &cFetched
);
95 while (SUCCEEDED(hr
) && cFetched
!= 0)
99 pPin
->QueryPinInfo(&PinInfo
);
100 PinInfo
.pFilter
->Release();
102 if (PinInfo
.dir
== PINDIR_INPUT
)
105 IPropertyBag
*pPropBag
;
106 IPersistPropertyBag
*pPersistPropBag
;
109 wcstombs(cCaption
, PinInfo
.achName
, sizeof(cCaption
));
110 for (int i
=strlen(cCaption
); i
<12; i
++)
112 pPin
->QueryInterface(IID_IPropertyBag
, (void**)&pPropBag
);
113 if SUCCEEDED(pPropBag
->Read(L
"LANGUAGE", &V
, NULL
))
114 wcstombs(cCaption
+12, V
.bstrVal
, sizeof(cCaption
)-12);
118 iIndex
= SendDlgItemMessage(m_Dlg
, IDC_MUXER_CHANNELS
, LB_ADDSTRING
, 0, (LPARAM
)cCaption
);
120 pPin
->QueryInterface(IID_IPersistPropertyBag
, (void**)&pPersistPropBag
);
121 SendDlgItemMessage(m_Dlg
, IDC_MUXER_CHANNELS
, LB_SETITEMDATA
, iIndex
, (LPARAM
) pPersistPropBag
);
124 hr
= pEnum
->Next(1, &pPin
, &cFetched
);
130 // Select the first stream ...
131 SendDlgItemMessage(m_Dlg
, IDC_MUXER_CHANNELS
, LB_SETCURSEL
, 0, 0);
132 LoadCurrentStreamComments();
137 HRESULT
COggMuxPropPage::OnDeactivate()
139 // Release the IPersistPropertyBag pointers
140 int iCount
= SendDlgItemMessage(m_Dlg
, IDC_MUXER_CHANNELS
, LB_GETCOUNT
, 0, 0);
141 for (int i
=0; i
<iCount
; i
++)
143 IPersistPropertyBag
* pPPBag
;
144 pPPBag
= (IPersistPropertyBag
*) SendDlgItemMessage(m_Dlg
, IDC_MUXER_CHANNELS
, LB_GETITEMDATA
, i
, 0);
150 void COggMuxPropPage::LoadCurrentStreamComments()
153 IPersistPropertyBag
* pPPBag
;
155 SendDlgItemMessage(m_Dlg
, IDC_TAGS
, LB_RESETCONTENT
, 0, 0);
156 SendDlgItemMessage(m_Dlg
, IDC_LANGSELECT
, CB_SETCURSEL
, (WPARAM
)-1, 0);
157 iIndex
= SendDlgItemMessage(m_Dlg
, IDC_MUXER_CHANNELS
, LB_GETCURSEL
, 0, 0);
164 SendDlgItemMessage(m_Dlg
, IDC_MUXER_CHANNELS
, LB_GETTEXT
, iIndex
, (LPARAM
)cCaption
);
166 iItemData
= SendDlgItemMessage(m_Dlg
, IDC_MUXER_CHANNELS
, LB_GETITEMDATA
, iIndex
, 0);
167 SendDlgItemMessage(m_Dlg
, IDC_MUXER_CHANNELS
, LB_DELETESTRING
, iIndex
, 0);
168 iIndex
= SendDlgItemMessage(m_Dlg
, IDC_MUXER_CHANNELS
, LB_INSERTSTRING
, iIndex
, (LPARAM
)cCaption
);
169 SendDlgItemMessage(m_Dlg
, IDC_MUXER_CHANNELS
, LB_SETITEMDATA
, iIndex
, (LPARAM
)iItemData
);
170 SendDlgItemMessage(m_Dlg
, IDC_MUXER_CHANNELS
, LB_SETCURSEL
, iIndex
, 0);
172 pPPBag
= (IPersistPropertyBag
*) SendDlgItemMessage(m_Dlg
, IDC_MUXER_CHANNELS
, LB_GETITEMDATA
, iIndex
, 0);
173 pPPBag
->Save(this, TRUE
, TRUE
);
176 EnableWindow(GetDlgItem(m_Dlg
, IDC_COMMDELETE
), FALSE
);
177 EnableWindow(GetDlgItem(m_Dlg
, IDC_COMMENT_SET
), FALSE
);
181 SendDlgItemMessage(m_Dlg
, IDC_COMMENT_TAG
, WM_SETTEXT
, 0, (WPARAM
)&cEmpty
);
182 SendDlgItemMessage(m_Dlg
, IDC_COMMENT_VALUE
, WM_SETTEXT
, 0, (WPARAM
)&cEmpty
);
185 void COggMuxPropPage::SetProperty(char* pProp
, char* pVal
)
188 IPersistPropertyBag
* pPPBag
;
194 V
.bstrVal
= SysAllocStringLen(NULL
, strlen(pVal
)+1);
195 mbstowcs(V
.bstrVal
, pVal
, strlen(pVal
)+1);
196 mbstowcs(wcProp
, pProp
, strlen(pProp
)+1);
198 iIndex
= SendDlgItemMessage(m_Dlg
, IDC_MUXER_CHANNELS
, LB_GETCURSEL
, 0, 0);
199 pPPBag
= (IPersistPropertyBag
*) SendDlgItemMessage(m_Dlg
, IDC_MUXER_CHANNELS
, LB_GETITEMDATA
, iIndex
, 0);
200 pPPBag
->QueryInterface(IID_IPropertyBag
, (void**)&pPBag
);
201 pPBag
->Write(wcProp
, &V
);
205 LoadCurrentStreamComments();
208 BOOL
COggMuxPropPage::OnReceiveMessage(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
215 if (uMsg
== WM_COMMAND
&& LOWORD(wParam
) == IDC_COMMENT_TAG
)
216 if (HIWORD(wParam
) == EN_CHANGE
)
218 SendDlgItemMessage(m_Dlg
, IDC_COMMENT_TAG
, WM_GETTEXT
, 1024, (WPARAM
)cTag
);
219 EnableWindow(GetDlgItem(m_Dlg
, IDC_COMMDELETE
), strlen(cTag
) > 0);
220 EnableWindow(GetDlgItem(m_Dlg
, IDC_COMMENT_SET
), strlen(cTag
) > 0);
224 if (uMsg
== WM_COMMAND
&& LOWORD(wParam
) == IDC_COMMDELETE
)
225 if (HIWORD(wParam
) == BN_CLICKED
)
227 SendDlgItemMessage(m_Dlg
, IDC_COMMENT_TAG
, WM_GETTEXT
, 1024, (WPARAM
)cTag
);
228 SetProperty(cTag
, "");
229 LoadCurrentStreamComments();
233 if (uMsg
== WM_COMMAND
&& LOWORD(wParam
) == IDC_COMMENT_SET
)
234 if (HIWORD(wParam
) == BN_CLICKED
)
236 SendDlgItemMessage(m_Dlg
, IDC_COMMENT_TAG
, WM_GETTEXT
, 1024, (WPARAM
)cTag
);
237 SendDlgItemMessage(m_Dlg
, IDC_COMMENT_VALUE
, WM_GETTEXT
, 1024, (WPARAM
)cValue
);
238 SetProperty(cTag
, cValue
);
239 LoadCurrentStreamComments();
243 if (uMsg
== WM_COMMAND
&& LOWORD(wParam
) == IDC_MUXER_CHANNELS
)
244 if (HIWORD(wParam
) == LBN_SELCHANGE
)
246 LoadCurrentStreamComments();
250 if (uMsg
== WM_COMMAND
&& LOWORD(wParam
) == IDC_TAGS
)
251 if (HIWORD(wParam
) == LBN_SELCHANGE
)
253 iIndex
= SendDlgItemMessage(m_Dlg
, IDC_TAGS
, LB_GETCURSEL
, 0, 0);
254 EnableWindow(GetDlgItem(m_Dlg
, IDC_COMMDELETE
), iIndex
>= 0);
255 EnableWindow(GetDlgItem(m_Dlg
, IDC_COMMENT_SET
), iIndex
>= 0);
261 SendDlgItemMessage(m_Dlg
, IDC_COMMENT_TAG
, WM_SETTEXT
, 0, (WPARAM
)&cEmpty
);
262 SendDlgItemMessage(m_Dlg
, IDC_COMMENT_VALUE
, WM_SETTEXT
, 0, (WPARAM
)&cEmpty
);
266 SendDlgItemMessage(m_Dlg
, IDC_TAGS
, LB_GETTEXT
, (LPARAM
)iIndex
, (WPARAM
)cTag
);
267 pPos
= strstr(cTag
, "=");
268 if (pPos
!= NULL
) *pPos
= '\0';
270 SendDlgItemMessage(m_Dlg
, IDC_COMMENT_TAG
, WM_SETTEXT
, 0, (WPARAM
)cTag
);
272 SendDlgItemMessage(m_Dlg
, IDC_COMMENT_VALUE
, WM_SETTEXT
, 0, (WPARAM
)(pPos
+1));
274 SendDlgItemMessage(m_Dlg
, IDC_COMMENT_VALUE
, WM_SETTEXT
, 0, (WPARAM
)&cEmpty
);
278 if (uMsg
== WM_COMMAND
&& LOWORD(wParam
) == IDC_LANGSELECT
)
282 if (HIWORD(wParam
) == CBN_SELCHANGE
)
284 int iIndex
= SendDlgItemMessage(m_Dlg
, IDC_LANGSELECT
, CB_GETCURSEL
, 0, 0);
285 SendDlgItemMessage(m_Dlg
, IDC_LANGSELECT
, CB_GETLBTEXT
, (WPARAM
)iIndex
, (LPARAM
)cLanguage
);
286 SetProperty("LANGUAGE", cLanguage
);
287 LoadCurrentStreamComments();
292 return CBasePropertyPage::OnReceiveMessage(hwnd
, uMsg
, wParam
, lParam
);
295 HRESULT
COggMuxPropPage::OnApplyChanges(void)
300 HRESULT STDMETHODCALLTYPE
COggMuxPropPage::Read(LPCOLESTR pszPropName
, VARIANT
*pVar
,
301 IErrorLog
*pErrorLog
)
306 HRESULT STDMETHODCALLTYPE
COggMuxPropPage::Write(LPCOLESTR pszPropName
, VARIANT
*pVar
)
309 char szCaption
[1024];
311 wcstombs(szName
, pszPropName
, sizeof(szName
));
314 VariantChangeType(pVar
, pVar
, 0, VT_BSTR
);
316 if (strcmp(szName
, "LANGUAGE") == 0)
320 // update the combo box
321 wcstombs(szCaption
, pVar
->bstrVal
, sizeof(szCaption
));
322 iIndex
= SendDlgItemMessage(m_Dlg
, IDC_LANGSELECT
, CB_FINDSTRING
, (WPARAM
)-1, (LPARAM
)szCaption
);
323 SendDlgItemMessage(m_Dlg
, IDC_LANGSELECT
, CB_SETCURSEL
, iIndex
, 0);
325 //update the channel list
326 iIndex
= SendDlgItemMessage(m_Dlg
, IDC_MUXER_CHANNELS
, LB_GETCURSEL
, 0, 0);
331 SendDlgItemMessage(m_Dlg
, IDC_MUXER_CHANNELS
, LB_GETTEXT
, iIndex
, (LPARAM
)szCaption
);
332 wcstombs(szCaption
+12, pVar
->bstrVal
, sizeof(szCaption
)-12);
333 iItemData
= SendDlgItemMessage(m_Dlg
, IDC_MUXER_CHANNELS
, LB_GETITEMDATA
, iIndex
, 0);
334 SendDlgItemMessage(m_Dlg
, IDC_MUXER_CHANNELS
, LB_DELETESTRING
, iIndex
, 0);
335 iIndex
= SendDlgItemMessage(m_Dlg
, IDC_MUXER_CHANNELS
, LB_INSERTSTRING
, iIndex
, (LPARAM
)szCaption
);
336 SendDlgItemMessage(m_Dlg
, IDC_MUXER_CHANNELS
, LB_SETITEMDATA
, iIndex
, (LPARAM
)iItemData
);
337 SendDlgItemMessage(m_Dlg
, IDC_MUXER_CHANNELS
, LB_SETCURSEL
, iIndex
, 0);
341 wsprintf(szCaption
, "%s=%S", szName
, pVar
->bstrVal
);
342 SendDlgItemMessage(m_Dlg
, IDC_TAGS
, LB_ADDSTRING
, 0, (LPARAM
)szCaption
);
348 CUnknown
*COggMuxPropPage::CreateInstance(LPUNKNOWN pUnk
, HRESULT
* phr
)
350 return new COggMuxPropPage(pUnk
, phr
);