CMakeSetupDialog.cpp 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373
  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. m_OKButton.EnableWindow(true);
  558. cmSystemTools::ResetErrorOccuredFlag();
  559. }
  560. // Callback for build projects button
  561. void CMakeSetupDialog::OnConfigure()
  562. {
  563. // enable error messages each time configure is pressed
  564. cmSystemTools::EnableMessages();
  565. this->RunCMake(false);
  566. }
  567. // callback for combo box menu where build selection
  568. void CMakeSetupDialog::OnSelendokWhereBuild()
  569. {
  570. m_WhereBuildControl.GetLBText(m_WhereBuildControl.GetCurSel(),
  571. m_WhereBuild);
  572. m_WhereBuildControl.SetWindowText( m_WhereBuild);
  573. this->UpdateData(FALSE);
  574. this->OnChangeWhereBuild();
  575. }
  576. // callback for combo box menu where source selection
  577. void CMakeSetupDialog::OnSelendokWhereSource()
  578. {
  579. m_WhereSourceControl.GetLBText(m_WhereSourceControl.GetCurSel(),
  580. m_WhereSource);
  581. this->UpdateData(FALSE);
  582. this->OnChangeWhereSource();
  583. }
  584. // callback for chaing source directory
  585. void CMakeSetupDialog::OnChangeWhereSource()
  586. {
  587. }
  588. // callback for changing the build directory
  589. void CMakeSetupDialog::OnChangeWhereBuild()
  590. {
  591. this->UpdateData();
  592. // The build dir has changed, check if there is a cache, and
  593. // grab the source dir from it
  594. std::string path = this->m_WhereBuild;
  595. cmSystemTools::ConvertToUnixSlashes(path);
  596. // adjust the cmake instance
  597. m_CMakeInstance->SetHomeOutputDirectory(m_WhereBuild);
  598. m_CMakeInstance->SetStartOutputDirectory(m_WhereBuild);
  599. std::string cache_file = path;
  600. cache_file += "/CMakeCache.txt";
  601. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  602. cmCacheManager::CacheIterator it = cachem->NewIterator();
  603. if (cmSystemTools::FileExists(cache_file.c_str()) &&
  604. cachem->LoadCache(path.c_str()) &&
  605. it.Find("CMAKE_HOME_DIRECTORY"))
  606. {
  607. path = ConvertToWindowsPath(it.GetValue());
  608. this->m_WhereSource = path.c_str();
  609. this->m_WhereSourceControl.SetWindowText(this->m_WhereSource);
  610. this->OnChangeWhereSource();
  611. }
  612. m_CacheEntriesList.RemoveAll();
  613. m_CacheEntriesList.ShowWindow(SW_SHOW);
  614. this->LoadCacheFromDiskToGUI();
  615. m_BuildPathChanged = true;
  616. }
  617. // copy from the cache manager to the cache edit list box
  618. void CMakeSetupDialog::FillCacheGUIFromCacheManager()
  619. {
  620. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  621. size_t size = m_CacheEntriesList.GetItems().size();
  622. bool reverseOrder = false;
  623. // if there are already entries in the cache, then
  624. // put the new ones in the top, so they show up first
  625. if(size)
  626. {
  627. reverseOrder = true;
  628. }
  629. // all the current values are not new any more
  630. std::set<CPropertyItem*> items = m_CacheEntriesList.GetItems();
  631. for(std::set<CPropertyItem*>::iterator i = items.begin();
  632. i != items.end(); ++i)
  633. {
  634. CPropertyItem* item = *i;
  635. item->m_NewValue = false;
  636. }
  637. for(cmCacheManager::CacheIterator i = cachem->NewIterator();
  638. !i.IsAtEnd(); i.Next())
  639. {
  640. const char* key = i.GetName();
  641. // if value has trailing space or tab, enclose it in single quotes
  642. // to enforce the fact that it has 'invisible' trailing stuff
  643. std::string value = i.GetValue();
  644. if (value.size() &&
  645. (value[value.size() - 1] == ' ' ||
  646. value[value.size() - 1] == '\t'))
  647. {
  648. value = '\'' + value + '\'';
  649. }
  650. if(!m_AdvancedValues)
  651. {
  652. if(i.GetPropertyAsBool("ADVANCED"))
  653. {
  654. m_CacheEntriesList.RemoveProperty(key);
  655. continue;
  656. }
  657. }
  658. switch(i.GetType() )
  659. {
  660. case cmCacheManager::BOOL:
  661. if(cmSystemTools::IsOn(value.c_str()))
  662. {
  663. m_CacheEntriesList.AddProperty(key,
  664. "ON",
  665. i.GetProperty("HELPSTRING"),
  666. CPropertyList::COMBO,"ON|OFF",
  667. reverseOrder
  668. );
  669. }
  670. else
  671. {
  672. m_CacheEntriesList.AddProperty(key,
  673. "OFF",
  674. i.GetProperty("HELPSTRING"),
  675. CPropertyList::COMBO,"ON|OFF",
  676. reverseOrder
  677. );
  678. }
  679. break;
  680. case cmCacheManager::PATH:
  681. m_CacheEntriesList.AddProperty(key,
  682. value.c_str(),
  683. i.GetProperty("HELPSTRING"),
  684. CPropertyList::PATH,"",
  685. reverseOrder
  686. );
  687. break;
  688. case cmCacheManager::FILEPATH:
  689. m_CacheEntriesList.AddProperty(key,
  690. value.c_str(),
  691. i.GetProperty("HELPSTRING"),
  692. CPropertyList::FILE,"",
  693. reverseOrder
  694. );
  695. break;
  696. case cmCacheManager::STRING:
  697. m_CacheEntriesList.AddProperty(key,
  698. value.c_str(),
  699. i.GetProperty("HELPSTRING"),
  700. CPropertyList::EDIT,"",
  701. reverseOrder
  702. );
  703. break;
  704. case cmCacheManager::INTERNAL:
  705. m_CacheEntriesList.RemoveProperty(key);
  706. break;
  707. }
  708. }
  709. m_OKButton.EnableWindow(false);
  710. if(cachem->GetSize() > 0 && !cmSystemTools::GetErrorOccuredFlag())
  711. {
  712. bool enable = true;
  713. items = m_CacheEntriesList.GetItems();
  714. for(std::set<CPropertyItem*>::iterator i = items.begin();
  715. i != items.end(); ++i)
  716. {
  717. CPropertyItem* item = *i;
  718. if(item->m_NewValue)
  719. {
  720. // if one new value then disable to OK button
  721. enable = false;
  722. break;
  723. }
  724. }
  725. if(enable)
  726. {
  727. m_OKButton.EnableWindow(true);
  728. }
  729. }
  730. // redraw the list
  731. m_CacheEntriesList.SetTopIndex(0);
  732. m_CacheEntriesList.Invalidate();
  733. }
  734. // copy from the list box to the cache manager
  735. void CMakeSetupDialog::FillCacheManagerFromCacheGUI()
  736. {
  737. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  738. std::set<CPropertyItem*> items = m_CacheEntriesList.GetItems();
  739. cmCacheManager::CacheIterator it = cachem->NewIterator();
  740. for(std::set<CPropertyItem*>::iterator i = items.begin();
  741. i != items.end(); ++i)
  742. {
  743. CPropertyItem* item = *i;
  744. if ( it.Find((const char*)item->m_propName) )
  745. {
  746. // if value is enclosed in single quotes ('foo') then remove them
  747. // they were used to enforce the fact that it had 'invisible'
  748. // trailing stuff
  749. if (item->m_curValue.GetLength() >= 2 &&
  750. item->m_curValue[0] == '\'' &&
  751. item->m_curValue[item->m_curValue.GetLength() - 1] == '\'')
  752. {
  753. it.SetValue(item->m_curValue.Mid(
  754. 1, item->m_curValue.GetLength() - 2));
  755. }
  756. else
  757. {
  758. it.SetValue(item->m_curValue);
  759. }
  760. }
  761. }
  762. }
  763. //! Load cache file from m_WhereBuild and display in GUI editor
  764. void CMakeSetupDialog::LoadCacheFromDiskToGUI()
  765. {
  766. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  767. if(m_WhereBuild != "")
  768. {
  769. cachem->LoadCache(m_WhereBuild);
  770. this->FillCacheGUIFromCacheManager();
  771. cmCacheManager::CacheIterator it =
  772. cachem->GetCacheIterator("CMAKE_GENERATOR");
  773. if(!it.IsAtEnd())
  774. {
  775. std::string curGen = it.GetValue();
  776. if(m_GeneratorChoiceString != curGen.c_str())
  777. {
  778. m_GeneratorChoiceString = curGen.c_str();
  779. this->UpdateData(FALSE);
  780. }
  781. }
  782. }
  783. }
  784. //! Save GUI values to cmCacheManager and then save to disk.
  785. void CMakeSetupDialog::SaveCacheFromGUI()
  786. {
  787. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  788. this->FillCacheManagerFromCacheGUI();
  789. if(m_WhereBuild != "")
  790. {
  791. cachem->SaveCache(m_WhereBuild);
  792. }
  793. }
  794. void CMakeSetupDialog::OnSize(UINT nType, int cx, int cy)
  795. {
  796. if (nType == SIZE_MINIMIZED)
  797. {
  798. CDialog::OnSize(nType, cx, cy);
  799. return;
  800. }
  801. if (m_oldCX == -1)
  802. {
  803. m_oldCX = cx;
  804. m_oldCY = cy;
  805. }
  806. int deltax = cx - m_oldCX;
  807. int deltay = cy - m_oldCY;
  808. m_oldCX = cx;
  809. m_oldCY = cy;
  810. CDialog::OnSize(nType, cx, cy);
  811. if (deltax == 0 && deltay == 0)
  812. {
  813. return;
  814. }
  815. if(m_CacheEntriesList.m_hWnd)
  816. {
  817. // get the original sizes/positions
  818. CRect cRect;
  819. m_AdvancedValuesControl.GetWindowRect(&cRect);
  820. this->ScreenToClient(&cRect);
  821. m_AdvancedValuesControl.SetWindowPos(&wndTop, cRect.left + deltax,
  822. cRect.top,
  823. 0, 0,
  824. SWP_NOCOPYBITS |
  825. SWP_NOSIZE | SWP_NOZORDER);
  826. m_BuildForLabel.GetWindowRect(&cRect);
  827. this->ScreenToClient(&cRect);
  828. m_BuildForLabel.SetWindowPos(&wndTop, cRect.left + deltax,
  829. cRect.top,
  830. 0, 0,
  831. SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOZORDER);
  832. m_GeneratorChoice.GetWindowRect(&cRect);
  833. this->ScreenToClient(&cRect);
  834. m_GeneratorChoice.SetWindowPos(&wndTop, cRect.left + deltax,
  835. cRect.top,
  836. 0, 0,
  837. SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOZORDER);
  838. m_BrowseSource.GetWindowRect(&cRect);
  839. this->ScreenToClient(&cRect);
  840. m_BrowseSource.SetWindowPos(&wndTop, cRect.left + deltax,
  841. cRect.top,
  842. 0, 0,
  843. SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOZORDER);
  844. m_BrowseBuild.GetWindowRect(&cRect);
  845. this->ScreenToClient(&cRect);
  846. m_BrowseBuild.SetWindowPos(&wndTop, cRect.left + deltax,
  847. cRect.top,
  848. 0, 0,
  849. SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOZORDER);
  850. m_WhereSourceControl.GetWindowRect(&cRect);
  851. m_WhereSourceControl.SetWindowPos(&wndTop, cRect.left, cRect.top,
  852. cRect.Width() + deltax,
  853. cRect.Height(),
  854. SWP_NOCOPYBITS |
  855. SWP_NOMOVE | SWP_NOZORDER);
  856. m_WhereBuildControl.GetWindowRect(&cRect);
  857. m_WhereBuildControl.SetWindowPos(&wndTop, cRect.left, cRect.top,
  858. cRect.Width() + deltax,
  859. cRect.Height(),
  860. SWP_NOCOPYBITS |
  861. SWP_NOMOVE | SWP_NOZORDER);
  862. m_ListFrame.GetWindowRect(&cRect);
  863. m_ListFrame.SetWindowPos(&wndTop, cRect.left, cRect.top,
  864. cRect.Width() + deltax,
  865. cRect.Height() + deltay,
  866. SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOZORDER);
  867. m_CacheEntriesList.GetWindowRect(&cRect);
  868. m_CacheEntriesList.SetWindowPos(&wndTop, cRect.left, cRect.top,
  869. cRect.Width() + deltax,
  870. cRect.Height() + deltay,
  871. SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOZORDER);
  872. deltax = int(deltax + m_deltaXRemainder);
  873. m_deltaXRemainder = float(deltax%2);
  874. m_MouseHelp.GetWindowRect(&cRect);
  875. this->ScreenToClient(&cRect);
  876. m_MouseHelp.SetWindowPos(&wndTop, cRect.left + deltax/2,
  877. cRect.top + deltay,
  878. 0, 0,
  879. SWP_NOCOPYBITS | SWP_NOSIZE | SWP_NOZORDER);
  880. m_VersionDisplay.GetWindowRect(&cRect);
  881. m_VersionDisplay.SetWindowPos(&wndBottom, 5, cy-23,
  882. cRect.Width() + deltax/2, cRect.Height(),
  883. SWP_NOCOPYBITS);
  884. m_StatusDisplay.GetWindowRect(&cRect);
  885. this->ScreenToClient(&cRect);
  886. m_StatusDisplay.SetWindowPos(&wndBottom, cRect.left + deltax/2,
  887. cRect.top + deltay,
  888. cRect.Width() + deltax/2, cRect.Height(),
  889. SWP_NOCOPYBITS);
  890. m_Configure.GetWindowRect(&cRect);
  891. this->ScreenToClient(&cRect);
  892. m_Configure.SetWindowPos(&wndTop, cRect.left + deltax/2,
  893. cRect.top + deltay,
  894. 0, 0,
  895. SWP_NOCOPYBITS | SWP_NOSIZE);
  896. m_CancelButton.GetWindowRect(&cRect);
  897. this->ScreenToClient(&cRect);
  898. m_CancelButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  899. cRect.top + deltay,
  900. 0, 0,
  901. SWP_NOCOPYBITS | SWP_NOSIZE);
  902. m_OKButton.GetWindowRect(&cRect);
  903. this->ScreenToClient(&cRect);
  904. m_OKButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  905. cRect.top + deltay,
  906. 0, 0,
  907. SWP_NOCOPYBITS | SWP_NOSIZE);
  908. m_HelpButton.GetWindowRect(&cRect);
  909. this->ScreenToClient(&cRect);
  910. m_HelpButton.SetWindowPos(&wndTop, cRect.left + deltax/2,
  911. cRect.top + deltay,
  912. 0, 0,
  913. SWP_NOCOPYBITS | SWP_NOSIZE);
  914. }
  915. }
  916. void CMakeSetupDialog::OnGetMinMaxInfo( MINMAXINFO FAR* lpMMI )
  917. {
  918. lpMMI->ptMinTrackSize.x = 550;
  919. lpMMI->ptMinTrackSize.y = 272;
  920. }
  921. void CMakeSetupDialog::OnCancel()
  922. {
  923. if(m_CacheEntriesList.IsDirty())
  924. {
  925. if(MessageBox("You have changed options but not rebuilt, "
  926. "are you sure you want to exit?", "Confirm Exit",
  927. MB_YESNO) == IDYES)
  928. {
  929. CDialog::OnOK();
  930. }
  931. }
  932. else
  933. {
  934. CDialog::OnOK();
  935. }
  936. }
  937. void CMakeSetupDialog::OnOk()
  938. {
  939. // enable error messages each time configure is pressed
  940. cmSystemTools::EnableMessages();
  941. m_CacheEntriesList.ClearDirty();
  942. this->RunCMake(true);
  943. if (!(::GetKeyState(VK_SHIFT) & 0x1000))
  944. {
  945. CDialog::OnOK();
  946. }
  947. }
  948. void CMakeSetupDialog::OnEditchangeGenerator()
  949. {
  950. // TODO: Add your control notification handler code here
  951. }
  952. // Create a shortcut on the desktop with the current Source/Build dir.
  953. int CMakeSetupDialog::CreateShortcut()
  954. {
  955. // Find the desktop folder and create the link name
  956. HKEY hKey;
  957. if(RegOpenKeyEx(HKEY_CURRENT_USER,
  958. "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
  959. 0, KEY_READ, &hKey) != ERROR_SUCCESS)
  960. {
  961. AfxMessageBox ("Create shortcut: unable to find 'Shell Folders' key in registry!");
  962. return 1;
  963. }
  964. DWORD dwType, dwSize;
  965. #define MAXPATH 1024
  966. char link_name[MAXPATH];
  967. dwSize = MAXPATH;
  968. if(RegQueryValueEx(hKey,
  969. (LPCTSTR)"Desktop",
  970. NULL,
  971. &dwType,
  972. (BYTE *)link_name,
  973. &dwSize) != ERROR_SUCCESS)
  974. {
  975. AfxMessageBox ("Create shortcut: unable to find 'Desktop' registry value in 'Shell Folders' key!");
  976. return 1;
  977. }
  978. if(dwType != REG_SZ)
  979. {
  980. AfxMessageBox ("Create shortcut: 'Desktop' registry value in 'Shell Folders' key has wrong type!");
  981. return 1;
  982. }
  983. strcat(link_name, "\\CMake - ");
  984. std::string current_dir = cmSystemTools::GetFilenameName((LPCTSTR)m_WhereSource);
  985. strcat(link_name, current_dir.c_str());
  986. strcat(link_name, ".lnk");
  987. // Find the path to the current executable
  988. char path_to_current_exe[MAXPATH];
  989. ::GetModuleFileName(NULL, path_to_current_exe, MAXPATH);
  990. // Create the shortcut
  991. HRESULT hres;
  992. IShellLink *psl;
  993. // Initialize the COM library
  994. hres = CoInitialize(NULL);
  995. if (! SUCCEEDED (hres))
  996. {
  997. AfxMessageBox ("Create shortcut: unable to initialize the COM library!");
  998. return 1;
  999. }
  1000. // Create an IShellLink object and get a pointer to the IShellLink
  1001. // interface (returned from CoCreateInstance).
  1002. hres = CoCreateInstance(CLSID_ShellLink,
  1003. NULL,
  1004. CLSCTX_INPROC_SERVER,
  1005. IID_IShellLink,
  1006. (void **)&psl);
  1007. if (! SUCCEEDED (hres))
  1008. {
  1009. AfxMessageBox ("Create shortcut: unable to create IShellLink instance!");
  1010. return 1;
  1011. }
  1012. IPersistFile *ppf;
  1013. // Query IShellLink for the IPersistFile interface for
  1014. // saving the shortcut in persistent storage.
  1015. hres = psl->QueryInterface(IID_IPersistFile, (void **)&ppf);
  1016. if (SUCCEEDED (hres))
  1017. {
  1018. // Set the path to the shortcut target.
  1019. hres = psl->SetPath(path_to_current_exe);
  1020. if (! SUCCEEDED (hres))
  1021. {
  1022. AfxMessageBox ("Create shortcut: SetPath failed!");
  1023. }
  1024. // Set the arguments of the shortcut.
  1025. CString args = " /H=\"" + m_WhereSource + "\" /B=\"" + m_WhereBuild + "\" /G=\"" + m_GeneratorChoiceString + "\" /A=\"" + (m_AdvancedValues ? "TRUE" : "FALSE") + "\"";
  1026. hres = psl->SetArguments(args);
  1027. if (! SUCCEEDED (hres))
  1028. {
  1029. AfxMessageBox ("Create shortcut: SetArguments failed!");
  1030. }
  1031. // Set the description of the shortcut.
  1032. hres = psl->SetDescription("Shortcut to CMakeSetup");
  1033. if (! SUCCEEDED (hres))
  1034. {
  1035. AfxMessageBox ("Create shortcut: SetDescription failed!");
  1036. }
  1037. // Ensure that the string consists of ANSI characters.
  1038. WORD wsz[MAX_PATH];
  1039. MultiByteToWideChar(CP_ACP, 0, link_name, -1, wsz, MAX_PATH);
  1040. // Save the shortcut via the IPersistFile::Save member function.
  1041. hres = ppf->Save(wsz, TRUE);
  1042. if (! SUCCEEDED (hres))
  1043. {
  1044. AfxMessageBox ("Create shortcut: Save failed!");
  1045. }
  1046. // Release the pointer to IPersistFile.
  1047. ppf->Release ();
  1048. }
  1049. // Release the pointer to IShellLink.
  1050. psl->Release ();
  1051. return 0;
  1052. }
  1053. void CMakeSetupDialog::OnHelpButton()
  1054. {
  1055. CMakeHelp dialog;
  1056. dialog.DoModal();
  1057. }
  1058. void CMakeSetupDialog::ShowAdvancedValues()
  1059. {
  1060. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  1061. for(cmCacheManager::CacheIterator i = cachem->NewIterator();
  1062. !i.IsAtEnd(); i.Next())
  1063. {
  1064. const char* key = i.GetName();
  1065. if(!i.GetPropertyAsBool("ADVANCED"))
  1066. {
  1067. continue;
  1068. }
  1069. switch(i.GetType() )
  1070. {
  1071. case cmCacheManager::BOOL:
  1072. if(cmSystemTools::IsOn(i.GetValue()))
  1073. {
  1074. m_CacheEntriesList.AddProperty(key,
  1075. "ON",
  1076. i.GetProperty("HELPSTRING"),
  1077. CPropertyList::COMBO,"ON|OFF",
  1078. true
  1079. );
  1080. }
  1081. else
  1082. {
  1083. m_CacheEntriesList.AddProperty(key,
  1084. "OFF",
  1085. i.GetProperty("HELPSTRING"),
  1086. CPropertyList::COMBO,"ON|OFF",
  1087. true
  1088. );
  1089. }
  1090. break;
  1091. case cmCacheManager::PATH:
  1092. m_CacheEntriesList.AddProperty(key,
  1093. i.GetValue(),
  1094. i.GetProperty("HELPSTRING"),
  1095. CPropertyList::PATH,"",
  1096. true
  1097. );
  1098. break;
  1099. case cmCacheManager::FILEPATH:
  1100. m_CacheEntriesList.AddProperty(key,
  1101. i.GetValue(),
  1102. i.GetProperty("HELPSTRING"),
  1103. CPropertyList::FILE,"",
  1104. true
  1105. );
  1106. break;
  1107. case cmCacheManager::STRING:
  1108. m_CacheEntriesList.AddProperty(key,
  1109. i.GetValue(),
  1110. i.GetProperty("HELPSTRING"),
  1111. CPropertyList::EDIT,"",
  1112. true
  1113. );
  1114. break;
  1115. case cmCacheManager::INTERNAL:
  1116. m_CacheEntriesList.RemoveProperty(key);
  1117. break;
  1118. }
  1119. }
  1120. }
  1121. void CMakeSetupDialog::RemoveAdvancedValues()
  1122. {
  1123. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  1124. for(cmCacheManager::CacheIterator i = cachem->NewIterator();
  1125. !i.IsAtEnd(); i.Next())
  1126. {
  1127. const char* key = i.GetName();
  1128. if(i.GetPropertyAsBool("ADVANCED"))
  1129. {
  1130. m_CacheEntriesList.RemoveProperty(key);
  1131. }
  1132. }
  1133. }
  1134. void CMakeSetupDialog::OnAdvancedValues()
  1135. {
  1136. this->UpdateData();
  1137. if(m_AdvancedValues)
  1138. {
  1139. this->ShowAdvancedValues();
  1140. }
  1141. else
  1142. {
  1143. this->RemoveAdvancedValues();
  1144. }
  1145. }
  1146. void CMakeSetupDialog::OnDoubleclickedAdvancedValues()
  1147. {
  1148. this->OnAdvancedValues();
  1149. }
  1150. // Handle param or single dropped file.
  1151. // If the dropped file is a build directory or any file in a
  1152. // build directory, set the source dir from the cache file,
  1153. // otherwise set the source and build dirs to this file (or dir).
  1154. void CMakeSetupDialog::ChangeDirectoriesFromFile(const char* buffer)
  1155. {
  1156. // Get the path to this file
  1157. std::string path = buffer;
  1158. if (!cmSystemTools::FileIsDirectory(path.c_str()))
  1159. {
  1160. path = cmSystemTools::GetFilenamePath(path);
  1161. }
  1162. else
  1163. {
  1164. cmSystemTools::ConvertToUnixSlashes(path);
  1165. }
  1166. // Check if it's a build dir and grab the cache
  1167. std::string cache_file = path;
  1168. cache_file += "/CMakeCache.txt";
  1169. cmCacheManager *cachem = this->m_CMakeInstance->GetCacheManager();
  1170. cmCacheManager::CacheIterator it =
  1171. cachem->NewIterator();
  1172. if (cmSystemTools::FileExists(cache_file.c_str()) &&
  1173. cachem->LoadCache(path.c_str()) &&
  1174. it.Find("CMAKE_HOME_DIRECTORY"))
  1175. {
  1176. path = ConvertToWindowsPath(path.c_str());
  1177. this->m_WhereBuild = path.c_str();
  1178. path = ConvertToWindowsPath(it.GetName());
  1179. this->m_WhereSource = path.c_str();
  1180. }
  1181. else
  1182. {
  1183. path = ConvertToWindowsPath(path.c_str());
  1184. this->m_WhereSource = this->m_WhereBuild = path.c_str();
  1185. }
  1186. }
  1187. // The framework calls this member function when the user releases the
  1188. // left mouse button over a window that has registered itself as the
  1189. // recipient of dropped files.
  1190. void CMakeSetupDialog::OnDropFiles(HDROP hDropInfo)
  1191. {
  1192. UINT nb_files = DragQueryFile(hDropInfo, 0xFFFFFFFF, NULL, 0);
  1193. if (nb_files > 0)
  1194. {
  1195. UINT buffer_size = DragQueryFile(hDropInfo, 0, NULL, 0);
  1196. char *buffer = new char [buffer_size + 1];
  1197. DragQueryFile(hDropInfo, 0, buffer, buffer_size + 1);
  1198. this->ChangeDirectoriesFromFile(buffer);
  1199. delete [] buffer;
  1200. this->m_WhereSourceControl.SetWindowText(this->m_WhereSource);
  1201. this->m_WhereBuildControl.SetWindowText(this->m_WhereBuild);
  1202. this->UpdateData(FALSE);
  1203. this->OnChangeWhereSource();
  1204. this->OnChangeWhereBuild();
  1205. }
  1206. DragFinish(hDropInfo);
  1207. }