CMakeSetupDialog.cpp 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357
  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::SetErrorCallback(MFCMessageCallback);
  110. m_RegistryKey = "Software\\Kitware\\CMakeSetup\\Settings\\StartPath";
  111. m_CacheEntriesList.m_CMakeSetupDialog = this;
  112. //{{AFX_DATA_INIT(CMakeSetupDialog)
  113. //}}AFX_DATA_INIT
  114. // Get the parameters from the command line info
  115. // If an unknown parameter is found, try to interpret it too, since it
  116. // is likely to be a file dropped on the shortcut :)
  117. if (cmdInfo.m_LastUnknownParameter.IsEmpty())
  118. {
  119. this->m_WhereSource = cmdInfo.m_WhereSource;
  120. this->m_WhereBuild = cmdInfo.m_WhereBuild;
  121. this->m_GeneratorChoiceString = cmdInfo.m_GeneratorChoiceString;
  122. this->m_AdvancedValues = cmdInfo.m_AdvancedValues;
  123. }
  124. else
  125. {
  126. this->m_WhereSource = _T("");
  127. this->m_WhereBuild = _T("");
  128. this->m_AdvancedValues = FALSE;
  129. this->m_GeneratorChoiceString = _T("");
  130. this->ChangeDirectoriesFromFile((LPCTSTR)cmdInfo.m_LastUnknownParameter);
  131. }
  132. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  133. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  134. m_BuildPathChanged = false;
  135. // Find the path to the cmake.exe executable
  136. char fname[1024];
  137. ::GetModuleFileName(NULL,fname,1023);
  138. // extract just the path part
  139. m_PathToExecutable = cmSystemTools::GetProgramPath(fname).c_str();
  140. // add the cmake.exe to the path
  141. m_PathToExecutable += "/cmake.exe";
  142. m_oldCX = -1;
  143. m_deltaXRemainder = 0;
  144. m_CMakeInstance = new cmake;
  145. m_CMakeInstance->SetProgressCallback(updateProgress, (void *)this);
  146. }
  147. void CMakeSetupDialog::DoDataExchange(CDataExchange* pDX)
  148. {
  149. CDialog::DoDataExchange(pDX);
  150. //{{AFX_DATA_MAP(CMakeSetupDialog)
  151. DDX_Control(pDX, IDC_AdvancedValues, m_AdvancedValuesControl);
  152. DDX_Control(pDX, IDC_BuildForLabel, m_BuildForLabel);
  153. DDX_Control(pDX, IDC_BROWSE_SOURCE, m_BrowseSource);
  154. DDX_Control(pDX, IDC_BROWSE_BUILD, m_BrowseBuild);
  155. DDX_Control(pDX, IDC_HELP_BUTTON, m_HelpButton);
  156. DDX_Control(pDX, IDC_Generator, m_GeneratorChoice);
  157. DDX_Control(pDX, IDC_OK, m_OKButton);
  158. DDX_Control(pDX, IDCANCEL, m_CancelButton);
  159. DDX_CBStringExact(pDX, IDC_WhereSource, m_WhereSource);
  160. DDX_CBStringExact(pDX, IDC_WhereBuild, m_WhereBuild);
  161. DDX_Control(pDX, IDC_FRAME, m_ListFrame);
  162. DDX_Control(pDX, IDC_WhereSource, m_WhereSourceControl);
  163. DDX_Control(pDX, IDC_WhereBuild, m_WhereBuildControl);
  164. DDX_Control(pDX, IDC_LIST2, m_CacheEntriesList);
  165. DDX_Control(pDX, IDC_MouseHelpCaption, m_MouseHelp);
  166. DDX_Control(pDX, IDC_CMAKE_VERSION, m_VersionDisplay);
  167. DDX_Control(pDX, IDC_BuildProjects, m_Configure);
  168. DDX_CBStringExact(pDX, IDC_Generator, m_GeneratorChoiceString);
  169. DDX_Check(pDX, IDC_AdvancedValues, m_AdvancedValues);
  170. //}}AFX_DATA_MAP
  171. }
  172. BEGIN_MESSAGE_MAP(CMakeSetupDialog, CDialog)
  173. //{{AFX_MSG_MAP(CMakeSetupDialog)
  174. ON_WM_SYSCOMMAND()
  175. ON_WM_PAINT()
  176. ON_WM_QUERYDRAGICON()
  177. ON_WM_DROPFILES()
  178. ON_BN_CLICKED(IDC_BUTTON2, OnBrowseWhereSource)
  179. ON_BN_CLICKED(IDC_BuildProjects, OnConfigure)
  180. ON_BN_CLICKED(IDC_BUTTON3, OnBrowseWhereBuild)
  181. ON_CBN_EDITCHANGE(IDC_WhereBuild, OnChangeWhereBuild)
  182. ON_CBN_SELCHANGE(IDC_WhereBuild, OnSelendokWhereBuild)
  183. ON_CBN_EDITCHANGE(IDC_WhereSource, OnChangeWhereSource)
  184. ON_CBN_SELENDOK(IDC_WhereSource, OnSelendokWhereSource)
  185. ON_WM_SIZE()
  186. ON_WM_GETMINMAXINFO()
  187. ON_BN_CLICKED(IDC_OK, OnOk)
  188. ON_CBN_EDITCHANGE(IDC_Generator, OnEditchangeGenerator)
  189. ON_BN_CLICKED(IDC_HELP_BUTTON, OnHelpButton)
  190. ON_BN_CLICKED(IDCANCEL, OnCancel)
  191. ON_BN_CLICKED(IDC_AdvancedValues, OnAdvancedValues)
  192. ON_BN_DOUBLECLICKED(IDC_AdvancedValues, OnDoubleclickedAdvancedValues)
  193. //}}AFX_MSG_MAP
  194. END_MESSAGE_MAP()
  195. /////////////////////////////////////////////////////////////////////////////
  196. // CMakeSetupDialog message handlers
  197. BOOL CMakeSetupDialog::OnInitDialog()
  198. {
  199. CDialog::OnInitDialog();
  200. this->DragAcceptFiles(true);
  201. // Add "Create shortcut" menu item to system menu.
  202. // IDM_CREATESHORTCUT must be in the system command range.
  203. ASSERT((IDM_CREATESHORTCUT & 0xFFF0) == IDM_CREATESHORTCUT);
  204. ASSERT(IDM_CREATESHORTCUT < 0xF000);
  205. // Add "About..." menu item to system menu.
  206. // IDM_ABOUTBOX must be in the system command range.
  207. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  208. ASSERT(IDM_ABOUTBOX < 0xF000);
  209. CMenu* pSysMenu = GetSystemMenu(FALSE);
  210. if (pSysMenu != NULL)
  211. {
  212. CString strCreateShortcutMenu;
  213. strCreateShortcutMenu.LoadString(IDS_CREATESHORTCUT);
  214. if (!strCreateShortcutMenu.IsEmpty())
  215. {
  216. pSysMenu->AppendMenu(MF_SEPARATOR);
  217. pSysMenu->AppendMenu(MF_STRING,
  218. IDM_CREATESHORTCUT,
  219. strCreateShortcutMenu);
  220. }
  221. CString strAboutMenu;
  222. strAboutMenu.LoadString(IDS_ABOUTBOX);
  223. if (!strAboutMenu.IsEmpty())
  224. {
  225. pSysMenu->AppendMenu(MF_SEPARATOR);
  226. pSysMenu->AppendMenu(MF_STRING,
  227. IDM_ABOUTBOX,
  228. strAboutMenu);
  229. }
  230. }
  231. // Set the icon for this dialog. The framework does this automatically
  232. // when the application's main window is not a dialog
  233. SetIcon(m_hIcon, TRUE); // Set big icon
  234. SetIcon(m_hIcon, FALSE); // Set small icon
  235. // Load source and build dirs from registry
  236. this->LoadFromRegistry();
  237. std::vector<std::string> names;
  238. this->m_CMakeInstance->GetRegisteredGenerators(names);
  239. for(std::vector<std::string>::iterator i = names.begin();
  240. i != names.end(); ++i)
  241. {
  242. m_GeneratorChoice.AddString(i->c_str());
  243. }
  244. if (m_GeneratorChoiceString == _T(""))
  245. {
  246. m_GeneratorChoiceString = "Visual Studio 6";
  247. }
  248. // try to load the cmake cache from disk
  249. this->LoadCacheFromDiskToGUI();
  250. m_WhereBuildControl.LimitText(2048);
  251. m_WhereSourceControl.LimitText(2048);
  252. m_GeneratorChoice.LimitText(2048);
  253. // Set the version number
  254. char tmp[1024];
  255. sprintf(tmp,"Version %d.%d - %s", cmake::GetMajorVersion(),
  256. cmake::GetMinorVersion(), cmake::GetReleaseVersion());
  257. SetDlgItemText(IDC_CMAKE_VERSION, tmp);
  258. SetDlgItemText(IDC_PROGRESS, "");
  259. this->UpdateData(FALSE);
  260. return TRUE; // return TRUE unless you set the focus to a control
  261. }
  262. // About dialog invoke
  263. void CMakeSetupDialog::OnSysCommand(UINT nID, LPARAM lParam)
  264. {
  265. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  266. {
  267. CAboutDlg dlgAbout;
  268. dlgAbout.DoModal();
  269. }
  270. else if ((nID & 0xFFF0) == IDM_CREATESHORTCUT)
  271. {
  272. CreateShortcut();
  273. }
  274. else
  275. {
  276. CDialog::OnSysCommand(nID, lParam);
  277. }
  278. }
  279. // If you add a minimize button to your dialog, you will need the code below
  280. // to draw the icon. For MFC applications using the document/view model,
  281. // this is automatically done for you by the framework.
  282. void CMakeSetupDialog::OnPaint()
  283. {
  284. if (IsIconic())
  285. {
  286. CPaintDC dc(this); // device context for painting
  287. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  288. // Center icon in client rectangle
  289. int cxIcon = GetSystemMetrics(SM_CXICON);
  290. int cyIcon = GetSystemMetrics(SM_CYICON);
  291. CRect rect;
  292. GetClientRect(&rect);
  293. int x = (rect.Width() - cxIcon + 1) / 2;
  294. int y = (rect.Height() - cyIcon + 1) / 2;
  295. // Draw the icon
  296. dc.DrawIcon(x, y, m_hIcon);
  297. }
  298. else
  299. {
  300. CDialog::OnPaint();
  301. }
  302. }
  303. // The system calls this to obtain the cursor to display while the user drags
  304. // the minimized window.
  305. HCURSOR CMakeSetupDialog::OnQueryDragIcon()
  306. {
  307. return (HCURSOR) m_hIcon;
  308. }
  309. // Browse button
  310. bool CMakeSetupDialog::Browse(CString &result, const char *title)
  311. {
  312. CPathDialog dlg("Select Path", title, result);
  313. if(dlg.DoModal()==IDOK)
  314. {
  315. result = dlg.GetPathName();
  316. return true;
  317. }
  318. else
  319. {
  320. return false;
  321. }
  322. }
  323. void CMakeSetupDialog::SaveToRegistry()
  324. {
  325. HKEY hKey;
  326. DWORD dwDummy;
  327. if(RegCreateKeyEx(HKEY_CURRENT_USER,
  328. m_RegistryKey,
  329. 0, "", REG_OPTION_NON_VOLATILE, KEY_READ|KEY_WRITE,
  330. NULL, &hKey, &dwDummy) != ERROR_SUCCESS)
  331. {
  332. return;
  333. }
  334. else
  335. {
  336. // save some values
  337. CString regvalue;
  338. this->ReadRegistryValue(hKey, &(regvalue),"WhereSource1","C:\\");
  339. int shiftEnd = 9;
  340. if(m_WhereSource != regvalue)
  341. {
  342. char keyName[1024];
  343. char keyName2[1024];
  344. int i;
  345. for (i = 2; i < 10; ++i)
  346. {
  347. regvalue = "";
  348. sprintf(keyName,"WhereSource%i",i);
  349. this->ReadRegistryValue(hKey, &(regvalue),keyName,"");
  350. // check for short circuit, if the new value is already in
  351. // the list then we stop
  352. if (m_WhereSource == regvalue)
  353. {
  354. shiftEnd = i - 1;
  355. }
  356. }
  357. for (i = shiftEnd; i; --i)
  358. {
  359. regvalue = "";
  360. sprintf(keyName,"WhereSource%i",i);
  361. sprintf(keyName2,"WhereSource%i",i+1);
  362. this->ReadRegistryValue(hKey, &(regvalue),keyName,"");
  363. if (strlen(regvalue))
  364. {
  365. RegSetValueEx(hKey, _T(keyName2), 0, REG_SZ,
  366. (CONST BYTE *)(const char *)regvalue,
  367. regvalue.GetLength());
  368. }
  369. }
  370. RegSetValueEx(hKey, _T("WhereSource1"), 0, REG_SZ,
  371. (CONST BYTE *)(const char *)m_WhereSource,
  372. m_WhereSource.GetLength());
  373. }
  374. this->ReadRegistryValue(hKey, &(regvalue),"WhereBuild1","C:\\");
  375. if(m_WhereBuild != regvalue)
  376. {
  377. int i;
  378. char keyName[1024];
  379. char keyName2[1024];
  380. for (i = 2; i < 10; ++i)
  381. {
  382. regvalue = "";
  383. sprintf(keyName,"WhereBuild%i",i);
  384. this->ReadRegistryValue(hKey, &(regvalue),keyName,"");
  385. // check for short circuit, if the new value is already in
  386. // the list then we stop
  387. if (m_WhereBuild == regvalue)
  388. {
  389. shiftEnd = i - 1;
  390. }
  391. }
  392. for (i = shiftEnd; i; --i)
  393. {
  394. regvalue = "";
  395. sprintf(keyName,"WhereBuild%i",i);
  396. sprintf(keyName2,"WhereBuild%i",i+1);
  397. this->ReadRegistryValue(hKey, &(regvalue),keyName,"");
  398. if (strlen(regvalue))
  399. {
  400. RegSetValueEx(hKey, _T(keyName2), 0, REG_SZ,
  401. (CONST BYTE *)(const char *)regvalue,
  402. regvalue.GetLength());
  403. }
  404. }
  405. RegSetValueEx(hKey, _T("WhereBuild1"), 0, REG_SZ,
  406. (CONST BYTE *)(const char *)m_WhereBuild,
  407. m_WhereBuild.GetLength());
  408. }
  409. }
  410. RegCloseKey(hKey);
  411. }
  412. void CMakeSetupDialog::ReadRegistryValue(HKEY hKey,
  413. CString *val,
  414. const char *key,
  415. const char *adefault)
  416. {
  417. DWORD dwType, dwSize;
  418. char *pb;
  419. dwType = REG_SZ;
  420. pb = val->GetBuffer(MAX_PATH);
  421. dwSize = MAX_PATH;
  422. if(RegQueryValueEx(hKey,_T(key), NULL, &dwType,
  423. (BYTE *)pb, &dwSize) != ERROR_SUCCESS)
  424. {
  425. val->ReleaseBuffer();
  426. *val = _T(adefault);
  427. }
  428. else
  429. {
  430. val->ReleaseBuffer();
  431. }
  432. }
  433. void CMakeSetupDialog::LoadFromRegistry()
  434. {
  435. HKEY hKey;
  436. if(RegOpenKeyEx(HKEY_CURRENT_USER,
  437. m_RegistryKey,
  438. 0, KEY_READ, &hKey) != ERROR_SUCCESS)
  439. {
  440. return;
  441. }
  442. else
  443. {
  444. // load some values
  445. if (m_WhereSource.IsEmpty())
  446. {
  447. this->ReadRegistryValue(hKey, &(m_WhereSource),"WhereSource1","C:\\");
  448. }
  449. if (m_WhereBuild.IsEmpty())
  450. {
  451. this->ReadRegistryValue(hKey, &(m_WhereBuild),"WhereBuild1","C:\\");
  452. }
  453. m_WhereSourceControl.AddString(m_WhereSource);
  454. m_WhereBuildControl.AddString(m_WhereBuild);
  455. char keyname[1024];
  456. CString regvalue;
  457. int i;
  458. for (i = 2; i <= 10; ++i)
  459. {
  460. sprintf(keyname,"WhereSource%i",i);
  461. regvalue = "";
  462. this->ReadRegistryValue(hKey, &(regvalue),keyname,"C:\\");
  463. if (strcmp("C:\\",regvalue))
  464. {
  465. m_WhereSourceControl.AddString(regvalue);
  466. }
  467. sprintf(keyname,"WhereBuild%i",i);
  468. regvalue = "";
  469. this->ReadRegistryValue(hKey, &(regvalue),keyname,"C:\\");
  470. if (strcmp("C:\\",regvalue))
  471. {
  472. m_WhereBuildControl.AddString(regvalue);
  473. }
  474. }
  475. }
  476. RegCloseKey(hKey);
  477. }
  478. // Callback for browse source button
  479. void CMakeSetupDialog::OnBrowseWhereSource()
  480. {
  481. this->UpdateData();
  482. Browse(m_WhereSource, "Enter Path to Source");
  483. this->UpdateData(false);
  484. this->OnChangeWhereSource();
  485. }
  486. // Callback for browser build button
  487. void CMakeSetupDialog::OnBrowseWhereBuild()
  488. {
  489. this->UpdateData();
  490. Browse(m_WhereBuild, "Enter Path to Build");
  491. this->UpdateData(false);
  492. this->OnChangeWhereBuild();
  493. }
  494. void CMakeSetupDialog::RunCMake(bool generateProjectFiles)
  495. {
  496. if(!cmSystemTools::FileExists(m_WhereBuild))
  497. {
  498. std::string message =
  499. "Build directory does not exist, should I create it?\n\n"
  500. "Directory: ";
  501. message += (const char*)m_WhereBuild;
  502. if(MessageBox(message.c_str(), "Create Directory", MB_OKCANCEL) == IDOK)
  503. {
  504. cmSystemTools::MakeDirectory(m_WhereBuild);
  505. }
  506. else
  507. {
  508. MessageBox("Build Project aborted, nothing done.");
  509. return;
  510. }
  511. }
  512. // set the wait cursor
  513. ::SetCursor(LoadCursor(NULL, IDC_WAIT));
  514. // get all the info from the dialog
  515. this->UpdateData();
  516. // always save the current gui values to disk
  517. this->SaveCacheFromGUI();
  518. // Make sure we are working from the cache on disk
  519. this->LoadCacheFromDiskToGUI();
  520. m_OKButton.EnableWindow(false);
  521. // setup the cmake instance
  522. if (generateProjectFiles)
  523. {
  524. if(m_CMakeInstance->Generate() != 0)
  525. {
  526. cmSystemTools::Error(
  527. "Error in generation process, project files may be invalid");
  528. }
  529. }
  530. else
  531. {
  532. m_CMakeInstance->SetHomeDirectory(m_WhereSource);
  533. m_CMakeInstance->SetStartDirectory(m_WhereSource);
  534. m_CMakeInstance->SetHomeOutputDirectory(m_WhereBuild);
  535. m_CMakeInstance->SetStartOutputDirectory(m_WhereBuild);
  536. m_CMakeInstance->SetGlobalGenerator(
  537. m_CMakeInstance->CreateGlobalGenerator(m_GeneratorChoiceString));
  538. m_CMakeInstance->SetCMakeCommand(m_PathToExecutable);
  539. m_CMakeInstance->LoadCache();
  540. if(m_CMakeInstance->Configure() != 0)
  541. {
  542. cmSystemTools::Error(
  543. "Error in configuration process, project files may be invalid");
  544. }
  545. // update the GUI with any new values in the caused by the
  546. // generation process
  547. this->LoadCacheFromDiskToGUI();
  548. }
  549. // save source and build paths to registry
  550. this->SaveToRegistry();
  551. // path is up-to-date now
  552. m_BuildPathChanged = false;
  553. // put the cursor back
  554. ::SetCursor(LoadCursor(NULL, IDC_ARROW));
  555. m_OKButton.EnableWindow(true);
  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_NOSIZE | SWP_NOZORDER);
  823. m_BuildForLabel.GetWindowRect(&cRect);
  824. this->ScreenToClient(&cRect);
  825. m_BuildForLabel.SetWindowPos(&wndTop, cRect.left + deltax,
  826. cRect.top,
  827. 0, 0,
  828. SWP_NOSIZE | SWP_NOZORDER);
  829. m_GeneratorChoice.GetWindowRect(&cRect);
  830. this->ScreenToClient(&cRect);
  831. m_GeneratorChoice.SetWindowPos(&wndTop, cRect.left + deltax,
  832. cRect.top,
  833. 0, 0,
  834. SWP_NOSIZE | SWP_NOZORDER);
  835. m_BrowseSource.GetWindowRect(&cRect);
  836. this->ScreenToClient(&cRect);
  837. m_BrowseSource.SetWindowPos(&wndTop, cRect.left + deltax,
  838. cRect.top,
  839. 0, 0,
  840. SWP_NOSIZE | SWP_NOZORDER);
  841. m_BrowseBuild.GetWindowRect(&cRect);
  842. this->ScreenToClient(&cRect);
  843. m_BrowseBuild.SetWindowPos(&wndTop, cRect.left + deltax,
  844. cRect.top,
  845. 0, 0,
  846. SWP_NOSIZE | SWP_NOZORDER);
  847. m_WhereSourceControl.GetWindowRect(&cRect);
  848. m_WhereSourceControl.SetWindowPos(&wndTop, cRect.left, cRect.top,
  849. cRect.Width() + deltax,
  850. cRect.Height() + deltay,
  851. SWP_NOMOVE | SWP_NOZORDER);
  852. m_WhereBuildControl.GetWindowRect(&cRect);
  853. m_WhereBuildControl.SetWindowPos(&wndTop, cRect.left, cRect.top,
  854. cRect.Width() + deltax,
  855. cRect.Height() + deltay,
  856. SWP_NOMOVE | SWP_NOZORDER);
  857. m_ListFrame.GetWindowRect(&cRect);
  858. m_ListFrame.SetWindowPos(&wndTop, cRect.left, cRect.top,
  859. cRect.Width() + deltax,
  860. cRect.Height() + deltay,
  861. SWP_NOMOVE | SWP_NOZORDER);
  862. m_CacheEntriesList.GetWindowRect(&cRect);
  863. m_CacheEntriesList.SetWindowPos(&wndTop, cRect.left, cRect.top,
  864. cRect.Width() + deltax,
  865. cRect.Height() + deltay,
  866. SWP_NOMOVE | SWP_NOZORDER);
  867. m_VersionDisplay.SetWindowPos(&wndTop, 5, cy-23, 0, 0,
  868. SWP_NOSIZE | SWP_NOZORDER);
  869. deltax = int(deltax + m_deltaXRemainder);
  870. m_deltaXRemainder = float(deltax%2);
  871. m_MouseHelp.GetWindowRect(&cRect);
  872. this->ScreenToClient(&cRect);
  873. m_MouseHelp.SetWindowPos(&wndTop, cRect.left + deltax/2,
  874. cRect.top + deltay,
  875. 0, 0,
  876. SWP_NOSIZE | SWP_NOZORDER);
  877. m_Configure.GetWindowRect(&cRect);
  878. this->ScreenToClient(&cRect);
  879. m_Configure.SetWindowPos(&wndTop, cRect.left + deltax/2,
  880. cRect.top + deltay,
  881. 0, 0,
  882. SWP_NOSIZE | SWP_NOZORDER);
  883. m_CancelButton.GetWindowRect(&cRect);
  884. this->ScreenToClient(&cRect);
  885. m_CancelButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  886. cRect.top + deltay,
  887. 0, 0,
  888. SWP_NOSIZE | SWP_NOZORDER);
  889. m_OKButton.GetWindowRect(&cRect);
  890. this->ScreenToClient(&cRect);
  891. m_OKButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  892. cRect.top + deltay,
  893. 0, 0,
  894. SWP_NOSIZE | SWP_NOZORDER);
  895. m_HelpButton.GetWindowRect(&cRect);
  896. this->ScreenToClient(&cRect);
  897. m_HelpButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  898. cRect.top + deltay,
  899. 0, 0,
  900. SWP_NOSIZE | SWP_NOZORDER);
  901. }
  902. }
  903. void CMakeSetupDialog::OnGetMinMaxInfo( MINMAXINFO FAR* lpMMI )
  904. {
  905. lpMMI->ptMinTrackSize.x = 550;
  906. lpMMI->ptMinTrackSize.y = 272;
  907. }
  908. void CMakeSetupDialog::OnCancel()
  909. {
  910. if(m_CacheEntriesList.IsDirty())
  911. {
  912. if(MessageBox("You have changed options but not rebuilt, "
  913. "are you sure you want to exit?", "Confirm Exit",
  914. MB_YESNO) == IDYES)
  915. {
  916. CDialog::OnOK();
  917. }
  918. }
  919. else
  920. {
  921. CDialog::OnOK();
  922. }
  923. }
  924. void CMakeSetupDialog::OnOk()
  925. {
  926. // enable error messages each time configure is pressed
  927. cmSystemTools::EnableMessages();
  928. m_CacheEntriesList.ClearDirty();
  929. this->RunCMake(true);
  930. if (!(::GetKeyState(VK_SHIFT) & 0x1000))
  931. {
  932. CDialog::OnOK();
  933. }
  934. }
  935. void CMakeSetupDialog::OnEditchangeGenerator()
  936. {
  937. // TODO: Add your control notification handler code here
  938. }
  939. // Create a shortcut on the desktop with the current Source/Build dir.
  940. int CMakeSetupDialog::CreateShortcut()
  941. {
  942. // Find the desktop folder and create the link name
  943. HKEY hKey;
  944. if(RegOpenKeyEx(HKEY_CURRENT_USER,
  945. "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
  946. 0, KEY_READ, &hKey) != ERROR_SUCCESS)
  947. {
  948. AfxMessageBox ("Create shortcut: unable to find 'Shell Folders' key in registry!");
  949. return 1;
  950. }
  951. DWORD dwType, dwSize;
  952. #define MAXPATH 1024
  953. char link_name[MAXPATH];
  954. dwSize = MAXPATH;
  955. if(RegQueryValueEx(hKey,
  956. (LPCTSTR)"Desktop",
  957. NULL,
  958. &dwType,
  959. (BYTE *)link_name,
  960. &dwSize) != ERROR_SUCCESS)
  961. {
  962. AfxMessageBox ("Create shortcut: unable to find 'Desktop' registry value in 'Shell Folders' key!");
  963. return 1;
  964. }
  965. if(dwType != REG_SZ)
  966. {
  967. AfxMessageBox ("Create shortcut: 'Desktop' registry value in 'Shell Folders' key has wrong type!");
  968. return 1;
  969. }
  970. strcat(link_name, "\\CMake - ");
  971. std::string current_dir = cmSystemTools::GetFilenameName((LPCTSTR)m_WhereSource);
  972. strcat(link_name, current_dir.c_str());
  973. strcat(link_name, ".lnk");
  974. // Find the path to the current executable
  975. char path_to_current_exe[MAXPATH];
  976. ::GetModuleFileName(NULL, path_to_current_exe, MAXPATH);
  977. // Create the shortcut
  978. HRESULT hres;
  979. IShellLink *psl;
  980. // Initialize the COM library
  981. hres = CoInitialize(NULL);
  982. if (! SUCCEEDED (hres))
  983. {
  984. AfxMessageBox ("Create shortcut: unable to initialize the COM library!");
  985. return 1;
  986. }
  987. // Create an IShellLink object and get a pointer to the IShellLink
  988. // interface (returned from CoCreateInstance).
  989. hres = CoCreateInstance(CLSID_ShellLink,
  990. NULL,
  991. CLSCTX_INPROC_SERVER,
  992. IID_IShellLink,
  993. (void **)&psl);
  994. if (! SUCCEEDED (hres))
  995. {
  996. AfxMessageBox ("Create shortcut: unable to create IShellLink instance!");
  997. return 1;
  998. }
  999. IPersistFile *ppf;
  1000. // Query IShellLink for the IPersistFile interface for
  1001. // saving the shortcut in persistent storage.
  1002. hres = psl->QueryInterface(IID_IPersistFile, (void **)&ppf);
  1003. if (SUCCEEDED (hres))
  1004. {
  1005. // Set the path to the shortcut target.
  1006. hres = psl->SetPath(path_to_current_exe);
  1007. if (! SUCCEEDED (hres))
  1008. {
  1009. AfxMessageBox ("Create shortcut: SetPath failed!");
  1010. }
  1011. // Set the arguments of the shortcut.
  1012. CString args = " /H=\"" + m_WhereSource + "\" /B=\"" + m_WhereBuild + "\" /G=\"" + m_GeneratorChoiceString + "\" /A=\"" + (m_AdvancedValues ? "TRUE" : "FALSE") + "\"";
  1013. hres = psl->SetArguments(args);
  1014. if (! SUCCEEDED (hres))
  1015. {
  1016. AfxMessageBox ("Create shortcut: SetArguments failed!");
  1017. }
  1018. // Set the description of the shortcut.
  1019. hres = psl->SetDescription("Shortcut to CMakeSetup");
  1020. if (! SUCCEEDED (hres))
  1021. {
  1022. AfxMessageBox ("Create shortcut: SetDescription failed!");
  1023. }
  1024. // Ensure that the string consists of ANSI characters.
  1025. WORD wsz[MAX_PATH];
  1026. MultiByteToWideChar(CP_ACP, 0, link_name, -1, wsz, MAX_PATH);
  1027. // Save the shortcut via the IPersistFile::Save member function.
  1028. hres = ppf->Save(wsz, TRUE);
  1029. if (! SUCCEEDED (hres))
  1030. {
  1031. AfxMessageBox ("Create shortcut: Save failed!");
  1032. }
  1033. // Release the pointer to IPersistFile.
  1034. ppf->Release ();
  1035. }
  1036. // Release the pointer to IShellLink.
  1037. psl->Release ();
  1038. return 0;
  1039. }
  1040. void CMakeSetupDialog::OnHelpButton()
  1041. {
  1042. CMakeHelp dialog;
  1043. dialog.DoModal();
  1044. }
  1045. void CMakeSetupDialog::ShowAdvancedValues()
  1046. {
  1047. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  1048. for(cmCacheManager::CacheIterator i = cachem->NewIterator();
  1049. !i.IsAtEnd(); i.Next())
  1050. {
  1051. const char* key = i.GetName();
  1052. if(!i.GetPropertyAsBool("ADVANCED"))
  1053. {
  1054. continue;
  1055. }
  1056. switch(i.GetType() )
  1057. {
  1058. case cmCacheManager::BOOL:
  1059. if(cmSystemTools::IsOn(i.GetValue()))
  1060. {
  1061. m_CacheEntriesList.AddProperty(key,
  1062. "ON",
  1063. i.GetProperty("HELPSTRING"),
  1064. CPropertyList::COMBO,"ON|OFF",
  1065. true
  1066. );
  1067. }
  1068. else
  1069. {
  1070. m_CacheEntriesList.AddProperty(key,
  1071. "OFF",
  1072. i.GetProperty("HELPSTRING"),
  1073. CPropertyList::COMBO,"ON|OFF",
  1074. true
  1075. );
  1076. }
  1077. break;
  1078. case cmCacheManager::PATH:
  1079. m_CacheEntriesList.AddProperty(key,
  1080. i.GetValue(),
  1081. i.GetProperty("HELPSTRING"),
  1082. CPropertyList::PATH,"",
  1083. true
  1084. );
  1085. break;
  1086. case cmCacheManager::FILEPATH:
  1087. m_CacheEntriesList.AddProperty(key,
  1088. i.GetValue(),
  1089. i.GetProperty("HELPSTRING"),
  1090. CPropertyList::FILE,"",
  1091. true
  1092. );
  1093. break;
  1094. case cmCacheManager::STRING:
  1095. m_CacheEntriesList.AddProperty(key,
  1096. i.GetValue(),
  1097. i.GetProperty("HELPSTRING"),
  1098. CPropertyList::EDIT,"",
  1099. true
  1100. );
  1101. break;
  1102. case cmCacheManager::INTERNAL:
  1103. m_CacheEntriesList.RemoveProperty(key);
  1104. break;
  1105. }
  1106. }
  1107. }
  1108. void CMakeSetupDialog::RemoveAdvancedValues()
  1109. {
  1110. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  1111. for(cmCacheManager::CacheIterator i = cachem->NewIterator();
  1112. !i.IsAtEnd(); i.Next())
  1113. {
  1114. const char* key = i.GetName();
  1115. if(i.GetPropertyAsBool("ADVANCED"))
  1116. {
  1117. m_CacheEntriesList.RemoveProperty(key);
  1118. }
  1119. }
  1120. }
  1121. void CMakeSetupDialog::OnAdvancedValues()
  1122. {
  1123. this->UpdateData();
  1124. if(m_AdvancedValues)
  1125. {
  1126. this->ShowAdvancedValues();
  1127. }
  1128. else
  1129. {
  1130. this->RemoveAdvancedValues();
  1131. }
  1132. }
  1133. void CMakeSetupDialog::OnDoubleclickedAdvancedValues()
  1134. {
  1135. this->OnAdvancedValues();
  1136. }
  1137. // Handle param or single dropped file.
  1138. // If the dropped file is a build directory or any file in a
  1139. // build directory, set the source dir from the cache file,
  1140. // otherwise set the source and build dirs to this file (or dir).
  1141. void CMakeSetupDialog::ChangeDirectoriesFromFile(const char* buffer)
  1142. {
  1143. // Get the path to this file
  1144. std::string path = buffer;
  1145. if (!cmSystemTools::FileIsDirectory(path.c_str()))
  1146. {
  1147. path = cmSystemTools::GetFilenamePath(path);
  1148. }
  1149. else
  1150. {
  1151. cmSystemTools::ConvertToUnixSlashes(path);
  1152. }
  1153. // Check if it's a build dir and grab the cache
  1154. std::string cache_file = path;
  1155. cache_file += "/CMakeCache.txt";
  1156. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  1157. cmCacheManager::CacheIterator it =
  1158. cachem->NewIterator();
  1159. if (cmSystemTools::FileExists(cache_file.c_str()) &&
  1160. cachem->LoadCache(path.c_str()) &&
  1161. it.Find("CMAKE_HOME_DIRECTORY"))
  1162. {
  1163. path = ConvertToWindowsPath(path.c_str());
  1164. this->m_WhereBuild = path.c_str();
  1165. path = ConvertToWindowsPath(it.GetName());
  1166. this->m_WhereSource = path.c_str();
  1167. }
  1168. else
  1169. {
  1170. path = ConvertToWindowsPath(path.c_str());
  1171. this->m_WhereSource = this->m_WhereBuild = path.c_str();
  1172. }
  1173. }
  1174. // The framework calls this member function when the user releases the
  1175. // left mouse button over a window that has registered itself as the
  1176. // recipient of dropped files.
  1177. void CMakeSetupDialog::OnDropFiles(HDROP hDropInfo)
  1178. {
  1179. UINT nb_files = DragQueryFile(hDropInfo, 0xFFFFFFFF, NULL, 0);
  1180. if (nb_files > 0)
  1181. {
  1182. UINT buffer_size = DragQueryFile(hDropInfo, 0, NULL, 0);
  1183. char *buffer = new char [buffer_size + 1];
  1184. DragQueryFile(hDropInfo, 0, buffer, buffer_size + 1);
  1185. this->ChangeDirectoriesFromFile(buffer);
  1186. delete [] buffer;
  1187. this->m_WhereSourceControl.SetWindowText(this->m_WhereSource);
  1188. this->m_WhereBuildControl.SetWindowText(this->m_WhereBuild);
  1189. this->UpdateData(FALSE);
  1190. this->OnChangeWhereSource();
  1191. this->OnChangeWhereBuild();
  1192. }
  1193. DragFinish(hDropInfo);
  1194. }