X64 transport [Part 5] (Update plugins.cpp)
[xy_vsfilter.git] / src / apps / mplayerc / VolumeCtrl.cpp
blob5d9decfa3c5d4ea6b2b3879ed7573e549ab2db0b
1 /*
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)
8 * any later version.
9 *
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
25 #include "stdafx.h"
26 #include "mplayerc.h"
27 #include "VolumeCtrl.h"
30 // CVolumeCtrl
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))
44 return(false);
46 SetRange(1, 100);
47 SetPosInternal(AfxGetAppSettings().nVolume);
48 SetPageSize(8);
49 SetLineSize(0);
51 return(true);
54 void CVolumeCtrl::SetPosInternal(int pos)
56 SetPos(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)
72 ON_WM_LBUTTONDOWN()
73 ON_WM_SETFOCUS()
74 ON_WM_HSCROLL_REFLECT()
75 END_MESSAGE_MAP()
77 // CVolumeCtrl message handlers
80 void CVolumeCtrl::OnNMCustomdraw(NMHDR* pNMHDR, LRESULT* pResult)
82 LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);
84 LRESULT lr = CDRF_DODEFAULT;
86 if(m_fSelfDrawn)
87 switch(pNMCD->dwDrawStage)
89 case CDDS_PREPAINT:
90 lr = CDRF_NOTIFYITEMDRAW;
91 break;
93 case CDDS_ITEMPREPAINT:
94 if(pNMCD->dwItemSpec == TBCD_CHANNEL)
96 CDC dc;
97 dc.Attach(pNMCD->hdc);
99 CRect r;
100 GetClientRect(r);
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);
113 dc.Detach();
114 lr = CDRF_SKIPDEFAULT;
116 else if(pNMCD->dwItemSpec == TBCD_THUMB)
118 CDC dc;
119 dc.Attach(pNMCD->hdc);
120 pNMCD->rc.bottom--;
121 CRect r(pNMCD->rc);
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));
133 dc.Detach();
134 lr = CDRF_SKIPDEFAULT;
137 break;
140 pNMCD->uItemState &= ~CDIS_FOCUS;
142 *pResult = lr;
145 void CVolumeCtrl::OnLButtonDown(UINT nFlags, CPoint point)
147 CRect r;
148 GetChannelRect(&r);
150 if(r.left >= r.right) return;
152 int start, stop;
153 GetRange(start, stop);
155 int pos = GetPos();
157 r.left += 3;
158 r.right -= 4;
160 if(point.x < r.left) SetPos(start);
161 else if(point.x >= r.right) SetPos(stop);
162 else
164 int w = r.right - r.left;
165 if(start < stop)
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);