VSRipDlg.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 // VSRipDlg.cpp : implementation file
00023 //
00024 
00025 #include "stdafx.h"
00026 #include <afxpriv.h>
00027 #include "VSRip.h"
00028 #include "VSRipDlg.h"
00029 
00030 #ifdef _DEBUG
00031 #define new DEBUG_NEW
00032 #endif
00033 
00034 
00035 // CVSRipDlg dialog
00036 
00037 CVSRipDlg::CVSRipDlg(CWnd* pParent /*=NULL*/)
00038         : CDialog(CVSRipDlg::IDD, pParent)
00039 {
00040         m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
00041         m_dlgpos = NULL;
00042 
00043         m_pVSFRipper = new CVobSubFileRipper();
00044 }
00045 
00046 CVSRipDlg::~CVSRipDlg()
00047 {
00048         m_pVSFRipper->SetCallBack(NULL);
00049 }
00050 
00051 void CVSRipDlg::DoDataExchange(CDataExchange* pDX)
00052 {
00053         CDialog::DoDataExchange(pDX);
00054         DDX_Control(pDX, IDC_DLGRECT, m_dlgrect);
00055         DDX_Control(pDX, IDC_HEADERSEP, m_hdrline);
00056         DDX_Control(pDX, IDC_FOOTERSEP, m_ftrline);
00057 }
00058 
00059 void CVSRipDlg::ShowNext()
00060 {
00061         POSITION prev = m_dlgpos;
00062         m_dlgpos = GetNext();
00063 
00064         if(prev && prev != m_dlgpos)
00065         {
00066                 m_dlgs.GetAt(prev)->OnNext();
00067                 m_dlgs.GetAt(prev)->ShowWindow(SW_HIDE);
00068         }
00069 
00070         if(m_dlgpos)
00071         {
00072                 CVSRipPage* pDlg = m_dlgs.GetAt(m_dlgpos);
00073                 CRect dr;
00074                 m_dlgrect.GetClientRect(dr);
00075                 m_dlgrect.MapWindowPoints(this, dr);
00076                 pDlg->MoveWindow(dr);
00077                 pDlg->ShowWindow(SW_SHOWNORMAL);
00078                 Invalidate();
00079         }
00080 }
00081 
00082 void CVSRipDlg::ShowPrev()
00083 {
00084         POSITION next = m_dlgpos;
00085         m_dlgpos = GetPrev();
00086 
00087         if(next && next != m_dlgpos)
00088         {
00089                 m_dlgs.GetAt(next)->OnPrev();
00090                 m_dlgs.GetAt(next)->ShowWindow(SW_HIDE);
00091         }
00092 
00093         if(m_dlgpos)
00094         {
00095                 CVSRipPage* pDlg = m_dlgs.GetAt(m_dlgpos);
00096                 CRect dr;
00097                 m_dlgrect.GetClientRect(dr);
00098                 m_dlgrect.MapWindowPoints(this, dr);
00099                 pDlg->MoveWindow(dr);
00100                 pDlg->ShowWindow(SW_SHOWNORMAL);
00101                 Invalidate();
00102         }
00103 }
00104 
00105 POSITION CVSRipDlg::GetNext()
00106 {
00107         POSITION pos = m_dlgpos;
00108         if(pos && m_dlgs.GetAt(pos)->CanGoNext()) m_dlgs.GetNext(pos);
00109         else if(pos && !m_dlgs.GetAt(pos)->CanGoNext()) pos = NULL;
00110         else pos = m_dlgs.GetHeadPosition();
00111         return(pos);
00112 }
00113 
00114 POSITION CVSRipDlg::GetPrev()
00115 {
00116         POSITION pos = m_dlgpos;
00117         if(pos && m_dlgs.GetAt(pos)->CanGoPrev()) m_dlgs.GetPrev(pos);
00118         else if(pos && !m_dlgs.GetAt(pos)->CanGoPrev()) pos = NULL;
00119         else pos = m_dlgs.GetTailPosition();
00120         return(pos);
00121 }
00122 
00123 BEGIN_MESSAGE_MAP(CVSRipDlg, CDialog)
00124         ON_WM_PAINT()
00125         ON_WM_QUERYDRAGICON()
00126         ON_MESSAGE_VOID(WM_KICKIDLE, OnKickIdle)
00127         ON_BN_CLICKED(IDC_BUTTON1, OnPrev)
00128         ON_UPDATE_COMMAND_UI(IDC_BUTTON1, OnUpdatePrev)
00129         ON_BN_CLICKED(IDC_BUTTON2, OnNext)
00130         ON_UPDATE_COMMAND_UI(IDC_BUTTON2, OnUpdateNext)
00131         ON_BN_CLICKED(IDCANCEL, OnClose)
00132         ON_UPDATE_COMMAND_UI(IDCANCEL, OnUpdateClose)
00133 END_MESSAGE_MAP()
00134 
00135 // CVSRipDlg message handlers
00136 
00137 BOOL CVSRipDlg::OnInitDialog()
00138 {
00139         CDialog::OnInitDialog();
00140 
00141         // Set the icon for this dialog.  The framework does this automatically
00142         //  when the application's main window is not a dialog
00143         SetIcon(m_hIcon, TRUE);                 // Set big icon
00144         SetIcon(m_hIcon, FALSE);                // Set small icon
00145 
00146         if(CMenu* pSysMenu = GetSystemMenu(FALSE))
00147         {
00148                 pSysMenu->RemoveMenu(SC_SIZE, MF_BYCOMMAND);
00149                 pSysMenu->RemoveMenu(SC_MAXIMIZE, MF_BYCOMMAND);
00150         }
00151 
00152         CRect cr;
00153         GetClientRect(cr);
00154         CRect r;
00155         m_hdrline.GetClientRect(r);
00156         m_hdrline.MapWindowPoints(this, r);
00157         r.left = 0;
00158         r.right = cr.right;
00159         r.bottom+=2;
00160         m_hdrline.MoveWindow(r);
00161         m_ftrline.GetClientRect(r);
00162         m_ftrline.MapWindowPoints(this, r);
00163         r.left = 0;
00164         r.right = cr.right;
00165         r.bottom+=2;
00166         m_ftrline.MoveWindow(r);
00167 
00168         m_pVSFRipper = new CVobSubFileRipper();
00169 
00170         CAutoPtr<CVSRipPage> pPage;
00171 
00172         pPage.Attach(new CVSRipFileDlg(m_pVSFRipper));
00173         pPage->Create(CVSRipFileDlg::IDD, this);
00174         m_dlgs.AddTail(pPage);
00175 
00176         pPage.Attach(new CVSRipPGCDlg(m_pVSFRipper));
00177         pPage->Create(CVSRipPGCDlg::IDD, this);
00178         m_dlgs.AddTail(pPage);
00179 
00180         pPage.Attach(new CVSRipIndexingDlg(m_pVSFRipper));
00181         pPage->Create(CVSRipIndexingDlg::IDD, this);
00182         m_dlgs.AddTail(pPage);
00183 
00184         if(__argc > 1)
00185         {
00186                 m_pVSFRipper->SetCallBack((IVSFRipperCallback*)m_dlgs.GetTail());
00187 
00188                 if(S_OK != m_pVSFRipper->LoadParamFile(CString(__targv[1])))
00189                 {
00190                         AfxMessageBox(_T("Error parsing parameter file!"), MB_OK);
00191                         EndDialog(IDCANCEL);
00192                         return FALSE;
00193                 }
00194 
00195                 ShowPrev();
00196         }
00197         else
00198         {
00199         ShowNext();
00200         }
00201 
00202         return TRUE;  // return TRUE  unless you set the focus to a control
00203 }
00204 
00205 // If you add a minimize button to your dialog, you will need the code below
00206 //  to draw the icon.  For MFC applications using the document/view model,
00207 //  this is automatically done for you by the framework.
00208 
00209 void CVSRipDlg::OnPaint() 
00210 {
00211         if (IsIconic())
00212         {
00213                 CPaintDC dc(this); // device context for painting
00214 
00215                 SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
00216 
00217                 // Center icon in client rectangle
00218                 int cxIcon = GetSystemMetrics(SM_CXICON);
00219                 int cyIcon = GetSystemMetrics(SM_CYICON);
00220                 CRect rect;
00221                 GetClientRect(&rect);
00222                 int x = (rect.Width() - cxIcon + 1) / 2;
00223                 int y = (rect.Height() - cyIcon + 1) / 2;
00224 
00225                 // Draw the icon
00226                 dc.DrawIcon(x, y, m_hIcon);
00227         }
00228         else
00229         {
00230                 CPaintDC dc(this); // device context for painting
00231 
00232                 CWnd* pHdrSep = GetDlgItem(IDC_HEADERSEP);
00233                 CRect r;
00234                 m_hdrline.GetClientRect(r);
00235                 m_hdrline.MapWindowPoints(this, r);
00236                 CRect cr;
00237                 GetClientRect(cr);
00238                 dc.FillSolidRect(CRect(0,0,cr.right,r.top), 0xffffff);
00239 
00240                 if(m_dlgpos)
00241                 {
00242                         CVSRipPage* pWnd = m_dlgs.GetAt(m_dlgpos);
00243                         CFont hdrfont, descfont;
00244                         hdrfont.CreateFont(16,0,0,0,FW_BOLD,0,0,0,DEFAULT_CHARSET,
00245                                 OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,ANTIALIASED_QUALITY,DEFAULT_PITCH,
00246                                 _T("Times New Roman"));
00247                         descfont.CreateFont(14,0,0,0,FW_NORMAL,0,0,0,DEFAULT_CHARSET,
00248                                 OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,ANTIALIASED_QUALITY,DEFAULT_PITCH,
00249                                 _T("Arial"));
00250                         CFont* pOld = dc.SelectObject(&hdrfont);
00251                         dc.DrawText(pWnd->GetHeaderText(), CRect(10,5,cr.right,r.top), DT_WORDBREAK);
00252                         dc.SelectObject(&descfont);
00253                         dc.DrawText(pWnd->GetDescText(), CRect(20,22,cr.right,r.top), DT_WORDBREAK);
00254                         dc.SelectObject(pOld);
00255                 }
00256 
00257                 CDialog::OnPaint();
00258         }
00259 }
00260 
00261 void CVSRipDlg::OnKickIdle()
00262 {
00263         UpdateDialogControls(this, false);
00264 
00265         for(CWnd* pChild = GetWindow(GW_CHILD); pChild; pChild = pChild->GetNextWindow())
00266         {
00267                 if(pChild->IsKindOf(RUNTIME_CLASS(CVSRipPage)))
00268                         pChild->UpdateDialogControls(pChild, false);
00269         }
00270 }
00271 
00272 // The system calls this function to obtain the cursor to display while the user drags
00273 //  the minimized window.
00274 HCURSOR CVSRipDlg::OnQueryDragIcon()
00275 {
00276         return static_cast<HCURSOR>(m_hIcon);
00277 }
00278 
00279 void CVSRipDlg::OnPrev()
00280 {
00281         ShowPrev();
00282 }
00283 
00284 void CVSRipDlg::OnUpdatePrev(CCmdUI* pCmdUI)
00285 {
00286         if(m_dlgpos) pCmdUI->SetText(m_dlgs.GetAt(m_dlgpos)->GetPrevText());
00287         pCmdUI->Enable(!!GetPrev());
00288 }
00289 
00290 void CVSRipDlg::OnNext()
00291 {
00292         ShowNext();
00293 }
00294 
00295 void CVSRipDlg::OnUpdateNext(CCmdUI* pCmdUI)
00296 {
00297         if(m_dlgpos) pCmdUI->SetText(m_dlgs.GetAt(m_dlgpos)->GetNextText());
00298         pCmdUI->Enable(!!GetNext());
00299 }
00300 
00301 void CVSRipDlg::OnClose()
00302 {
00303         if(m_dlgpos) m_dlgs.GetAt(m_dlgpos)->OnClose();
00304 
00305         OnCancel();
00306 }
00307 
00308 void CVSRipDlg::OnUpdateClose(CCmdUI* pCmdUI)
00309 {
00310         if(m_dlgpos) pCmdUI->SetText(m_dlgs.GetAt(m_dlgpos)->GetCloseText());
00311         pCmdUI->Enable(!m_dlgpos || m_dlgs.GetAt(m_dlgpos)->CanClose());
00312 }

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