FavoriteOrganizeDlg.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 // FavoriteOrganizeDlg.cpp : implementation file
00023 //
00024 
00025 #include "stdafx.h"
00026 #include "mplayerc.h"
00027 #include "FavoriteOrganizeDlg.h"
00028 
00029 
00030 // CFavoriteOrganizeDlg dialog
00031 
00032 //IMPLEMENT_DYNAMIC(CFavoriteOrganizeDlg, CResizableDialog)
00033 CFavoriteOrganizeDlg::CFavoriteOrganizeDlg(CWnd* pParent /*=NULL*/)
00034         : CResizableDialog(CFavoriteOrganizeDlg::IDD, pParent)
00035 {
00036 }
00037 
00038 CFavoriteOrganizeDlg::~CFavoriteOrganizeDlg()
00039 {
00040 }
00041 
00042 void CFavoriteOrganizeDlg::SetupList(bool fSave)
00043 {
00044         int i = m_tab.GetCurSel();
00045 
00046         if(fSave)
00047         {
00048                 CList<CString> sl;
00049 
00050                 for(int j = 0; j < m_list.GetItemCount(); j++)
00051                 {
00052                         CString desc = m_list.GetItemText(j, 0);
00053                         desc.Remove(';');
00054                         CString str = m_sl[i].GetAt((POSITION)m_list.GetItemData(j));
00055                         sl.AddTail(desc + str.Mid(str.Find(';')));
00056                 }
00057 
00058                 m_sl[i].RemoveAll();
00059                 m_sl[i].AddTail(&sl);
00060         }
00061         else
00062         {
00063                 m_list.DeleteAllItems();
00064 
00065                 POSITION pos = m_sl[i].GetHeadPosition(), tmp;
00066                 while(pos) 
00067                 {
00068                         tmp = pos;
00069                         CString s = m_sl[i].GetNext(pos);
00070                         int i = s.Find(';');
00071                         if(i >= 0) s = s.Left(i);
00072                         m_list.SetItemData(m_list.InsertItem(m_list.GetItemCount(), s), (DWORD_PTR)tmp);
00073                 }
00074 
00075                 m_list.SetRedraw(FALSE);
00076 
00077                 CRect r;
00078                 m_list.GetClientRect(r);
00079                 m_list.SetColumnWidth(0, -1);
00080                 m_list.SetColumnWidth(0, max(m_list.GetColumnWidth(0), r.Size().cx));
00081 
00082                 m_list.SetRedraw(TRUE);
00083         }
00084 }
00085 
00086 void CFavoriteOrganizeDlg::DoDataExchange(CDataExchange* pDX)
00087 {
00088         __super::DoDataExchange(pDX);
00089         DDX_Control(pDX, IDC_TAB1, m_tab);
00090         DDX_Control(pDX, IDC_LIST2, m_list);
00091 }
00092 
00093 
00094 BEGIN_MESSAGE_MAP(CFavoriteOrganizeDlg, CResizableDialog)
00095         ON_NOTIFY(TCN_SELCHANGE, IDC_TAB1, OnTcnSelchangeTab1)
00096         ON_WM_DRAWITEM()
00097         ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
00098         ON_BN_CLICKED(IDC_BUTTON2, OnBnClickedButton2)
00099         ON_BN_CLICKED(IDC_BUTTON3, OnBnClickedButton3)
00100         ON_BN_CLICKED(IDC_BUTTON7, OnBnClickedButton7)
00101         ON_NOTIFY(TCN_SELCHANGING, IDC_TAB1, OnTcnSelchangingTab1)
00102         ON_BN_CLICKED(IDOK, OnBnClickedOk)
00103         ON_WM_ACTIVATE()
00104         ON_NOTIFY(LVN_ENDLABELEDIT, IDC_LIST2, OnLvnEndlabeleditList2)
00105         ON_WM_SIZE()
00106 END_MESSAGE_MAP()
00107 
00108 
00109 // CFavoriteOrganizeDlg message handlers
00110 
00111 BOOL CFavoriteOrganizeDlg::OnInitDialog()
00112 {
00113         __super::OnInitDialog();
00114 
00115         m_tab.InsertItem(0, _T("Files"));
00116         m_tab.InsertItem(1, _T("DVDs"));
00117 //      m_tab.InsertItem(2, _T("Devices"));
00118         m_tab.SetCurSel(0);
00119 
00120         m_list.InsertColumn(0, _T(""));
00121         m_list.SetExtendedStyle(m_list.GetExtendedStyle()|LVS_EX_FULLROWSELECT);
00122 
00123         AfxGetAppSettings().GetFav(FAV_FILE, m_sl[0]);
00124         AfxGetAppSettings().GetFav(FAV_DVD, m_sl[1]);
00125         AfxGetAppSettings().GetFav(FAV_DEVICE, m_sl[2]);
00126         
00127         SetupList(false);
00128 
00129         AddAnchor(IDC_TAB1, TOP_LEFT, BOTTOM_RIGHT);
00130         AddAnchor(IDC_LIST2, TOP_LEFT, BOTTOM_RIGHT);
00131         AddAnchor(IDC_BUTTON1, TOP_RIGHT);
00132         AddAnchor(IDC_BUTTON2, TOP_RIGHT);
00133         AddAnchor(IDC_BUTTON3, TOP_RIGHT);
00134         AddAnchor(IDC_BUTTON7, TOP_RIGHT);
00135         AddAnchor(IDOK, BOTTOM_RIGHT);
00136 
00137         return TRUE;  // return TRUE unless you set the focus to a control
00138         // EXCEPTION: OCX Property Pages should return FALSE
00139 }
00140 
00141 void CFavoriteOrganizeDlg::OnTcnSelchangeTab1(NMHDR* pNMHDR, LRESULT* pResult)
00142 {
00143         SetupList(false);
00144 
00145         m_list.SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
00146 
00147         *pResult = 0;
00148 }
00149 
00150 void CFavoriteOrganizeDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
00151 {
00152         if(nIDCtl != IDC_LIST2) return;
00153 
00154         int nItem = lpDrawItemStruct->itemID;
00155         CRect rcItem = lpDrawItemStruct->rcItem;
00156 
00157         CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
00158 
00159         if(!!m_list.GetItemState(nItem, LVIS_SELECTED))
00160         {
00161                 FillRect(pDC->m_hDC, rcItem, CBrush(0xf1dacc));
00162                 FrameRect(pDC->m_hDC, rcItem, CBrush(0xc56a31));
00163         }
00164         else
00165         {
00166                 CBrush b;
00167                 b.CreateSysColorBrush(COLOR_WINDOW);
00168                 FillRect(pDC->m_hDC, rcItem, b);
00169         }
00170 
00171         CString str = m_list.GetItemText(nItem, 0);
00172 
00173         pDC->SetTextColor(0);
00174         pDC->TextOut(rcItem.left+3, (rcItem.top+rcItem.bottom - pDC->GetTextExtent(str).cy)/2, str);
00175 }
00176 
00177 void CFavoriteOrganizeDlg::OnBnClickedButton1()
00178 {
00179         if(POSITION pos = m_list.GetFirstSelectedItemPosition())
00180         {
00181                 m_list.SetFocus();
00182                 m_list.EditLabel(m_list.GetNextSelectedItem(pos));
00183         }
00184 }
00185 
00186 void CFavoriteOrganizeDlg::OnLvnEndlabeleditList2(NMHDR* pNMHDR, LRESULT* pResult)
00187 {
00188         NMLVDISPINFO* pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
00189         if(pDispInfo->item.iItem >= 0 && pDispInfo->item.pszText)
00190                 m_list.SetItemText(pDispInfo->item.iItem, 0, pDispInfo->item.pszText);
00191         *pResult = 0;
00192 }
00193 
00194 void CFavoriteOrganizeDlg::OnBnClickedButton2()
00195 {
00196         if(POSITION pos = m_list.GetFirstSelectedItemPosition())
00197         {
00198                 int nItem = m_list.GetNextSelectedItem(pos);
00199                 if(nItem < 0 || nItem >= m_list.GetItemCount()) return;
00200 
00201                 m_list.DeleteItem(nItem);
00202 
00203                 nItem = min(nItem, m_list.GetItemCount()-1);
00204 
00205                 m_list.SetSelectionMark(nItem);
00206                 m_list.SetItemState(nItem, LVIS_SELECTED, LVIS_SELECTED);
00207         }
00208 }
00209 
00210 void CFavoriteOrganizeDlg::OnBnClickedButton3()
00211 {
00212         if(POSITION pos = m_list.GetFirstSelectedItemPosition())
00213         {
00214                 int nItem = m_list.GetNextSelectedItem(pos);
00215                 if(nItem <= 0) return;
00216 
00217                 DWORD_PTR data = m_list.GetItemData(nItem);
00218                 CString str = m_list.GetItemText(nItem, 0);
00219 
00220                 m_list.DeleteItem(nItem);
00221 
00222                 nItem--;
00223 
00224                 m_list.InsertItem(nItem, str);
00225                 m_list.SetItemData(nItem, data);
00226                 m_list.SetSelectionMark(nItem);
00227                 m_list.SetItemState(nItem, LVIS_SELECTED, LVIS_SELECTED);
00228         }
00229 }
00230 
00231 void CFavoriteOrganizeDlg::OnBnClickedButton7()
00232 {
00233         if(POSITION pos = m_list.GetFirstSelectedItemPosition())
00234         {
00235                 int nItem = m_list.GetNextSelectedItem(pos);
00236                 if(nItem < 0 || nItem >= m_list.GetItemCount()-1) return;
00237 
00238                 DWORD_PTR data = m_list.GetItemData(nItem);
00239                 CString str = m_list.GetItemText(nItem, 0);
00240 
00241                 m_list.DeleteItem(nItem);
00242 
00243                 nItem++;
00244 
00245                 m_list.InsertItem(nItem, str);
00246                 m_list.SetItemData(nItem, data);
00247                 m_list.SetSelectionMark(nItem);
00248                 m_list.SetItemState(nItem, LVIS_SELECTED, LVIS_SELECTED);
00249         }
00250 }
00251 
00252 void CFavoriteOrganizeDlg::OnTcnSelchangingTab1(NMHDR *pNMHDR, LRESULT *pResult)
00253 {
00254         SetupList(true);
00255 
00256         *pResult = 0;
00257 }
00258 
00259 void CFavoriteOrganizeDlg::OnBnClickedOk()
00260 {
00261         SetupList(true);
00262 
00263         AfxGetAppSettings().SetFav(FAV_FILE, m_sl[0]);
00264         AfxGetAppSettings().SetFav(FAV_DVD, m_sl[1]);
00265         AfxGetAppSettings().SetFav(FAV_DEVICE, m_sl[2]);
00266 
00267         OnOK();
00268 }
00269 
00270 void CFavoriteOrganizeDlg::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
00271 {
00272         __super::OnActivate(nState, pWndOther, bMinimized);
00273 
00274         if(nState == WA_ACTIVE)
00275                 m_list.SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
00276 }
00277 
00278 void CFavoriteOrganizeDlg::OnSize(UINT nType, int cx, int cy)
00279 {
00280         __super::OnSize(nType, cx, cy);
00281 
00282         if(IsWindow(m_list))
00283                 m_list.SetColumnWidth(0, LVSCW_AUTOSIZE_USEHEADER);
00284 }

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