Make mv's use signed chars explicitly.
[xiph/unicode.git] / oggds / OggMuxDS / OggMuxPropPage.cpp
blobea9d6a484a69649f627aa9b61e1866f759364008
1 /*******************************************************************************
2 * *
3 * This file is part of the Ogg Vorbis DirectShow filter collection *
4 * *
5 * Copyright (c) 2001, Tobias Waldvogel *
6 * All rights reserved. *
7 * *
8 * Redistribution and use in source and binary forms, with or without *
9 * modification, are permitted provided that the following conditions are met: *
10 * *
11 * - Redistributions of source code must retain the above copyright notice, *
12 * this list of conditions and the following disclaimer. *
13 * *
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. *
17 * *
18 * - The names of the contributors may not be used to endorse or promote *
19 * products derived from this software without specific prior written *
20 * permission. *
21 * *
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. *
33 * *
34 *******************************************************************************/
36 #include "OggMuxDS.h"
37 #include "..\resource.h"
40 // Property Page
43 COggMuxPropPage::COggMuxPropPage(LPUNKNOWN pUnk, HRESULT *phr) :
44 CBasePropertyPage(NAME("Ogg Multiplexer property page"), pUnk,
45 IDD_PROPPAGE_MUXER, IDS_PROPPAGE_MUXER_TITLE),
46 m_pFilter(NULL)
48 m_pFilter = NULL;
49 *phr = NOERROR;
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()
69 if (m_pFilter)
71 m_pFilter->Release();
72 m_pFilter = NULL;
74 return NOERROR;
77 HRESULT COggMuxPropPage::OnActivate()
79 HRESULT hr;
80 IEnumPins *pEnum;
81 IPin *pPin;
82 ULONG cFetched;
83 VARIANT V;
85 VariantInit(&V);
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)
97 PIN_INFO PinInfo;
99 pPin->QueryPinInfo(&PinInfo);
100 PinInfo.pFilter->Release();
102 if (PinInfo.dir == PINDIR_INPUT)
104 int iIndex;
105 IPropertyBag *pPropBag;
106 IPersistPropertyBag *pPersistPropBag;
107 char cCaption[256];
109 wcstombs(cCaption, PinInfo.achName, sizeof(cCaption));
110 for (int i=strlen(cCaption); i<12; i++)
111 cCaption[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);
115 else
116 cCaption[12] = '\0';
117 pPropBag->Release();
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);
123 pPin->Release();
124 hr = pEnum->Next(1, &pPin, &cFetched);
126 pEnum->Release();
128 VariantClear(&V);
130 // Select the first stream ...
131 SendDlgItemMessage(m_Dlg, IDC_MUXER_CHANNELS, LB_SETCURSEL, 0, 0);
132 LoadCurrentStreamComments();
134 return NOERROR;
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);
145 pPPBag->Release();
147 return NOERROR;
150 void COggMuxPropPage::LoadCurrentStreamComments()
152 long iIndex;
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);
159 if (iIndex >= 0)
161 long iItemData;
162 char cCaption[1024];
164 SendDlgItemMessage(m_Dlg, IDC_MUXER_CHANNELS, LB_GETTEXT, iIndex, (LPARAM)cCaption);
165 cCaption[12] = '\0';
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);
179 char cEmpty = '\0';
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)
187 VARIANT V;
188 IPersistPropertyBag* pPPBag;
189 IPropertyBag* pPBag;
190 long iIndex;
191 wchar_t wcProp[32];
193 V.vt = VT_BSTR;
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);
202 pPBag->Release();
203 VariantClear(&V);
205 LoadCurrentStreamComments();
208 BOOL COggMuxPropPage::OnReceiveMessage(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
210 long iIndex;
211 char cTag[1024];
212 char cValue[1024];
213 char cEmpty = '\0';
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);
221 return TRUE;
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();
230 return TRUE;
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();
240 return TRUE;
243 if (uMsg == WM_COMMAND && LOWORD(wParam) == IDC_MUXER_CHANNELS)
244 if (HIWORD(wParam) == LBN_SELCHANGE)
246 LoadCurrentStreamComments();
247 return TRUE;
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);
257 char* pPos;
259 if (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);
263 return TRUE;
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);
271 if (pPos)
272 SendDlgItemMessage(m_Dlg, IDC_COMMENT_VALUE, WM_SETTEXT, 0, (WPARAM)(pPos+1));
273 else
274 SendDlgItemMessage(m_Dlg, IDC_COMMENT_VALUE, WM_SETTEXT, 0, (WPARAM)&cEmpty);
275 return TRUE;
278 if (uMsg == WM_COMMAND && LOWORD(wParam) == IDC_LANGSELECT)
280 char cLanguage[256];
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();
288 return TRUE;
292 return CBasePropertyPage::OnReceiveMessage(hwnd, uMsg, wParam, lParam);
295 HRESULT COggMuxPropPage::OnApplyChanges(void)
297 return NOERROR;
300 HRESULT STDMETHODCALLTYPE COggMuxPropPage::Read(LPCOLESTR pszPropName, VARIANT *pVar,
301 IErrorLog *pErrorLog)
303 return NOERROR;
306 HRESULT STDMETHODCALLTYPE COggMuxPropPage::Write(LPCOLESTR pszPropName, VARIANT *pVar)
308 char szName[128];
309 char szCaption[1024];
311 wcstombs(szName, pszPropName, sizeof(szName));
313 strupr(szName);
314 VariantChangeType(pVar, pVar, 0, VT_BSTR);
316 if (strcmp(szName, "LANGUAGE") == 0)
318 int iIndex;
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);
327 if (iIndex >= 0)
329 long iItemData;
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);
344 return NOERROR;
348 CUnknown *COggMuxPropPage::CreateInstance(LPUNKNOWN pUnk, HRESULT * phr)
350 return new COggMuxPropPage(pUnk, phr);