CMakeSetupDialog.cpp 39 KB

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