Support unrar64.dll
[xy_vsfilter.git] / src / apps / mplayerc / PlayerToolBar.cpp
blob9bcf75d19964d33b0be891a31972cc8e4bf546ae
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 // PlayerToolBar.cpp : implementation file
25 #include "stdafx.h"
26 #include "mplayerc.h"
27 #include <math.h>
28 #include <atlbase.h>
29 #include <afxpriv.h>
30 #include "PlayerToolBar.h"
31 #include "MainFrm.h"
33 typedef HRESULT (__stdcall * SetWindowThemeFunct)(HWND hwnd, LPCWSTR pszSubAppName, LPCWSTR pszSubIdList);
35 // CPlayerToolBar
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))
52 return FALSE;
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);
62 UINT styles[] =
64 TBBS_CHECKGROUP, TBBS_CHECKGROUP, TBBS_CHECKGROUP,
65 TBBS_SEPARATOR,
66 TBBS_BUTTON, TBBS_BUTTON, TBBS_BUTTON, TBBS_BUTTON,
67 TBBS_SEPARATOR,
68 TBBS_BUTTON/*|TBSTYLE_DROPDOWN*/,
69 TBBS_SEPARATOR,
70 TBBS_SEPARATOR,
71 TBBS_CHECKBOX,
72 /*TBBS_SEPARATOR,*/
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" ");
86 FreeLibrary(h);
90 return TRUE;
93 BOOL CPlayerToolBar::PreCreateWindow(CREATESTRUCT& cs)
95 if(!__super::PreCreateWindow(cs))
96 return FALSE;
98 m_dwStyle &= ~CBRS_BORDER_TOP;
99 m_dwStyle &= ~CBRS_BORDER_BOTTOM;
100 // m_dwStyle |= CBRS_SIZE_FIXED;
102 return TRUE;
105 void CPlayerToolBar::ArrangeControls()
107 if(!::IsWindow(m_volctrl.m_hWnd)) return;
109 CRect r;
110 GetClientRect(&r);
112 CRect br = GetBorders();
114 CRect r10;
115 GetItemRect(10, &r10);
117 CRect vr;
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);
122 UINT nID;
123 UINT nStyle;
124 int iImage;
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();
132 TBBUTTONINFO bi;
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();
144 TBBUTTONINFO bi;
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)
169 ON_WM_PAINT()
170 ON_WM_SIZE()
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)
176 ON_WM_NCPAINT()
177 ON_WM_LBUTTONDOWN()
178 END_MESSAGE_MAP()
180 // CPlayerToolBar message handlers
182 void CPlayerToolBar::OnPaint()
184 if(m_bDelayedButtonLayout)
185 Layout();
187 CPaintDC dc(this); // device context for painting
189 DefWindowProc(WM_PAINT, WPARAM(dc.m_hDC), 0);
192 UINT nID;
193 UINT nStyle = 0;
194 int iImage = 0;
195 GetButtonInfo(11, nID, nStyle, iImage);
196 CRect ItemRect;
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);
206 ArrangeControls();
209 void CPlayerToolBar::OnInitialUpdate()
211 ArrangeControls();
214 BOOL CPlayerToolBar::OnVolumeMute(UINT nID)
216 SetMute(!IsMuted());
217 return FALSE;
220 void CPlayerToolBar::OnUpdateVolumeMute(CCmdUI* pCmdUI)
222 pCmdUI->Enable(true);
223 pCmdUI->SetCheck(IsMuted());
226 BOOL CPlayerToolBar::OnVolumeUp(UINT nID)
228 m_volctrl.IncreaseVolume();
229 return FALSE;
232 BOOL CPlayerToolBar::OnVolumeDown(UINT nID)
234 m_volctrl.DecreaseVolume();
235 return FALSE;
238 void CPlayerToolBar::OnNcPaint() // when using XP styles the NC area isn't drawn for our toolbar...
240 CRect wr, cr;
242 CWindowDC dc(this);
243 GetClientRect(&cr);
244 ClientToScreen(&cr);
245 GetWindowRect(&wr);
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))
259 continue;
261 CRect r;
262 GetItemRect(i, r);
263 if(r.PtInRect(point))
265 __super::OnLButtonDown(nFlags, point);
266 return;
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));