1
0

CMakeSetupDialog.cpp 44 KB

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