2 * Copyright (C) 2003-2006 Gabest
3 * http://www.gabest.org
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNU Make; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
22 // VolumeCtrl.cpp : implementation file
27 #include "VolumeCtrl.h"
32 IMPLEMENT_DYNAMIC(CVolumeCtrl
, CSliderCtrl
)
33 CVolumeCtrl::CVolumeCtrl(bool fSelfDrawn
) : m_fSelfDrawn(fSelfDrawn
)
37 CVolumeCtrl::~CVolumeCtrl()
41 bool CVolumeCtrl::Create(CWnd
* pParentWnd
)
43 if(!CSliderCtrl::Create(WS_CHILD
|WS_VISIBLE
|TBS_NOTICKS
|TBS_HORZ
, CRect(0,0,0,0), pParentWnd
, IDC_SLIDER1
))
47 SetPosInternal(AfxGetAppSettings().nVolume
);
54 void CVolumeCtrl::SetPosInternal(int pos
)
57 GetParent()->PostMessage(WM_HSCROLL
, MAKEWPARAM((short)pos
, SB_THUMBPOSITION
), (LPARAM
)m_hWnd
); // this will be reflected back on us
60 void CVolumeCtrl::IncreaseVolume()
62 SetPosInternal(GetPos() + GetPageSize());
65 void CVolumeCtrl::DecreaseVolume()
67 SetPosInternal(GetPos() - GetPageSize());
70 BEGIN_MESSAGE_MAP(CVolumeCtrl
, CSliderCtrl
)
71 ON_NOTIFY_REFLECT(NM_CUSTOMDRAW
, OnNMCustomdraw
)
74 ON_WM_HSCROLL_REFLECT()
77 // CVolumeCtrl message handlers
80 void CVolumeCtrl::OnNMCustomdraw(NMHDR
* pNMHDR
, LRESULT
* pResult
)
82 LPNMCUSTOMDRAW pNMCD
= reinterpret_cast<LPNMCUSTOMDRAW
>(pNMHDR
);
84 LRESULT lr
= CDRF_DODEFAULT
;
87 switch(pNMCD
->dwDrawStage
)
90 lr
= CDRF_NOTIFYITEMDRAW
;
93 case CDDS_ITEMPREPAINT
:
94 if(pNMCD
->dwItemSpec
== TBCD_CHANNEL
)
97 dc
.Attach(pNMCD
->hdc
);
101 r
.DeflateRect(8, 4, 10, 6);
102 CopyRect(&pNMCD
->rc
, &r
);
103 CPen
shadow(PS_SOLID
, 1, GetSysColor(COLOR_3DSHADOW
));
104 CPen
light(PS_SOLID
, 1, GetSysColor(COLOR_3DHILIGHT
));
105 CPen
* old
= dc
.SelectObject(&light
);
106 dc
.MoveTo(pNMCD
->rc
.right
, pNMCD
->rc
.top
);
107 dc
.LineTo(pNMCD
->rc
.right
, pNMCD
->rc
.bottom
);
108 dc
.LineTo(pNMCD
->rc
.left
, pNMCD
->rc
.bottom
);
109 dc
.SelectObject(&shadow
);
110 dc
.LineTo(pNMCD
->rc
.right
, pNMCD
->rc
.top
);
111 dc
.SelectObject(old
);
114 lr
= CDRF_SKIPDEFAULT
;
116 else if(pNMCD
->dwItemSpec
== TBCD_THUMB
)
119 dc
.Attach(pNMCD
->hdc
);
122 r
.DeflateRect(0, 0, 1, 0);
124 COLORREF shadow
= GetSysColor(COLOR_3DSHADOW
);
125 COLORREF light
= GetSysColor(COLOR_3DHILIGHT
);
126 dc
.Draw3dRect(&r
, light
, 0);
127 r
.DeflateRect(0, 0, 1, 1);
128 dc
.Draw3dRect(&r
, light
, shadow
);
129 r
.DeflateRect(1, 1, 1, 1);
130 dc
.FillSolidRect(&r
, GetSysColor(COLOR_BTNFACE
));
131 dc
.SetPixel(r
.left
+7, r
.top
-1, GetSysColor(COLOR_BTNFACE
));
134 lr
= CDRF_SKIPDEFAULT
;
140 pNMCD
->uItemState
&= ~CDIS_FOCUS
;
145 void CVolumeCtrl::OnLButtonDown(UINT nFlags
, CPoint point
)
150 if(r
.left
>= r
.right
) return;
153 GetRange(start
, stop
);
160 if(point
.x
< r
.left
) SetPos(start
);
161 else if(point
.x
>= r
.right
) SetPos(stop
);
164 int w
= r
.right
- r
.left
;
166 SetPosInternal(start
+ ((stop
- start
) * (point
.x
- r
.left
) + (w
/2)) / w
);
169 CSliderCtrl::OnLButtonDown(nFlags
, point
);
172 void CVolumeCtrl::OnSetFocus(CWnd
* pOldWnd
)
174 CSliderCtrl::OnSetFocus(pOldWnd
);
176 AfxGetMainWnd()->SetFocus(); // don't focus on us, parents will take care of our positioning
179 void CVolumeCtrl::HScroll(UINT nSBCode
, UINT nPos
)
181 AfxGetAppSettings().nVolume
= GetPos();
183 CFrameWnd
* pFrame
= GetParentFrame();
184 if(pFrame
&& pFrame
!= GetParent())
185 pFrame
->PostMessage(WM_HSCROLL
, MAKEWPARAM((short)nPos
, nSBCode
), (LPARAM
)m_hWnd
);