- Main Page
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

# PlayerToolBar.cpp

    00001 /*
    00002  *      Copyright (C) 2003-2005 Gabest
    00003  *      http://www.gabest.org
    00004  *
    00005  *  This Program is free software; you can redistribute it and/or modify
    00006  *  it under the terms of the GNU General Public License as published by
    00007  *  the Free Software Foundation; either version 2, or (at your option)
    00008  *  any later version.
    00009  *
    00010  *  This Program is distributed in the hope that it will be useful,
    00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    00013  *  GNU General Public License for more details.
    00014  *
    00015  *  You should have received a copy of the GNU General Public License
    00016  *  along with GNU Make; see the file COPYING.  If not, write to
    00017  *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
    00018  *  http://www.gnu.org/copyleft/gpl.html
    00019  *
    00020  */
    00021
    00022 // PlayerToolBar.cpp : implementation file
    00023 //
    00024
    00025 #include "stdafx.h"
    00026 #include "mplayerc.h"
    00027 #include <math.h>
    00028 #include <atlbase.h>
    00029 #include <afxpriv.h>
    00030 #include "PlayerToolBar.h"
    00031 #include "MainFrm.h"
    00032
    00033 typedef HRESULT (__stdcall * SetWindowThemeFunct)(HWND hwnd, LPCWSTR pszSubAppName, LPCWSTR pszSubIdList);
    00034
    00035 // CPlayerToolBar
    00036
    00037 IMPLEMENT_DYNAMIC(CPlayerToolBar, CToolBar)
    00038 CPlayerToolBar::CPlayerToolBar()
    00039 {
    00040 }
    00041
    00042 CPlayerToolBar::~CPlayerToolBar()
    00043 {
    00044 }
    00045
    00046 BOOL CPlayerToolBar::Create(CWnd* pParentWnd)
    00047 {
    00048         if(!__super::CreateEx(pParentWnd,
    00049                 TBSTYLE_FLAT|TBSTYLE_TRANSPARENT|TBSTYLE_AUTOSIZE,
    00050                 WS_CHILD|WS_VISIBLE|CBRS_ALIGN_BOTTOM|CBRS_TOOLTIPS, CRect(2,2,0,3))
    00051         || !LoadToolBar(ID_PLAYERTOOLBAR))
    00052                 return FALSE;
    00053
    00054         GetToolBarCtrl().SetExtendedStyle(TBSTYLE_EX_DRAWDDARROWS);
    00055
    00056         CToolBarCtrl& tb = GetToolBarCtrl();
    00057         tb.DeleteButton(tb.GetButtonCount()-1);
    00058         tb.DeleteButton(tb.GetButtonCount()-1);
    00059
    00060         SetMute(AfxGetAppSettings().fMute);
    00061
    00062         UINT styles[] =
    00063         {
    00064                 TBBS_CHECKGROUP, TBBS_CHECKGROUP, TBBS_CHECKGROUP,
    00065                 TBBS_SEPARATOR,
    00066                 TBBS_BUTTON, TBBS_BUTTON, TBBS_BUTTON, TBBS_BUTTON,
    00067                 TBBS_SEPARATOR,
    00068                 TBBS_BUTTON/*|TBSTYLE_DROPDOWN*/,
    00069                 TBBS_SEPARATOR,
    00070                 TBBS_SEPARATOR,
    00071                 TBBS_CHECKBOX,
    00072                 /*TBBS_SEPARATOR,*/
    00073         };
    00074
    00075         for(int i = 0; i < countof(styles); i++)
    00076                 SetButtonStyle(i, styles[i]|TBBS_DISABLED);
    00077
    00078         m_volctrl.Create(this);
    00079
    00080         if(AfxGetAppSettings().fDisabeXPToolbars)
    00081         {
    00082                 if(HMODULE h = LoadLibrary(_T("uxtheme.dll")))
    00083                 {
    00084                         SetWindowThemeFunct f = (SetWindowThemeFunct)GetProcAddress(h, "SetWindowTheme");
    00085                         if(f) f(m_hWnd, L" ", L" ");
    00086                         FreeLibrary(h);
    00087                 }
    00088         }
    00089
    00090         return TRUE;
    00091 }
    00092
    00093 BOOL CPlayerToolBar::PreCreateWindow(CREATESTRUCT& cs)
    00094 {
    00095         if(!__super::PreCreateWindow(cs))
    00096                 return FALSE;
    00097
    00098         m_dwStyle &= ~CBRS_BORDER_TOP;
    00099         m_dwStyle &= ~CBRS_BORDER_BOTTOM;
    00100 //      m_dwStyle |= CBRS_SIZE_FIXED;
    00101
    00102         return TRUE;
    00103 }
    00104
    00105 void CPlayerToolBar::ArrangeControls()
    00106 {
    00107         if(!::IsWindow(m_volctrl.m_hWnd)) return;
    00108
    00109         CRect r;
    00110         GetClientRect(&r);
    00111
    00112         CRect br = GetBorders();
    00113
    00114         CRect r10;
    00115         GetItemRect(10, &r10);
    00116
    00117         CRect vr;
    00118         m_volctrl.GetClientRect(&vr);
    00119         CRect vr2(r.right+br.right-60, r.top-1, r.right+br.right+6, r.bottom);
    00120         m_volctrl.MoveWindow(vr2);
    00121
    00122         UINT nID;
    00123         UINT nStyle;
    00124         int iImage;
    00125         GetButtonInfo(12, nID, nStyle, iImage);
    00126         SetButtonInfo(11, GetItemID(11), TBBS_SEPARATOR, vr2.left - iImage - r10.right - 11);
    00127 }
    00128
    00129 void CPlayerToolBar::SetMute(bool fMute)
    00130 {
    00131         CToolBarCtrl& tb = GetToolBarCtrl();
    00132         TBBUTTONINFO bi;
    00133         bi.cbSize = sizeof(bi);
    00134         bi.dwMask = TBIF_IMAGE;
    00135         bi.iImage = fMute?13:12;
    00136         tb.SetButtonInfo(ID_VOLUME_MUTE, &bi);
    00137
    00138         AfxGetAppSettings().fMute = fMute;
    00139 }
    00140
    00141 bool CPlayerToolBar::IsMuted()
    00142 {
    00143         CToolBarCtrl& tb = GetToolBarCtrl();
    00144         TBBUTTONINFO bi;
    00145         bi.cbSize = sizeof(bi);
    00146         bi.dwMask = TBIF_IMAGE;
    00147         tb.GetButtonInfo(ID_VOLUME_MUTE, &bi);
    00148         return(bi.iImage==13);
    00149 }
    00150
    00151 int CPlayerToolBar::GetVolume()
    00152 {
    00153         int volume = m_volctrl.GetPos();
    00154         volume = (int)((log10(1.0*volume)-2)*5000);
    00155         volume = max(min(volume, 0), -10000);
    00156         return(IsMuted() ? -10000 : volume);
    00157 }
    00158
    00159 void CPlayerToolBar::SetVolume(int volume)
    00160 {
    00161 /*
    00162         volume = (int)pow(10, ((double)volume)/5000+2);
    00163         volume = max(min(volume, 100), 1);
    00164 */
    00165         m_volctrl.SetPosInternal(volume);
    00166 }
    00167
    00168 BEGIN_MESSAGE_MAP(CPlayerToolBar, CToolBar)
    00169         ON_WM_PAINT()
    00170         ON_WM_SIZE()
    00171         ON_MESSAGE_VOID(WM_INITIALUPDATE, OnInitialUpdate)
    00172         ON_COMMAND_EX(ID_VOLUME_MUTE, OnVolumeMute)
    00173         ON_UPDATE_COMMAND_UI(ID_VOLUME_MUTE, OnUpdateVolumeMute)
    00174         ON_COMMAND_EX(ID_VOLUME_UP, OnVolumeUp)
    00175         ON_COMMAND_EX(ID_VOLUME_DOWN, OnVolumeDown)
    00176         ON_WM_NCPAINT()
    00177         ON_WM_LBUTTONDOWN()
    00178 END_MESSAGE_MAP()
    00179
    00180 // CPlayerToolBar message handlers
    00181
    00182 void CPlayerToolBar::OnPaint()
    00183 {
    00184         if(m_bDelayedButtonLayout)
    00185                 Layout();
    00186
    00187         CPaintDC dc(this); // device context for painting
    00188
    00189         DefWindowProc(WM_PAINT, WPARAM(dc.m_hDC), 0);
    00190
    00191         {
    00192                 UINT nID;
    00193                 UINT nStyle = 0;
    00194                 int iImage = 0;
    00195                 GetButtonInfo(11, nID, nStyle, iImage);
    00196                 CRect ItemRect;
    00197                 GetItemRect(11, ItemRect);
    00198                 dc.FillSolidRect(ItemRect, GetSysColor(COLOR_BTNFACE));
    00199         }
    00200 }
    00201
    00202 void CPlayerToolBar::OnSize(UINT nType, int cx, int cy)
    00203 {
    00204         __super::OnSize(nType, cx, cy);
    00205
    00206         ArrangeControls();
    00207 }
    00208
    00209 void CPlayerToolBar::OnInitialUpdate()
    00210 {
    00211         ArrangeControls();
    00212 }
    00213
    00214 BOOL CPlayerToolBar::OnVolumeMute(UINT nID)
    00215 {
    00216         SetMute(!IsMuted());
    00217         return FALSE;
    00218 }
    00219
    00220 void CPlayerToolBar::OnUpdateVolumeMute(CCmdUI* pCmdUI)
    00221 {
    00222         pCmdUI->Enable(true);
    00223         pCmdUI->SetCheck(IsMuted());
    00224 }
    00225
    00226 BOOL CPlayerToolBar::OnVolumeUp(UINT nID)
    00227 {
    00228         m_volctrl.IncreaseVolume();
    00229         return FALSE;
    00230 }
    00231
    00232 BOOL CPlayerToolBar::OnVolumeDown(UINT nID)
    00233 {
    00234         m_volctrl.DecreaseVolume();
    00235         return FALSE;
    00236 }
    00237
    00238 void CPlayerToolBar::OnNcPaint() // when using XP styles the NC area isn't drawn for our toolbar...
    00239 {
    00240         CRect wr, cr;
    00241
    00242         CWindowDC dc(this);
    00243         GetClientRect(&cr);
    00244         ClientToScreen(&cr);
    00245         GetWindowRect(&wr);
    00246         cr.OffsetRect(-wr.left, -wr.top);
    00247         wr.OffsetRect(-wr.left, -wr.top);
    00248         dc.ExcludeClipRect(&cr);
    00249         dc.FillSolidRect(wr, GetSysColor(COLOR_BTNFACE));
    00250
    00251         // Do not call CToolBar::OnNcPaint() for painting messages
    00252 }
    00253
    00254 void CPlayerToolBar::OnLButtonDown(UINT nFlags, CPoint point)
    00255 {
    00256         for(int i = 0, j = GetToolBarCtrl().GetButtonCount(); i < j; i++)
    00257         {
    00258                 if(GetButtonStyle(i)&(TBBS_SEPARATOR|TBBS_DISABLED))
    00259                         continue;
    00260
    00261                 CRect r;
    00262                 GetItemRect(i, r);
    00263                 if(r.PtInRect(point))
    00264                 {
    00265                         __super::OnLButtonDown(nFlags, point);
    00266                         return;
    00267                 }
    00268         }
    00269
    00270         CMainFrame* pFrame = ((CMainFrame*)GetParentFrame());
    00271         if(!pFrame->m_fFullScreen)
    00272         {
    00273                 MapWindowPoints(pFrame, &point, 1);
    00274                 pFrame->PostMessage(WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x, point.y));
    00275         }
    00276 }