CMakeSetupDialog.cpp 32 KB

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