CMakeSetupDialog.cpp 36 KB

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