CMakeSetupDialog.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  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. // save some values
  235. CString regvalue;
  236. this->ReadRegistryValue(hKey, &(regvalue),"WhereSource1","C:\\");
  237. int shiftEnd = 9;
  238. if(m_WhereSource != regvalue)
  239. {
  240. char keyName[1024];
  241. char keyName2[1024];
  242. int i;
  243. for (i = 2; i < 10; ++i)
  244. {
  245. regvalue = "";
  246. sprintf(keyName,"WhereSource%i",i);
  247. this->ReadRegistryValue(hKey, &(regvalue),keyName,"");
  248. // check for short circuit, if the new value is already in
  249. // the list then we stop
  250. if (m_WhereSource == regvalue)
  251. {
  252. shiftEnd = i - 1;
  253. }
  254. }
  255. for (i = shiftEnd; i; --i)
  256. {
  257. regvalue = "";
  258. sprintf(keyName,"WhereSource%i",i);
  259. sprintf(keyName2,"WhereSource%i",i+1);
  260. this->ReadRegistryValue(hKey, &(regvalue),keyName,"");
  261. if (strlen(regvalue))
  262. {
  263. RegSetValueEx(hKey, _T(keyName2), 0, REG_SZ,
  264. (CONST BYTE *)(const char *)regvalue,
  265. regvalue.GetLength());
  266. }
  267. }
  268. RegSetValueEx(hKey, _T("WhereSource1"), 0, REG_SZ,
  269. (CONST BYTE *)(const char *)m_WhereSource,
  270. m_WhereSource.GetLength());
  271. }
  272. this->ReadRegistryValue(hKey, &(regvalue),"WhereBuild1","C:\\");
  273. if(m_WhereBuild != regvalue)
  274. {
  275. int i;
  276. char keyName[1024];
  277. char keyName2[1024];
  278. for (i = 2; i < 10; ++i)
  279. {
  280. regvalue = "";
  281. sprintf(keyName,"WhereBuild%i",i);
  282. this->ReadRegistryValue(hKey, &(regvalue),keyName,"");
  283. // check for short circuit, if the new value is already in
  284. // the list then we stop
  285. if (m_WhereBuild == regvalue)
  286. {
  287. shiftEnd = i - 1;
  288. }
  289. }
  290. for (i = shiftEnd; i; --i)
  291. {
  292. regvalue = "";
  293. sprintf(keyName,"WhereBuild%i",i);
  294. sprintf(keyName2,"WhereBuild%i",i+1);
  295. this->ReadRegistryValue(hKey, &(regvalue),keyName,"");
  296. if (strlen(regvalue))
  297. {
  298. RegSetValueEx(hKey, _T(keyName2), 0, REG_SZ,
  299. (CONST BYTE *)(const char *)regvalue,
  300. regvalue.GetLength());
  301. }
  302. }
  303. RegSetValueEx(hKey, _T("WhereBuild1"), 0, REG_SZ,
  304. (CONST BYTE *)(const char *)m_WhereBuild,
  305. m_WhereBuild.GetLength());
  306. }
  307. }
  308. RegCloseKey(hKey);
  309. }
  310. void CMakeSetupDialog::ReadRegistryValue(HKEY hKey,
  311. CString *val,
  312. const char *key,
  313. const char *adefault)
  314. {
  315. DWORD dwType, dwSize;
  316. char *pb;
  317. dwType = REG_SZ;
  318. pb = val->GetBuffer(MAX_PATH);
  319. dwSize = MAX_PATH;
  320. if(RegQueryValueEx(hKey,_T(key), NULL, &dwType,
  321. (BYTE *)pb, &dwSize) != ERROR_SUCCESS)
  322. {
  323. val->ReleaseBuffer();
  324. *val = _T(adefault);
  325. }
  326. else
  327. {
  328. val->ReleaseBuffer();
  329. }
  330. }
  331. void CMakeSetupDialog::LoadFromRegistry()
  332. {
  333. HKEY hKey;
  334. if(RegOpenKeyEx(HKEY_CURRENT_USER,
  335. m_RegistryKey,
  336. 0, KEY_READ, &hKey) != ERROR_SUCCESS)
  337. {
  338. return;
  339. }
  340. else
  341. {
  342. // load some values
  343. if (m_WhereSource.IsEmpty())
  344. {
  345. this->ReadRegistryValue(hKey, &(m_WhereSource),"WhereSource1","C:\\");
  346. }
  347. if (m_WhereBuild.IsEmpty())
  348. {
  349. this->ReadRegistryValue(hKey, &(m_WhereBuild),"WhereBuild1","C:\\");
  350. }
  351. m_WhereSourceControl.AddString(m_WhereSource);
  352. m_WhereBuildControl.AddString(m_WhereBuild);
  353. char keyname[1024];
  354. CString regvalue;
  355. int i;
  356. for (i = 2; i <= 10; ++i)
  357. {
  358. sprintf(keyname,"WhereSource%i",i);
  359. regvalue = "";
  360. this->ReadRegistryValue(hKey, &(regvalue),keyname,"C:\\");
  361. if (strcmp("C:\\",regvalue))
  362. {
  363. m_WhereSourceControl.AddString(regvalue);
  364. }
  365. sprintf(keyname,"WhereBuild%i",i);
  366. regvalue = "";
  367. this->ReadRegistryValue(hKey, &(regvalue),keyname,"C:\\");
  368. if (strcmp("C:\\",regvalue))
  369. {
  370. m_WhereBuildControl.AddString(regvalue);
  371. }
  372. }
  373. }
  374. RegCloseKey(hKey);
  375. }
  376. // Callback for browse source button
  377. void CMakeSetupDialog::OnBrowseWhereSource()
  378. {
  379. this->UpdateData();
  380. Browse(m_WhereSource, "Enter Path to Source");
  381. this->UpdateData(false);
  382. this->OnChangeWhereSource();
  383. }
  384. // Callback for browser build button
  385. void CMakeSetupDialog::OnBrowseWhereBuild()
  386. {
  387. this->UpdateData();
  388. Browse(m_WhereBuild, "Enter Path to Build");
  389. this->UpdateData(false);
  390. this->OnChangeWhereBuild();
  391. }
  392. void CMakeSetupDialog::RunCMake(bool generateProjectFiles)
  393. {
  394. if(!cmSystemTools::FileExists(m_WhereBuild))
  395. {
  396. std::string message =
  397. "Build directory does not exist, should I create it?\n\n"
  398. "Directory: ";
  399. message += (const char*)m_WhereBuild;
  400. if(MessageBox(message.c_str(), "Create Directory", MB_OKCANCEL) == IDOK)
  401. {
  402. cmSystemTools::MakeDirectory(m_WhereBuild);
  403. }
  404. else
  405. {
  406. MessageBox("Build Project aborted, nothing done.");
  407. return;
  408. }
  409. }
  410. // set the wait cursor
  411. ::SetCursor(LoadCursor(NULL, IDC_WAIT));
  412. // get all the info from the dialog
  413. this->UpdateData();
  414. // always save the current gui values to disk
  415. this->SaveCacheFromGUI();
  416. // Make sure we are working from the cache on disk
  417. this->LoadCacheFromDiskToGUI();
  418. // create a cmake object
  419. cmake make;
  420. // create the arguments for the cmake object
  421. std::vector<std::string> args;
  422. args.push_back((const char*)m_PathToExecutable);
  423. std::string arg;
  424. arg = "-H";
  425. arg += m_WhereSource;
  426. args.push_back(arg);
  427. arg = "-B";
  428. arg += m_WhereBuild;
  429. args.push_back(arg);
  430. arg = "-G";
  431. arg += m_GeneratorChoiceString;
  432. args.push_back(arg);
  433. // run the generate process
  434. if(make.Generate(args, generateProjectFiles) != 0)
  435. {
  436. cmSystemTools::Error(
  437. "Error in generation process, project files may be invalid");
  438. cmSystemTools::ResetErrorOccuredFlag();
  439. }
  440. // update the GUI with any new values in the caused by the
  441. // generation process
  442. this->LoadCacheFromDiskToGUI();
  443. // save source and build paths to registry
  444. this->SaveToRegistry();
  445. // path is up-to-date now
  446. m_BuildPathChanged = false;
  447. // put the cursor back
  448. ::SetCursor(LoadCursor(NULL, IDC_ARROW));
  449. }
  450. // Callback for build projects button
  451. void CMakeSetupDialog::OnConfigure()
  452. {
  453. this->RunCMake(false);
  454. }
  455. // callback for combo box menu where build selection
  456. void CMakeSetupDialog::OnSelendokWhereBuild()
  457. {
  458. m_WhereBuildControl.GetLBText(m_WhereBuildControl.GetCurSel(),
  459. m_WhereBuild);
  460. m_WhereBuildControl.SetWindowText( m_WhereBuild);
  461. this->UpdateData(FALSE);
  462. this->OnChangeWhereBuild();
  463. }
  464. // callback for combo box menu where source selection
  465. void CMakeSetupDialog::OnSelendokWhereSource()
  466. {
  467. m_WhereSourceControl.GetLBText(m_WhereSourceControl.GetCurSel(),
  468. m_WhereSource);
  469. this->UpdateData(FALSE);
  470. this->OnChangeWhereSource();
  471. }
  472. // callback for chaing source directory
  473. void CMakeSetupDialog::OnChangeWhereSource()
  474. {
  475. }
  476. // callback for changing the build directory
  477. void CMakeSetupDialog::OnChangeWhereBuild()
  478. {
  479. this->UpdateData();
  480. m_CacheEntriesList.RemoveAll();
  481. m_CacheEntriesList.ShowWindow(SW_SHOW);
  482. this->LoadCacheFromDiskToGUI();
  483. m_BuildPathChanged = true;
  484. }
  485. // copy from the cache manager to the cache edit list box
  486. void CMakeSetupDialog::FillCacheGUIFromCacheManager()
  487. {
  488. int size = m_CacheEntriesList.GetItems().size();
  489. bool reverseOrder = false;
  490. // if there are already entries in the cache, then
  491. // put the new ones in the top, so they show up first
  492. if(size)
  493. {
  494. reverseOrder = true;
  495. }
  496. // all the current values are not new any more
  497. std::set<CPropertyItem*> items = m_CacheEntriesList.GetItems();
  498. for(std::set<CPropertyItem*>::iterator i = items.begin();
  499. i != items.end(); ++i)
  500. {
  501. CPropertyItem* item = *i;
  502. item->m_NewValue = false;
  503. }
  504. const cmCacheManager::CacheEntryMap &cache =
  505. cmCacheManager::GetInstance()->GetCacheMap();
  506. if(cache.size() == 0)
  507. {
  508. m_OKButton.EnableWindow(false);
  509. }
  510. else
  511. {
  512. m_OKButton.EnableWindow(true);
  513. }
  514. for(cmCacheManager::CacheEntryMap::const_iterator i = cache.begin();
  515. i != cache.end(); ++i)
  516. {
  517. const char* key = i->first.c_str();
  518. const cmCacheManager::CacheEntry& value = i->second;
  519. switch(value.m_Type )
  520. {
  521. case cmCacheManager::BOOL:
  522. if(cmSystemTools::IsOn(value.m_Value.c_str()))
  523. {
  524. m_CacheEntriesList.AddProperty(key,
  525. "ON",
  526. value.m_HelpString.c_str(),
  527. CPropertyList::COMBO,"ON|OFF",
  528. reverseOrder
  529. );
  530. }
  531. else
  532. {
  533. m_CacheEntriesList.AddProperty(key,
  534. "OFF",
  535. value.m_HelpString.c_str(),
  536. CPropertyList::COMBO,"ON|OFF",
  537. reverseOrder
  538. );
  539. }
  540. break;
  541. case cmCacheManager::PATH:
  542. m_CacheEntriesList.AddProperty(key,
  543. value.m_Value.c_str(),
  544. value.m_HelpString.c_str(),
  545. CPropertyList::PATH,"",
  546. reverseOrder
  547. );
  548. break;
  549. case cmCacheManager::FILEPATH:
  550. m_CacheEntriesList.AddProperty(key,
  551. value.m_Value.c_str(),
  552. value.m_HelpString.c_str(),
  553. CPropertyList::FILE,"",
  554. reverseOrder
  555. );
  556. break;
  557. case cmCacheManager::STRING:
  558. m_CacheEntriesList.AddProperty(key,
  559. value.m_Value.c_str(),
  560. value.m_HelpString.c_str(),
  561. CPropertyList::EDIT,"",
  562. reverseOrder
  563. );
  564. break;
  565. case cmCacheManager::INTERNAL:
  566. m_CacheEntriesList.RemoveProperty(key);
  567. break;
  568. }
  569. }
  570. // redraw the list
  571. m_CacheEntriesList.SetTopIndex(0);
  572. m_CacheEntriesList.Invalidate();
  573. }
  574. // copy from the list box to the cache manager
  575. void CMakeSetupDialog::FillCacheManagerFromCacheGUI()
  576. {
  577. cmCacheManager::GetInstance()->GetCacheMap();
  578. std::set<CPropertyItem*> items = m_CacheEntriesList.GetItems();
  579. for(std::set<CPropertyItem*>::iterator i = items.begin();
  580. i != items.end(); ++i)
  581. {
  582. CPropertyItem* item = *i;
  583. cmCacheManager::CacheEntry *entry =
  584. cmCacheManager::GetInstance()->GetCacheEntry(
  585. (const char*)item->m_propName);
  586. if (entry)
  587. {
  588. entry->m_Value = item->m_curValue;
  589. }
  590. }
  591. }
  592. //! Load cache file from m_WhereBuild and display in GUI editor
  593. void CMakeSetupDialog::LoadCacheFromDiskToGUI()
  594. {
  595. if(m_WhereBuild != "")
  596. {
  597. cmCacheManager::GetInstance()->LoadCache(m_WhereBuild);
  598. this->FillCacheGUIFromCacheManager();
  599. if(cmCacheManager::GetInstance()->GetCacheEntry("CMAKE_GENERATOR"))
  600. {
  601. std::string curGen =
  602. cmCacheManager::GetInstance()->GetCacheEntry("CMAKE_GENERATOR")->m_Value;
  603. if(m_GeneratorChoiceString != curGen.c_str())
  604. {
  605. m_GeneratorChoiceString = curGen.c_str();
  606. this->UpdateData(FALSE);
  607. }
  608. }
  609. }
  610. }
  611. //! Save GUI values to cmCacheManager and then save to disk.
  612. void CMakeSetupDialog::SaveCacheFromGUI()
  613. {
  614. this->FillCacheManagerFromCacheGUI();
  615. if(m_WhereBuild != "")
  616. {
  617. cmCacheManager::GetInstance()->SaveCache(m_WhereBuild);
  618. }
  619. }
  620. void CMakeSetupDialog::OnSize(UINT nType, int cx, int cy)
  621. {
  622. if (nType == SIZE_MINIMIZED)
  623. {
  624. CDialog::OnSize(nType, cx, cy);
  625. return;
  626. }
  627. if (m_oldCX == -1)
  628. {
  629. m_oldCX = cx;
  630. m_oldCY = cy;
  631. }
  632. int deltax = cx - m_oldCX;
  633. int deltay = cy - m_oldCY;
  634. m_oldCX = cx;
  635. m_oldCY = cy;
  636. CDialog::OnSize(nType, cx, cy);
  637. if (deltax == 0 && deltay == 0)
  638. {
  639. return;
  640. }
  641. if(m_CacheEntriesList.m_hWnd)
  642. {
  643. // get the original sizes/positions
  644. CRect cRect;
  645. m_ListFrame.GetWindowRect(&cRect);
  646. m_ListFrame.SetWindowPos(&wndTop, cRect.left, cRect.top,
  647. cRect.Width() + deltax,
  648. cRect.Height() + deltay,
  649. SWP_NOMOVE | SWP_NOZORDER);
  650. m_CacheEntriesList.GetWindowRect(&cRect);
  651. m_CacheEntriesList.SetWindowPos(&wndTop, cRect.left, cRect.top,
  652. cRect.Width() + deltax,
  653. cRect.Height() + deltay,
  654. SWP_NOMOVE | SWP_NOZORDER);
  655. m_VersionDisplay.SetWindowPos(&wndTop, 5, cy-23, 0, 0,
  656. SWP_NOSIZE | SWP_NOZORDER);
  657. deltax = deltax + m_deltaXRemainder;
  658. m_deltaXRemainder = deltax%2;
  659. m_MouseHelp.GetWindowRect(&cRect);
  660. this->ScreenToClient(&cRect);
  661. m_MouseHelp.SetWindowPos(&wndTop, cRect.left + deltax/2,
  662. cRect.top + deltay,
  663. 0, 0,
  664. SWP_NOSIZE | SWP_NOZORDER);
  665. m_Configure.GetWindowRect(&cRect);
  666. this->ScreenToClient(&cRect);
  667. m_Configure.SetWindowPos(&wndTop, cRect.left + deltax/2,
  668. cRect.top + deltay,
  669. 0, 0,
  670. SWP_NOSIZE | SWP_NOZORDER);
  671. m_CancelButton.GetWindowRect(&cRect);
  672. this->ScreenToClient(&cRect);
  673. m_CancelButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  674. cRect.top + deltay,
  675. 0, 0,
  676. SWP_NOSIZE | SWP_NOZORDER);
  677. m_OKButton.GetWindowRect(&cRect);
  678. this->ScreenToClient(&cRect);
  679. m_OKButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  680. cRect.top + deltay,
  681. 0, 0,
  682. SWP_NOSIZE | SWP_NOZORDER);
  683. }
  684. }
  685. void CMakeSetupDialog::OnGetMinMaxInfo( MINMAXINFO FAR* lpMMI )
  686. {
  687. lpMMI->ptMinTrackSize.x = 550;
  688. lpMMI->ptMinTrackSize.y = 272;
  689. }
  690. void CMakeSetupDialog::OnCancel()
  691. {
  692. if(m_CacheEntriesList.IsDirty())
  693. {
  694. if(MessageBox("You have changed options but not rebuilt, "
  695. "are you sure you want to exit?", "Confirm Exit",
  696. MB_YESNO) == IDYES)
  697. {
  698. CDialog::OnOK();
  699. }
  700. }
  701. else
  702. {
  703. CDialog::OnOK();
  704. }
  705. }
  706. void CMakeSetupDialog::OnOk()
  707. {
  708. m_CacheEntriesList.ClearDirty();
  709. this->RunCMake(true);
  710. cmMakefileGenerator::UnRegisterGenerators();
  711. CDialog::OnOK();
  712. }
  713. void CMakeSetupDialog::OnEditchangeGenerator()
  714. {
  715. // TODO: Add your control notification handler code here
  716. }