CMakeSetupDialog.cpp 32 KB

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