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 *******************************************************************************/
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
;
47 switch( uMsg
) // Begin message switch
51 CREATESTRUCT
* pcs
= (CREATESTRUCT
*)lParam
;
52 pOggSplitter
= reinterpret_cast<COggSplitter
*>(pcs
->lpCreateParams
);
57 if (lParam
== WM_LBUTTONDOWN
|| lParam
== WM_RBUTTONDOWN
)
58 if (pOggSplitter
) pOggSplitter
->ShowPopupMenu();
66 return DefWindowProc(hwnd
, uMsg
, wParam
, lParam
);
71 void COggSplitter::InitTrayIcon()
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
;
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
;
106 Shell_NotifyIcon(NIM_DELETE
, &myTrayIcon
);
108 DestroyWindow(m_hTrayWnd
);
109 UnregisterClass(szTrayWndClass
, g_hInst
);
112 void COggSplitter::ShowPopupMenu()
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?
132 while ((j
< cGroups
) && (groupID
[j
] != dwGroup
)) j
++;
134 if (j
== cGroups
) // There is still no submenu ..
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
)
147 pMenuType
= GetLocString(sidTypeVideo
);
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
);
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
" ");
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
;
186 myItem
.dwTypeData
= szItemText
;
187 myItem
.cch
= strlen(myItem
.dwTypeData
);
189 InsertMenuItem(groupMenu
[j
], -1, TRUE
, &myItem
);
192 DeleteMediaType(pmt
);
193 CoTaskMemFree(pwzCaption
);
197 HMENU hPropMenu
= NULL
;
198 char szName
[MAX_FILTER_NAME
];
200 // If we are in the graph find all filters with property pages
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
);
223 IBaseFilter
* pFilter
;
224 ISpecifyPropertyPages
* pSPP
;
226 DWORD dwID
= ID_MENUITEM_PROPERTIES
;
228 m_pGraph
->EnumFilters(&pEnum
);
232 if (FAILED(pEnum
->Next(1, &pFilter
, &cFetched
)))
237 if (SUCCEEDED(pFilter
->QueryInterface(IID_ISpecifyPropertyPages
,
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
;
253 myItem
.dwTypeData
= szName
;
254 myItem
.cch
= strlen(myItem
.dwTypeData
);
255 InsertMenuItem(hPropMenu
, -1, TRUE
, &myItem
);
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
);
279 GetMenuString(hPropMenu
, dwSelection
, szName
, MAX_FILTER_NAME
, MF_BYCOMMAND
);
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
,
292 IUnknown
* pFilterUnk
;
293 pFilter
->QueryInterface(IID_IUnknown
, (void **)&pFilterUnk
);
296 pSPP
->GetPages(&caGUID
);
298 OleCreatePropertyFrame(m_hTrayWnd
, 0, 0, wszName
, 1, &pFilterUnk
,
299 caGUID
.cElems
, caGUID
.pElems
, 0, 0, NULL
);
300 pFilterUnk
->Release();
301 CoTaskMemFree(caGUID
.pElems
);