1
0

CMakeSetupDialog.cpp 32 KB

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