CMakeSetupDialog.cpp 44 KB

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