CMakeSetupDialog.cpp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008
  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. m_OKButton.EnableWindow(false);
  452. // create a cmake object
  453. cmake make;
  454. // create the arguments for the cmake object
  455. std::vector<std::string> args;
  456. args.push_back((const char*)m_PathToExecutable);
  457. std::string arg;
  458. arg = "-H";
  459. arg += m_WhereSource;
  460. args.push_back(arg);
  461. arg = "-B";
  462. arg += m_WhereBuild;
  463. args.push_back(arg);
  464. arg = "-G";
  465. arg += m_GeneratorChoiceString;
  466. args.push_back(arg);
  467. // run the generate process
  468. if(make.Generate(args, generateProjectFiles) != 0)
  469. {
  470. cmSystemTools::Error(
  471. "Error in generation process, project files may be invalid");
  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. cmSystemTools::ResetErrorOccuredFlag();
  483. }
  484. // Callback for build projects button
  485. void CMakeSetupDialog::OnConfigure()
  486. {
  487. // enable error messages each time configure is pressed
  488. cmSystemTools::EnableMessages();
  489. this->RunCMake(false);
  490. }
  491. // callback for combo box menu where build selection
  492. void CMakeSetupDialog::OnSelendokWhereBuild()
  493. {
  494. m_WhereBuildControl.GetLBText(m_WhereBuildControl.GetCurSel(),
  495. m_WhereBuild);
  496. m_WhereBuildControl.SetWindowText( m_WhereBuild);
  497. this->UpdateData(FALSE);
  498. this->OnChangeWhereBuild();
  499. }
  500. // callback for combo box menu where source selection
  501. void CMakeSetupDialog::OnSelendokWhereSource()
  502. {
  503. m_WhereSourceControl.GetLBText(m_WhereSourceControl.GetCurSel(),
  504. m_WhereSource);
  505. this->UpdateData(FALSE);
  506. this->OnChangeWhereSource();
  507. }
  508. // callback for chaing source directory
  509. void CMakeSetupDialog::OnChangeWhereSource()
  510. {
  511. }
  512. // callback for changing the build directory
  513. void CMakeSetupDialog::OnChangeWhereBuild()
  514. {
  515. this->UpdateData();
  516. m_CacheEntriesList.RemoveAll();
  517. m_CacheEntriesList.ShowWindow(SW_SHOW);
  518. this->LoadCacheFromDiskToGUI();
  519. m_BuildPathChanged = true;
  520. }
  521. // copy from the cache manager to the cache edit list box
  522. void CMakeSetupDialog::FillCacheGUIFromCacheManager()
  523. {
  524. int size = m_CacheEntriesList.GetItems().size();
  525. bool reverseOrder = false;
  526. // if there are already entries in the cache, then
  527. // put the new ones in the top, so they show up first
  528. if(size)
  529. {
  530. reverseOrder = true;
  531. }
  532. // all the current values are not new any more
  533. std::set<CPropertyItem*> items = m_CacheEntriesList.GetItems();
  534. for(std::set<CPropertyItem*>::iterator i = items.begin();
  535. i != items.end(); ++i)
  536. {
  537. CPropertyItem* item = *i;
  538. item->m_NewValue = false;
  539. }
  540. const cmCacheManager::CacheEntryMap &cache =
  541. cmCacheManager::GetInstance()->GetCacheMap();
  542. for(cmCacheManager::CacheEntryMap::const_iterator i = cache.begin();
  543. i != cache.end(); ++i)
  544. {
  545. const char* key = i->first.c_str();
  546. const cmCacheManager::CacheEntry& value = i->second;
  547. switch(value.m_Type )
  548. {
  549. case cmCacheManager::BOOL:
  550. if(cmSystemTools::IsOn(value.m_Value.c_str()))
  551. {
  552. m_CacheEntriesList.AddProperty(key,
  553. "ON",
  554. value.m_HelpString.c_str(),
  555. CPropertyList::COMBO,"ON|OFF",
  556. reverseOrder
  557. );
  558. }
  559. else
  560. {
  561. m_CacheEntriesList.AddProperty(key,
  562. "OFF",
  563. value.m_HelpString.c_str(),
  564. CPropertyList::COMBO,"ON|OFF",
  565. reverseOrder
  566. );
  567. }
  568. break;
  569. case cmCacheManager::PATH:
  570. m_CacheEntriesList.AddProperty(key,
  571. value.m_Value.c_str(),
  572. value.m_HelpString.c_str(),
  573. CPropertyList::PATH,"",
  574. reverseOrder
  575. );
  576. break;
  577. case cmCacheManager::FILEPATH:
  578. m_CacheEntriesList.AddProperty(key,
  579. value.m_Value.c_str(),
  580. value.m_HelpString.c_str(),
  581. CPropertyList::FILE,"",
  582. reverseOrder
  583. );
  584. break;
  585. case cmCacheManager::STRING:
  586. m_CacheEntriesList.AddProperty(key,
  587. value.m_Value.c_str(),
  588. value.m_HelpString.c_str(),
  589. CPropertyList::EDIT,"",
  590. reverseOrder
  591. );
  592. break;
  593. case cmCacheManager::INTERNAL:
  594. m_CacheEntriesList.RemoveProperty(key);
  595. break;
  596. }
  597. }
  598. m_OKButton.EnableWindow(false);
  599. if(cache.size() > 0 && !cmSystemTools::GetErrorOccuredFlag())
  600. {
  601. bool enable = true;
  602. items = m_CacheEntriesList.GetItems();
  603. for(std::set<CPropertyItem*>::iterator i = items.begin();
  604. i != items.end(); ++i)
  605. {
  606. CPropertyItem* item = *i;
  607. if(item->m_NewValue)
  608. {
  609. // if one new value then disable to OK button
  610. enable = false;
  611. break;
  612. }
  613. }
  614. if(enable)
  615. {
  616. m_OKButton.EnableWindow(true);
  617. }
  618. }
  619. // redraw the list
  620. m_CacheEntriesList.SetTopIndex(0);
  621. m_CacheEntriesList.Invalidate();
  622. }
  623. // copy from the list box to the cache manager
  624. void CMakeSetupDialog::FillCacheManagerFromCacheGUI()
  625. {
  626. cmCacheManager::GetInstance()->GetCacheMap();
  627. std::set<CPropertyItem*> items = m_CacheEntriesList.GetItems();
  628. for(std::set<CPropertyItem*>::iterator i = items.begin();
  629. i != items.end(); ++i)
  630. {
  631. CPropertyItem* item = *i;
  632. cmCacheManager::CacheEntry *entry =
  633. cmCacheManager::GetInstance()->GetCacheEntry(
  634. (const char*)item->m_propName);
  635. if (entry)
  636. {
  637. entry->m_Value = item->m_curValue;
  638. }
  639. }
  640. }
  641. //! Load cache file from m_WhereBuild and display in GUI editor
  642. void CMakeSetupDialog::LoadCacheFromDiskToGUI()
  643. {
  644. if(m_WhereBuild != "")
  645. {
  646. cmCacheManager::GetInstance()->LoadCache(m_WhereBuild);
  647. this->FillCacheGUIFromCacheManager();
  648. if(cmCacheManager::GetInstance()->GetCacheEntry("CMAKE_GENERATOR"))
  649. {
  650. std::string curGen =
  651. cmCacheManager::GetInstance()->GetCacheEntry("CMAKE_GENERATOR")->m_Value;
  652. if(m_GeneratorChoiceString != curGen.c_str())
  653. {
  654. m_GeneratorChoiceString = curGen.c_str();
  655. this->UpdateData(FALSE);
  656. }
  657. }
  658. }
  659. }
  660. //! Save GUI values to cmCacheManager and then save to disk.
  661. void CMakeSetupDialog::SaveCacheFromGUI()
  662. {
  663. this->FillCacheManagerFromCacheGUI();
  664. if(m_WhereBuild != "")
  665. {
  666. cmCacheManager::GetInstance()->SaveCache(m_WhereBuild);
  667. }
  668. }
  669. void CMakeSetupDialog::OnSize(UINT nType, int cx, int cy)
  670. {
  671. if (nType == SIZE_MINIMIZED)
  672. {
  673. CDialog::OnSize(nType, cx, cy);
  674. return;
  675. }
  676. if (m_oldCX == -1)
  677. {
  678. m_oldCX = cx;
  679. m_oldCY = cy;
  680. }
  681. int deltax = cx - m_oldCX;
  682. int deltay = cy - m_oldCY;
  683. m_oldCX = cx;
  684. m_oldCY = cy;
  685. CDialog::OnSize(nType, cx, cy);
  686. if (deltax == 0 && deltay == 0)
  687. {
  688. return;
  689. }
  690. if(m_CacheEntriesList.m_hWnd)
  691. {
  692. // get the original sizes/positions
  693. CRect cRect;
  694. m_ListFrame.GetWindowRect(&cRect);
  695. m_ListFrame.SetWindowPos(&wndTop, cRect.left, cRect.top,
  696. cRect.Width() + deltax,
  697. cRect.Height() + deltay,
  698. SWP_NOMOVE | SWP_NOZORDER);
  699. m_CacheEntriesList.GetWindowRect(&cRect);
  700. m_CacheEntriesList.SetWindowPos(&wndTop, cRect.left, cRect.top,
  701. cRect.Width() + deltax,
  702. cRect.Height() + deltay,
  703. SWP_NOMOVE | SWP_NOZORDER);
  704. m_VersionDisplay.SetWindowPos(&wndTop, 5, cy-23, 0, 0,
  705. SWP_NOSIZE | SWP_NOZORDER);
  706. deltax = deltax + m_deltaXRemainder;
  707. m_deltaXRemainder = deltax%2;
  708. m_MouseHelp.GetWindowRect(&cRect);
  709. this->ScreenToClient(&cRect);
  710. m_MouseHelp.SetWindowPos(&wndTop, cRect.left + deltax/2,
  711. cRect.top + deltay,
  712. 0, 0,
  713. SWP_NOSIZE | SWP_NOZORDER);
  714. m_Configure.GetWindowRect(&cRect);
  715. this->ScreenToClient(&cRect);
  716. m_Configure.SetWindowPos(&wndTop, cRect.left + deltax/2,
  717. cRect.top + deltay,
  718. 0, 0,
  719. SWP_NOSIZE | SWP_NOZORDER);
  720. m_CancelButton.GetWindowRect(&cRect);
  721. this->ScreenToClient(&cRect);
  722. m_CancelButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  723. cRect.top + deltay,
  724. 0, 0,
  725. SWP_NOSIZE | SWP_NOZORDER);
  726. m_OKButton.GetWindowRect(&cRect);
  727. this->ScreenToClient(&cRect);
  728. m_OKButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  729. cRect.top + deltay,
  730. 0, 0,
  731. SWP_NOSIZE | SWP_NOZORDER);
  732. m_HelpButton.GetWindowRect(&cRect);
  733. this->ScreenToClient(&cRect);
  734. m_HelpButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  735. cRect.top + deltay,
  736. 0, 0,
  737. SWP_NOSIZE | SWP_NOZORDER);
  738. }
  739. }
  740. void CMakeSetupDialog::OnGetMinMaxInfo( MINMAXINFO FAR* lpMMI )
  741. {
  742. lpMMI->ptMinTrackSize.x = 550;
  743. lpMMI->ptMinTrackSize.y = 272;
  744. }
  745. void CMakeSetupDialog::OnCancel()
  746. {
  747. if(m_CacheEntriesList.IsDirty())
  748. {
  749. if(MessageBox("You have changed options but not rebuilt, "
  750. "are you sure you want to exit?", "Confirm Exit",
  751. MB_YESNO) == IDYES)
  752. {
  753. CDialog::OnOK();
  754. }
  755. }
  756. else
  757. {
  758. CDialog::OnOK();
  759. }
  760. }
  761. void CMakeSetupDialog::OnOk()
  762. {
  763. // enable error messages each time configure is pressed
  764. cmSystemTools::EnableMessages();
  765. m_CacheEntriesList.ClearDirty();
  766. this->RunCMake(true);
  767. cmMakefileGenerator::UnRegisterGenerators();
  768. CDialog::OnOK();
  769. }
  770. void CMakeSetupDialog::OnEditchangeGenerator()
  771. {
  772. // TODO: Add your control notification handler code here
  773. }
  774. // Create a shortcut on the desktop with the current Source/Build dir.
  775. int CMakeSetupDialog::CreateShortcut()
  776. {
  777. // m_WhereSource = cmdInfo.m_WhereSource;
  778. // m_WhereBuild = cmdInfo.m_WhereBuild;
  779. // Find the desktop folder and create the link name
  780. HKEY hKey;
  781. if(RegOpenKeyEx(HKEY_CURRENT_USER,
  782. "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
  783. 0, KEY_READ, &hKey) != ERROR_SUCCESS)
  784. {
  785. AfxMessageBox ("Create shortcut: unable to find 'Shell Folders' key in registry!");
  786. return 1;
  787. }
  788. DWORD dwType, dwSize;
  789. #define MAXPATH 1024
  790. char link_name[MAXPATH];
  791. dwSize = MAXPATH;
  792. if(RegQueryValueEx(hKey,
  793. (LPCTSTR)"Desktop",
  794. NULL,
  795. &dwType,
  796. (BYTE *)link_name,
  797. &dwSize) != ERROR_SUCCESS)
  798. {
  799. AfxMessageBox ("Create shortcut: unable to find 'Desktop' registry value in 'Shell Folders' key!");
  800. return 1;
  801. }
  802. if(dwType != REG_SZ)
  803. {
  804. AfxMessageBox ("Create shortcut: 'Desktop' registry value in 'Shell Folders' key has wrong type!");
  805. return 1;
  806. }
  807. strcat(link_name, "\\CMake - ");
  808. std::string current_dir = cmSystemTools::GetFilenameName((LPCTSTR)m_WhereSource);
  809. strcat(link_name, current_dir.c_str());
  810. strcat(link_name, ".lnk");
  811. // Find the path to the current executable
  812. char path_to_current_exe[MAXPATH];
  813. ::GetModuleFileName(NULL, path_to_current_exe, MAXPATH);
  814. // Create the shortcut
  815. HRESULT hres;
  816. IShellLink *psl;
  817. // Initialize the COM library
  818. hres = CoInitialize(NULL);
  819. if (! SUCCEEDED (hres))
  820. {
  821. AfxMessageBox ("Create shortcut: unable to initialize the COM library!");
  822. return 1;
  823. }
  824. // Create an IShellLink object and get a pointer to the IShellLink
  825. // interface (returned from CoCreateInstance).
  826. hres = CoCreateInstance(CLSID_ShellLink,
  827. NULL,
  828. CLSCTX_INPROC_SERVER,
  829. IID_IShellLink,
  830. (void **)&psl);
  831. if (! SUCCEEDED (hres))
  832. {
  833. AfxMessageBox ("Create shortcut: unable to create IShellLink instance!");
  834. return 1;
  835. }
  836. IPersistFile *ppf;
  837. // Query IShellLink for the IPersistFile interface for
  838. // saving the shortcut in persistent storage.
  839. hres = psl->QueryInterface(IID_IPersistFile, (void **)&ppf);
  840. if (SUCCEEDED (hres))
  841. {
  842. // Set the path to the shortcut target.
  843. hres = psl->SetPath(path_to_current_exe);
  844. if (! SUCCEEDED (hres))
  845. {
  846. AfxMessageBox ("Create shortcut: SetPath failed!");
  847. }
  848. // Set the arguments of the shortcut.
  849. CString args = " /H=" + m_WhereSource + " /B=" + m_WhereBuild;
  850. hres = psl->SetArguments(args);
  851. if (! SUCCEEDED (hres))
  852. {
  853. AfxMessageBox ("Create shortcut: SetArguments failed!");
  854. }
  855. // Set the description of the shortcut.
  856. hres = psl->SetDescription("Shortcut to CMakeSetup");
  857. if (! SUCCEEDED (hres))
  858. {
  859. AfxMessageBox ("Create shortcut: SetDescription failed!");
  860. }
  861. // Ensure that the string consists of ANSI characters.
  862. WORD wsz[MAX_PATH];
  863. MultiByteToWideChar(CP_ACP, 0, link_name, -1, wsz, MAX_PATH);
  864. // Save the shortcut via the IPersistFile::Save member function.
  865. hres = ppf->Save(wsz, TRUE);
  866. if (! SUCCEEDED (hres))
  867. {
  868. AfxMessageBox ("Create shortcut: Save failed!");
  869. }
  870. // Release the pointer to IPersistFile.
  871. ppf->Release ();
  872. }
  873. // Release the pointer to IShellLink.
  874. psl->Release ();
  875. return 0;
  876. }
  877. void CMakeSetupDialog::OnHelpButton()
  878. {
  879. CMakeHelp dialog;
  880. dialog.DoModal();
  881. }