CMakeSetupDialog.cpp 20 KB

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