CMakeSetupDialog.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  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. m_OKButton.EnableWindow(false);
  146. return TRUE; // return TRUE unless you set the focus to a control
  147. }
  148. // About dialog invoke
  149. void CMakeSetupDialog::OnSysCommand(UINT nID, LPARAM lParam)
  150. {
  151. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  152. {
  153. CAboutDlg dlgAbout;
  154. dlgAbout.DoModal();
  155. }
  156. else
  157. {
  158. CDialog::OnSysCommand(nID, lParam);
  159. }
  160. }
  161. // If you add a minimize button to your dialog, you will need the code below
  162. // to draw the icon. For MFC applications using the document/view model,
  163. // this is automatically done for you by the framework.
  164. void CMakeSetupDialog::OnPaint()
  165. {
  166. if (IsIconic())
  167. {
  168. CPaintDC dc(this); // device context for painting
  169. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  170. // Center icon in client rectangle
  171. int cxIcon = GetSystemMetrics(SM_CXICON);
  172. int cyIcon = GetSystemMetrics(SM_CYICON);
  173. CRect rect;
  174. GetClientRect(&rect);
  175. int x = (rect.Width() - cxIcon + 1) / 2;
  176. int y = (rect.Height() - cyIcon + 1) / 2;
  177. // Draw the icon
  178. dc.DrawIcon(x, y, m_hIcon);
  179. }
  180. else
  181. {
  182. CDialog::OnPaint();
  183. }
  184. }
  185. // The system calls this to obtain the cursor to display while the user drags
  186. // the minimized window.
  187. HCURSOR CMakeSetupDialog::OnQueryDragIcon()
  188. {
  189. return (HCURSOR) m_hIcon;
  190. }
  191. // Browse button
  192. bool CMakeSetupDialog::Browse(CString &result, const char *title)
  193. {
  194. CPathDialog dlg("Select Path", title, result);
  195. if(dlg.DoModal()==IDOK)
  196. {
  197. result = dlg.GetPathName();
  198. return true;
  199. }
  200. else
  201. {
  202. return false;
  203. }
  204. }
  205. void CMakeSetupDialog::SaveToRegistry()
  206. {
  207. HKEY hKey;
  208. DWORD dwDummy;
  209. if(RegCreateKeyEx(HKEY_CURRENT_USER,
  210. m_RegistryKey,
  211. 0, "", REG_OPTION_NON_VOLATILE, KEY_READ|KEY_WRITE,
  212. NULL, &hKey, &dwDummy) != ERROR_SUCCESS)
  213. {
  214. return;
  215. }
  216. else
  217. {
  218. // load some values
  219. CString regvalue;
  220. this->ReadRegistryValue(hKey, &(regvalue),"WhereSource","C:\\");
  221. if(m_WhereSource != regvalue)
  222. {
  223. regvalue = "";
  224. this->ReadRegistryValue(hKey, &(regvalue),"WhereSource3","");
  225. RegSetValueEx(hKey, _T("WhereSource4"), 0, REG_SZ,
  226. (CONST BYTE *)(const char *)regvalue,
  227. regvalue.GetLength());
  228. regvalue = "";
  229. this->ReadRegistryValue(hKey, &(regvalue),"WhereSource2","");
  230. RegSetValueEx(hKey, _T("WhereSource3"), 0, REG_SZ,
  231. (CONST BYTE *)(const char *)regvalue,
  232. regvalue.GetLength());
  233. regvalue = "";
  234. this->ReadRegistryValue(hKey, &(regvalue),"WhereSource","");
  235. RegSetValueEx(hKey, _T("WhereSource2"), 0, REG_SZ,
  236. (CONST BYTE *)(const char *)regvalue,
  237. regvalue.GetLength());
  238. RegSetValueEx(hKey, _T("WhereSource"), 0, REG_SZ,
  239. (CONST BYTE *)(const char *)m_WhereSource,
  240. m_WhereSource.GetLength());
  241. }
  242. this->ReadRegistryValue(hKey, &(regvalue),"WhereBuild","C:\\");
  243. if(m_WhereBuild != regvalue)
  244. {
  245. regvalue = "";
  246. this->ReadRegistryValue(hKey, &(regvalue),"WhereBuild3","");
  247. RegSetValueEx(hKey, _T("WhereBuild4"), 0, REG_SZ,
  248. (CONST BYTE *)(const char *)regvalue,
  249. regvalue.GetLength());
  250. regvalue = "";
  251. this->ReadRegistryValue(hKey, &(regvalue),"WhereBuild2","");
  252. RegSetValueEx(hKey, _T("WhereBuild3"), 0, REG_SZ,
  253. (CONST BYTE *)(const char *)regvalue,
  254. regvalue.GetLength());
  255. regvalue = "";
  256. this->ReadRegistryValue(hKey, &(regvalue),"WhereBuild","");
  257. RegSetValueEx(hKey, _T("WhereBuild2"), 0, REG_SZ,
  258. (CONST BYTE *)(const char *)regvalue,
  259. regvalue.GetLength());
  260. RegSetValueEx(hKey, _T("WhereBuild"), 0, REG_SZ,
  261. (CONST BYTE *)(const char *)m_WhereBuild,
  262. m_WhereBuild.GetLength());
  263. }
  264. }
  265. RegCloseKey(hKey);
  266. }
  267. void CMakeSetupDialog::ReadRegistryValue(HKEY hKey,
  268. CString *val,
  269. const char *key,
  270. const char *adefault)
  271. {
  272. DWORD dwType, dwSize;
  273. char *pb;
  274. dwType = REG_SZ;
  275. pb = val->GetBuffer(MAX_PATH);
  276. dwSize = MAX_PATH;
  277. if(RegQueryValueEx(hKey,_T(key), NULL, &dwType,
  278. (BYTE *)pb, &dwSize) != ERROR_SUCCESS)
  279. {
  280. val->ReleaseBuffer();
  281. *val = _T(adefault);
  282. }
  283. else
  284. {
  285. val->ReleaseBuffer();
  286. }
  287. }
  288. void CMakeSetupDialog::LoadFromRegistry()
  289. {
  290. HKEY hKey;
  291. if(RegOpenKeyEx(HKEY_CURRENT_USER,
  292. m_RegistryKey,
  293. 0, KEY_READ, &hKey) != ERROR_SUCCESS)
  294. {
  295. return;
  296. }
  297. else
  298. {
  299. // load some values
  300. this->ReadRegistryValue(hKey, &(m_WhereSource),"WhereSource","C:\\");
  301. this->ReadRegistryValue(hKey, &(m_WhereBuild),"WhereBuild","C:\\");
  302. m_WhereSourceControl.AddString(m_WhereSource);
  303. m_WhereBuildControl.AddString(m_WhereBuild);
  304. CString regvalue;
  305. this->ReadRegistryValue(hKey, &(regvalue),"WhereSource2","C:\\");
  306. m_WhereSourceControl.AddString(regvalue);
  307. regvalue = "";
  308. this->ReadRegistryValue(hKey, &(regvalue),"WhereBuild2","C:\\");
  309. m_WhereBuildControl.AddString(regvalue);
  310. regvalue = "";
  311. this->ReadRegistryValue(hKey, &(regvalue),"WhereSource3","C:\\");
  312. m_WhereSourceControl.AddString(regvalue);
  313. regvalue = "";
  314. this->ReadRegistryValue(hKey, &(regvalue),"WhereBuild3","C:\\");
  315. m_WhereBuildControl.AddString(regvalue);
  316. regvalue = "";
  317. this->ReadRegistryValue(hKey, &(regvalue),"WhereSource4","C:\\");
  318. m_WhereSourceControl.AddString(regvalue);
  319. regvalue = "";
  320. this->ReadRegistryValue(hKey, &(regvalue),"WhereBuild4","C:\\");
  321. m_WhereBuildControl.AddString(regvalue);
  322. }
  323. RegCloseKey(hKey);
  324. }
  325. // Callback for browse source button
  326. void CMakeSetupDialog::OnBrowseWhereSource()
  327. {
  328. this->UpdateData();
  329. Browse(m_WhereSource, "Enter Path to Source");
  330. this->UpdateData(false);
  331. this->OnChangeWhereSource();
  332. }
  333. // Callback for browser build button
  334. void CMakeSetupDialog::OnBrowseWhereBuild()
  335. {
  336. this->UpdateData();
  337. Browse(m_WhereBuild, "Enter Path to Build");
  338. this->UpdateData(false);
  339. this->OnChangeWhereBuild();
  340. }
  341. void CMakeSetupDialog::RunCMake(bool generateProjectFiles)
  342. {
  343. if(!cmSystemTools::FileExists(m_WhereBuild))
  344. {
  345. std::string message =
  346. "Build directory does not exist, should I create it?\n\n"
  347. "Directory: ";
  348. message += (const char*)m_WhereBuild;
  349. if(MessageBox(message.c_str(), "Create Directory", MB_OKCANCEL) == IDOK)
  350. {
  351. cmSystemTools::MakeDirectory(m_WhereBuild);
  352. }
  353. else
  354. {
  355. MessageBox("Build Project aborted, nothing done.");
  356. return;
  357. }
  358. }
  359. // set the wait cursor
  360. ::SetCursor(LoadCursor(NULL, IDC_WAIT));
  361. // get all the info from the dialog
  362. this->UpdateData();
  363. if(!m_BuildPathChanged)
  364. {
  365. // if the build path has not changed save the
  366. // current GUI values to the cache
  367. this->SaveCacheFromGUI();
  368. }
  369. // Make sure we are working from the cache on disk
  370. this->LoadCacheFromDiskToGUI();
  371. // create a cmake object
  372. cmake make;
  373. // create the arguments for the cmake object
  374. std::vector<std::string> args;
  375. args.push_back((const char*)m_PathToExecutable);
  376. std::string arg;
  377. arg = "-H";
  378. arg += m_WhereSource;
  379. args.push_back(arg);
  380. arg = "-B";
  381. arg += m_WhereBuild;
  382. args.push_back(arg);
  383. // run the generate process
  384. if(make.Generate(args, generateProjectFiles) != 0)
  385. {
  386. cmSystemTools::Error(
  387. "Error in generation process, project files may be invalid");
  388. cmSystemTools::ResetErrorOccuredFlag();
  389. }
  390. // update the GUI with any new values in the caused by the
  391. // generation process
  392. this->LoadCacheFromDiskToGUI();
  393. // save source and build paths to registry
  394. this->SaveToRegistry();
  395. // path is up-to-date now
  396. m_BuildPathChanged = false;
  397. // put the cursor back
  398. ::SetCursor(LoadCursor(NULL, IDC_ARROW));
  399. }
  400. // Callback for build projects button
  401. void CMakeSetupDialog::OnConfigure()
  402. {
  403. this->RunCMake(false);
  404. // if cache has values then enb
  405. m_OKButton.EnableWindow(true);
  406. }
  407. // callback for combo box menu where build selection
  408. void CMakeSetupDialog::OnSelendokWhereBuild()
  409. {
  410. m_WhereBuildControl.GetLBText(m_WhereBuildControl.GetCurSel(),
  411. m_WhereBuild);
  412. m_WhereBuildControl.SetWindowText( m_WhereBuild);
  413. this->UpdateData(FALSE);
  414. this->OnChangeWhereBuild();
  415. }
  416. // callback for combo box menu where source selection
  417. void CMakeSetupDialog::OnSelendokWhereSource()
  418. {
  419. m_WhereSourceControl.GetLBText(m_WhereSourceControl.GetCurSel(),
  420. m_WhereSource);
  421. this->UpdateData(FALSE);
  422. this->OnChangeWhereSource();
  423. }
  424. // callback for chaing source directory
  425. void CMakeSetupDialog::OnChangeWhereSource()
  426. {
  427. }
  428. // callback for changing the build directory
  429. void CMakeSetupDialog::OnChangeWhereBuild()
  430. {
  431. this->UpdateData();
  432. m_CacheEntriesList.RemoveAll();
  433. m_CacheEntriesList.ShowWindow(SW_SHOW);
  434. this->LoadCacheFromDiskToGUI();
  435. m_BuildPathChanged = true;
  436. }
  437. // copy from the cache manager to the cache edit list box
  438. void CMakeSetupDialog::FillCacheGUIFromCacheManager()
  439. {
  440. int size = m_CacheEntriesList.GetItems().size();
  441. bool reverseOrder = false;
  442. // if there are already entries in the cache, then
  443. // put the new ones in the top, so they show up first
  444. if(size)
  445. {
  446. reverseOrder = true;
  447. }
  448. // all the current values are not new any more
  449. std::set<CPropertyItem*> items = m_CacheEntriesList.GetItems();
  450. for(std::set<CPropertyItem*>::iterator i = items.begin();
  451. i != items.end(); ++i)
  452. {
  453. CPropertyItem* item = *i;
  454. item->m_NewValue = false;
  455. }
  456. const cmCacheManager::CacheEntryMap &cache =
  457. cmCacheManager::GetInstance()->GetCacheMap();
  458. for(cmCacheManager::CacheEntryMap::const_iterator i = cache.begin();
  459. i != cache.end(); ++i)
  460. {
  461. const char* key = i->first.c_str();
  462. const cmCacheManager::CacheEntry& value = i->second;
  463. switch(value.m_Type )
  464. {
  465. case cmCacheManager::BOOL:
  466. if(cmCacheManager::GetInstance()->IsOn(key))
  467. {
  468. m_CacheEntriesList.AddProperty(key,
  469. "ON",
  470. value.m_HelpString.c_str(),
  471. CPropertyList::CHECKBOX,"",
  472. reverseOrder
  473. );
  474. }
  475. else
  476. {
  477. m_CacheEntriesList.AddProperty(key,
  478. "OFF",
  479. value.m_HelpString.c_str(),
  480. CPropertyList::CHECKBOX,"",
  481. reverseOrder
  482. );
  483. }
  484. break;
  485. case cmCacheManager::PATH:
  486. m_CacheEntriesList.AddProperty(key,
  487. value.m_Value.c_str(),
  488. value.m_HelpString.c_str(),
  489. CPropertyList::PATH,"",
  490. reverseOrder
  491. );
  492. break;
  493. case cmCacheManager::FILEPATH:
  494. m_CacheEntriesList.AddProperty(key,
  495. value.m_Value.c_str(),
  496. value.m_HelpString.c_str(),
  497. CPropertyList::FILE,"",
  498. reverseOrder
  499. );
  500. break;
  501. case cmCacheManager::STRING:
  502. m_CacheEntriesList.AddProperty(key,
  503. value.m_Value.c_str(),
  504. value.m_HelpString.c_str(),
  505. CPropertyList::EDIT,"",
  506. reverseOrder
  507. );
  508. break;
  509. case cmCacheManager::INTERNAL:
  510. break;
  511. }
  512. }
  513. // redraw the list
  514. m_CacheEntriesList.SetTopIndex(0);
  515. m_CacheEntriesList.Invalidate();
  516. }
  517. // copy from the list box to the cache manager
  518. void CMakeSetupDialog::FillCacheManagerFromCacheGUI()
  519. {
  520. cmCacheManager::GetInstance()->GetCacheMap();
  521. std::set<CPropertyItem*> items = m_CacheEntriesList.GetItems();
  522. for(std::set<CPropertyItem*>::iterator i = items.begin();
  523. i != items.end(); ++i)
  524. {
  525. CPropertyItem* item = *i;
  526. cmCacheManager::CacheEntry *entry =
  527. cmCacheManager::GetInstance()->GetCacheEntry(
  528. (const char*)item->m_propName);
  529. if (entry)
  530. {
  531. entry->m_Value = item->m_curValue;
  532. }
  533. }
  534. }
  535. //! Load cache file from m_WhereBuild and display in GUI editor
  536. void CMakeSetupDialog::LoadCacheFromDiskToGUI()
  537. {
  538. if(m_WhereBuild != "")
  539. {
  540. cmCacheManager::GetInstance()->LoadCache(m_WhereBuild);
  541. this->FillCacheGUIFromCacheManager();
  542. }
  543. }
  544. //! Save GUI values to cmCacheManager and then save to disk.
  545. void CMakeSetupDialog::SaveCacheFromGUI()
  546. {
  547. this->FillCacheManagerFromCacheGUI();
  548. if(m_WhereBuild != "")
  549. {
  550. cmCacheManager::GetInstance()->SaveCache(m_WhereBuild);
  551. }
  552. }
  553. void CMakeSetupDialog::OnSize(UINT nType, int cx, int cy)
  554. {
  555. if (nType == SIZE_MINIMIZED)
  556. {
  557. CDialog::OnSize(nType, cx, cy);
  558. return;
  559. }
  560. if (m_oldCX == -1)
  561. {
  562. m_oldCX = cx;
  563. m_oldCY = cy;
  564. }
  565. int deltax = cx - m_oldCX;
  566. int deltay = cy - m_oldCY;
  567. m_oldCX = cx;
  568. m_oldCY = cy;
  569. CDialog::OnSize(nType, cx, cy);
  570. if (deltax == 0 && deltay == 0)
  571. {
  572. return;
  573. }
  574. if(m_CacheEntriesList.m_hWnd)
  575. {
  576. // get the original sizes/positions
  577. CRect cRect;
  578. m_ListFrame.GetWindowRect(&cRect);
  579. m_ListFrame.SetWindowPos(&wndTop, cRect.left, cRect.top,
  580. cRect.Width() + deltax,
  581. cRect.Height() + deltay,
  582. SWP_NOMOVE | SWP_NOZORDER);
  583. m_CacheEntriesList.GetWindowRect(&cRect);
  584. m_CacheEntriesList.SetWindowPos(&wndTop, cRect.left, cRect.top,
  585. cRect.Width() + deltax,
  586. cRect.Height() + deltay,
  587. SWP_NOMOVE | SWP_NOZORDER);
  588. m_VersionDisplay.SetWindowPos(&wndTop, 5, cy-23, 0, 0,
  589. SWP_NOSIZE | SWP_NOZORDER);
  590. deltax = deltax + m_deltaXRemainder;
  591. m_deltaXRemainder = deltax%2;
  592. m_MouseHelp.GetWindowRect(&cRect);
  593. this->ScreenToClient(&cRect);
  594. m_MouseHelp.SetWindowPos(&wndTop, cRect.left + deltax/2,
  595. cRect.top + deltay,
  596. 0, 0,
  597. SWP_NOSIZE | SWP_NOZORDER);
  598. m_Configure.GetWindowRect(&cRect);
  599. this->ScreenToClient(&cRect);
  600. m_Configure.SetWindowPos(&wndTop, cRect.left + deltax/2,
  601. cRect.top + deltay,
  602. 0, 0,
  603. SWP_NOSIZE | SWP_NOZORDER);
  604. m_CancelButton.GetWindowRect(&cRect);
  605. this->ScreenToClient(&cRect);
  606. m_CancelButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  607. cRect.top + deltay,
  608. 0, 0,
  609. SWP_NOSIZE | SWP_NOZORDER);
  610. m_OKButton.GetWindowRect(&cRect);
  611. this->ScreenToClient(&cRect);
  612. m_OKButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  613. cRect.top + deltay,
  614. 0, 0,
  615. SWP_NOSIZE | SWP_NOZORDER);
  616. }
  617. }
  618. void CMakeSetupDialog::OnGetMinMaxInfo( MINMAXINFO FAR* lpMMI )
  619. {
  620. lpMMI->ptMinTrackSize.x = 550;
  621. lpMMI->ptMinTrackSize.y = 272;
  622. }
  623. void CMakeSetupDialog::OnCancel()
  624. {
  625. if(m_OKButton.IsWindowEnabled())
  626. {
  627. if(MessageBox("You have changed options but not rebuilt, "
  628. "are you sure you want to exit?", "Confirm Exit",
  629. MB_YESNO) == IDYES)
  630. {
  631. CDialog::OnOK();
  632. }
  633. }
  634. else
  635. {
  636. CDialog::OnOK();
  637. }
  638. }
  639. void CMakeSetupDialog::OnOk()
  640. {
  641. m_CacheEntriesList.ClearDirty();
  642. this->RunCMake(true);
  643. CDialog::OnOK();
  644. }