// netDoc.cpp : implementation of the CNetDoc class // #include "stdafx.h" #include "net.h" #include "netDoc.h" #include "MainFrm.h" #include "defines.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif extern CNetApp theApp; ///////////////////////////////////////////////////////////////////////////// // CNetDoc IMPLEMENT_DYNCREATE(CNetDoc, CDocument) BEGIN_MESSAGE_MAP(CNetDoc, CDocument) //{{AFX_MSG_MAP(CNetDoc) ON_COMMAND(ID_FILE_CLOSE, OnFileClose) ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs) ON_UPDATE_COMMAND_UI(ID_FILE_SAVE_AS, OnUpdateFileSaveAs) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CNetDoc construction/destruction CNetDoc::CNetDoc() { CMainFrame *pMainFrame = GETMAINFRAME; if (pMainFrame->m_bCreateBitmapWindow) { m_pBitmapWindow = new LBitmapWindow; } else { m_pBitmapWindow = NULL; } m_pInetRemoteClient = NULL; m_bBitmapWindowInList = FALSE; } CNetDoc::~CNetDoc() { CMainFrame *pMain = GETMAINFRAME; if (m_pBitmapWindow != NULL) { if (m_bBitmapWindowInList == FALSE) { delete m_pBitmapWindow; m_pBitmapWindow = NULL; } } if(pMain->m_bServerStarted) { L_CHAR ExtraInfo[10]; L_UINT32 uExtraLength; memset(ExtraInfo, 0, sizeof(ExtraInfo)); sprintf(ExtraInfo, "%u", m_uWindowID); uExtraLength = strlen(ExtraInfo) + 1; pMain->m_Inet.SendCloseWinRsp(m_pInetRemoteClient, 0, uExtraLength, ExtraInfo, 1); } } BOOL CNetDoc::OnNewDocument() { if (!CDocument::OnNewDocument()) return FALSE; CMainFrame *pMainFrame = GETMAINFRAME; // if client want to get bitmap // or server received bitmap after the client send it if (pMainFrame->m_bCreateBitmapWindow) { m_pBitmapWindow->Copy(*pMainFrame->m_pBitmapBase); m_pBitmapWindow->SetZoomPercent(100); memset(theApp.m_szCaption, 0, sizeof(theApp.m_szCaption)); if(pMainFrame->m_bServerStarted) { lstrcpy(theApp.m_szCaption,_T("Bitmap received from remote computer")); } else { pMainFrame->m_hLastLoadedWnd = m_pBitmapWindow->GetBitmapWnd(); lstrcpy(theApp.m_szCaption,_T("Bitmap received from remote server")); } } else // if server side and just the client created the window { m_pBitmapWindow = NULL; } if(pMainFrame->m_bServerStarted) { m_pInetRemoteClient = pMainFrame->m_pInetRemoteServer; pMainFrame->m_pInetRemoteServer = NULL; } SetTitle(theApp.m_szCaption); return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CNetDoc serialization void CNetDoc::Serialize(CArchive& ar) { if (ar.IsStoring()) { // TODO: add storing code here } else { // TODO: add loading code here } } ///////////////////////////////////////////////////////////////////////////// // CNetDoc diagnostics #ifdef _DEBUG void CNetDoc::AssertValid() const { CDocument::AssertValid(); } void CNetDoc::Dump(CDumpContext& dc) const { CDocument::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CNetDoc commands BOOL CNetDoc::OnOpenDocument(LPCTSTR lpszPathName) { L_BOOL bRet = TRUE; if (!CDocument::OnOpenDocument(lpszPathName)) return FALSE; L_TCHAR szMsg[_MAX_PATH]; L_TCHAR szFileName[_MAX_PATH]; lstrcpy(szFileName, lpszPathName); L_INT nRet = this->m_pBitmapWindow->Load(szFileName); if (nRet == SUCCESS) { //Set properties } else if(nRet == ERROR_PDF_BAD_INITIALIZATION_FILES) { if( IDYES == MessageBox( AfxGetMainWnd()->m_hWnd, TEXT("LEADTOOLS PDF plugin is not found, do you want to download the plugin now?"), TEXT("Open file"), MB_ICONEXCLAMATION | MB_YESNO)) ShellExecute(AfxGetMainWnd()->m_hWnd, TEXT("open"), TEXT("http://www.leadtools.com/ReleaseDownloads/v14/LEADTOOLSPDFRuntime.exe"), NULL, NULL, SW_SHOWNORMAL); bRet = FALSE; } else { wsprintf(szMsg, _T("Error [%d] Loading File[%s]"), nRet, szFileName); AfxMessageBox(szMsg); bRet = FALSE; } return bRet; } BOOL CNetDoc::OnSaveDocument(LPCTSTR lpszPathName) { LBitmapBase Bitmap; LFile LeadFile ; FILEINFO FileInfo ; L_TCHAR szMsg[_MAX_PATH]; L_TCHAR szFileName[_MAX_PATH]; L_INT nRet = 0; lstrcpy(szFileName, lpszPathName); LeadFile.SetBitmap(&Bitmap) ; LeadFile.SetFileName(szFileName) ; LeadFile.GetInfo(&FileInfo, sizeof(FILEINFO)); nRet = m_pBitmapWindow->Save(szFileName,FileInfo.Format,0,2, 1, NULL); if (nRet != SUCCESS) { wsprintf(szMsg, _T("Error [%d] Saving File[%s]"), nRet, szFileName); AfxMessageBox(szMsg); } else { SetModifiedFlag(FALSE); } return (nRet == SUCCESS); } void CNetDoc::OnFileClose() { CDocument::OnFileClose(); } void CNetDoc::OnFileSaveAs() { OPENFILENAME SaveFileName; SAVEDLGPARAMS SaveParms; memset(&SaveParms, 0, sizeof(SAVEDLGPARAMS)); memset(&SaveFileName, 0, sizeof(OPENFILENAME)); SaveFileName.lStructSize = sizeof (OPENFILENAME); SaveFileName.lpstrTitle = _T("Save As"); m_pBitmapWindow->DialogFile()->SetOpenFileName(&SaveFileName); m_pBitmapWindow->DialogFile()->GetSaveParams(&SaveParms, sizeof(SaveParms)); SaveParms.uStructSize = sizeof(SAVEDLGPARAMS); SaveParms.pBitmap = m_pBitmapWindow->GetHandle(); SaveParms.nBitsPerPixel = m_pBitmapWindow->GetBitsPerPixel(); SaveParms.nFormat = FILE_BMP; SaveParms.nQFactor = 2; SaveParms.nStampBits = 24; SaveParms.nStampWidth = 120; SaveParms.nStampHeight = 120; SaveParms.uSaveMulti = MULTIPAGE_OPERATION_REPLACE ; SaveParms.uDlgFlags = DLG_SAVE_SHOW_FILEOPTIONS_PROGRESSIVE | DLG_SAVE_SHOW_FILEOPTIONS_MULTIPAGE | DLG_SAVE_SHOW_FILEOPTIONS_STAMP | DLG_SAVE_SHOW_FILEOPTIONS_QFACTOR | DLG_SAVE_SHOW_FILEOPTIONS_J2KOPTIONS | DLG_SAVE_SHOW_FILEOPTIONS_BASICJ2KOPTIONS ; m_pBitmapWindow->DialogFile()->SetSaveParams(&SaveParms); if(m_pBitmapWindow->DialogFile()->DoModalSave(m_pBitmapWindow->GetBitmapWnd())==SUCCESS_DLG_OK) { L_INT nRet = 0; FILEJ2KOPTIONS FileJ2KOptions ; ZeroMemory(&FileJ2KOptions,sizeof(FILEJ2KOPTIONS)); m_pBitmapWindow->DialogFile()->GetSaveParams(&SaveParms, sizeof(SaveParms)); if((SaveParms.nFormat == FILE_J2K)|| (SaveParms.nFormat == FILE_JP2)|| (SaveParms.nFormat == FILE_CMW)|| (SaveParms.nFormat == FILE_TIF_J2K)|| (SaveParms.nFormat == FILE_TIF_CMW)) { /*Restore the old J2K Options*/ LFileSettings::GetJ2KOptions(&FileJ2KOptions,sizeof(FILEJ2KOPTIONS)); LFileSettings::SetJ2KOptions(&SaveParms.FileJ2KOptions); } nRet = m_pBitmapWindow->Save(SaveParms.szFileName, SaveParms.nFormat, SaveParms.nBitsPerPixel, SaveParms.nQFactor, NULL); if((SaveParms.nFormat == FILE_J2K)|| (SaveParms.nFormat == FILE_JP2)|| (SaveParms.nFormat == FILE_CMW)|| (SaveParms.nFormat == FILE_TIF_J2K)|| (SaveParms.nFormat == FILE_TIF_CMW)) { /*Restore the old J2K Options*/ LFileSettings::SetJ2KOptions(&SaveParms.FileJ2KOptions); } if (nRet != SUCCESS) { L_TCHAR szMsg[_MAX_PATH]; wsprintf(szMsg, _T("Error [%d] Saving File[%s]"), nRet, SaveParms.szFileName); AfxMessageBox(szMsg); } else { L_TCHAR zsFileName[255]; L_TCHAR zsName[50]; L_TCHAR zsExt[5]; memset(zsFileName,0,sizeof(zsFileName)); memset(zsName,0,sizeof(zsName)); memset(zsExt,0,sizeof(zsExt)); L_UINT uSize = sizeof(zsFileName); m_pBitmapWindow->GetFileName(zsFileName, &uSize); _tsplitpath(zsFileName, NULL, NULL, zsName, zsExt); lstrcat(zsName, zsExt); SetTitle(zsName); m_pBitmapWindow->Load(); } } } void CNetDoc::OnUpdateFileSaveAs(CCmdUI* pCmdUI) { pCmdUI->Enable((m_pBitmapWindow != NULL)); } void CNetDoc::OnCloseDocument() { CMainFrame *pMain = GETMAINFRAME; HWND hwnd = NULL; if (!pMain || !m_pBitmapWindow) { CDocument::OnCloseDocument(); return; } if ( LDictionary_IsBitmap(m_pBitmapWindow) ) { hwnd = m_pBitmapWindow->GetBitmapWnd(); } if (pMain->m_bConnectedToRemoteServer && hwnd == pMain->m_hLastLoadedWnd) { pMain->m_bGetBitmap = TRUE; pMain->m_hLastLoadedWnd = NULL; } CDocument::OnCloseDocument(); }