CMakeSetupDialog.cpp 39 KB

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