CMakeSetupDialog.cpp 21 KB

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