ConvertPropsDlg.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 // ConvertPropsDlg.cpp : implementation file
00023 //
00024 
00025 #include "stdafx.h"
00026 #include "mplayerc.h"
00027 #include "ConvertPropsDlg.h"
00028 
00029 
00030 // CConvertPropsDlg dialog
00031 
00032 CConvertPropsDlg::CConvertPropsDlg(bool fPin, CWnd* pParent /*=NULL*/)
00033         : CResizableDialog(CConvertPropsDlg::IDD, pParent)
00034         , m_fPin(fPin)
00035 {
00036 }
00037 
00038 CConvertPropsDlg::~CConvertPropsDlg()
00039 {
00040 }
00041 
00042 void CConvertPropsDlg::DoDataExchange(CDataExchange* pDX)
00043 {
00044         __super::DoDataExchange(pDX);
00045         DDX_Control(pDX, IDC_COMBO1, m_fcc);
00046         DDX_Control(pDX, IDC_EDIT1, m_text);
00047         DDX_Control(pDX, IDC_LIST1, m_list);
00048 }
00049 
00050 
00051 BEGIN_MESSAGE_MAP(CConvertPropsDlg, CResizableDialog)
00052         ON_NOTIFY(NM_CLICK, IDC_LIST1, OnNMClickList1)
00053         ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
00054         ON_UPDATE_COMMAND_UI(IDC_BUTTON1, OnUpdateButton1)
00055         ON_CBN_EDITCHANGE(IDC_COMBO1, OnCbnEditchangeCombo1)
00056         ON_CBN_SELCHANGE(IDC_COMBO1, OnCbnSelchangeCombo1)
00057         ON_NOTIFY(LVN_KEYDOWN, IDC_LIST1, OnLvnKeydownList1)
00058 END_MESSAGE_MAP()
00059 
00060 
00061 // CConvertPropsDlg message handlers
00062 
00063 BOOL CConvertPropsDlg::OnInitDialog()
00064 {
00065         __super::OnInitDialog();
00066 
00067         AddAnchor(IDC_COMBO1, TOP_LEFT);
00068         AddAnchor(IDC_EDIT1, TOP_LEFT, TOP_RIGHT);
00069         AddAnchor(IDC_BUTTON1, TOP_RIGHT);
00070         AddAnchor(IDC_LIST1, TOP_LEFT, BOTTOM_RIGHT);
00071         AddAnchor(IDOK, BOTTOM_CENTER);
00072         AddAnchor(IDCANCEL, BOTTOM_CENTER);
00073 
00074         if(m_fPin)
00075         {
00076                 m_fcc.AddString(_T("NAME"));
00077                 m_fcc.AddString(_T("LANG"));
00078                 m_fcc.AddString(_T("DESC"));
00079                 m_fcc.AddString(_T("SGRP"));
00080         }
00081         else
00082         {
00083                 m_fcc.AddString(_T("TITL"));
00084                 m_fcc.AddString(_T("AUTH"));
00085                 m_fcc.AddString(_T("RTNG"));
00086                 m_fcc.AddString(_T("CPYR"));
00087                 m_fcc.AddString(_T("DESC"));
00088         }
00089 
00090         m_list.InsertColumn(0, _T("ID"), LVCFMT_LEFT, 75);
00091         m_list.InsertColumn(1, _T("Text"), LVCFMT_LEFT, 280);
00092 
00093         m_list.SetExtendedStyle(m_list.GetExtendedStyle()|LVS_EX_FULLROWSELECT);
00094 
00095         POSITION pos = m_props.GetStartPosition();
00096         while(pos)
00097         {
00098                 CString key, value;
00099                 m_props.GetNextAssoc(pos, key, value);
00100                 SetItem(key, value);
00101         }
00102 
00103         return TRUE;  // return TRUE unless you set the focus to a control
00104         // EXCEPTION: OCX Property Pages should return FALSE
00105 }
00106 
00107 void CConvertPropsDlg::SetItem(CString key, CString value)
00108 {
00109         LVFINDINFO fi;
00110         fi.flags = LVFI_STRING;
00111         fi.psz = key;
00112 
00113         int i = m_list.FindItem(&fi);
00114         if(i < 0) i = m_list.InsertItem(m_list.GetItemCount(), _T(""));
00115 
00116         key.Trim();
00117         value.Trim();
00118         
00119         if(value.IsEmpty())
00120         {
00121                 m_list.DeleteItem(i);
00122                 return;
00123         }
00124 
00125         if(key == _T("LANG") && value.GetLength() != 3)
00126         {
00127                 m_list.DeleteItem(i);
00128                 AfxMessageBox(_T("LANG has to be a three letter ISO 639-2 language code."), MB_OK);
00129                 return;
00130         }
00131 
00132         m_list.SetItemText(i, 0, key);
00133         m_list.SetItemText(i, 1, value);
00134 }
00135 
00136 void CConvertPropsDlg::OnOK()
00137 {
00138         m_props.RemoveAll();
00139 
00140         for(int i = 0; i < m_list.GetItemCount(); i++)
00141                 m_props[m_list.GetItemText(i, 0)] = m_list.GetItemText(i, 1);
00142 
00143         __super::OnOK();
00144 }
00145 
00146 void CConvertPropsDlg::OnNMClickList1(NMHDR *pNMHDR, LRESULT *pResult)
00147 {
00148         LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)pNMHDR;
00149 
00150         if(lpnmlv->iItem >= 0)
00151         {
00152                 m_fcc.SetWindowText(m_list.GetItemText(lpnmlv->iItem, 0));
00153                 m_text.SetWindowText(m_list.GetItemText(lpnmlv->iItem, 1));
00154         }
00155 
00156         *pResult = 0;
00157 }
00158 
00159 void CConvertPropsDlg::OnBnClickedButton1()
00160 {
00161         CString key, value;
00162         m_fcc.GetWindowText(key);
00163         m_text.GetWindowText(value);
00164         if(key.GetLength() != 4) {AfxMessageBox(_T("ID must be 4 characters long!"), MB_OK); return;}
00165         SetItem(key, value);
00166 }
00167 
00168 void CConvertPropsDlg::OnUpdateButton1(CCmdUI* pCmdUI)
00169 {
00170         pCmdUI->Enable(GetDlgItem(IDC_EDIT1)->GetWindowTextLength() > 0);
00171 }
00172 
00173 void CConvertPropsDlg::OnCbnEditchangeCombo1()
00174 {
00175         int i = m_fcc.GetCurSel();
00176         if(i < 0) return;
00177 
00178         CString key;
00179         m_fcc.GetLBText(i, key);
00180 
00181         LVFINDINFO fi;
00182         fi.flags = LVFI_STRING;
00183         fi.psz = key;
00184 
00185         i = m_list.FindItem(&fi);
00186         if(i > 0) m_text.SetWindowText(m_list.GetItemText(i, 1));
00187 }
00188 
00189 void CConvertPropsDlg::OnCbnSelchangeCombo1()
00190 {
00191         OnCbnEditchangeCombo1();
00192 }
00193 
00194 void CConvertPropsDlg::OnLvnKeydownList1(NMHDR *pNMHDR, LRESULT *pResult)
00195 {
00196         LPNMLVKEYDOWN pLVKeyDow = reinterpret_cast<LPNMLVKEYDOWN>(pNMHDR);
00197 
00198         int i = m_fcc.GetCurSel();
00199         if(i >= 0) m_list.DeleteItem(i);
00200 
00201         *pResult = 0;
00202 }

Generated on Tue Dec 13 14:46:48 2005 for guliverkli by  doxygen 1.4.5