// SaveListDlg.cpp : implementation file // #include "stdafx.h" #include "segdemo.h" #include "SaveListDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CSaveListDlg dialog CSaveListDlg::CSaveListDlg(CWnd* pParent /*=NULL*/) : CDialog(CSaveListDlg::IDD, pParent) { m_pRasterList = NULL; CoCreateInstance(CLSID_LEADRaster, NULL, CLSCTX_ALL, IID_ILEADRaster, (void**)&m_pRasterList); //{{AFX_DATA_INIT(CSaveListDlg) //}}AFX_DATA_INIT } CSaveListDlg::~CSaveListDlg() { if(m_pRasterList) m_pRasterList->Release(); } void CSaveListDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CSaveListDlg) DDX_Control(pDX, IDC_MRC_LIST_UP_BUT, m_btnUp); DDX_Control(pDX, IDC_MRC_LIST_DOWN_BUT, m_btnDown); DDX_Control(pDX, IDC_MRC_LST_SAV_CMB, m_cmbSaveList); DDX_Control(pDX, IDC_MRC_SAVE_LST, m_SaveList); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CSaveListDlg, CDialog) //{{AFX_MSG_MAP(CSaveListDlg) ON_BN_CLICKED(IDC_MRC_LIST_UP_BUT, OnMrcListUp) ON_BN_CLICKED(IDC_MRC_LIST_DOWN_BUT, OnMrcListDown) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CSaveListDlg message handlers BOOL CSaveListDlg::OnInitDialog() { CDialog::OnInitDialog(); HICON hIcon; int i =0; CString StripName; m_cmbSaveList.AddString(TEXT("Standard MRC")); m_cmbSaveList.AddString(TEXT("LEAD MRC")); m_cmbSaveList.AddString(TEXT("PDF")); m_cmbSaveList.SetCurSel(0); hIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_DOWN)); m_btnDown.SetIcon(hIcon); hIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_UP)); m_btnUp.SetIcon(hIcon); POSITION pos = AfxGetApp()->GetFirstDocTemplatePosition(); while (pos != NULL) { CDocTemplate* pTemplate = AfxGetApp()->GetNextDocTemplate(pos); POSITION posDoc = pTemplate->GetFirstDocPosition(); while(posDoc != NULL) { CSegDemoDoc * pDoc = (CSegDemoDoc *)pTemplate->GetNextDoc(posDoc); m_SaveList.AddString(Strip(pDoc->GetTitle())); m_pRasterList->InsertBitmapListItem(-1, pDoc ->m_pRaster->GetBitmap()); m_SaveList.SetItemData(i,i); i++; } } m_SaveList.SetCurSel(0); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } CString CSaveListDlg ::Strip(CString szTitle) { int nEndPos = szTitle.GetLength() - 1; int nSlashPos; int nCount; TCHAR cX = '\0'; CString StripName = ""; for(nSlashPos = nEndPos; nSlashPos >= 0; nSlashPos--) { if(szTitle.GetAt(nSlashPos) == '\\') break; } for(nCount = 0, nSlashPos++; nSlashPos < nEndPos; nSlashPos++, nCount++) { if (szTitle.GetAt(nSlashPos) == '.') break; StripName.Insert(nCount, szTitle.GetAt(nSlashPos)); } return StripName; } void CSaveListDlg::OnMrcListUp() { int nIndex; CString StripName; unsigned int uItemData; int nListCount; nListCount = m_SaveList.GetCount(); nIndex = m_SaveList.GetCurSel(); if(nIndex == 0) return; m_SaveList.GetText(nIndex, StripName); uItemData = m_SaveList.GetItemData(nIndex); m_SaveList.InsertString(min(nListCount, max (0, nIndex - 1 )), StripName); m_SaveList.SetItemData(min(nListCount, max (0, nIndex - 1 )), uItemData); m_SaveList.SetCurSel(min(nListCount, max (0, nIndex - 1 ))); nListCount = m_SaveList.GetCount(); nIndex = m_SaveList.GetCurSel(); m_SaveList.DeleteString(min(nListCount, max (0, nIndex + 2))); } void CSaveListDlg::OnMrcListDown() { int nIndex; CString StripName; unsigned int uItemData; int nListCount; nListCount = m_SaveList.GetCount(); nIndex = m_SaveList.GetCurSel(); if(nIndex == nListCount-1) return; m_SaveList.GetText(nIndex, StripName); uItemData = m_SaveList.GetItemData(nIndex); m_SaveList.GetItemData(nIndex); m_SaveList.InsertString(min(nListCount + 1, max (0, nIndex + 2)), StripName); m_SaveList.SetItemData(min(nListCount + 1, max (0, nIndex + 2)), uItemData); m_SaveList.SetCurSel(min(nListCount + 1, max (0, nIndex + 2))); nListCount = m_SaveList.GetCount(); nIndex = m_SaveList.GetCurSel(); m_SaveList.DeleteString(min(nListCount, max (0, nIndex - 2))); } void CSaveListDlg::OnOK() { CSegDemoApp* pApp = (CSegDemoApp*)AfxGetApp(); pApp->m_pRasterFileDlg->PutFileFormatsCount(1); switch(m_cmbSaveList.GetCurSel()) { case 0: pApp->m_pRasterFileDlg->GetFileFormats(0)->PutFormat(FF_SAVE_TIFF); pApp->m_pRasterFileDlg->GetFileFormats(0)->PutBitsPerPixelCount(1); pApp->m_pRasterFileDlg->GetFileFormats(0)->PutBitsPerPixelFormat(0, 24); pApp->m_pRasterFileDlg->GetFileFormats(0)->PutSubFormat(0, FF_SAVE_SUB_TIFF24_MRC); pApp->m_pRasterIO->PutPictureCoder(MRC_PICTURE_COMPRESSION_JPEG); pApp->m_pRasterIO->PutPictureQFactor(pApp->m_MrcOptions.nPictureQFactor); pApp->m_pRasterIO->PutMaskCoder((MRCMaskCoderConstants)pApp->m_MrcOptions.nMaskCoder); break; case 1: pApp->m_pRasterFileDlg->GetFileFormats(0)->PutFormat(FF_SAVE_TIFF); pApp->m_pRasterFileDlg->GetFileFormats(0)->PutBitsPerPixelCount(1); pApp->m_pRasterFileDlg->GetFileFormats(0)->PutBitsPerPixelFormat(0, 24); pApp->m_pRasterFileDlg->GetFileFormats(0)->PutSubFormat(0, FF_SAVE_SUB_TIFF24_LEAD_MRC); pApp->m_pRasterIO->PutPictureQFactor(pApp->m_MrcOptions.nPictureQFactor); pApp->m_pRasterIO->PutMaskCoder((MRCMaskCoderConstants)pApp->m_MrcOptions.nMaskCoder); pApp->m_pRasterIO->PutPictureCoder((MRCPictureCoderConstants)pApp->m_MrcOptions.nPictureCoder); pApp->m_pRasterIO->PutText2BitCoder((MRCText2BitCoderConstants)pApp->m_MrcOptions.nTextCoder2Bit); pApp->m_pRasterIO->PutGrayscale8BitQFactor(pApp->m_MrcOptions.nGrayscale8BitFactor); pApp->m_pRasterIO->PutGrayscale2BitCoder((MRCGrayscale2BitCoderConstants)pApp->m_MrcOptions.nGrayscale2BitCoder); pApp->m_pRasterIO->PutGrayscale8BitCoder((MRCGrayscale8BitCoderConstants)pApp->m_MrcOptions.nGrayscale8BitCoder); break; case 2: pApp->m_pRasterFileDlg->GetFileFormats(0)->PutFormat(FF_SAVE_PDF); pApp->m_pRasterFileDlg->GetFileFormats(0)->PutBitsPerPixelCount(1); pApp->m_pRasterFileDlg->GetFileFormats(0)->PutBitsPerPixelFormat(0, 24); pApp->m_pRasterFileDlg->GetFileFormats(0)->PutSubFormat(0, FF_SAVE_SUB_PDF24_PDF_LEAD_MRC); pApp->m_pRasterIO->PutPictureQFactor(pApp->m_PdfOptions.nPictureQFactor); pApp->m_pRasterIO->PutMaskCoder((MRCMaskCoderConstants)(pApp->m_PdfOptions.nMaskCoder + MRC_PDF_ONEBIT_COMPRESSION_ZIP)); pApp->m_pRasterIO->PutPictureCoder((MRCPictureCoderConstants)(MRC_PDF_PICTURE_COMPRESSION_JPEG)); pApp->m_pRasterIO->PutText2BitCoder((MRCText2BitCoderConstants)(pApp->m_PdfOptions.nTextCoder2Bit + MRC_PDF_TEXT_COMPRESSION_ZIP)); pApp->m_pRasterIO->PutGrayscale8BitQFactor(pApp->m_MrcOptions.nGrayscale8BitFactor); pApp->m_pRasterIO->PutGrayscale2BitCoder((MRCGrayscale2BitCoderConstants)pApp->m_MrcOptions.nGrayscale2BitCoder); pApp->m_pRasterIO->PutGrayscale8BitCoder((MRCGrayscale8BitCoderConstants)pApp->m_MrcOptions.nGrayscale8BitCoder); break; } pApp->m_pRasterFileDlg->PutFilter("ALL|*.*|TIF|*.tif|PDF|*.pdf"); pApp->m_pRasterFileDlg->PutEnableMethodErrors(FALSE); pApp->m_pRasterFileDlg->PutSubTypeIndex(0); pApp->m_pRasterFileDlg->PutSaveQFactor(2); pApp->m_pRasterFileDlg->PutFileDlgFlags(OFN_OVERWRITEPROMPT); pApp->m_pRasterFileDlg->PutUIFlags(SAVE_SHOW_FILEOPTIONS_BASICJ2KOPTIONS| SAVE_SHOW_FILEOPTIONS_J2KOPTIONS | SAVE_SHOW_FILEOPTIONS_MULTIPAGE | SAVE_SHOW_FILEOPTIONS_QFACTOR); pApp->m_pRasterFileDlg->PutDialogTitle("Save as LEAD MRC"); int nRet = pApp->m_pRasterFileDlg->ShowSaveDlg((long)pApp->GetMainWnd()->GetSafeHwnd()); if(nRet !=0) { pApp->DisplayLEADError(nRet); } else { if(pApp->m_pRasterFileDlg->GetDialogStatus()!= DLG_OK) return; } ILEADRaster *pRasterSaveList = NULL; CoCreateInstance(CLSID_LEADRaster, NULL, CLSCTX_ALL, IID_ILEADRaster, (void**)&pRasterSaveList); for(int i = 0; i < m_SaveList.GetCount(); ++i) { m_pRasterList->PutBitmapListIndex((short)m_SaveList.GetItemData(i)); pRasterSaveList->InsertBitmapListItem(i, m_pRasterList->GetBitmap()); } pApp->m_pRasterIO->PutMRCRasterCount(m_SaveList.GetCount()); int nCount = 0; POSITION pos = pApp->GetFirstDocTemplatePosition(); while (pos != NULL) { CDocTemplate* pTemplate = pApp->GetNextDocTemplate(pos); POSITION posDoc = pTemplate->GetFirstDocPosition(); while(posDoc != NULL) { CSegDemoDoc * pDoc = (CSegDemoDoc *)pTemplate->GetNextDoc(posDoc); pApp->m_pRasterIO->PutMRCRaster((short)m_SaveList.GetItemData(nCount), pDoc->m_pRasterMrc); nCount++; } } nRet = pApp->m_pRasterIO->SaveList(pRasterSaveList , pApp->m_pRasterFileDlg->GetFileName() , (RasterFileConstants)pApp->m_pRasterFileDlg->GetSaveFormat()); CDialog::OnOK(); }