CMakeSetupDialog.cpp 26 KB

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