PPageLogo.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 // CPPageLogo.cpp : implementation file
00023 //
00024 
00025 #include "stdafx.h"
00026 #include "mplayerc.h"
00027 #include "MainFrm.h"
00028 #include "PPageLogo.h"
00029 
00030 // CPPageLogo dialog
00031 
00032 IMPLEMENT_DYNAMIC(CPPageLogo, CPPageBase)
00033 CPPageLogo::CPPageLogo()
00034         : CPPageBase(CPPageLogo::IDD, CPPageLogo::IDD)
00035         , m_intext(0)
00036         , m_logofn(_T(""))
00037         , m_author(_T(""))
00038 {
00039         m_logoids.AddTail(IDB_LOGO0);
00040         m_logoids.AddTail(IDB_LOGO1);
00041         m_logoids.AddTail(IDB_LOGO2);
00042         m_logoids.AddTail(IDB_LOGO3);
00043         m_logoids.AddTail(IDB_LOGO4);
00044         m_logoids.AddTail(IDB_LOGO5);
00045         m_logoids.AddTail(IDB_LOGO6);
00046         m_logoids.AddTail(IDB_LOGO7);
00047 }
00048 
00049 CPPageLogo::~CPPageLogo()
00050 {
00051 }
00052 
00053 void CPPageLogo::DoDataExchange(CDataExchange* pDX)
00054 {
00055         __super::DoDataExchange(pDX);
00056         DDX_Radio(pDX, IDC_RADIO1, m_intext);
00057         DDX_Text(pDX, IDC_LOGOFILENAME, m_logofn);
00058         DDX_Control(pDX, IDC_LOGOPREVIEW, m_logopreview);
00059         DDX_Text(pDX, IDC_AUTHOR, m_author);
00060 }
00061 
00062 
00063 BEGIN_MESSAGE_MAP(CPPageLogo, CPPageBase)
00064         ON_BN_CLICKED(IDC_RADIO1, OnBnClickedRadio1)
00065         ON_BN_CLICKED(IDC_RADIO2, OnBnClickedRadio2)
00066         ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN1, OnDeltaposSpin1)
00067         ON_BN_CLICKED(IDC_BUTTON2, OnBnClickedButton2)
00068 END_MESSAGE_MAP()
00069 
00070 
00071 // CPPageLogo message handlers
00072 
00073 BOOL CPPageLogo::OnInitDialog()
00074 {
00075         __super::OnInitDialog();
00076 
00077         AppSettings& s = AfxGetAppSettings();
00078 
00079         m_intext = s.logoext?1:0;
00080         m_logofn = s.logofn;
00081         m_logoidpos = NULL;
00082 
00083         UpdateData(FALSE);
00084 
00085         for(POSITION pos = m_logoids.GetHeadPosition(); pos; m_logoids.GetNext(pos)) 
00086         {
00087                 if(m_logoids.GetAt(pos) == s.logoid)
00088                 {
00089                         m_logoidpos = pos;
00090                         break;
00091                 }
00092         }
00093 
00094         if(!m_intext) OnBnClickedRadio1();
00095         else OnBnClickedRadio2();
00096 
00097         return TRUE;  // return TRUE unless you set the focus to a control
00098         // EXCEPTION: OCX Property Pages should return FALSE
00099 }
00100 
00101 BOOL CPPageLogo::OnApply()
00102 {
00103         UpdateData();
00104 
00105         AppSettings& s = AfxGetAppSettings();
00106 
00107         s.logoext = !!m_intext;
00108         s.logofn = m_logofn;
00109         s.logoid = m_logoids.GetAt(m_logoidpos);
00110 
00111         ((CMainFrame*)AfxGetMainWnd())->m_wndView.LoadLogo();
00112 
00113         return __super::OnApply();
00114 }
00115 
00116 
00117 void CPPageLogo::OnBnClickedRadio1()
00118 {
00119         ASSERT(m_logoidpos);
00120 
00121         m_author.Empty();
00122 
00123         m_logobm.Destroy();
00124         UINT id = m_logoids.GetAt(m_logoidpos);
00125         if(IDB_LOGO0 != id)
00126         {
00127                 m_logobm.LoadFromResource(::AfxGetInstanceHandle(), id);
00128                 if(!m_author.LoadString(id))
00129                         m_author = _T("Author unknown. Contact me if you made this logo!");
00130         }
00131         m_logopreview.SetBitmap(m_logobm);
00132         Invalidate();
00133 
00134         m_intext = 0;
00135         UpdateData(FALSE);
00136 
00137         SetModified();
00138 }
00139 
00140 void CPPageLogo::OnBnClickedRadio2()
00141 {
00142         UpdateData();
00143 
00144         m_author.Empty();
00145 
00146         m_logobm.Destroy();
00147         if(AfxGetAppSettings().fXpOrBetter)
00148                 m_logobm.Load(m_logofn);
00149         else if(HANDLE h = LoadImage(NULL, m_logofn, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE))
00150                 m_logobm.Attach((HBITMAP)h);
00151         m_logopreview.SetBitmap(m_logobm);
00152         Invalidate();
00153 
00154         m_intext = 1;
00155         UpdateData(FALSE);
00156 
00157         SetModified();
00158 }
00159 
00160 void CPPageLogo::OnDeltaposSpin1(NMHDR *pNMHDR, LRESULT *pResult)
00161 {
00162         LPNMUPDOWN pNMUpDown = reinterpret_cast<LPNMUPDOWN>(pNMHDR);
00163 
00164         if(pNMUpDown->iDelta < 0)
00165         {
00166                 m_logoids.GetNext(m_logoidpos);
00167                 if(!m_logoidpos) m_logoidpos = m_logoids.GetHeadPosition();
00168         }
00169         else
00170         {
00171                 m_logoids.GetPrev(m_logoidpos);
00172                 if(!m_logoidpos) m_logoidpos = m_logoids.GetTailPosition();
00173         }
00174 
00175         OnBnClickedRadio1();
00176 
00177         *pResult = 0;
00178 }
00179 
00180 void CPPageLogo::OnBnClickedButton2()
00181 {
00182         CFileDialog dlg(TRUE, NULL, m_logofn, 
00183                 OFN_EXPLORER|OFN_ENABLESIZING|OFN_HIDEREADONLY, 
00184                 AfxGetAppSettings().fXpOrBetter 
00185                 ? _T("Images (*.bmp;*.jpg;*.gif;*.png)|*.bmp;*.jpg;*.gif;*.png|All files (*.*)|*.*||")
00186                 : _T("Images (*.bmp)|*.bmp|All files (*.*)|*.*||")
00187                 , this, 0);
00188 
00189         if(dlg.DoModal() == IDOK)
00190         {
00191                 m_logofn = dlg.GetPathName();
00192                 UpdateData(FALSE);
00193                 OnBnClickedRadio2();
00194         }
00195 }

Generated on Tue Dec 13 14:47:01 2005 for guliverkli by  doxygen 1.4.5