Recognizes if input is ogg or not.
[xiph.git] / oggds / OggSplitterDS / TrayIcon.cpp
blob61ab552083e59c7fbfd30181fed83fd8643d7853
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 "OggSplitterDS.h"
37 #include "..\resource.h"
38 #include "..\LocStrings.h"
40 #define ID_MENUITEM_PROPERTIES 16384
42 LRESULT CALLBACK TrayWndProc(HWND hwnd, UINT uMsg, WPARAM wParam,LPARAM lParam)
44 static COggSplitter* pOggSplitter = NULL;
45 BOOL bReturn = FALSE;
47 switch( uMsg ) // Begin message switch
49 case WM_CREATE:
51 CREATESTRUCT* pcs = (CREATESTRUCT*)lParam;
52 pOggSplitter = reinterpret_cast<COggSplitter*>(pcs->lpCreateParams);
53 return 0;
55 case WM_CALLBACK:
57 if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN)
58 if (pOggSplitter) pOggSplitter->ShowPopupMenu();
59 return 0;
61 case WM_DESTROY:
63 return 0;
65 default:
66 return DefWindowProc(hwnd, uMsg, wParam, lParam);
67 } // end uMsg switch
68 return 0;
71 void COggSplitter::InitTrayIcon()
73 WNDCLASSEX myClass;
75 memset(&myClass, 0, sizeof(myClass));
76 myClass.cbSize = sizeof(myClass);
77 myClass.lpfnWndProc = TrayWndProc;
78 myClass.hInstance = g_hInst;
79 myClass.lpszClassName = szTrayWndClass;
81 RegisterClassEx(&myClass);
82 m_hTrayWnd = CreateWindowEx(0, szTrayWndClass, szTrayWndClass,
83 0, 0, 0, 1, 1, NULL, NULL, g_hInst, this);
85 NOTIFYICONDATA myTrayIcon;
87 memset(&myTrayIcon, 0, sizeof(myTrayIcon));
88 myTrayIcon.cbSize = sizeof(myTrayIcon);
89 myTrayIcon.hWnd = m_hTrayWnd;
90 myTrayIcon.uID = 0;
91 myTrayIcon.uFlags = NIF_MESSAGE | NIF_TIP | NIF_ICON;
92 myTrayIcon.uCallbackMessage = WM_CALLBACK;
93 myTrayIcon.hIcon = LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_TRAY));
94 strcpy(myTrayIcon.szTip, GetLocString(sidTrayToolTip));
95 Shell_NotifyIcon(NIM_ADD, &myTrayIcon);
98 void COggSplitter::DestroyTrayIcon()
100 NOTIFYICONDATA myTrayIcon;
102 memset(&myTrayIcon, 0, sizeof(myTrayIcon));
103 myTrayIcon.cbSize = sizeof(myTrayIcon);
104 myTrayIcon.hWnd = m_hTrayWnd;
105 myTrayIcon.uID = 0;
106 Shell_NotifyIcon(NIM_DELETE, &myTrayIcon);
108 DestroyWindow(m_hTrayWnd);
109 UnregisterClass(szTrayWndClass, g_hInst);
112 void COggSplitter::ShowPopupMenu()
114 int groupID[16];
115 HMENU groupMenu[16];
116 int cGroups = 0;
117 MENUITEMINFO myItem;
119 int i = 0;
121 AM_MEDIA_TYPE* pmt;
122 DWORD dwGroup;
123 DWORD dwFlags;
124 wchar_t* pwzCaption;
126 HMENU hPopup = CreatePopupMenu();
128 while (Info(i, &pmt, &dwFlags, NULL, &dwGroup, &pwzCaption, NULL, NULL) == NOERROR)
130 // Is there already a submenu for this group?
131 int j = 0;
132 while ((j < cGroups) && (groupID[j] != dwGroup)) j++;
134 if (j == cGroups) // There is still no submenu ..
136 char* pMenuType;
138 if (!pmt)
139 pMenuType = GetLocString(sidTypeOther);
140 else if (pmt->majortype == MEDIATYPE_Audio)
141 pMenuType = GetLocString(sidTypeAudio);
142 else if (pmt->majortype == MEDIATYPE_Text)
143 pMenuType = GetLocString(sidTypeSubtitle);
144 else if (pmt->majortype == MEDIATYPE_Video)
146 if (pmt->pbFormat)
147 pMenuType = GetLocString(sidTypeVideo);
148 else
149 pMenuType = GetLocString(sidTypeChapter);
152 groupMenu[j] = CreatePopupMenu();
153 groupID[j] = dwGroup;
155 memset(&myItem, 0, sizeof(myItem));
156 myItem.cbSize = sizeof(myItem);
157 myItem.fMask = MIIM_TYPE | MIIM_SUBMENU;
158 myItem.fType = MFT_STRING;
159 myItem.hSubMenu = groupMenu[j];
160 myItem.dwTypeData = pMenuType;
161 myItem.cch = strlen(pMenuType);
162 InsertMenuItem(hPopup, -1, TRUE, &myItem);
163 cGroups++;
166 char szItemText[128];
167 wchar_t* pwzItemText = pwzCaption;
169 // Let´s skip the first word if not chapter
170 if (pmt && ((pmt->majortype != MEDIATYPE_Video) || pmt->pbFormat))
172 pwzItemText = wcsstr(pwzItemText, L" ");
173 pwzItemText++;
176 wsprintf(szItemText, "%S", pwzItemText);
178 memset(&myItem, 0, sizeof(myItem));
179 myItem.cbSize = sizeof(myItem);
180 myItem.fMask = MIIM_TYPE | MIIM_ID | MIIM_STATE;
181 myItem.fType = MFT_STRING | MFT_RADIOCHECK;
182 myItem.fState = MFS_ENABLED;
183 if (dwFlags == AMSTREAMSELECTINFO_ENABLED)
184 myItem.fState |= MFS_CHECKED;
185 myItem.wID = i;
186 myItem.dwTypeData = szItemText;
187 myItem.cch = strlen(myItem.dwTypeData);
189 InsertMenuItem(groupMenu[j], -1, TRUE, &myItem);
191 if (pmt)
192 DeleteMediaType(pmt);
193 CoTaskMemFree(pwzCaption);
194 i++;
197 HMENU hPropMenu = NULL;
198 char szName[MAX_FILTER_NAME];
200 // If we are in the graph find all filters with property pages
201 if (m_pGraph)
203 hPropMenu = CreatePopupMenu();
205 // Insert the separator
206 memset(&myItem, 0, sizeof(myItem));
207 myItem.cbSize = sizeof(myItem);
208 myItem.fMask = MIIM_TYPE;
209 myItem.fType = MFT_SEPARATOR;
210 InsertMenuItem(hPopup, -1, TRUE, &myItem);
212 // Insert the properties item
213 memset(&myItem, 0, sizeof(myItem));
214 myItem.cbSize = sizeof(myItem);
215 myItem.fMask = MIIM_TYPE | MIIM_SUBMENU;
216 myItem.fType = MFT_STRING;
217 myItem.hSubMenu = hPropMenu;
218 myItem.dwTypeData = GetLocString(sidProperties);
219 myItem.cch = strlen(myItem.dwTypeData);
220 InsertMenuItem(hPopup, -1, TRUE, &myItem);
222 IEnumFilters* pEnum;
223 IBaseFilter* pFilter;
224 ISpecifyPropertyPages* pSPP;
225 ULONG cFetched;
226 DWORD dwID = ID_MENUITEM_PROPERTIES;
228 m_pGraph->EnumFilters(&pEnum);
232 if (FAILED(pEnum->Next(1, &pFilter, &cFetched)))
233 cFetched = 0;
235 if (cFetched)
237 if (SUCCEEDED(pFilter->QueryInterface(IID_ISpecifyPropertyPages,
238 (void**)&pSPP)))
240 pSPP->Release();
242 FILTER_INFO Info;
244 pFilter->QueryFilterInfo(&Info);
245 wsprintf(szName, "%S", Info.achName);
246 Info.pGraph->Release();
248 memset(&myItem, 0, sizeof(myItem));
249 myItem.cbSize = sizeof(myItem);
250 myItem.fMask = MIIM_TYPE | MIIM_ID;
251 myItem.fType = MFT_STRING;
252 myItem.wID = dwID;
253 myItem.dwTypeData = szName;
254 myItem.cch = strlen(myItem.dwTypeData);
255 InsertMenuItem(hPropMenu, -1, TRUE, &myItem);
256 dwID++;
258 pFilter->Release();
260 } while (cFetched);
261 pEnum->Release();
264 POINT ptCursorPos;
265 DWORD dwSelection;
267 GetCursorPos(&ptCursorPos);
268 SetForegroundWindow(m_hTrayWnd);
269 PostMessage(m_hTrayWnd, WM_NULL, 0, 0);
270 dwSelection = TrackPopupMenu(hPopup, TPM_NONOTIFY | TPM_RETURNCMD,
271 ptCursorPos.x, ptCursorPos.y, 0, m_hTrayWnd, NULL);
273 if (dwSelection < ID_MENUITEM_PROPERTIES)
275 Enable(dwSelection, AMSTREAMSELECTENABLE_ENABLE);
276 return;
279 GetMenuString(hPropMenu, dwSelection, szName, MAX_FILTER_NAME, MF_BYCOMMAND);
280 if (m_pGraph)
282 wchar_t wszName[MAX_FILTER_NAME];
283 IBaseFilter* pFilter;
284 ISpecifyPropertyPages* pSPP;
286 wsprintfW(wszName, L"%s", szName);
287 if (SUCCEEDED(m_pGraph->FindFilterByName(wszName, &pFilter)))
289 if (SUCCEEDED(pFilter->QueryInterface(IID_ISpecifyPropertyPages,
290 (void**)&pSPP)))
292 IUnknown* pFilterUnk;
293 pFilter->QueryInterface(IID_IUnknown, (void **)&pFilterUnk);
295 CAUUID caGUID;
296 pSPP->GetPages(&caGUID);
297 pSPP->Release();
298 OleCreatePropertyFrame(m_hTrayWnd, 0, 0, wszName, 1, &pFilterUnk,
299 caGUID.cElems, caGUID.pElems, 0, 0, NULL);
300 pFilterUnk->Release();
301 CoTaskMemFree(caGUID.pElems);
303 pFilter->Release();
307 DestroyMenu(hPopup);