CMakeSetupDialog.cpp 39 KB

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