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 // PlayerToolBar.cpp : implementation file
30 #include "PlayerToolBar.h"
33 typedef HRESULT (__stdcall
* SetWindowThemeFunct
)(HWND hwnd
, LPCWSTR pszSubAppName
, LPCWSTR pszSubIdList
);
37 IMPLEMENT_DYNAMIC(CPlayerToolBar
, CToolBar
)
38 CPlayerToolBar::CPlayerToolBar()
42 CPlayerToolBar::~CPlayerToolBar()
46 BOOL
CPlayerToolBar::Create(CWnd
* pParentWnd
)
48 if(!__super::CreateEx(pParentWnd
,
49 TBSTYLE_FLAT
|TBSTYLE_TRANSPARENT
|TBSTYLE_AUTOSIZE
,
50 WS_CHILD
|WS_VISIBLE
|CBRS_ALIGN_BOTTOM
|CBRS_TOOLTIPS
, CRect(2,2,0,3))
51 || !LoadToolBar(IDB_PLAYERTOOLBAR
))
54 GetToolBarCtrl().SetExtendedStyle(TBSTYLE_EX_DRAWDDARROWS
);
56 CToolBarCtrl
& tb
= GetToolBarCtrl();
57 tb
.DeleteButton(tb
.GetButtonCount()-1);
58 tb
.DeleteButton(tb
.GetButtonCount()-1);
60 SetMute(AfxGetAppSettings().fMute
);
64 TBBS_CHECKGROUP
, TBBS_CHECKGROUP
, TBBS_CHECKGROUP
,
66 TBBS_BUTTON
, TBBS_BUTTON
, TBBS_BUTTON
, TBBS_BUTTON
,
68 TBBS_BUTTON
/*|TBSTYLE_DROPDOWN*/,
75 for(int i
= 0; i
< countof(styles
); i
++)
76 SetButtonStyle(i
, styles
[i
]|TBBS_DISABLED
);
78 m_volctrl
.Create(this);
80 if(AfxGetAppSettings().fDisabeXPToolbars
)
82 if(HMODULE h
= LoadLibrary(_T("uxtheme.dll")))
84 SetWindowThemeFunct f
= (SetWindowThemeFunct
)GetProcAddress(h
, "SetWindowTheme");
85 if(f
) f(m_hWnd
, L
" ", L
" ");
93 BOOL
CPlayerToolBar::PreCreateWindow(CREATESTRUCT
& cs
)
95 if(!__super::PreCreateWindow(cs
))
98 m_dwStyle
&= ~CBRS_BORDER_TOP
;
99 m_dwStyle
&= ~CBRS_BORDER_BOTTOM
;
100 // m_dwStyle |= CBRS_SIZE_FIXED;
105 void CPlayerToolBar::ArrangeControls()
107 if(!::IsWindow(m_volctrl
.m_hWnd
)) return;
112 CRect br
= GetBorders();
115 GetItemRect(10, &r10
);
118 m_volctrl
.GetClientRect(&vr
);
119 CRect
vr2(r
.right
+br
.right
-60, r
.top
-1, r
.right
+br
.right
+6, r
.bottom
);
120 m_volctrl
.MoveWindow(vr2
);
125 GetButtonInfo(12, nID
, nStyle
, iImage
);
126 SetButtonInfo(11, GetItemID(11), TBBS_SEPARATOR
, vr2
.left
- iImage
- r10
.right
- 11);
129 void CPlayerToolBar::SetMute(bool fMute
)
131 CToolBarCtrl
& tb
= GetToolBarCtrl();
133 bi
.cbSize
= sizeof(bi
);
134 bi
.dwMask
= TBIF_IMAGE
;
135 bi
.iImage
= fMute
?13:12;
136 tb
.SetButtonInfo(ID_VOLUME_MUTE
, &bi
);
138 AfxGetAppSettings().fMute
= fMute
;
141 bool CPlayerToolBar::IsMuted()
143 CToolBarCtrl
& tb
= GetToolBarCtrl();
145 bi
.cbSize
= sizeof(bi
);
146 bi
.dwMask
= TBIF_IMAGE
;
147 tb
.GetButtonInfo(ID_VOLUME_MUTE
, &bi
);
148 return(bi
.iImage
==13);
151 int CPlayerToolBar::GetVolume()
153 int volume
= m_volctrl
.GetPos();
154 volume
= (int)((log10(1.0*volume
)-2)*5000);
155 volume
= max(min(volume
, 0), -10000);
156 return(IsMuted() ? -10000 : volume
);
159 void CPlayerToolBar::SetVolume(int volume
)
162 volume = (int)pow(10, ((double)volume)/5000+2);
163 volume = max(min(volume, 100), 1);
165 m_volctrl
.SetPosInternal(volume
);
168 BEGIN_MESSAGE_MAP(CPlayerToolBar
, CToolBar
)
171 ON_MESSAGE_VOID(WM_INITIALUPDATE
, OnInitialUpdate
)
172 ON_COMMAND_EX(ID_VOLUME_MUTE
, OnVolumeMute
)
173 ON_UPDATE_COMMAND_UI(ID_VOLUME_MUTE
, OnUpdateVolumeMute
)
174 ON_COMMAND_EX(ID_VOLUME_UP
, OnVolumeUp
)
175 ON_COMMAND_EX(ID_VOLUME_DOWN
, OnVolumeDown
)
180 // CPlayerToolBar message handlers
182 void CPlayerToolBar::OnPaint()
184 if(m_bDelayedButtonLayout
)
187 CPaintDC
dc(this); // device context for painting
189 DefWindowProc(WM_PAINT
, WPARAM(dc
.m_hDC
), 0);
195 GetButtonInfo(11, nID
, nStyle
, iImage
);
197 GetItemRect(11, ItemRect
);
198 dc
.FillSolidRect(ItemRect
, GetSysColor(COLOR_BTNFACE
));
202 void CPlayerToolBar::OnSize(UINT nType
, int cx
, int cy
)
204 __super::OnSize(nType
, cx
, cy
);
209 void CPlayerToolBar::OnInitialUpdate()
214 BOOL
CPlayerToolBar::OnVolumeMute(UINT nID
)
220 void CPlayerToolBar::OnUpdateVolumeMute(CCmdUI
* pCmdUI
)
222 pCmdUI
->Enable(true);
223 pCmdUI
->SetCheck(IsMuted());
226 BOOL
CPlayerToolBar::OnVolumeUp(UINT nID
)
228 m_volctrl
.IncreaseVolume();
232 BOOL
CPlayerToolBar::OnVolumeDown(UINT nID
)
234 m_volctrl
.DecreaseVolume();
238 void CPlayerToolBar::OnNcPaint() // when using XP styles the NC area isn't drawn for our toolbar...
246 cr
.OffsetRect(-wr
.left
, -wr
.top
);
247 wr
.OffsetRect(-wr
.left
, -wr
.top
);
248 dc
.ExcludeClipRect(&cr
);
249 dc
.FillSolidRect(wr
, GetSysColor(COLOR_BTNFACE
));
251 // Do not call CToolBar::OnNcPaint() for painting messages
254 void CPlayerToolBar::OnLButtonDown(UINT nFlags
, CPoint point
)
256 for(int i
= 0, j
= GetToolBarCtrl().GetButtonCount(); i
< j
; i
++)
258 if(GetButtonStyle(i
)&(TBBS_SEPARATOR
|TBBS_DISABLED
))
263 if(r
.PtInRect(point
))
265 __super::OnLButtonDown(nFlags
, point
);
270 CMainFrame
* pFrame
= ((CMainFrame
*)GetParentFrame());
271 if(!pFrame
->m_fFullScreen
)
273 MapWindowPoints(pFrame
, &point
, 1);
274 pFrame
->PostMessage(WM_NCLBUTTONDOWN
, HTCAPTION
, MAKELPARAM(point
.x
, point
.y
));