CMakeSetupDialog.cpp 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003
  1. // pcbuilderdialogDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "CMakeSetup.h"
  5. #include "MakeHelp.h"
  6. #include "PathDialog.h"
  7. #include "CMakeSetupDialog.h"
  8. #include "CMakeCommandLineInfo.h"
  9. #include "../cmCacheManager.h"
  10. #include "../cmake.h"
  11. #include "../cmMakefileGenerator.h"
  12. #ifdef _DEBUG
  13. #define new DEBUG_NEW
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CAboutDlg dialog used for App About
  19. class CAboutDlg : public CDialog
  20. {
  21. public:
  22. CAboutDlg();
  23. // Dialog Data
  24. //{{AFX_DATA(CAboutDlg)
  25. enum { IDD = IDD_ABOUTBOX };
  26. //}}AFX_DATA
  27. // ClassWizard generated virtual function overrides
  28. //{{AFX_VIRTUAL(CAboutDlg)
  29. protected:
  30. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
  31. //}}AFX_VIRTUAL
  32. // Implementation
  33. protected:
  34. //{{AFX_MSG(CAboutDlg)
  35. //}}AFX_MSG
  36. DECLARE_MESSAGE_MAP()
  37. };
  38. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  39. {
  40. //{{AFX_DATA_INIT(CAboutDlg)
  41. //}}AFX_DATA_INIT
  42. }
  43. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  44. {
  45. CDialog::DoDataExchange(pDX);
  46. //{{AFX_DATA_MAP(CAboutDlg)
  47. //}}AFX_DATA_MAP
  48. }
  49. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  50. //{{AFX_MSG_MAP(CAboutDlg)
  51. // No message handlers
  52. //}}AFX_MSG_MAP
  53. END_MESSAGE_MAP();
  54. void MFCMessageCallback(const char* m, const char* title, bool& nomore)
  55. {
  56. std::string message = m;
  57. message += "\n\n(Press Cancel to suppress any further messages.)";
  58. if(::MessageBox(0, message.c_str(), title,
  59. MB_OKCANCEL) == IDCANCEL)
  60. {
  61. nomore = true;
  62. }
  63. }
  64. /////////////////////////////////////////////////////////////////////////////
  65. // CMakeSetupDialog dialog
  66. CMakeSetupDialog::CMakeSetupDialog(const CMakeCommandLineInfo& cmdInfo,
  67. CWnd* pParent /*=NULL*/)
  68. : CDialog(CMakeSetupDialog::IDD, pParent)
  69. {
  70. cmSystemTools::SetErrorCallback(MFCMessageCallback);
  71. m_RegistryKey = "Software\\Kitware\\CMakeSetup\\Settings\\StartPath";
  72. //{{AFX_DATA_INIT(CMakeSetupDialog)
  73. m_WhereSource = cmdInfo.m_WhereSource;
  74. m_WhereBuild = cmdInfo.m_WhereBuild;
  75. m_GeneratorChoiceString = _T("");
  76. //}}AFX_DATA_INIT
  77. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  78. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  79. m_BuildPathChanged = false;
  80. // Find the path to the cmake.exe executable
  81. char fname[1024];
  82. ::GetModuleFileName(NULL,fname,1023);
  83. // extract just the path part
  84. m_PathToExecutable = cmSystemTools::GetProgramPath(fname).c_str();
  85. // add the cmake.exe to the path
  86. m_PathToExecutable += "/cmake.exe";
  87. m_oldCX = -1;
  88. m_deltaXRemainder = 0;
  89. }
  90. void CMakeSetupDialog::DoDataExchange(CDataExchange* pDX)
  91. {
  92. CDialog::DoDataExchange(pDX);
  93. //{{AFX_DATA_MAP(CMakeSetupDialog)
  94. DDX_Control(pDX, IDC_HELP_BUTTON, m_HelpButton);
  95. DDX_Control(pDX, IDC_Generator, m_GeneratorChoice);
  96. DDX_Control(pDX, IDC_OK, m_OKButton);
  97. DDX_Control(pDX, IDCANCEL, m_CancelButton);
  98. DDX_CBStringExact(pDX, IDC_WhereSource, m_WhereSource);
  99. DDX_CBStringExact(pDX, IDC_WhereBuild, m_WhereBuild);
  100. DDX_Control(pDX, IDC_FRAME, m_ListFrame);
  101. DDX_Control(pDX, IDC_WhereSource, m_WhereSourceControl);
  102. DDX_Control(pDX, IDC_WhereBuild, m_WhereBuildControl);
  103. DDX_Control(pDX, IDC_LIST2, m_CacheEntriesList);
  104. DDX_Control(pDX, IDC_MouseHelpCaption, m_MouseHelp);
  105. DDX_Control(pDX, IDC_CMAKE_VERSION, m_VersionDisplay);
  106. DDX_Control(pDX, IDC_BuildProjects, m_Configure);
  107. DDX_CBStringExact(pDX, IDC_Generator, m_GeneratorChoiceString);
  108. //}}AFX_DATA_MAP
  109. }
  110. BEGIN_MESSAGE_MAP(CMakeSetupDialog, CDialog)
  111. //{{AFX_MSG_MAP(CMakeSetupDialog)
  112. ON_WM_SYSCOMMAND()
  113. ON_WM_PAINT()
  114. ON_WM_QUERYDRAGICON()
  115. ON_BN_CLICKED(IDC_BUTTON2, OnBrowseWhereSource)
  116. ON_BN_CLICKED(IDC_BuildProjects, OnConfigure)
  117. ON_BN_CLICKED(IDC_BUTTON3, OnBrowseWhereBuild)
  118. ON_CBN_EDITCHANGE(IDC_WhereBuild, OnChangeWhereBuild)
  119. ON_CBN_SELCHANGE(IDC_WhereBuild, OnSelendokWhereBuild)
  120. ON_CBN_EDITCHANGE(IDC_WhereSource, OnChangeWhereSource)
  121. ON_CBN_SELENDOK(IDC_WhereSource, OnSelendokWhereSource)
  122. ON_WM_SIZE()
  123. ON_WM_GETMINMAXINFO()
  124. ON_BN_CLICKED(IDC_OK, OnOk)
  125. ON_CBN_EDITCHANGE(IDC_Generator, OnEditchangeGenerator)
  126. ON_BN_CLICKED(IDCANCEL, OnCancel)
  127. ON_BN_CLICKED(IDC_HELP_BUTTON, OnHelpButton)
  128. //}}AFX_MSG_MAP
  129. END_MESSAGE_MAP()
  130. /////////////////////////////////////////////////////////////////////////////
  131. // CMakeSetupDialog message handlers
  132. BOOL CMakeSetupDialog::OnInitDialog()
  133. {
  134. CDialog::OnInitDialog();
  135. // Add "Create shortcut" menu item to system menu.
  136. // IDM_CREATESHORTCUT must be in the system command range.
  137. ASSERT((IDM_CREATESHORTCUT & 0xFFF0) == IDM_CREATESHORTCUT);
  138. ASSERT(IDM_CREATESHORTCUT < 0xF000);
  139. // Add "About..." menu item to system menu.
  140. // IDM_ABOUTBOX must be in the system command range.
  141. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  142. ASSERT(IDM_ABOUTBOX < 0xF000);
  143. CMenu* pSysMenu = GetSystemMenu(FALSE);
  144. if (pSysMenu != NULL)
  145. {
  146. CString strCreateShortcutMenu;
  147. strCreateShortcutMenu.LoadString(IDS_CREATESHORTCUT);
  148. if (!strCreateShortcutMenu.IsEmpty())
  149. {
  150. pSysMenu->AppendMenu(MF_SEPARATOR);
  151. pSysMenu->AppendMenu(MF_STRING,
  152. IDM_CREATESHORTCUT,
  153. strCreateShortcutMenu);
  154. }
  155. CString strAboutMenu;
  156. strAboutMenu.LoadString(IDS_ABOUTBOX);
  157. if (!strAboutMenu.IsEmpty())
  158. {
  159. pSysMenu->AppendMenu(MF_SEPARATOR);
  160. pSysMenu->AppendMenu(MF_STRING,
  161. IDM_ABOUTBOX,
  162. strAboutMenu);
  163. }
  164. }
  165. // Set the icon for this dialog. The framework does this automatically
  166. // when the application's main window is not a dialog
  167. SetIcon(m_hIcon, TRUE); // Set big icon
  168. SetIcon(m_hIcon, FALSE); // Set small icon
  169. // Load source and build dirs from registry
  170. this->LoadFromRegistry();
  171. cmake m; // force a register of generators
  172. std::vector<std::string> names;
  173. cmMakefileGenerator::GetRegisteredGenerators(names);
  174. for(std::vector<std::string>::iterator i = names.begin();
  175. i != names.end(); ++i)
  176. {
  177. m_GeneratorChoice.AddString(i->c_str());
  178. }
  179. m_GeneratorChoiceString = "Visual Studio 6";
  180. // try to load the cmake cache from disk
  181. this->LoadCacheFromDiskToGUI();
  182. m_WhereBuildControl.LimitText(2048);
  183. m_WhereSourceControl.LimitText(2048);
  184. m_GeneratorChoice.LimitText(2048);
  185. // Set the version number
  186. char tmp[1024];
  187. sprintf(tmp,"Version %d.%d", cmMakefile::GetMajorVersion(),
  188. cmMakefile::GetMinorVersion());
  189. SetDlgItemText(IDC_CMAKE_VERSION, tmp);
  190. this->UpdateData(FALSE);
  191. return TRUE; // return TRUE unless you set the focus to a control
  192. }
  193. // About dialog invoke
  194. void CMakeSetupDialog::OnSysCommand(UINT nID, LPARAM lParam)
  195. {
  196. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  197. {
  198. CAboutDlg dlgAbout;
  199. dlgAbout.DoModal();
  200. }
  201. else if ((nID & 0xFFF0) == IDM_CREATESHORTCUT)
  202. {
  203. CreateShortcut();
  204. }
  205. else
  206. {
  207. CDialog::OnSysCommand(nID, lParam);
  208. }
  209. }
  210. // If you add a minimize button to your dialog, you will need the code below
  211. // to draw the icon. For MFC applications using the document/view model,
  212. // this is automatically done for you by the framework.
  213. void CMakeSetupDialog::OnPaint()
  214. {
  215. if (IsIconic())
  216. {
  217. CPaintDC dc(this); // device context for painting
  218. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  219. // Center icon in client rectangle
  220. int cxIcon = GetSystemMetrics(SM_CXICON);
  221. int cyIcon = GetSystemMetrics(SM_CYICON);
  222. CRect rect;
  223. GetClientRect(&rect);
  224. int x = (rect.Width() - cxIcon + 1) / 2;
  225. int y = (rect.Height() - cyIcon + 1) / 2;
  226. // Draw the icon
  227. dc.DrawIcon(x, y, m_hIcon);
  228. }
  229. else
  230. {
  231. CDialog::OnPaint();
  232. }
  233. }
  234. // The system calls this to obtain the cursor to display while the user drags
  235. // the minimized window.
  236. HCURSOR CMakeSetupDialog::OnQueryDragIcon()
  237. {
  238. return (HCURSOR) m_hIcon;
  239. }
  240. // Browse button
  241. bool CMakeSetupDialog::Browse(CString &result, const char *title)
  242. {
  243. CPathDialog dlg("Select Path", title, result);
  244. if(dlg.DoModal()==IDOK)
  245. {
  246. result = dlg.GetPathName();
  247. return true;
  248. }
  249. else
  250. {
  251. return false;
  252. }
  253. }
  254. void CMakeSetupDialog::SaveToRegistry()
  255. {
  256. HKEY hKey;
  257. DWORD dwDummy;
  258. if(RegCreateKeyEx(HKEY_CURRENT_USER,
  259. m_RegistryKey,
  260. 0, "", REG_OPTION_NON_VOLATILE, KEY_READ|KEY_WRITE,
  261. NULL, &hKey, &dwDummy) != ERROR_SUCCESS)
  262. {
  263. return;
  264. }
  265. else
  266. {
  267. // save some values
  268. CString regvalue;
  269. this->ReadRegistryValue(hKey, &(regvalue),"WhereSource1","C:\\");
  270. int shiftEnd = 9;
  271. if(m_WhereSource != regvalue)
  272. {
  273. char keyName[1024];
  274. char keyName2[1024];
  275. int i;
  276. for (i = 2; i < 10; ++i)
  277. {
  278. regvalue = "";
  279. sprintf(keyName,"WhereSource%i",i);
  280. this->ReadRegistryValue(hKey, &(regvalue),keyName,"");
  281. // check for short circuit, if the new value is already in
  282. // the list then we stop
  283. if (m_WhereSource == regvalue)
  284. {
  285. shiftEnd = i - 1;
  286. }
  287. }
  288. for (i = shiftEnd; i; --i)
  289. {
  290. regvalue = "";
  291. sprintf(keyName,"WhereSource%i",i);
  292. sprintf(keyName2,"WhereSource%i",i+1);
  293. this->ReadRegistryValue(hKey, &(regvalue),keyName,"");
  294. if (strlen(regvalue))
  295. {
  296. RegSetValueEx(hKey, _T(keyName2), 0, REG_SZ,
  297. (CONST BYTE *)(const char *)regvalue,
  298. regvalue.GetLength());
  299. }
  300. }
  301. RegSetValueEx(hKey, _T("WhereSource1"), 0, REG_SZ,
  302. (CONST BYTE *)(const char *)m_WhereSource,
  303. m_WhereSource.GetLength());
  304. }
  305. this->ReadRegistryValue(hKey, &(regvalue),"WhereBuild1","C:\\");
  306. if(m_WhereBuild != regvalue)
  307. {
  308. int i;
  309. char keyName[1024];
  310. char keyName2[1024];
  311. for (i = 2; i < 10; ++i)
  312. {
  313. regvalue = "";
  314. sprintf(keyName,"WhereBuild%i",i);
  315. this->ReadRegistryValue(hKey, &(regvalue),keyName,"");
  316. // check for short circuit, if the new value is already in
  317. // the list then we stop
  318. if (m_WhereBuild == regvalue)
  319. {
  320. shiftEnd = i - 1;
  321. }
  322. }
  323. for (i = shiftEnd; i; --i)
  324. {
  325. regvalue = "";
  326. sprintf(keyName,"WhereBuild%i",i);
  327. sprintf(keyName2,"WhereBuild%i",i+1);
  328. this->ReadRegistryValue(hKey, &(regvalue),keyName,"");
  329. if (strlen(regvalue))
  330. {
  331. RegSetValueEx(hKey, _T(keyName2), 0, REG_SZ,
  332. (CONST BYTE *)(const char *)regvalue,
  333. regvalue.GetLength());
  334. }
  335. }
  336. RegSetValueEx(hKey, _T("WhereBuild1"), 0, REG_SZ,
  337. (CONST BYTE *)(const char *)m_WhereBuild,
  338. m_WhereBuild.GetLength());
  339. }
  340. }
  341. RegCloseKey(hKey);
  342. }
  343. void CMakeSetupDialog::ReadRegistryValue(HKEY hKey,
  344. CString *val,
  345. const char *key,
  346. const char *adefault)
  347. {
  348. DWORD dwType, dwSize;
  349. char *pb;
  350. dwType = REG_SZ;
  351. pb = val->GetBuffer(MAX_PATH);
  352. dwSize = MAX_PATH;
  353. if(RegQueryValueEx(hKey,_T(key), NULL, &dwType,
  354. (BYTE *)pb, &dwSize) != ERROR_SUCCESS)
  355. {
  356. val->ReleaseBuffer();
  357. *val = _T(adefault);
  358. }
  359. else
  360. {
  361. val->ReleaseBuffer();
  362. }
  363. }
  364. void CMakeSetupDialog::LoadFromRegistry()
  365. {
  366. HKEY hKey;
  367. if(RegOpenKeyEx(HKEY_CURRENT_USER,
  368. m_RegistryKey,
  369. 0, KEY_READ, &hKey) != ERROR_SUCCESS)
  370. {
  371. return;
  372. }
  373. else
  374. {
  375. // load some values
  376. if (m_WhereSource.IsEmpty())
  377. {
  378. this->ReadRegistryValue(hKey, &(m_WhereSource),"WhereSource1","C:\\");
  379. }
  380. if (m_WhereBuild.IsEmpty())
  381. {
  382. this->ReadRegistryValue(hKey, &(m_WhereBuild),"WhereBuild1","C:\\");
  383. }
  384. m_WhereSourceControl.AddString(m_WhereSource);
  385. m_WhereBuildControl.AddString(m_WhereBuild);
  386. char keyname[1024];
  387. CString regvalue;
  388. int i;
  389. for (i = 2; i <= 10; ++i)
  390. {
  391. sprintf(keyname,"WhereSource%i",i);
  392. regvalue = "";
  393. this->ReadRegistryValue(hKey, &(regvalue),keyname,"C:\\");
  394. if (strcmp("C:\\",regvalue))
  395. {
  396. m_WhereSourceControl.AddString(regvalue);
  397. }
  398. sprintf(keyname,"WhereBuild%i",i);
  399. regvalue = "";
  400. this->ReadRegistryValue(hKey, &(regvalue),keyname,"C:\\");
  401. if (strcmp("C:\\",regvalue))
  402. {
  403. m_WhereBuildControl.AddString(regvalue);
  404. }
  405. }
  406. }
  407. RegCloseKey(hKey);
  408. }
  409. // Callback for browse source button
  410. void CMakeSetupDialog::OnBrowseWhereSource()
  411. {
  412. this->UpdateData();
  413. Browse(m_WhereSource, "Enter Path to Source");
  414. this->UpdateData(false);
  415. this->OnChangeWhereSource();
  416. }
  417. // Callback for browser build button
  418. void CMakeSetupDialog::OnBrowseWhereBuild()
  419. {
  420. this->UpdateData();
  421. Browse(m_WhereBuild, "Enter Path to Build");
  422. this->UpdateData(false);
  423. this->OnChangeWhereBuild();
  424. }
  425. void CMakeSetupDialog::RunCMake(bool generateProjectFiles)
  426. {
  427. if(!cmSystemTools::FileExists(m_WhereBuild))
  428. {
  429. std::string message =
  430. "Build directory does not exist, should I create it?\n\n"
  431. "Directory: ";
  432. message += (const char*)m_WhereBuild;
  433. if(MessageBox(message.c_str(), "Create Directory", MB_OKCANCEL) == IDOK)
  434. {
  435. cmSystemTools::MakeDirectory(m_WhereBuild);
  436. }
  437. else
  438. {
  439. MessageBox("Build Project aborted, nothing done.");
  440. return;
  441. }
  442. }
  443. // set the wait cursor
  444. ::SetCursor(LoadCursor(NULL, IDC_WAIT));
  445. // get all the info from the dialog
  446. this->UpdateData();
  447. // always save the current gui values to disk
  448. this->SaveCacheFromGUI();
  449. // Make sure we are working from the cache on disk
  450. this->LoadCacheFromDiskToGUI();
  451. // create a cmake object
  452. cmake make;
  453. // create the arguments for the cmake object
  454. std::vector<std::string> args;
  455. args.push_back((const char*)m_PathToExecutable);
  456. std::string arg;
  457. arg = "-H";
  458. arg += m_WhereSource;
  459. args.push_back(arg);
  460. arg = "-B";
  461. arg += m_WhereBuild;
  462. args.push_back(arg);
  463. arg = "-G";
  464. arg += m_GeneratorChoiceString;
  465. args.push_back(arg);
  466. // run the generate process
  467. if(make.Generate(args, generateProjectFiles) != 0)
  468. {
  469. cmSystemTools::Error(
  470. "Error in generation process, project files may be invalid");
  471. cmSystemTools::ResetErrorOccuredFlag();
  472. }
  473. // update the GUI with any new values in the caused by the
  474. // generation process
  475. this->LoadCacheFromDiskToGUI();
  476. // save source and build paths to registry
  477. this->SaveToRegistry();
  478. // path is up-to-date now
  479. m_BuildPathChanged = false;
  480. // put the cursor back
  481. ::SetCursor(LoadCursor(NULL, IDC_ARROW));
  482. }
  483. // Callback for build projects button
  484. void CMakeSetupDialog::OnConfigure()
  485. {
  486. this->RunCMake(false);
  487. }
  488. // callback for combo box menu where build selection
  489. void CMakeSetupDialog::OnSelendokWhereBuild()
  490. {
  491. m_WhereBuildControl.GetLBText(m_WhereBuildControl.GetCurSel(),
  492. m_WhereBuild);
  493. m_WhereBuildControl.SetWindowText( m_WhereBuild);
  494. this->UpdateData(FALSE);
  495. this->OnChangeWhereBuild();
  496. }
  497. // callback for combo box menu where source selection
  498. void CMakeSetupDialog::OnSelendokWhereSource()
  499. {
  500. m_WhereSourceControl.GetLBText(m_WhereSourceControl.GetCurSel(),
  501. m_WhereSource);
  502. this->UpdateData(FALSE);
  503. this->OnChangeWhereSource();
  504. }
  505. // callback for chaing source directory
  506. void CMakeSetupDialog::OnChangeWhereSource()
  507. {
  508. }
  509. // callback for changing the build directory
  510. void CMakeSetupDialog::OnChangeWhereBuild()
  511. {
  512. this->UpdateData();
  513. m_CacheEntriesList.RemoveAll();
  514. m_CacheEntriesList.ShowWindow(SW_SHOW);
  515. this->LoadCacheFromDiskToGUI();
  516. m_BuildPathChanged = true;
  517. }
  518. // copy from the cache manager to the cache edit list box
  519. void CMakeSetupDialog::FillCacheGUIFromCacheManager()
  520. {
  521. int size = m_CacheEntriesList.GetItems().size();
  522. bool reverseOrder = false;
  523. // if there are already entries in the cache, then
  524. // put the new ones in the top, so they show up first
  525. if(size)
  526. {
  527. reverseOrder = true;
  528. }
  529. // all the current values are not new any more
  530. std::set<CPropertyItem*> items = m_CacheEntriesList.GetItems();
  531. for(std::set<CPropertyItem*>::iterator i = items.begin();
  532. i != items.end(); ++i)
  533. {
  534. CPropertyItem* item = *i;
  535. item->m_NewValue = false;
  536. }
  537. const cmCacheManager::CacheEntryMap &cache =
  538. cmCacheManager::GetInstance()->GetCacheMap();
  539. for(cmCacheManager::CacheEntryMap::const_iterator i = cache.begin();
  540. i != cache.end(); ++i)
  541. {
  542. const char* key = i->first.c_str();
  543. const cmCacheManager::CacheEntry& value = i->second;
  544. switch(value.m_Type )
  545. {
  546. case cmCacheManager::BOOL:
  547. if(cmSystemTools::IsOn(value.m_Value.c_str()))
  548. {
  549. m_CacheEntriesList.AddProperty(key,
  550. "ON",
  551. value.m_HelpString.c_str(),
  552. CPropertyList::COMBO,"ON|OFF",
  553. reverseOrder
  554. );
  555. }
  556. else
  557. {
  558. m_CacheEntriesList.AddProperty(key,
  559. "OFF",
  560. value.m_HelpString.c_str(),
  561. CPropertyList::COMBO,"ON|OFF",
  562. reverseOrder
  563. );
  564. }
  565. break;
  566. case cmCacheManager::PATH:
  567. m_CacheEntriesList.AddProperty(key,
  568. value.m_Value.c_str(),
  569. value.m_HelpString.c_str(),
  570. CPropertyList::PATH,"",
  571. reverseOrder
  572. );
  573. break;
  574. case cmCacheManager::FILEPATH:
  575. m_CacheEntriesList.AddProperty(key,
  576. value.m_Value.c_str(),
  577. value.m_HelpString.c_str(),
  578. CPropertyList::FILE,"",
  579. reverseOrder
  580. );
  581. break;
  582. case cmCacheManager::STRING:
  583. m_CacheEntriesList.AddProperty(key,
  584. value.m_Value.c_str(),
  585. value.m_HelpString.c_str(),
  586. CPropertyList::EDIT,"",
  587. reverseOrder
  588. );
  589. break;
  590. case cmCacheManager::INTERNAL:
  591. m_CacheEntriesList.RemoveProperty(key);
  592. break;
  593. }
  594. }
  595. m_OKButton.EnableWindow(false);
  596. if(cache.size() > 0)
  597. {
  598. bool enable = true;
  599. items = m_CacheEntriesList.GetItems();
  600. for(std::set<CPropertyItem*>::iterator i = items.begin();
  601. i != items.end(); ++i)
  602. {
  603. CPropertyItem* item = *i;
  604. if(item->m_NewValue)
  605. {
  606. // if one new value then disable to OK button
  607. enable = false;
  608. break;
  609. }
  610. }
  611. if(enable)
  612. {
  613. m_OKButton.EnableWindow(true);
  614. }
  615. }
  616. // redraw the list
  617. m_CacheEntriesList.SetTopIndex(0);
  618. m_CacheEntriesList.Invalidate();
  619. }
  620. // copy from the list box to the cache manager
  621. void CMakeSetupDialog::FillCacheManagerFromCacheGUI()
  622. {
  623. cmCacheManager::GetInstance()->GetCacheMap();
  624. std::set<CPropertyItem*> items = m_CacheEntriesList.GetItems();
  625. for(std::set<CPropertyItem*>::iterator i = items.begin();
  626. i != items.end(); ++i)
  627. {
  628. CPropertyItem* item = *i;
  629. cmCacheManager::CacheEntry *entry =
  630. cmCacheManager::GetInstance()->GetCacheEntry(
  631. (const char*)item->m_propName);
  632. if (entry)
  633. {
  634. entry->m_Value = item->m_curValue;
  635. }
  636. }
  637. }
  638. //! Load cache file from m_WhereBuild and display in GUI editor
  639. void CMakeSetupDialog::LoadCacheFromDiskToGUI()
  640. {
  641. if(m_WhereBuild != "")
  642. {
  643. cmCacheManager::GetInstance()->LoadCache(m_WhereBuild);
  644. this->FillCacheGUIFromCacheManager();
  645. if(cmCacheManager::GetInstance()->GetCacheEntry("CMAKE_GENERATOR"))
  646. {
  647. std::string curGen =
  648. cmCacheManager::GetInstance()->GetCacheEntry("CMAKE_GENERATOR")->m_Value;
  649. if(m_GeneratorChoiceString != curGen.c_str())
  650. {
  651. m_GeneratorChoiceString = curGen.c_str();
  652. this->UpdateData(FALSE);
  653. }
  654. }
  655. }
  656. }
  657. //! Save GUI values to cmCacheManager and then save to disk.
  658. void CMakeSetupDialog::SaveCacheFromGUI()
  659. {
  660. this->FillCacheManagerFromCacheGUI();
  661. if(m_WhereBuild != "")
  662. {
  663. cmCacheManager::GetInstance()->SaveCache(m_WhereBuild);
  664. }
  665. }
  666. void CMakeSetupDialog::OnSize(UINT nType, int cx, int cy)
  667. {
  668. if (nType == SIZE_MINIMIZED)
  669. {
  670. CDialog::OnSize(nType, cx, cy);
  671. return;
  672. }
  673. if (m_oldCX == -1)
  674. {
  675. m_oldCX = cx;
  676. m_oldCY = cy;
  677. }
  678. int deltax = cx - m_oldCX;
  679. int deltay = cy - m_oldCY;
  680. m_oldCX = cx;
  681. m_oldCY = cy;
  682. CDialog::OnSize(nType, cx, cy);
  683. if (deltax == 0 && deltay == 0)
  684. {
  685. return;
  686. }
  687. if(m_CacheEntriesList.m_hWnd)
  688. {
  689. // get the original sizes/positions
  690. CRect cRect;
  691. m_ListFrame.GetWindowRect(&cRect);
  692. m_ListFrame.SetWindowPos(&wndTop, cRect.left, cRect.top,
  693. cRect.Width() + deltax,
  694. cRect.Height() + deltay,
  695. SWP_NOMOVE | SWP_NOZORDER);
  696. m_CacheEntriesList.GetWindowRect(&cRect);
  697. m_CacheEntriesList.SetWindowPos(&wndTop, cRect.left, cRect.top,
  698. cRect.Width() + deltax,
  699. cRect.Height() + deltay,
  700. SWP_NOMOVE | SWP_NOZORDER);
  701. m_VersionDisplay.SetWindowPos(&wndTop, 5, cy-23, 0, 0,
  702. SWP_NOSIZE | SWP_NOZORDER);
  703. deltax = deltax + m_deltaXRemainder;
  704. m_deltaXRemainder = deltax%2;
  705. m_MouseHelp.GetWindowRect(&cRect);
  706. this->ScreenToClient(&cRect);
  707. m_MouseHelp.SetWindowPos(&wndTop, cRect.left + deltax/2,
  708. cRect.top + deltay,
  709. 0, 0,
  710. SWP_NOSIZE | SWP_NOZORDER);
  711. m_Configure.GetWindowRect(&cRect);
  712. this->ScreenToClient(&cRect);
  713. m_Configure.SetWindowPos(&wndTop, cRect.left + deltax/2,
  714. cRect.top + deltay,
  715. 0, 0,
  716. SWP_NOSIZE | SWP_NOZORDER);
  717. m_CancelButton.GetWindowRect(&cRect);
  718. this->ScreenToClient(&cRect);
  719. m_CancelButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  720. cRect.top + deltay,
  721. 0, 0,
  722. SWP_NOSIZE | SWP_NOZORDER);
  723. m_OKButton.GetWindowRect(&cRect);
  724. this->ScreenToClient(&cRect);
  725. m_OKButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  726. cRect.top + deltay,
  727. 0, 0,
  728. SWP_NOSIZE | SWP_NOZORDER);
  729. m_HelpButton.GetWindowRect(&cRect);
  730. this->ScreenToClient(&cRect);
  731. m_HelpButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  732. cRect.top + deltay,
  733. 0, 0,
  734. SWP_NOSIZE | SWP_NOZORDER);
  735. }
  736. }
  737. void CMakeSetupDialog::OnGetMinMaxInfo( MINMAXINFO FAR* lpMMI )
  738. {
  739. lpMMI->ptMinTrackSize.x = 550;
  740. lpMMI->ptMinTrackSize.y = 272;
  741. }
  742. void CMakeSetupDialog::OnCancel()
  743. {
  744. if(m_CacheEntriesList.IsDirty())
  745. {
  746. if(MessageBox("You have changed options but not rebuilt, "
  747. "are you sure you want to exit?", "Confirm Exit",
  748. MB_YESNO) == IDYES)
  749. {
  750. CDialog::OnOK();
  751. }
  752. }
  753. else
  754. {
  755. CDialog::OnOK();
  756. }
  757. }
  758. void CMakeSetupDialog::OnOk()
  759. {
  760. m_CacheEntriesList.ClearDirty();
  761. this->RunCMake(true);
  762. cmMakefileGenerator::UnRegisterGenerators();
  763. CDialog::OnOK();
  764. }
  765. void CMakeSetupDialog::OnEditchangeGenerator()
  766. {
  767. // TODO: Add your control notification handler code here
  768. }
  769. // Create a shortcut on the desktop with the current Source/Build dir.
  770. int CMakeSetupDialog::CreateShortcut()
  771. {
  772. // m_WhereSource = cmdInfo.m_WhereSource;
  773. // m_WhereBuild = cmdInfo.m_WhereBuild;
  774. // Find the desktop folder and create the link name
  775. HKEY hKey;
  776. if(RegOpenKeyEx(HKEY_CURRENT_USER,
  777. "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
  778. 0, KEY_READ, &hKey) != ERROR_SUCCESS)
  779. {
  780. AfxMessageBox ("Create shortcut: unable to find 'Shell Folders' key in registry!");
  781. return 1;
  782. }
  783. DWORD dwType, dwSize;
  784. #define MAXPATH 1024
  785. char link_name[MAXPATH];
  786. dwSize = MAXPATH;
  787. if(RegQueryValueEx(hKey,
  788. (LPCTSTR)"Desktop",
  789. NULL,
  790. &dwType,
  791. (BYTE *)link_name,
  792. &dwSize) != ERROR_SUCCESS)
  793. {
  794. AfxMessageBox ("Create shortcut: unable to find 'Desktop' registry value in 'Shell Folders' key!");
  795. return 1;
  796. }
  797. if(dwType != REG_SZ)
  798. {
  799. AfxMessageBox ("Create shortcut: 'Desktop' registry value in 'Shell Folders' key has wrong type!");
  800. return 1;
  801. }
  802. strcat(link_name, "\\CMake - ");
  803. std::string current_dir = cmSystemTools::GetFilenameName((LPCTSTR)m_WhereSource);
  804. strcat(link_name, current_dir.c_str());
  805. strcat(link_name, ".lnk");
  806. // Find the path to the current executable
  807. char path_to_current_exe[MAXPATH];
  808. ::GetModuleFileName(NULL, path_to_current_exe, MAXPATH);
  809. // Create the shortcut
  810. HRESULT hres;
  811. IShellLink *psl;
  812. // Initialize the COM library
  813. hres = CoInitialize(NULL);
  814. if (! SUCCEEDED (hres))
  815. {
  816. AfxMessageBox ("Create shortcut: unable to initialize the COM library!");
  817. return 1;
  818. }
  819. // Create an IShellLink object and get a pointer to the IShellLink
  820. // interface (returned from CoCreateInstance).
  821. hres = CoCreateInstance(CLSID_ShellLink,
  822. NULL,
  823. CLSCTX_INPROC_SERVER,
  824. IID_IShellLink,
  825. (void **)&psl);
  826. if (! SUCCEEDED (hres))
  827. {
  828. AfxMessageBox ("Create shortcut: unable to create IShellLink instance!");
  829. return 1;
  830. }
  831. IPersistFile *ppf;
  832. // Query IShellLink for the IPersistFile interface for
  833. // saving the shortcut in persistent storage.
  834. hres = psl->QueryInterface(IID_IPersistFile, (void **)&ppf);
  835. if (SUCCEEDED (hres))
  836. {
  837. // Set the path to the shortcut target.
  838. hres = psl->SetPath(path_to_current_exe);
  839. if (! SUCCEEDED (hres))
  840. {
  841. AfxMessageBox ("Create shortcut: SetPath failed!");
  842. }
  843. // Set the arguments of the shortcut.
  844. CString args = " /H=" + m_WhereSource + " /B=" + m_WhereBuild;
  845. hres = psl->SetArguments(args);
  846. if (! SUCCEEDED (hres))
  847. {
  848. AfxMessageBox ("Create shortcut: SetArguments failed!");
  849. }
  850. // Set the description of the shortcut.
  851. hres = psl->SetDescription("Shortcut to CMakeSetup");
  852. if (! SUCCEEDED (hres))
  853. {
  854. AfxMessageBox ("Create shortcut: SetDescription failed!");
  855. }
  856. // Ensure that the string consists of ANSI characters.
  857. WORD wsz[MAX_PATH];
  858. MultiByteToWideChar(CP_ACP, 0, link_name, -1, wsz, MAX_PATH);
  859. // Save the shortcut via the IPersistFile::Save member function.
  860. hres = ppf->Save(wsz, TRUE);
  861. if (! SUCCEEDED (hres))
  862. {
  863. AfxMessageBox ("Create shortcut: Save failed!");
  864. }
  865. // Release the pointer to IPersistFile.
  866. ppf->Release ();
  867. }
  868. // Release the pointer to IShellLink.
  869. psl->Release ();
  870. return 0;
  871. }
  872. void CMakeSetupDialog::OnHelpButton()
  873. {
  874. CMakeHelp dialog;
  875. dialog.DoModal();
  876. }