CMakeSetupDialog.cpp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. // pcbuilderdialogDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "CMakeSetup.h"
  5. #include "CMakeSetupDialog.h"
  6. #include "../cmDSWMakefile.h"
  7. #include "../itkVC60Configure.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CAboutDlg dialog used for App About
  15. class CAboutDlg : public CDialog
  16. {
  17. public:
  18. CAboutDlg();
  19. // Dialog Data
  20. //{{AFX_DATA(CAboutDlg)
  21. enum { IDD = IDD_ABOUTBOX };
  22. //}}AFX_DATA
  23. // ClassWizard generated virtual function overrides
  24. //{{AFX_VIRTUAL(CAboutDlg)
  25. protected:
  26. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  27. //}}AFX_VIRTUAL
  28. // Implementation
  29. protected:
  30. //{{AFX_MSG(CAboutDlg)
  31. //}}AFX_MSG
  32. DECLARE_MESSAGE_MAP()
  33. };
  34. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  35. {
  36. //{{AFX_DATA_INIT(CAboutDlg)
  37. //}}AFX_DATA_INIT
  38. }
  39. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  40. {
  41. CDialog::DoDataExchange(pDX);
  42. //{{AFX_DATA_MAP(CAboutDlg)
  43. //}}AFX_DATA_MAP
  44. }
  45. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  46. //{{AFX_MSG_MAP(CAboutDlg)
  47. // No message handlers
  48. //}}AFX_MSG_MAP
  49. END_MESSAGE_MAP();
  50. /////////////////////////////////////////////////////////////////////////////
  51. // CMakeSetupDialog dialog
  52. CMakeSetupDialog::CMakeSetupDialog(CWnd* pParent /*=NULL*/)
  53. : CDialog(CMakeSetupDialog::IDD, pParent)
  54. {
  55. //{{AFX_DATA_INIT(CMakeSetupDialog)
  56. m_WhereSource = _T("");
  57. m_WhereBuild = _T("");
  58. //}}AFX_DATA_INIT
  59. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  60. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  61. m_WhereSource = _T("");
  62. this->LoadFromRegistry();
  63. }
  64. void CMakeSetupDialog::DoDataExchange(CDataExchange* pDX)
  65. {
  66. CDialog::DoDataExchange(pDX);
  67. //{{AFX_DATA_MAP(CMakeSetupDialog)
  68. DDX_Text(pDX, IDC_WhereSource, m_WhereSource);
  69. DDX_Text(pDX, IDC_WhereBuild, m_WhereBuild);
  70. //}}AFX_DATA_MAP
  71. }
  72. BEGIN_MESSAGE_MAP(CMakeSetupDialog, CDialog)
  73. //{{AFX_MSG_MAP(CMakeSetupDialog)
  74. ON_WM_SYSCOMMAND()
  75. ON_WM_PAINT()
  76. ON_WM_QUERYDRAGICON()
  77. ON_EN_CHANGE(IDC_WhereSource, OnChangeEdit1)
  78. ON_BN_CLICKED(IDC_BUTTON2, OnBrowse)
  79. ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
  80. //}}AFX_MSG_MAP
  81. END_MESSAGE_MAP()
  82. /////////////////////////////////////////////////////////////////////////////
  83. // CMakeSetupDialog message handlers
  84. BOOL CMakeSetupDialog::OnInitDialog()
  85. {
  86. CDialog::OnInitDialog();
  87. // Add "About..." menu item to system menu.
  88. // IDM_ABOUTBOX must be in the system command range.
  89. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  90. ASSERT(IDM_ABOUTBOX < 0xF000);
  91. CMenu* pSysMenu = GetSystemMenu(FALSE);
  92. if (pSysMenu != NULL)
  93. {
  94. CString strAboutMenu;
  95. strAboutMenu.LoadString(IDS_ABOUTBOX);
  96. if (!strAboutMenu.IsEmpty())
  97. {
  98. pSysMenu->AppendMenu(MF_SEPARATOR);
  99. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  100. }
  101. }
  102. // Set the icon for this dialog. The framework does this automatically
  103. // when the application's main window is not a dialog
  104. SetIcon(m_hIcon, TRUE); // Set big icon
  105. SetIcon(m_hIcon, FALSE); // Set small icon
  106. // TODO: Add extra initialization here
  107. return TRUE; // return TRUE unless you set the focus to a control
  108. }
  109. void CMakeSetupDialog::OnSysCommand(UINT nID, LPARAM lParam)
  110. {
  111. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  112. {
  113. CAboutDlg dlgAbout;
  114. dlgAbout.DoModal();
  115. }
  116. else
  117. {
  118. CDialog::OnSysCommand(nID, lParam);
  119. }
  120. }
  121. // If you add a minimize button to your dialog, you will need the code below
  122. // to draw the icon. For MFC applications using the document/view model,
  123. // this is automatically done for you by the framework.
  124. void CMakeSetupDialog::OnPaint()
  125. {
  126. if (IsIconic())
  127. {
  128. CPaintDC dc(this); // device context for painting
  129. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  130. // Center icon in client rectangle
  131. int cxIcon = GetSystemMetrics(SM_CXICON);
  132. int cyIcon = GetSystemMetrics(SM_CYICON);
  133. CRect rect;
  134. GetClientRect(&rect);
  135. int x = (rect.Width() - cxIcon + 1) / 2;
  136. int y = (rect.Height() - cyIcon + 1) / 2;
  137. // Draw the icon
  138. dc.DrawIcon(x, y, m_hIcon);
  139. }
  140. else
  141. {
  142. CDialog::OnPaint();
  143. }
  144. }
  145. // The system calls this to obtain the cursor to display while the user drags
  146. // the minimized window.
  147. HCURSOR CMakeSetupDialog::OnQueryDragIcon()
  148. {
  149. return (HCURSOR) m_hIcon;
  150. }
  151. void CMakeSetupDialog::OnChangeEdit1()
  152. {
  153. // TODO: If this is a RICHEDIT control, the control will not
  154. // send this notification unless you override the CDialog::OnInitDialog()
  155. // function and call CRichEditCtrl().SetEventMask()
  156. // with the ENM_CHANGE flag ORed into the mask.
  157. // TODO: Add your control notification handler code here
  158. }
  159. void CMakeSetupDialog::OnBrowse()
  160. {
  161. this->UpdateData();
  162. Browse(m_WhereSource, "Enter Path to Insight Source");
  163. this->UpdateData(false);
  164. }
  165. bool CMakeSetupDialog::Browse(CString &result, const char *title)
  166. {
  167. // don't know what to do with initial right now...
  168. char szPathName[4096];
  169. BROWSEINFO bi;
  170. bi.hwndOwner = m_hWnd;
  171. bi.pidlRoot = NULL;
  172. bi.pszDisplayName = (LPTSTR)szPathName;
  173. bi.lpszTitle = title;
  174. bi.ulFlags = BIF_BROWSEINCLUDEFILES ;
  175. bi.lpfn = NULL;
  176. LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
  177. bool bSuccess = (bool)SHGetPathFromIDList(pidl, szPathName);
  178. if(bSuccess)
  179. {
  180. result = szPathName;
  181. }
  182. return bSuccess;
  183. }
  184. void CMakeSetupDialog::OnOK()
  185. {
  186. // get all the info from the screen
  187. this->UpdateData();
  188. // configure the system for VC60
  189. itkVC60Configure config;
  190. config.SetWhereSource(m_WhereSource);
  191. config.SetWhereBuild(m_WhereBuild);
  192. config.Configure();
  193. cmDSWMakefile builder;
  194. // Set the ITK home directory
  195. builder.SetHomeDirectory(m_WhereSource);
  196. // Set the CMakeLists.txt file
  197. CString makefileIn = m_WhereSource;
  198. makefileIn += "/CMakeLists.txt";
  199. builder.ReadMakefile(makefileIn);
  200. // Set the output directory
  201. builder.SetOutputDirectory(m_WhereBuild);
  202. // set the directory which contains the CMakeLists.txt
  203. builder.SetCurrentDirectory(m_WhereSource);
  204. // Create the master DSW file and all children dsp files for ITK
  205. builder.OutputDSWFile();
  206. CDialog::OnOK();
  207. this->SaveToRegistry();
  208. }
  209. void CMakeSetupDialog::OnButton3()
  210. {
  211. this->UpdateData();
  212. Browse(m_WhereBuild, "Enter Path to Insight Build");
  213. this->UpdateData(false);
  214. }
  215. void CMakeSetupDialog::SaveToRegistry()
  216. {
  217. HKEY hKey;
  218. DWORD dwDummy;
  219. if(RegCreateKeyEx(HKEY_CURRENT_USER,
  220. _T("Software\\Kitware\\CMakeSetup\\Settings"),
  221. 0, "", REG_OPTION_NON_VOLATILE, KEY_READ|KEY_WRITE,
  222. NULL, &hKey, &dwDummy) != ERROR_SUCCESS)
  223. {
  224. return;
  225. }
  226. else
  227. {
  228. RegSetValueEx(hKey, _T("WhereSource"), 0, REG_SZ,
  229. (CONST BYTE *)(const char *)m_WhereSource,
  230. m_WhereSource.GetLength());
  231. RegSetValueEx(hKey, _T("WhereBuild"), 0, REG_SZ,
  232. (CONST BYTE *)(const char *)m_WhereBuild,
  233. m_WhereBuild.GetLength());
  234. }
  235. RegCloseKey(hKey);
  236. }
  237. void CMakeSetupDialog::ReadRegistryValue(HKEY hKey,
  238. CString *val,
  239. char *key,
  240. char *adefault)
  241. {
  242. DWORD dwType, dwSize;
  243. char *pb;
  244. dwType = REG_SZ;
  245. pb = val->GetBuffer(MAX_PATH);
  246. dwSize = MAX_PATH;
  247. if(RegQueryValueEx(hKey,_T(key), NULL, &dwType,
  248. (BYTE *)pb, &dwSize) != ERROR_SUCCESS)
  249. {
  250. val->ReleaseBuffer();
  251. *val = _T(adefault);
  252. }
  253. else
  254. {
  255. val->ReleaseBuffer();
  256. }
  257. }
  258. void CMakeSetupDialog::LoadFromRegistry()
  259. {
  260. HKEY hKey;
  261. if(RegOpenKeyEx(HKEY_CURRENT_USER,
  262. _T("Software\\Kitware\\CMakeSetup\\Settings"),
  263. 0, KEY_READ, &hKey) != ERROR_SUCCESS)
  264. {
  265. return;
  266. }
  267. else
  268. {
  269. // save some values
  270. this->ReadRegistryValue(hKey, &(m_WhereSource),"WhereSource","C:\\Insight");
  271. this->ReadRegistryValue(hKey, &(m_WhereBuild),"WhereBuild",
  272. "C:\\Insight");
  273. }
  274. RegCloseKey(hKey);
  275. }