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
|
/*
* $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 "VolumeCtrl.h"
// CVolumeCtrl
IMPLEMENT_DYNAMIC(CVolumeCtrl, CSliderCtrl)
CVolumeCtrl::CVolumeCtrl(bool fSelfDrawn) : m_fSelfDrawn(fSelfDrawn)
{
}
CVolumeCtrl::~CVolumeCtrl()
{
}
bool CVolumeCtrl::Create(CWnd* pParentWnd)
{
if(!CSliderCtrl::Create(WS_CHILD|WS_VISIBLE|TBS_NOTICKS|TBS_HORZ, CRect(0,0,0,0), pParentWnd, IDC_SLIDER1)) {
return(false);
}
SetRange(1, 100);
SetPosInternal(AfxGetAppSettings().nVolume);
SetPageSize(5);
SetLineSize(0);
return(true);
}
void CVolumeCtrl::SetPosInternal(int pos)
{
SetPos(pos);
GetParent()->PostMessage(WM_HSCROLL, MAKEWPARAM((short)pos, SB_THUMBPOSITION), (LPARAM)m_hWnd); // this will be reflected back on us
}
void CVolumeCtrl::IncreaseVolume()
{
(GetPos() == 1) ? SetPosInternal(GetPos() + GetPageSize() - 1) : SetPosInternal(GetPos() + GetPageSize());
}
void CVolumeCtrl::DecreaseVolume()
{
SetPosInternal(GetPos() - GetPageSize());
}
BEGIN_MESSAGE_MAP(CVolumeCtrl, CSliderCtrl)
ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnNMCustomdraw)
ON_WM_LBUTTONDOWN()
ON_WM_SETFOCUS()
ON_WM_HSCROLL_REFLECT()
ON_WM_SETCURSOR()
END_MESSAGE_MAP()
// CVolumeCtrl message handlers
void CVolumeCtrl::OnNMCustomdraw(NMHDR* pNMHDR, LRESULT* pResult)
{
LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);
LRESULT lr = CDRF_DODEFAULT;
if(m_fSelfDrawn)
switch(pNMCD->dwDrawStage) {
case CDDS_PREPAINT:
lr = CDRF_NOTIFYITEMDRAW;
break;
case CDDS_ITEMPREPAINT:
if(pNMCD->dwItemSpec == TBCD_CHANNEL) {
CDC dc;
dc.Attach(pNMCD->hdc);
CRect r;
GetClientRect(r);
r.DeflateRect(8, 4, 10, 6);
CopyRect(&pNMCD->rc, &r);
CPen shadow(PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW));
CPen light(PS_SOLID, 1, GetSysColor(COLOR_3DHILIGHT));
CPen* old = dc.SelectObject(&light);
dc.MoveTo(pNMCD->rc.right, pNMCD->rc.top);
dc.LineTo(pNMCD->rc.right, pNMCD->rc.bottom);
dc.LineTo(pNMCD->rc.left, pNMCD->rc.bottom);
dc.SelectObject(&shadow);
dc.LineTo(pNMCD->rc.right, pNMCD->rc.top);
dc.SelectObject(old);
dc.Detach();
lr = CDRF_SKIPDEFAULT;
} else if(pNMCD->dwItemSpec == TBCD_THUMB) {
CDC dc;
dc.Attach(pNMCD->hdc);
pNMCD->rc.bottom--;
CRect r(pNMCD->rc);
r.DeflateRect(0, 0, 1, 0);
COLORREF shadow = GetSysColor(COLOR_3DSHADOW);
COLORREF light = GetSysColor(COLOR_3DHILIGHT);
dc.Draw3dRect(&r, light, 0);
r.DeflateRect(0, 0, 1, 1);
dc.Draw3dRect(&r, light, shadow);
r.DeflateRect(1, 1, 1, 1);
dc.FillSolidRect(&r, GetSysColor(COLOR_BTNFACE));
dc.SetPixel(r.left+7, r.top-1, GetSysColor(COLOR_BTNFACE));
dc.Detach();
lr = CDRF_SKIPDEFAULT;
}
break;
};
pNMCD->uItemState &= ~CDIS_FOCUS;
*pResult = lr;
}
void CVolumeCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
CRect r;
GetChannelRect(&r);
if(r.left >= r.right) {
return;
}
int start, stop;
GetRange(start, stop);
r.left += 3;
r.right -= 4;
if(point.x < r.left) {
SetPos(start);
} else if(point.x >= r.right) {
SetPos(stop);
} else {
int w = r.right - r.left;
if(start < stop) {
SetPosInternal(start + ((stop - start) * (point.x - r.left) + (w/2)) / w);
}
}
CSliderCtrl::OnLButtonDown(nFlags, point);
}
void CVolumeCtrl::OnSetFocus(CWnd* pOldWnd)
{
CSliderCtrl::OnSetFocus(pOldWnd);
AfxGetMainWnd()->SetFocus(); // don't focus on us, parents will take care of our positioning
}
void CVolumeCtrl::HScroll(UINT nSBCode, UINT nPos)
{
AfxGetAppSettings().nVolume = GetPos();
CFrameWnd* pFrame = GetParentFrame();
if(pFrame && pFrame != GetParent()) {
pFrame->PostMessage(WM_HSCROLL, MAKEWPARAM((short)nPos, nSBCode), (LPARAM)m_hWnd);
}
}
BOOL CVolumeCtrl::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_HAND));
return TRUE;
}
|