- Main Page
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

# SubtitleDlDlg.cpp

    00001 // SubtitleDlDlg.cpp : implementation file
    00002 //
    00003
    00004 #include "stdafx.h"
    00005 #include "mplayerc.h"
    00006 #include "SubtitleDlDlg.h"
    00007
    00008
    00009 // CSubtitleDlDlg dialog
    00010
    00011 //IMPLEMENT_DYNAMIC(CSubtitleDlDlg, CResizableDialog)
    00012 CSubtitleDlDlg::CSubtitleDlDlg(CList<isdb_movie>& movies, CWnd* pParent /*=NULL*/)
    00013         : CResizableDialog(CSubtitleDlDlg::IDD, pParent)
    00014 {
    00015         m_movies.AddTail(&movies);
    00016 }
    00017
    00018 CSubtitleDlDlg::~CSubtitleDlDlg()
    00019 {
    00020 }
    00021
    00022 int CSubtitleDlDlg::GetChecked(int iItem)
    00023 {
    00024         LVITEM lvi;
    00025         lvi.iItem = iItem;
    00026         lvi.iSubItem = 0;
    00027         lvi.mask = LVIF_IMAGE;
    00028         m_list.GetItem(&lvi);
    00029         return(lvi.iImage);
    00030 }
    00031
    00032 void CSubtitleDlDlg::SetChecked(int iItem, int iChecked)
    00033 {
    00034         LVITEM lvi;
    00035         lvi.iItem = iItem;
    00036         lvi.iSubItem = 0;
    00037         lvi.mask = LVIF_IMAGE;
    00038         lvi.iImage = iChecked;
    00039         m_list.SetItem(&lvi);
    00040 }
    00041
    00042 void CSubtitleDlDlg::DoDataExchange(CDataExchange* pDX)
    00043 {
    00044         __super::DoDataExchange(pDX);
    00045         DDX_Control(pDX, IDC_LIST1, m_list);
    00046 }
    00047
    00048
    00049 BEGIN_MESSAGE_MAP(CSubtitleDlDlg, CResizableDialog)
    00050         ON_NOTIFY(NM_CLICK, IDC_LIST1, OnNMClickList1)
    00051         ON_UPDATE_COMMAND_UI(IDOK, OnUpdateOk)
    00052 END_MESSAGE_MAP()
    00053
    00054 // CSubtitleDlDlg message handlers
    00055
    00056 BOOL CSubtitleDlDlg::OnInitDialog()
    00057 {
    00058         __super::OnInitDialog();
    00059
    00060
    00061         AddAnchor(IDC_LIST1, TOP_LEFT, BOTTOM_RIGHT);
    00062         AddAnchor(IDC_CHECK1, BOTTOM_LEFT);
    00063         AddAnchor(IDOK, BOTTOM_RIGHT);
    00064
    00065         CSize s(200, 150);
    00066         SetMinTrackSize(s);
    00067
    00068
    00069         m_list.SetExtendedStyle(m_list.GetExtendedStyle()|LVS_EX_FULLROWSELECT);
    00070
    00071         m_list.InsertColumn(COL_FILENAME, _T("File"), LVCFMT_LEFT, 160);
    00072         m_list.InsertColumn(COL_LANGUAGE, _T("Language"), LVCFMT_CENTER, 80);
    00073         m_list.InsertColumn(COL_FORMAT, _T("Format"), LVCFMT_CENTER, 50);
    00074         m_list.InsertColumn(COL_DISC, _T("Disc"), LVCFMT_CENTER, 50);
    00075         m_list.InsertColumn(COL_TITLES, _T("Title(s)"), LVCFMT_LEFT, 300);
    00076
    00077         m_onoff.Create(IDB_ONOFF, 12, 3, 0xffffff);
    00078         m_list.SetImageList(&m_onoff, LVSIL_SMALL);
    00079
    00080
    00081         int i = 0;
    00082
    00083         POSITION pos = m_movies.GetHeadPosition();
    00084         while(pos)
    00085         {
    00086                 isdb_movie& m = m_movies.GetNext(pos);
    00087
    00088                 CStringA titlesA = Implode(m.titles, '|');
    00089                 titlesA.Replace("|", ", ");
    00090                 CString titles = UTF8To16(titlesA);
    00091
    00092                 POSITION pos2 = m.subs.GetHeadPosition();
    00093                 while(pos2)
    00094                 {
    00095                         isdb_subtitle& s = m.subs.GetNext(pos2);
    00096                         CString name = UTF8To16(s.name);
    00097                         CString language = s.language;
    00098                         CString format = s.format;
    00099                         CString disc;
    00100                         disc.Format(_T("%d/%d"), s.disc_no, s.discs);
    00101
    00102                         int iItem = m_list.InsertItem(i++, _T(""));
    00103                         m_list.SetItemData(iItem, (DWORD_PTR)&s);
    00104                         m_list.SetItemText(iItem, COL_FILENAME, name);
    00105                         m_list.SetItemText(iItem, COL_LANGUAGE, language);
    00106                         m_list.SetItemText(iItem, COL_FORMAT, format);
    00107                         m_list.SetItemText(iItem, COL_DISC, disc);
    00108                         m_list.SetItemText(iItem, COL_TITLES, titles);
    00109                 }
    00110         }
    00111
    00112         m_selsubs.RemoveAll();
    00113
    00114         return TRUE;  // return TRUE unless you set the focus to a control
    00115         // EXCEPTION: OCX Property Pages should return FALSE
    00116 }
    00117
    00118 void CSubtitleDlDlg::OnOK()
    00119 {
    00120         for(int i = 0; i < m_list.GetItemCount(); i++)
    00121                 if(GetChecked(i))
    00122                         m_selsubs.AddTail(*(isdb_subtitle*)m_list.GetItemData(i));
    00123
    00124         m_fReplaceSubs = IsDlgButtonChecked(IDC_CHECK1) == BST_CHECKED;
    00125
    00126         __super::OnOK();
    00127 }
    00128
    00129 void CSubtitleDlDlg::OnNMClickList1(NMHDR *pNMHDR, LRESULT *pResult)
    00130 {
    00131         LPNMLISTVIEW lpnmlv = (LPNMLISTVIEW)pNMHDR;
    00132
    00133         if(lpnmlv->iItem >= 0)
    00134         {
    00135                 CRect r;
    00136                 m_list.GetItemRect(lpnmlv->iItem, r, LVIR_ICON);
    00137                 if(r.PtInRect(lpnmlv->ptAction))
    00138                 {
    00139                         SetChecked(lpnmlv->iItem, (GetChecked(lpnmlv->iItem)&1) == 0 ? 1 : 0);
    00140                 }
    00141         }
    00142
    00143         *pResult = 0;
    00144 }
    00145
    00146 void CSubtitleDlDlg::OnUpdateOk(CCmdUI* pCmdUI)
    00147 {
    00148         bool fEnable = false;
    00149         for(int i = 0; !fEnable && i < m_list.GetItemCount(); i++)
    00150                 fEnable = !!GetChecked(i);
    00151
    00152         pCmdUI->Enable(fEnable);
    00153 }