CMakeSetupDialog.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  1. // pcbuilderdialogDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "CMakeSetup.h"
  5. #include "PathDialog.h"
  6. #include "CMakeSetupDialog.h"
  7. #include "CMakeCommandLineInfo.h"
  8. #include "../cmCacheManager.h"
  9. #include "../cmake.h"
  10. #include "../cmMakefileGenerator.h"
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CAboutDlg dialog used for App About
  18. class CAboutDlg : public CDialog
  19. {
  20. public:
  21. CAboutDlg();
  22. // Dialog Data
  23. //{{AFX_DATA(CAboutDlg)
  24. enum { IDD = IDD_ABOUTBOX };
  25. //}}AFX_DATA
  26. // ClassWizard generated virtual function overrides
  27. //{{AFX_VIRTUAL(CAboutDlg)
  28. protected:
  29. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  30. //}}AFX_VIRTUAL
  31. // Implementation
  32. protected:
  33. //{{AFX_MSG(CAboutDlg)
  34. //}}AFX_MSG
  35. DECLARE_MESSAGE_MAP()
  36. };
  37. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  38. {
  39. //{{AFX_DATA_INIT(CAboutDlg)
  40. //}}AFX_DATA_INIT
  41. }
  42. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  43. {
  44. CDialog::DoDataExchange(pDX);
  45. //{{AFX_DATA_MAP(CAboutDlg)
  46. //}}AFX_DATA_MAP
  47. }
  48. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  49. //{{AFX_MSG_MAP(CAboutDlg)
  50. // No message handlers
  51. //}}AFX_MSG_MAP
  52. END_MESSAGE_MAP();
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CMakeSetupDialog dialog
  55. CMakeSetupDialog::CMakeSetupDialog(const CMakeCommandLineInfo& cmdInfo,
  56. CWnd* pParent /*=NULL*/)
  57. : CDialog(CMakeSetupDialog::IDD, pParent)
  58. {
  59. m_RegistryKey = "Software\\Kitware\\CMakeSetup\\Settings\\StartPath";
  60. //{{AFX_DATA_INIT(CMakeSetupDialog)
  61. m_WhereSource = cmdInfo.m_WhereSource;
  62. m_WhereBuild = cmdInfo.m_WhereBuild;
  63. m_GeneratorChoiceString = _T("");
  64. //}}AFX_DATA_INIT
  65. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  66. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  67. m_BuildPathChanged = false;
  68. // Find the path to the cmake.exe executable
  69. char fname[1024];
  70. ::GetModuleFileName(NULL,fname,1023);
  71. // extract just the path part
  72. m_PathToExecutable = cmSystemTools::GetProgramPath(fname).c_str();
  73. // add the cmake.exe to the path
  74. m_PathToExecutable += "/cmake.exe";
  75. m_oldCX = -1;
  76. m_deltaXRemainder = 0;
  77. }
  78. void CMakeSetupDialog::DoDataExchange(CDataExchange* pDX)
  79. {
  80. CDialog::DoDataExchange(pDX);
  81. //{{AFX_DATA_MAP(CMakeSetupDialog)
  82. DDX_Control(pDX, IDC_Generator, m_GeneratorChoice);
  83. DDX_Control(pDX, IDC_OK, m_OKButton);
  84. DDX_Control(pDX, IDCANCEL, m_CancelButton);
  85. DDX_CBStringExact(pDX, IDC_WhereSource, m_WhereSource);
  86. DDX_CBStringExact(pDX, IDC_WhereBuild, m_WhereBuild);
  87. DDX_Control(pDX, IDC_FRAME, m_ListFrame);
  88. DDX_Control(pDX, IDC_WhereSource, m_WhereSourceControl);
  89. DDX_Control(pDX, IDC_WhereBuild, m_WhereBuildControl);
  90. DDX_Control(pDX, IDC_LIST2, m_CacheEntriesList);
  91. DDX_Control(pDX, IDC_MouseHelpCaption, m_MouseHelp);
  92. DDX_Control(pDX, IDC_CMAKE_VERSION, m_VersionDisplay);
  93. DDX_Control(pDX, IDC_BuildProjects, m_Configure);
  94. DDX_CBStringExact(pDX, IDC_Generator, m_GeneratorChoiceString);
  95. //}}AFX_DATA_MAP
  96. }
  97. BEGIN_MESSAGE_MAP(CMakeSetupDialog, CDialog)
  98. //{{AFX_MSG_MAP(CMakeSetupDialog)
  99. ON_WM_SYSCOMMAND()
  100. ON_WM_PAINT()
  101. ON_WM_QUERYDRAGICON()
  102. ON_BN_CLICKED(IDC_BUTTON2, OnBrowseWhereSource)
  103. ON_BN_CLICKED(IDC_BuildProjects, OnConfigure)
  104. ON_BN_CLICKED(IDC_BUTTON3, OnBrowseWhereBuild)
  105. ON_CBN_EDITCHANGE(IDC_WhereBuild, OnChangeWhereBuild)
  106. ON_CBN_SELCHANGE(IDC_WhereBuild, OnSelendokWhereBuild)
  107. ON_CBN_EDITCHANGE(IDC_WhereSource, OnChangeWhereSource)
  108. ON_CBN_SELENDOK(IDC_WhereSource, OnSelendokWhereSource)
  109. ON_WM_SIZE()
  110. ON_WM_GETMINMAXINFO()
  111. ON_BN_CLICKED(IDC_OK, OnOk)
  112. ON_BN_CLICKED(IDCANCEL, OnCancel)
  113. ON_CBN_EDITCHANGE(IDC_Generator, OnEditchangeGenerator)
  114. //}}AFX_MSG_MAP
  115. END_MESSAGE_MAP()
  116. /////////////////////////////////////////////////////////////////////////////
  117. // CMakeSetupDialog message handlers
  118. BOOL CMakeSetupDialog::OnInitDialog()
  119. {
  120. CDialog::OnInitDialog();
  121. // Add "About..." menu item to system menu.
  122. // IDM_ABOUTBOX must be in the system command range.
  123. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  124. ASSERT(IDM_ABOUTBOX < 0xF000);
  125. CMenu* pSysMenu = GetSystemMenu(FALSE);
  126. if (pSysMenu != NULL)
  127. {
  128. CString strAboutMenu;
  129. strAboutMenu.LoadString(IDS_ABOUTBOX);
  130. if (!strAboutMenu.IsEmpty())
  131. {
  132. pSysMenu->AppendMenu(MF_SEPARATOR);
  133. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  134. }
  135. }
  136. // Set the icon for this dialog. The framework does this automatically
  137. // when the application's main window is not a dialog
  138. SetIcon(m_hIcon, TRUE); // Set big icon
  139. SetIcon(m_hIcon, FALSE); // Set small icon
  140. // Load source and build dirs from registry
  141. this->LoadFromRegistry();
  142. cmake m; // force a register of generators
  143. std::vector<std::string> names;
  144. cmMakefileGenerator::GetRegisteredGenerators(names);
  145. for(std::vector<std::string>::iterator i = names.begin();
  146. i != names.end(); ++i)
  147. {
  148. m_GeneratorChoice.AddString(i->c_str());
  149. }
  150. m_GeneratorChoiceString = "Visual Studio 6";
  151. // try to load the cmake cache from disk
  152. this->LoadCacheFromDiskToGUI();
  153. m_WhereBuildControl.LimitText(2048);
  154. m_WhereSourceControl.LimitText(2048);
  155. m_GeneratorChoice.LimitText(2048);
  156. // Set the version number
  157. char tmp[1024];
  158. sprintf(tmp,"Version %d.%d", cmMakefile::GetMajorVersion(),
  159. cmMakefile::GetMinorVersion());
  160. SetDlgItemText(IDC_CMAKE_VERSION, tmp);
  161. this->UpdateData(FALSE);
  162. return TRUE; // return TRUE unless you set the focus to a control
  163. }
  164. // About dialog invoke
  165. void CMakeSetupDialog::OnSysCommand(UINT nID, LPARAM lParam)
  166. {
  167. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  168. {
  169. CAboutDlg dlgAbout;
  170. dlgAbout.DoModal();
  171. }
  172. else
  173. {
  174. CDialog::OnSysCommand(nID, lParam);
  175. }
  176. }
  177. // If you add a minimize button to your dialog, you will need the code below
  178. // to draw the icon. For MFC applications using the document/view model,
  179. // this is automatically done for you by the framework.
  180. void CMakeSetupDialog::OnPaint()
  181. {
  182. if (IsIconic())
  183. {
  184. CPaintDC dc(this); // device context for painting
  185. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  186. // Center icon in client rectangle
  187. int cxIcon = GetSystemMetrics(SM_CXICON);
  188. int cyIcon = GetSystemMetrics(SM_CYICON);
  189. CRect rect;
  190. GetClientRect(&rect);
  191. int x = (rect.Width() - cxIcon + 1) / 2;
  192. int y = (rect.Height() - cyIcon + 1) / 2;
  193. // Draw the icon
  194. dc.DrawIcon(x, y, m_hIcon);
  195. }
  196. else
  197. {
  198. CDialog::OnPaint();
  199. }
  200. }
  201. // The system calls this to obtain the cursor to display while the user drags
  202. // the minimized window.
  203. HCURSOR CMakeSetupDialog::OnQueryDragIcon()
  204. {
  205. return (HCURSOR) m_hIcon;
  206. }
  207. // Browse button
  208. bool CMakeSetupDialog::Browse(CString &result, const char *title)
  209. {
  210. CPathDialog dlg("Select Path", title, result);
  211. if(dlg.DoModal()==IDOK)
  212. {
  213. result = dlg.GetPathName();
  214. return true;
  215. }
  216. else
  217. {
  218. return false;
  219. }
  220. }
  221. void CMakeSetupDialog::SaveToRegistry()
  222. {
  223. HKEY hKey;
  224. DWORD dwDummy;
  225. if(RegCreateKeyEx(HKEY_CURRENT_USER,
  226. m_RegistryKey,
  227. 0, "", REG_OPTION_NON_VOLATILE, KEY_READ|KEY_WRITE,
  228. NULL, &hKey, &dwDummy) != ERROR_SUCCESS)
  229. {
  230. return;
  231. }
  232. else
  233. {
  234. // load some values
  235. CString regvalue;
  236. this->ReadRegistryValue(hKey, &(regvalue),"WhereSource","C:\\");
  237. if(m_WhereSource != regvalue)
  238. {
  239. regvalue = "";
  240. this->ReadRegistryValue(hKey, &(regvalue),"WhereSource3","");
  241. RegSetValueEx(hKey, _T("WhereSource4"), 0, REG_SZ,
  242. (CONST BYTE *)(const char *)regvalue,
  243. regvalue.GetLength());
  244. regvalue = "";
  245. this->ReadRegistryValue(hKey, &(regvalue),"WhereSource2","");
  246. RegSetValueEx(hKey, _T("WhereSource3"), 0, REG_SZ,
  247. (CONST BYTE *)(const char *)regvalue,
  248. regvalue.GetLength());
  249. regvalue = "";
  250. this->ReadRegistryValue(hKey, &(regvalue),"WhereSource","");
  251. RegSetValueEx(hKey, _T("WhereSource2"), 0, REG_SZ,
  252. (CONST BYTE *)(const char *)regvalue,
  253. regvalue.GetLength());
  254. RegSetValueEx(hKey, _T("WhereSource"), 0, REG_SZ,
  255. (CONST BYTE *)(const char *)m_WhereSource,
  256. m_WhereSource.GetLength());
  257. }
  258. this->ReadRegistryValue(hKey, &(regvalue),"WhereBuild","C:\\");
  259. if(m_WhereBuild != regvalue)
  260. {
  261. regvalue = "";
  262. this->ReadRegistryValue(hKey, &(regvalue),"WhereBuild3","");
  263. RegSetValueEx(hKey, _T("WhereBuild4"), 0, REG_SZ,
  264. (CONST BYTE *)(const char *)regvalue,
  265. regvalue.GetLength());
  266. regvalue = "";
  267. this->ReadRegistryValue(hKey, &(regvalue),"WhereBuild2","");
  268. RegSetValueEx(hKey, _T("WhereBuild3"), 0, REG_SZ,
  269. (CONST BYTE *)(const char *)regvalue,
  270. regvalue.GetLength());
  271. regvalue = "";
  272. this->ReadRegistryValue(hKey, &(regvalue),"WhereBuild","");
  273. RegSetValueEx(hKey, _T("WhereBuild2"), 0, REG_SZ,
  274. (CONST BYTE *)(const char *)regvalue,
  275. regvalue.GetLength());
  276. RegSetValueEx(hKey, _T("WhereBuild"), 0, REG_SZ,
  277. (CONST BYTE *)(const char *)m_WhereBuild,
  278. m_WhereBuild.GetLength());
  279. }
  280. }
  281. RegCloseKey(hKey);
  282. }
  283. void CMakeSetupDialog::ReadRegistryValue(HKEY hKey,
  284. CString *val,
  285. const char *key,
  286. const char *adefault)
  287. {
  288. DWORD dwType, dwSize;
  289. char *pb;
  290. dwType = REG_SZ;
  291. pb = val->GetBuffer(MAX_PATH);
  292. dwSize = MAX_PATH;
  293. if(RegQueryValueEx(hKey,_T(key), NULL, &dwType,
  294. (BYTE *)pb, &dwSize) != ERROR_SUCCESS)
  295. {
  296. val->ReleaseBuffer();
  297. *val = _T(adefault);
  298. }
  299. else
  300. {
  301. val->ReleaseBuffer();
  302. }
  303. }
  304. void CMakeSetupDialog::LoadFromRegistry()
  305. {
  306. HKEY hKey;
  307. if(RegOpenKeyEx(HKEY_CURRENT_USER,
  308. m_RegistryKey,
  309. 0, KEY_READ, &hKey) != ERROR_SUCCESS)
  310. {
  311. return;
  312. }
  313. else
  314. {
  315. // load some values
  316. if (m_WhereSource.IsEmpty())
  317. {
  318. this->ReadRegistryValue(hKey, &(m_WhereSource),"WhereSource","C:\\");
  319. }
  320. if (m_WhereBuild.IsEmpty())
  321. {
  322. this->ReadRegistryValue(hKey, &(m_WhereBuild),"WhereBuild","C:\\");
  323. }
  324. m_WhereSourceControl.AddString(m_WhereSource);
  325. m_WhereBuildControl.AddString(m_WhereBuild);
  326. CString regvalue;
  327. this->ReadRegistryValue(hKey, &(regvalue),"WhereSource2","C:\\");
  328. m_WhereSourceControl.AddString(regvalue);
  329. regvalue = "";
  330. this->ReadRegistryValue(hKey, &(regvalue),"WhereBuild2","C:\\");
  331. m_WhereBuildControl.AddString(regvalue);
  332. regvalue = "";
  333. this->ReadRegistryValue(hKey, &(regvalue),"WhereSource3","C:\\");
  334. m_WhereSourceControl.AddString(regvalue);
  335. regvalue = "";
  336. this->ReadRegistryValue(hKey, &(regvalue),"WhereBuild3","C:\\");
  337. m_WhereBuildControl.AddString(regvalue);
  338. regvalue = "";
  339. this->ReadRegistryValue(hKey, &(regvalue),"WhereSource4","C:\\");
  340. m_WhereSourceControl.AddString(regvalue);
  341. regvalue = "";
  342. this->ReadRegistryValue(hKey, &(regvalue),"WhereBuild4","C:\\");
  343. m_WhereBuildControl.AddString(regvalue);
  344. }
  345. RegCloseKey(hKey);
  346. }
  347. // Callback for browse source button
  348. void CMakeSetupDialog::OnBrowseWhereSource()
  349. {
  350. this->UpdateData();
  351. Browse(m_WhereSource, "Enter Path to Source");
  352. this->UpdateData(false);
  353. this->OnChangeWhereSource();
  354. }
  355. // Callback for browser build button
  356. void CMakeSetupDialog::OnBrowseWhereBuild()
  357. {
  358. this->UpdateData();
  359. Browse(m_WhereBuild, "Enter Path to Build");
  360. this->UpdateData(false);
  361. this->OnChangeWhereBuild();
  362. }
  363. void CMakeSetupDialog::RunCMake(bool generateProjectFiles)
  364. {
  365. if(!cmSystemTools::FileExists(m_WhereBuild))
  366. {
  367. std::string message =
  368. "Build directory does not exist, should I create it?\n\n"
  369. "Directory: ";
  370. message += (const char*)m_WhereBuild;
  371. if(MessageBox(message.c_str(), "Create Directory", MB_OKCANCEL) == IDOK)
  372. {
  373. cmSystemTools::MakeDirectory(m_WhereBuild);
  374. }
  375. else
  376. {
  377. MessageBox("Build Project aborted, nothing done.");
  378. return;
  379. }
  380. }
  381. // set the wait cursor
  382. ::SetCursor(LoadCursor(NULL, IDC_WAIT));
  383. // get all the info from the dialog
  384. this->UpdateData();
  385. // always save the current gui values to disk
  386. this->SaveCacheFromGUI();
  387. // Make sure we are working from the cache on disk
  388. this->LoadCacheFromDiskToGUI();
  389. // create a cmake object
  390. cmake make;
  391. // create the arguments for the cmake object
  392. std::vector<std::string> args;
  393. args.push_back((const char*)m_PathToExecutable);
  394. std::string arg;
  395. arg = "-H";
  396. arg += m_WhereSource;
  397. args.push_back(arg);
  398. arg = "-B";
  399. arg += m_WhereBuild;
  400. args.push_back(arg);
  401. arg = "-G";
  402. arg += m_GeneratorChoiceString;
  403. args.push_back(arg);
  404. // run the generate process
  405. if(make.Generate(args, generateProjectFiles) != 0)
  406. {
  407. cmSystemTools::Error(
  408. "Error in generation process, project files may be invalid");
  409. cmSystemTools::ResetErrorOccuredFlag();
  410. }
  411. // update the GUI with any new values in the caused by the
  412. // generation process
  413. this->LoadCacheFromDiskToGUI();
  414. // save source and build paths to registry
  415. this->SaveToRegistry();
  416. // path is up-to-date now
  417. m_BuildPathChanged = false;
  418. // put the cursor back
  419. ::SetCursor(LoadCursor(NULL, IDC_ARROW));
  420. }
  421. // Callback for build projects button
  422. void CMakeSetupDialog::OnConfigure()
  423. {
  424. this->RunCMake(false);
  425. }
  426. // callback for combo box menu where build selection
  427. void CMakeSetupDialog::OnSelendokWhereBuild()
  428. {
  429. m_WhereBuildControl.GetLBText(m_WhereBuildControl.GetCurSel(),
  430. m_WhereBuild);
  431. m_WhereBuildControl.SetWindowText( m_WhereBuild);
  432. this->UpdateData(FALSE);
  433. this->OnChangeWhereBuild();
  434. }
  435. // callback for combo box menu where source selection
  436. void CMakeSetupDialog::OnSelendokWhereSource()
  437. {
  438. m_WhereSourceControl.GetLBText(m_WhereSourceControl.GetCurSel(),
  439. m_WhereSource);
  440. this->UpdateData(FALSE);
  441. this->OnChangeWhereSource();
  442. }
  443. // callback for chaing source directory
  444. void CMakeSetupDialog::OnChangeWhereSource()
  445. {
  446. }
  447. // callback for changing the build directory
  448. void CMakeSetupDialog::OnChangeWhereBuild()
  449. {
  450. this->UpdateData();
  451. m_CacheEntriesList.RemoveAll();
  452. m_CacheEntriesList.ShowWindow(SW_SHOW);
  453. this->LoadCacheFromDiskToGUI();
  454. m_BuildPathChanged = true;
  455. }
  456. // copy from the cache manager to the cache edit list box
  457. void CMakeSetupDialog::FillCacheGUIFromCacheManager()
  458. {
  459. int size = m_CacheEntriesList.GetItems().size();
  460. bool reverseOrder = false;
  461. // if there are already entries in the cache, then
  462. // put the new ones in the top, so they show up first
  463. if(size)
  464. {
  465. reverseOrder = true;
  466. }
  467. // all the current values are not new any more
  468. std::set<CPropertyItem*> items = m_CacheEntriesList.GetItems();
  469. for(std::set<CPropertyItem*>::iterator i = items.begin();
  470. i != items.end(); ++i)
  471. {
  472. CPropertyItem* item = *i;
  473. item->m_NewValue = false;
  474. }
  475. const cmCacheManager::CacheEntryMap &cache =
  476. cmCacheManager::GetInstance()->GetCacheMap();
  477. if(cache.size() == 0)
  478. {
  479. m_OKButton.EnableWindow(false);
  480. }
  481. else
  482. {
  483. m_OKButton.EnableWindow(true);
  484. }
  485. for(cmCacheManager::CacheEntryMap::const_iterator i = cache.begin();
  486. i != cache.end(); ++i)
  487. {
  488. const char* key = i->first.c_str();
  489. const cmCacheManager::CacheEntry& value = i->second;
  490. switch(value.m_Type )
  491. {
  492. case cmCacheManager::BOOL:
  493. if(cmSystemTools::IsOn(value.m_Value.c_str()))
  494. {
  495. m_CacheEntriesList.AddProperty(key,
  496. "ON",
  497. value.m_HelpString.c_str(),
  498. CPropertyList::CHECKBOX,"",
  499. reverseOrder
  500. );
  501. }
  502. else
  503. {
  504. m_CacheEntriesList.AddProperty(key,
  505. "OFF",
  506. value.m_HelpString.c_str(),
  507. CPropertyList::CHECKBOX,"",
  508. reverseOrder
  509. );
  510. }
  511. break;
  512. case cmCacheManager::PATH:
  513. m_CacheEntriesList.AddProperty(key,
  514. value.m_Value.c_str(),
  515. value.m_HelpString.c_str(),
  516. CPropertyList::PATH,"",
  517. reverseOrder
  518. );
  519. break;
  520. case cmCacheManager::FILEPATH:
  521. m_CacheEntriesList.AddProperty(key,
  522. value.m_Value.c_str(),
  523. value.m_HelpString.c_str(),
  524. CPropertyList::FILE,"",
  525. reverseOrder
  526. );
  527. break;
  528. case cmCacheManager::STRING:
  529. m_CacheEntriesList.AddProperty(key,
  530. value.m_Value.c_str(),
  531. value.m_HelpString.c_str(),
  532. CPropertyList::EDIT,"",
  533. reverseOrder
  534. );
  535. break;
  536. case cmCacheManager::INTERNAL:
  537. m_CacheEntriesList.RemoveProperty(key);
  538. break;
  539. }
  540. }
  541. // redraw the list
  542. m_CacheEntriesList.SetTopIndex(0);
  543. m_CacheEntriesList.Invalidate();
  544. }
  545. // copy from the list box to the cache manager
  546. void CMakeSetupDialog::FillCacheManagerFromCacheGUI()
  547. {
  548. cmCacheManager::GetInstance()->GetCacheMap();
  549. std::set<CPropertyItem*> items = m_CacheEntriesList.GetItems();
  550. for(std::set<CPropertyItem*>::iterator i = items.begin();
  551. i != items.end(); ++i)
  552. {
  553. CPropertyItem* item = *i;
  554. cmCacheManager::CacheEntry *entry =
  555. cmCacheManager::GetInstance()->GetCacheEntry(
  556. (const char*)item->m_propName);
  557. if (entry)
  558. {
  559. entry->m_Value = item->m_curValue;
  560. }
  561. }
  562. }
  563. //! Load cache file from m_WhereBuild and display in GUI editor
  564. void CMakeSetupDialog::LoadCacheFromDiskToGUI()
  565. {
  566. if(m_WhereBuild != "")
  567. {
  568. cmCacheManager::GetInstance()->LoadCache(m_WhereBuild);
  569. this->FillCacheGUIFromCacheManager();
  570. if(cmCacheManager::GetInstance()->GetCacheEntry("CMAKE_GENERATOR"))
  571. {
  572. std::string curGen =
  573. cmCacheManager::GetInstance()->GetCacheEntry("CMAKE_GENERATOR")->m_Value;
  574. if(m_GeneratorChoiceString != curGen.c_str())
  575. {
  576. m_GeneratorChoiceString = curGen.c_str();
  577. this->UpdateData(FALSE);
  578. }
  579. }
  580. }
  581. }
  582. //! Save GUI values to cmCacheManager and then save to disk.
  583. void CMakeSetupDialog::SaveCacheFromGUI()
  584. {
  585. this->FillCacheManagerFromCacheGUI();
  586. if(m_WhereBuild != "")
  587. {
  588. cmCacheManager::GetInstance()->SaveCache(m_WhereBuild);
  589. }
  590. }
  591. void CMakeSetupDialog::OnSize(UINT nType, int cx, int cy)
  592. {
  593. if (nType == SIZE_MINIMIZED)
  594. {
  595. CDialog::OnSize(nType, cx, cy);
  596. return;
  597. }
  598. if (m_oldCX == -1)
  599. {
  600. m_oldCX = cx;
  601. m_oldCY = cy;
  602. }
  603. int deltax = cx - m_oldCX;
  604. int deltay = cy - m_oldCY;
  605. m_oldCX = cx;
  606. m_oldCY = cy;
  607. CDialog::OnSize(nType, cx, cy);
  608. if (deltax == 0 && deltay == 0)
  609. {
  610. return;
  611. }
  612. if(m_CacheEntriesList.m_hWnd)
  613. {
  614. // get the original sizes/positions
  615. CRect cRect;
  616. m_ListFrame.GetWindowRect(&cRect);
  617. m_ListFrame.SetWindowPos(&wndTop, cRect.left, cRect.top,
  618. cRect.Width() + deltax,
  619. cRect.Height() + deltay,
  620. SWP_NOMOVE | SWP_NOZORDER);
  621. m_CacheEntriesList.GetWindowRect(&cRect);
  622. m_CacheEntriesList.SetWindowPos(&wndTop, cRect.left, cRect.top,
  623. cRect.Width() + deltax,
  624. cRect.Height() + deltay,
  625. SWP_NOMOVE | SWP_NOZORDER);
  626. m_VersionDisplay.SetWindowPos(&wndTop, 5, cy-23, 0, 0,
  627. SWP_NOSIZE | SWP_NOZORDER);
  628. deltax = deltax + m_deltaXRemainder;
  629. m_deltaXRemainder = deltax%2;
  630. m_MouseHelp.GetWindowRect(&cRect);
  631. this->ScreenToClient(&cRect);
  632. m_MouseHelp.SetWindowPos(&wndTop, cRect.left + deltax/2,
  633. cRect.top + deltay,
  634. 0, 0,
  635. SWP_NOSIZE | SWP_NOZORDER);
  636. m_Configure.GetWindowRect(&cRect);
  637. this->ScreenToClient(&cRect);
  638. m_Configure.SetWindowPos(&wndTop, cRect.left + deltax/2,
  639. cRect.top + deltay,
  640. 0, 0,
  641. SWP_NOSIZE | SWP_NOZORDER);
  642. m_CancelButton.GetWindowRect(&cRect);
  643. this->ScreenToClient(&cRect);
  644. m_CancelButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  645. cRect.top + deltay,
  646. 0, 0,
  647. SWP_NOSIZE | SWP_NOZORDER);
  648. m_OKButton.GetWindowRect(&cRect);
  649. this->ScreenToClient(&cRect);
  650. m_OKButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  651. cRect.top + deltay,
  652. 0, 0,
  653. SWP_NOSIZE | SWP_NOZORDER);
  654. }
  655. }
  656. void CMakeSetupDialog::OnGetMinMaxInfo( MINMAXINFO FAR* lpMMI )
  657. {
  658. lpMMI->ptMinTrackSize.x = 550;
  659. lpMMI->ptMinTrackSize.y = 272;
  660. }
  661. void CMakeSetupDialog::OnCancel()
  662. {
  663. if(m_CacheEntriesList.IsDirty())
  664. {
  665. if(MessageBox("You have changed options but not rebuilt, "
  666. "are you sure you want to exit?", "Confirm Exit",
  667. MB_YESNO) == IDYES)
  668. {
  669. CDialog::OnOK();
  670. }
  671. }
  672. else
  673. {
  674. CDialog::OnOK();
  675. }
  676. }
  677. void CMakeSetupDialog::OnOk()
  678. {
  679. m_CacheEntriesList.ClearDirty();
  680. this->RunCMake(true);
  681. cmMakefileGenerator::UnRegisterGenerators();
  682. CDialog::OnOK();
  683. }
  684. void CMakeSetupDialog::OnEditchangeGenerator()
  685. {
  686. // TODO: Add your control notification handler code here
  687. }