CMakeSetupDialog.cpp 22 KB

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