1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
|
/*
* $Id$
*
* (C) 2003-2006 Gabest
* (C) 2006-2010 see AUTHORS
*
* This file is part of mplayerc.
*
* Mplayerc is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Mplayerc is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "stdafx.h"
#include "mplayerc.h"
#include <math.h>
#include <atlbase.h>
#include <afxpriv.h>
#include "PlayerToolBar.h"
#include "MainFrm.h"
typedef HRESULT (__stdcall * SetWindowThemeFunct)(HWND hwnd, LPCWSTR pszSubAppName, LPCWSTR pszSubIdList);
// CPlayerToolBar
IMPLEMENT_DYNAMIC(CPlayerToolBar, CToolBar)
CPlayerToolBar::CPlayerToolBar()
{
}
CPlayerToolBar::~CPlayerToolBar()
{
}
BOOL CPlayerToolBar::Create(CWnd* pParentWnd)
{
if(!__super::CreateEx(pParentWnd,
TBSTYLE_FLAT|TBSTYLE_TRANSPARENT|TBSTYLE_AUTOSIZE,
WS_CHILD|WS_VISIBLE|CBRS_ALIGN_BOTTOM|CBRS_TOOLTIPS, CRect(2,2,0,3))) {
return FALSE;
}
if(!LoadToolBar(IDB_PLAYERTOOLBAR)) {
return FALSE;
}
GetToolBarCtrl().SetExtendedStyle(TBSTYLE_EX_DRAWDDARROWS);
CToolBarCtrl& tb = GetToolBarCtrl();
tb.DeleteButton(tb.GetButtonCount()-1);
tb.DeleteButton(tb.GetButtonCount()-1);
SetMute(AfxGetAppSettings().fMute);
UINT styles[] = {
TBBS_CHECKGROUP, TBBS_CHECKGROUP, TBBS_CHECKGROUP,
TBBS_SEPARATOR,
TBBS_BUTTON, TBBS_BUTTON, TBBS_BUTTON, TBBS_BUTTON,
TBBS_SEPARATOR,
TBBS_BUTTON/*|TBSTYLE_DROPDOWN*/,
TBBS_SEPARATOR,
TBBS_SEPARATOR,
TBBS_CHECKBOX,
/*TBBS_SEPARATOR,*/
};
for(int i = 0; i < countof(styles); i++) {
SetButtonStyle(i, styles[i]|TBBS_DISABLED);
}
m_volctrl.Create(this);
if(AfxGetAppSettings().fDisableXPToolbars) {
if(HMODULE h = LoadLibrary(_T("uxtheme.dll"))) {
SetWindowThemeFunct f = (SetWindowThemeFunct)GetProcAddress(h, "SetWindowTheme");
if(f) {
f(m_hWnd, L" ", L" ");
}
FreeLibrary(h);
}
}
// quick and dirty code from foxx1337; will leak, but don't care yet
m_nButtonHeight = 16; // hardcoded from MainFrm.cpp - DEFCLIENTW; min width should be 9 * button width + 60 + 91
HBITMAP hBmp = static_cast<HBITMAP>(::LoadImage(NULL, _T("toolbar.bmp"), IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_CREATEDIBSECTION));
if(NULL != hBmp) {
CBitmap *bmp = new CBitmap();
bmp->Attach(hBmp);
BITMAP bitmapBmp;
bmp->GetBitmap(&bitmapBmp);
if(bitmapBmp.bmWidth == bitmapBmp.bmHeight * 15) {
// the manual specifies that sizeButton should be sizeImage inflated by (7, 6)
SetSizes(CSize(bitmapBmp.bmHeight + 7, bitmapBmp.bmHeight + 6), CSize(bitmapBmp.bmHeight, bitmapBmp.bmHeight));
CDC dc;
dc.CreateCompatibleDC(NULL);
BITMAPINFOHEADER bih;
bih.biSize = sizeof(BITMAPINFOHEADER);
GetDIBits(dc, hBmp, 0, 0, NULL, reinterpret_cast<BITMAPINFO*>(&bih), DIB_RGB_COLORS);
int fileDepth = bih.biBitCount;
CImageList *imageList = new CImageList();
if(32 == fileDepth) {
imageList->Create(bitmapBmp.bmHeight, bitmapBmp.bmHeight, ILC_COLOR32 | ILC_MASK, 1, 0);
imageList->Add(bmp, static_cast<CBitmap*>(0)); // alpha is the mask
} else {
imageList->Create(bitmapBmp.bmHeight, bitmapBmp.bmHeight, ILC_COLOR24 | ILC_MASK, 1, 0);
imageList->Add(bmp, RGB(255, 0, 255));
}
m_nButtonHeight = bitmapBmp.bmHeight;
GetToolBarCtrl().SetImageList(imageList);
}
delete bmp;
DeleteObject(hBmp);
}
return TRUE;
}
BOOL CPlayerToolBar::PreCreateWindow(CREATESTRUCT& cs)
{
if(!__super::PreCreateWindow(cs)) {
return FALSE;
}
m_dwStyle &= ~CBRS_BORDER_TOP;
m_dwStyle &= ~CBRS_BORDER_BOTTOM;
// m_dwStyle |= CBRS_SIZE_FIXED;
return TRUE;
}
void CPlayerToolBar::ArrangeControls()
{
if(!::IsWindow(m_volctrl.m_hWnd)) {
return;
}
CRect r;
GetClientRect(&r);
CRect br = GetBorders();
CRect r10;
GetItemRect(10, &r10);
CRect vr;
m_volctrl.GetClientRect(&vr);
CRect vr2(r.right + br.right - 60, r.bottom - 25, r.right +br.right + 6, r.bottom);
m_volctrl.MoveWindow(vr2);
UINT nID;
UINT nStyle;
int iImage;
GetButtonInfo(12, nID, nStyle, iImage);
SetButtonInfo(11, GetItemID(11), TBBS_SEPARATOR, vr2.left - iImage - r10.right - (r10.bottom - r10.top) + 11);
}
void CPlayerToolBar::SetMute(bool fMute)
{
CToolBarCtrl& tb = GetToolBarCtrl();
TBBUTTONINFO bi;
bi.cbSize = sizeof(bi);
bi.dwMask = TBIF_IMAGE;
bi.iImage = fMute?13:12;
tb.SetButtonInfo(ID_VOLUME_MUTE, &bi);
AfxGetAppSettings().fMute = fMute;
}
bool CPlayerToolBar::IsMuted()
{
CToolBarCtrl& tb = GetToolBarCtrl();
TBBUTTONINFO bi;
bi.cbSize = sizeof(bi);
bi.dwMask = TBIF_IMAGE;
tb.GetButtonInfo(ID_VOLUME_MUTE, &bi);
return(bi.iImage==13);
}
int CPlayerToolBar::GetVolume()
{
int volume = m_volctrl.GetPos();
volume = (int)((log10(1.0*volume)-2)*5000);
volume = max(min(volume, 0), -10000);
return(IsMuted() ? -10000 : volume);
}
int CPlayerToolBar::GetMinWidth()
{
return m_nButtonHeight * 9 + 151;
}
void CPlayerToolBar::SetVolume(int volume)
{
/*
volume = (int)pow(10, ((double)volume)/5000+2);
volume = max(min(volume, 100), 1);
*/
m_volctrl.SetPosInternal(volume);
}
BEGIN_MESSAGE_MAP(CPlayerToolBar, CToolBar)
ON_WM_PAINT()
ON_WM_SIZE()
ON_MESSAGE_VOID(WM_INITIALUPDATE, OnInitialUpdate)
ON_COMMAND_EX(ID_VOLUME_MUTE, OnVolumeMute)
ON_UPDATE_COMMAND_UI(ID_VOLUME_MUTE, OnUpdateVolumeMute)
ON_COMMAND_EX(ID_VOLUME_UP, OnVolumeUp)
ON_COMMAND_EX(ID_VOLUME_DOWN, OnVolumeDown)
ON_WM_NCPAINT()
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
END_MESSAGE_MAP()
// CPlayerToolBar message handlers
void CPlayerToolBar::OnPaint()
{
if(m_bDelayedButtonLayout) {
Layout();
}
CPaintDC dc(this); // device context for painting
DefWindowProc(WM_PAINT, WPARAM(dc.m_hDC), 0);
{
UINT nID;
UINT nStyle = 0;
int iImage = 0;
GetButtonInfo(11, nID, nStyle, iImage);
CRect ItemRect;
GetItemRect(11, ItemRect);
dc.FillSolidRect(ItemRect, GetSysColor(COLOR_BTNFACE));
}
}
void CPlayerToolBar::OnSize(UINT nType, int cx, int cy)
{
__super::OnSize(nType, cx, cy);
ArrangeControls();
}
void CPlayerToolBar::OnInitialUpdate()
{
ArrangeControls();
}
BOOL CPlayerToolBar::OnVolumeMute(UINT nID)
{
SetMute(!IsMuted());
return FALSE;
}
void CPlayerToolBar::OnUpdateVolumeMute(CCmdUI* pCmdUI)
{
pCmdUI->Enable(true);
pCmdUI->SetCheck(IsMuted());
}
BOOL CPlayerToolBar::OnVolumeUp(UINT nID)
{
m_volctrl.IncreaseVolume();
return FALSE;
}
BOOL CPlayerToolBar::OnVolumeDown(UINT nID)
{
m_volctrl.DecreaseVolume();
return FALSE;
}
void CPlayerToolBar::OnNcPaint() // when using XP styles the NC area isn't drawn for our toolbar...
{
CRect wr, cr;
CWindowDC dc(this);
GetClientRect(&cr);
ClientToScreen(&cr);
GetWindowRect(&wr);
cr.OffsetRect(-wr.left, -wr.top);
wr.OffsetRect(-wr.left, -wr.top);
dc.ExcludeClipRect(&cr);
dc.FillSolidRect(wr, GetSysColor(COLOR_BTNFACE));
// Do not call CToolBar::OnNcPaint() for painting messages
}
void CPlayerToolBar::OnMouseMove(UINT nFlags, CPoint point)
{
int i = getHitButtonIdx(point);
if((i==-1) || (GetButtonStyle(i)&(TBBS_SEPARATOR|TBBS_DISABLED))) {
;
} else {
if((i>11) || ((i<10) && ((CMainFrame*)GetParentFrame())->IsSomethingLoaded())) {
::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_HAND));
}
}
__super::OnMouseMove(nFlags, point);
}
void CPlayerToolBar::OnLButtonDown(UINT nFlags, CPoint point)
{
int i = getHitButtonIdx(point);
CMainFrame* pFrame = ((CMainFrame*)GetParentFrame());
if((i==-1) || (GetButtonStyle(i)&(TBBS_SEPARATOR|TBBS_DISABLED))) {
if(!pFrame->m_fFullScreen) {
MapWindowPoints(pFrame, &point, 1);
pFrame->PostMessage(WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x, point.y));
}
} else {
if((i>11) || ((i<10) && pFrame->IsSomethingLoaded())) {
::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_HAND));
}
__super::OnLButtonDown(nFlags, point);
}
}
int CPlayerToolBar::getHitButtonIdx(CPoint point)
{
int hit = -1; // -1 means not on any buttons, mute button is 12/13, others < 10, 11 is empty space between
CRect r;
for(int i = 0, j = GetToolBarCtrl().GetButtonCount(); i < j; i++) {
GetItemRect(i, r);
if(r.PtInRect(point)) {
hit = i;
break;
}
}
return hit;
}
|