Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

514 lines
13 KiB

  1. // NewFile.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "resource.h"
  5. #include "NewFile.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CNewFile property page
  13. TCHAR* pszFileNames[] = {_T("GPD"), _T("UFM"), _T("GTT")};
  14. TCHAR* pszExt[] = {_T(".GPD"), _T(".UFM"), _T(".GTT") };
  15. int iBitmap[] = {IDB_GPD_VIEWER,IDB_FONT_VIEWER,IDB_GLYPHMAP};
  16. WORD wID[] = {120,122,124 } ;
  17. IMPLEMENT_DYNCREATE(CNewFile, CPropertyPage)
  18. CNewFile::CNewFile() : CPropertyPage(CNewFile::IDD),FILES_NUM(3)
  19. {
  20. //{{AFX_DATA_INIT(CNewFile)
  21. m_csFileLoc = _T("");
  22. m_csNewFile = _T("");
  23. //}}AFX_DATA_INIT
  24. // m_bproj = FALSE ;
  25. }
  26. CNewFile::CNewFile(CPropertySheet *pcps): CPropertyPage(CNewFile::IDD),FILES_NUM(3)
  27. {
  28. // m_pcps = pcps ;
  29. }
  30. CNewFile::~CNewFile()
  31. {
  32. }
  33. void CNewFile::DoDataExchange(CDataExchange* pDX)
  34. {
  35. CPropertyPage::DoDataExchange(pDX);
  36. //{{AFX_DATA_MAP(CNewFile)
  37. DDX_Control(pDX, IDC_NEWFILES_LIST, m_clcFileName);
  38. DDX_Text(pDX, IDC_FILE_LOC, m_csFileLoc);
  39. DDX_Text(pDX, IDC_NEWFILENAME, m_csNewFile);
  40. //}}AFX_DATA_MAP
  41. }
  42. BEGIN_MESSAGE_MAP(CNewFile, CPropertyPage)
  43. //{{AFX_MSG_MAP(CNewFile)
  44. ON_BN_CLICKED(IDC_Browser, OnBrowser)
  45. ON_NOTIFY(NM_DBLCLK, IDC_NEWFILES_LIST, OnDblclkNewfilesList)
  46. ON_EN_CHANGE(IDC_NEWFILENAME, OnChangeNewFilename)
  47. ON_NOTIFY(NM_CLICK, IDC_NEWFILES_LIST, OnClickNewfilesList)
  48. //}}AFX_MSG_MAP
  49. END_MESSAGE_MAP()
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CNewFile message handlers
  52. /********************************************************************************
  53. BOOL CNewFile::OnSetActive()
  54. Do: Enumerate the file list to the list control box
  55. Args:
  56. Ret.
  57. *********************************************************************************/
  58. BOOL CNewFile::OnSetActive()
  59. {
  60. m_clcFileName.DeleteAllItems();
  61. // create object for imagelist, it didn't work when use this as reference.
  62. CImageList* pcil = new CImageList ;
  63. pcil->Create(32,32,ILC_COLOR4,3,1);
  64. CBitmap cb;
  65. for (int j =0; j< FILES_NUM; j++) {
  66. cb.LoadBitmap(iBitmap[j]);
  67. pcil->Add(&cb,RGB(0,0,0) );
  68. cb.DeleteObject();
  69. }
  70. m_clcFileName.SetImageList(pcil,LVSIL_NORMAL);
  71. // set the items with image and text
  72. LV_ITEM lvi;
  73. for (int i = 0; i< FILES_NUM; i++)
  74. {
  75. lvi.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM ;
  76. lvi.iItem = i;
  77. lvi.iSubItem = 0;
  78. lvi.pszText = pszFileNames[i];
  79. lvi.iImage = i;
  80. lvi.lParam = (ULONG_PTR)pszExt[i];
  81. m_clcFileName.InsertItem(&lvi);
  82. }
  83. return CPropertyPage::OnSetActive();
  84. }
  85. /********************************************************************************
  86. BOOL CNewFile::CallNewDoc()
  87. Do: this is workhourse. it load the resource file for gpd, gtt, ufm, creat gtt, ufm
  88. directory, and then creat file.
  89. *********************************************************************************/
  90. BOOL CNewFile::CallNewDoc()
  91. {
  92. UpdateData();
  93. /* Tell what is selected
  94. if (ufm, gtt)
  95. make new file based on selected files base.
  96. if( project file)
  97. {
  98. run Wizard :
  99. : user chose GPD template ->
  100. 1.Do this template make rc file(?)
  101. 2.what UFM, GTT are included in template
  102. 3.how can take care of ufm, gtt mentioned GPD
  103. 4.what user chose when make GPD template.
  104. Make sub directory W2K, UFM, GTT.
  105. }
  106. */
  107. // get selected file text name (ex. .UFM, .GTT
  108. int idContext = m_clcFileName.GetNextItem(-1,
  109. LVNI_ALL | LVNI_FOCUSED | LVNI_SELECTED);
  110. if (idContext == -1 )
  111. return FALSE ;
  112. union {ULONG_PTR lParam; LPCTSTR lpstrExt;};
  113. // get extention for file
  114. lParam = m_clcFileName.GetItemData(idContext);
  115. // compare the selected file name and parsing
  116. // Call new Document
  117. CWinApp *cwa = AfxGetApp();
  118. POSITION pos = cwa->GetFirstDocTemplatePosition();
  119. CString csExtName;
  120. CDocTemplate *pcdt ;
  121. while (pos != NULL){
  122. pcdt = cwa -> GetNextDocTemplate(pos);
  123. ASSERT (pcdt != NULL);
  124. ASSERT (pcdt ->IsKindOf(RUNTIME_CLASS(CDocTemplate)));
  125. pcdt ->GetDocString(csExtName, CDocTemplate::filterExt);
  126. if (csExtName == lpstrExt){
  127. // 1. create the file when a.created with project file b. created with file name
  128. // if (m_bproj || m_csNewFile.GetLength() != 0) {
  129. if (! m_csNewFile.GetLength())
  130. m_csNewFile = _T("Untitled") ;
  131. if (m_csNewFile.GetLength() != 0) {
  132. // check the file name if user put or not
  133. if (m_csNewFile.GetLength() == 0 ) {
  134. CString csErr ;
  135. csErr.LoadString(IDS_NoFileName) ;
  136. AfxMessageBox(csErr, MB_ICONEXCLAMATION);
  137. return FALSE ;
  138. } ;
  139. // make UFM, GTT directory if user create these file
  140. CString csDir = m_csFileLoc.Right(m_csFileLoc.ReverseFind(_T('\\'))) ;
  141. // create directory
  142. SECURITY_ATTRIBUTES st;
  143. st.nLength = sizeof(SECURITY_ATTRIBUTES);
  144. st.lpSecurityDescriptor = NULL;
  145. st.bInheritHandle = FALSE ;
  146. try {
  147. if (!csExtName.CompareNoCase(_T(".UFM")) ){
  148. if (!!csDir.CompareNoCase(_T("UFM")) ) {
  149. m_csFileLoc += _T("\\UFM") ;
  150. CreateDirectory(m_csFileLoc,&st) ;
  151. }
  152. }
  153. else if (!csExtName.CompareNoCase(_T(".GTT")) ){
  154. if (!!csDir.CompareNoCase(_T("GTT") ) ) {
  155. m_csFileLoc += _T("\\GTT") ;
  156. CreateDirectory(m_csFileLoc,&st) ;
  157. }
  158. }
  159. }
  160. catch (CException* pce) {
  161. pce->ReportError() ;
  162. pce->Delete() ;
  163. return FALSE ;
  164. } ;
  165. // check if specified named file is exist or not in the directory
  166. CString csFileName = m_csFileLoc +_T("\\") + m_csNewFile + csExtName;
  167. CFileFind cff ;
  168. if ( cff.FindFile(csFileName) ) {
  169. CString csMsg ;
  170. csMsg.LoadString(IDS_FileNewExist) ;
  171. if (AfxMessageBox (csMsg, MB_YESNO ) == IDNO)
  172. return FALSE ;
  173. }
  174. CFile cf(csFileName,CFile::modeCreate | CFile::modeWrite ) ;
  175. // load the UFM, GTT, GPD from the resources.
  176. for (unsigned i = 0 ; i < sizeof (*pszExt) ; i ++ ) {
  177. if (!csExtName.CompareNoCase(pszExt[i] ) )
  178. break;
  179. } ;
  180. WORD wi = wID [i] ;
  181. HRSRC hrsrc = FindResource(AfxGetResourceHandle(), MAKEINTRESOURCE(wID[i]),
  182. MAKEINTRESOURCE(IDR_NEWFILE));
  183. if (!hrsrc) {
  184. CString csErr ;
  185. csErr.LoadString(IDS_ResourceError) ;
  186. AfxMessageBox(csErr, MB_ICONEXCLAMATION ) ;
  187. return FALSE;
  188. } ;
  189. HGLOBAL hgMap = LoadResource(AfxGetResourceHandle(), hrsrc);
  190. if (!hgMap)
  191. return FALSE; // This should never happen!
  192. int nsize = SizeofResource(AfxGetResourceHandle(),hrsrc ) ;
  193. LPVOID lpv = LockResource(hgMap);
  194. cf.Write(lpv,nsize) ;
  195. cf.Close() ;
  196. pcdt->OpenDocumentFile(csFileName) ;
  197. // add the new file into the project tree.
  198. }
  199. else // 2.created the file with no file name, project
  200. pcdt->OpenDocumentFile(NULL);
  201. return TRUE;
  202. }
  203. }
  204. return FALSE;
  205. }
  206. /********************************************************************************
  207. void CNewFile::OnBrowser()
  208. Do: Using the old version browser rather than SHELL. code reuse in the MDT and
  209. faster than SHELL to be loaded
  210. Args:
  211. Ret.
  212. *********************************************************************************/
  213. void CNewFile::OnBrowser()
  214. {
  215. OPENFILENAME ofn ; // Used to send/get info to/from common dlg
  216. char acpath[_MAX_PATH] ; // Path is saved here (or an error message)
  217. BOOL brc = FALSE ; // Return code
  218. // Update the contents of csinitdir
  219. UpdateData(TRUE) ;
  220. // Load the open file name structure
  221. ofn.lStructSize = sizeof(ofn) ;
  222. ofn.hwndOwner = m_hWnd ;
  223. ofn.hInstance = GetModuleHandle(_T("MINIDEV.EXE")) ;
  224. ofn.lpstrFilter = ofn.lpstrCustomFilter = NULL ;
  225. ofn.nMaxCustFilter = ofn.nFilterIndex = 0 ;
  226. strcpy(acpath, _T("JUNK")) ; // No need to localize this string
  227. ofn.lpstrFile = acpath ;
  228. ofn.nMaxFile = _MAX_PATH ;
  229. ofn.lpstrFileTitle = NULL ;
  230. ofn.nMaxFileTitle = 0 ;
  231. ofn.lpstrInitialDir = NULL ; // in parent dialog box
  232. ofn.lpstrTitle = NULL ;
  233. ofn.Flags = OFN_HIDEREADONLY /*| OFN_ENABLEHOOK */| OFN_NOCHANGEDIR
  234. | OFN_NOTESTFILECREATE | OFN_ENABLETEMPLATE | OFN_NONETWORKBUTTON ;
  235. ofn.lpstrDefExt = NULL ;
  236. ofn.lpTemplateName = MAKEINTRESOURCE(IDD_FILEOPENORD) ;
  237. ofn.lpfnHook = NULL ;
  238. // Display the dialog box. If the user cancels, just return.
  239. if (!GetOpenFileName(&ofn))
  240. return ;
  241. // Take the bogus file name off the path and put the path into the page's
  242. // edit box.
  243. acpath[ofn.nFileOffset - 1] = 0 ;
  244. m_csFileLoc = (LPCTSTR) acpath ;
  245. UpdateData(FALSE) ;
  246. /* if (pidlSelected)
  247. pMalloc->Free(pidlSelected) ;
  248. pMalloc->Release() ;
  249. */
  250. }
  251. /********************************************************************************
  252. void CNewFile::OnOK()
  253. Do:
  254. Args:
  255. Ret.
  256. *********************************************************************************/
  257. void CNewFile::OnOK()
  258. {
  259. //to do
  260. /*
  261. Read what item is selected and open the file
  262. */
  263. if(CallNewDoc())
  264. CPropertyPage::OnOK();
  265. }
  266. /********************************************************************************
  267. void CNewFile::OnDblclkNewfilesList(NMHDR* pNMHDR, LRESULT* pResult)
  268. Do: Call the CallNewDoc() like OK () button, we need to check the filename is set or not
  269. Args:
  270. Ret.
  271. *********************************************************************************/
  272. void CNewFile::OnDblclkNewfilesList(NMHDR* pNMHDR, LRESULT* pResult)
  273. {
  274. if (CallNewDoc() )
  275. EndDialog(IDD_NewFile) ;
  276. // bug; need to close the dialog ?? OnOK() call directly does not works.
  277. *pResult = 0 ;
  278. }
  279. /********************************************************************************
  280. void CNewFile::OnCheckProject()
  281. Do: Enable and disable by checking the Project file name checkec status
  282. Args:
  283. Ret.
  284. *********************************************************************************/
  285. /*
  286. void CNewFile::OnCheckProject()
  287. {
  288. CEdit cePrjName;
  289. CWnd *pcw ;
  290. if ( m_cbEnPrj.GetCheck() ) {// check the button
  291. pcw = GetDlgItem(IDC_EDIT_PRJ_NAME) ;
  292. cePrjName.Attach(pcw->m_hWnd ) ;
  293. cePrjName.EnableWindow(TRUE) ;
  294. cePrjName.Detach() ;
  295. }
  296. else {
  297. pcw = GetDlgItem(IDC_EDIT_PRJ_NAME) ;
  298. cePrjName.Attach(pcw->m_hWnd ) ;
  299. cePrjName.EnableWindow(FALSE) ;
  300. cePrjName.Detach() ;
  301. } ;
  302. } ;
  303. */
  304. /********************************************************************************
  305. BOOL CNewFile::OnInitDialog()
  306. Do: Enumberate File name list
  307. Args:
  308. Ret.
  309. *********************************************************************************/
  310. BOOL CNewFile::OnInitDialog()
  311. {
  312. CPropertyPage::OnInitDialog();
  313. m_pcps = DYNAMIC_DOWNCAST(CPropertySheet,GetOwner() ) ;
  314. m_pcps->GetDlgItem(IDHELP)->ShowWindow(SW_HIDE) ;
  315. // CMDIFrameWnd *pFrame = DYNAMIC_DOWNCAST(CMDIFrameWnd, AfxGetApp()->m_pMainWnd) ;
  316. // Get the active MDI child window.
  317. // CMDIChildWnd *pChild = DYNAMIC_DOWNCAST(CMDIChildWnd, pFrame->GetActiveFrame() );
  318. CString cstmp ;
  319. // CDocument *pDoc ;
  320. cstmp.LoadString(IDS_MDWExtension) ;
  321. /*
  322. for ( ; pChild ; pChild = (CMDIChildWnd* ) pChild->GetNextWindow() ) {
  323. pDoc = (CDocument *) pChild->GetActiveDocument();
  324. if(pDoc) {
  325. CString cs = pDoc->GetTitle() ;
  326. if(cs.Find(cstmp) != -1 ) {
  327. m_bproj = TRUE;
  328. break;
  329. }
  330. }
  331. else
  332. break;
  333. }
  334. if(m_bproj) {
  335. CheckDlgButton(IDC_CHECK_PROJECT,1);
  336. m_csPrjName = ((CProjectRecord*)pDoc)->DriverName();
  337. m_csFileLoc = ((CProjectRecord*)pDoc)->GetW2000Path();
  338. m_pcps->GetDlgItem(IDOK)->EnableWindow(FALSE) ;
  339. UpdateData(FALSE);
  340. }
  341. else{
  342. */
  343. // GetDlgItem(IDC_CHECK_PROJECT)->EnableWindow(FALSE);
  344. // GetDlgItem(IDC_STATIC_ADDTOPRJ)->EnableWindow(FALSE);
  345. CWinApp* pApp = AfxGetApp();
  346. CString csPath = pApp->m_pszHelpFilePath;
  347. m_csFileLoc = csPath.Left(csPath.ReverseFind(_T('\\') ) ) ;
  348. UpdateData(FALSE);
  349. // }
  350. return TRUE; // return TRUE unless you set the focus to a control
  351. // EXCEPTION: OCX Property Pages should return FALSE
  352. }
  353. /********************************************************************************
  354. void CNewFile::OnChangeNewFilename()
  355. Do: Called whenever File Name edit box clicked. just call SetOkButton()
  356. Args:
  357. Ret.
  358. *********************************************************************************/
  359. void CNewFile::OnChangeNewFilename()
  360. {
  361. // TODO: If this is a RICHEDIT control, the control will not
  362. // send this notification unless you override the CPropertyPage::OnInitDialog()
  363. // function and call CRichEditCtrl().SetEventMask()
  364. // with the ENM_CHANGE flag ORed into the mask.
  365. SetOkButton() ;
  366. }
  367. void CNewFile::OnClickNewfilesList(NMHDR* pNMHDR, LRESULT* pResult)
  368. {
  369. SetOkButton() ;
  370. *pResult = 0;
  371. }
  372. /********************************************************************************
  373. void CNewFile::SetOkButton()
  374. Do; Enable and disable OK button by checking the filename and
  375. selection of file on the list
  376. *********************************************************************************/
  377. void CNewFile::SetOkButton()
  378. {
  379. UpdateData() ;
  380. POSITION pos = m_clcFileName.GetFirstSelectedItemPosition();
  381. if (m_csNewFile.GetLength() != 0 && pos )
  382. m_pcps->GetDlgItem(IDOK)->EnableWindow() ;
  383. else
  384. m_pcps->GetDlgItem(IDOK)->EnableWindow(FALSE) ;
  385. }