CMakeSetupDialog.cpp 20.5 KB
Newer Older
1 2 3 4 5
// pcbuilderdialogDlg.cpp : implementation file
//

#include "stdafx.h"
#include "CMakeSetup.h"
6
#include "PathDialog.h"
7
#include "CMakeSetupDialog.h"
8
#include "../cmCacheManager.h"
9
#include "../cmake.h"
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
  CAboutDlg();

// Dialog Data
  //{{AFX_DATA(CAboutDlg)
  enum { IDD = IDD_ABOUTBOX };
  //}}AFX_DATA

  // ClassWizard generated virtual function overrides
  //{{AFX_VIRTUAL(CAboutDlg)
protected:
  virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  //}}AFX_VIRTUAL

// Implementation
protected:
  //{{AFX_MSG(CAboutDlg)
  //}}AFX_MSG
  DECLARE_MESSAGE_MAP()
    };

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
  //{{AFX_DATA_INIT(CAboutDlg)
  //}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
  CDialog::DoDataExchange(pDX);
  //{{AFX_DATA_MAP(CAboutDlg)
  //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  //{{AFX_MSG_MAP(CAboutDlg)
  // No message handlers
  //}}AFX_MSG_MAP
  END_MESSAGE_MAP();


/////////////////////////////////////////////////////////////////////////////
// CMakeSetupDialog dialog

CMakeSetupDialog::CMakeSetupDialog(CWnd* pParent /*=NULL*/)
  : CDialog(CMakeSetupDialog::IDD, pParent)
{
68
  m_RegistryKey  = "Software\\Kitware\\CMakeSetup\\Settings\\StartPath";
69
  
70
  //{{AFX_DATA_INIT(CMakeSetupDialog)
Bill Hoffman's avatar
Bill Hoffman committed
71
	m_WhereSource = _T("");
72
	m_WhereBuild = _T("");
Bill Hoffman's avatar
Bill Hoffman committed
73
	//}}AFX_DATA_INIT
74 75
  // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
76
  m_BuildPathChanged = false;
77 78 79 80 81 82 83
  // Find the path to the cmake.exe executable
  char fname[1024];
  ::GetModuleFileName(NULL,fname,1023);
  // extract just the path part
  m_PathToExecutable = cmSystemTools::GetProgramPath(fname).c_str();
  // add the cmake.exe to the path
  m_PathToExecutable += "/cmake.exe";
84 85 86
  
  m_oldCX = -1;
  m_deltaXRemainder = 0;
87 88 89 90 91 92
}

void CMakeSetupDialog::DoDataExchange(CDataExchange* pDX)
{
  CDialog::DoDataExchange(pDX);
  //{{AFX_DATA_MAP(CMakeSetupDialog)
93 94 95 96
	DDX_Control(pDX, IDC_OK, m_OKButton);
	DDX_Control(pDX, IDCANCEL, m_CancelButton);
	DDX_CBStringExact(pDX, IDC_WhereSource, m_WhereSource);
	DDX_CBStringExact(pDX, IDC_WhereBuild, m_WhereBuild);
97
	DDX_Control(pDX, IDC_FRAME, m_ListFrame);
Bill Hoffman's avatar
Bill Hoffman committed
98 99
	DDX_Control(pDX, IDC_WhereSource, m_WhereSourceControl);
	DDX_Control(pDX, IDC_WhereBuild, m_WhereBuildControl);
100
	DDX_Control(pDX, IDC_LIST2, m_CacheEntriesList);
101 102 103
	DDX_Control(pDX, IDC_MouseHelpCaption, m_MouseHelp);
	DDX_Control(pDX, IDC_CMAKE_VERSION, m_VersionDisplay);
	DDX_Control(pDX, IDC_BuildProjects, m_Configure);
104
	//}}AFX_DATA_MAP
105 106 107 108 109 110 111
}

BEGIN_MESSAGE_MAP(CMakeSetupDialog, CDialog)
  //{{AFX_MSG_MAP(CMakeSetupDialog)
  ON_WM_SYSCOMMAND()
  ON_WM_PAINT()
  ON_WM_QUERYDRAGICON()
112
  ON_BN_CLICKED(IDC_BUTTON2, OnBrowseWhereSource)
113
  ON_BN_CLICKED(IDC_BuildProjects, OnConfigure)
114
  ON_BN_CLICKED(IDC_BUTTON3, OnBrowseWhereBuild)
115 116 117
  ON_CBN_EDITCHANGE(IDC_WhereBuild, OnChangeWhereBuild)
  ON_CBN_SELCHANGE(IDC_WhereBuild, OnSelendokWhereBuild)
  ON_CBN_EDITCHANGE(IDC_WhereSource, OnChangeWhereSource)
Bill Hoffman's avatar
Bill Hoffman committed
118
  ON_CBN_SELENDOK(IDC_WhereSource, OnSelendokWhereSource)
119 120
	ON_WM_SIZE()
  ON_WM_GETMINMAXINFO()
121 122
  ON_BN_CLICKED(IDCANCEL, OnCancel)
	ON_BN_CLICKED(IDC_OK, OnOk)
Bill Hoffman's avatar
Bill Hoffman committed
123 124
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()
125 126 127 128

/////////////////////////////////////////////////////////////////////////////
// CMakeSetupDialog message handlers

Bill Hoffman's avatar
Bill Hoffman committed
129
BOOL CMakeSetupDialog::OnInitDialog()
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
{
  CDialog::OnInitDialog();

  // Add "About..." menu item to system menu.

  // IDM_ABOUTBOX must be in the system command range.
  ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  ASSERT(IDM_ABOUTBOX < 0xF000);

  CMenu* pSysMenu = GetSystemMenu(FALSE);
  if (pSysMenu != NULL)
    {
    CString strAboutMenu;
    strAboutMenu.LoadString(IDS_ABOUTBOX);
    if (!strAboutMenu.IsEmpty())
      {
      pSysMenu->AppendMenu(MF_SEPARATOR);
      pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
      }
    }

  // Set the icon for this dialog.  The framework does this automatically
  //  when the application's main window is not a dialog
  SetIcon(m_hIcon, TRUE);			// Set big icon
  SetIcon(m_hIcon, FALSE);		// Set small icon
Bill Hoffman's avatar
Bill Hoffman committed
155 156 157
  // Load source and build dirs from registry
  this->LoadFromRegistry();
  // try to load the cmake cache from disk
158
  this->LoadCacheFromDiskToGUI();
159 160
  m_WhereBuildControl.LimitText(2048);
  m_WhereSourceControl.LimitText(2048);
Ken Martin's avatar
Ken Martin committed
161 162
  // Set the version number
  char tmp[1024];
163 164
  sprintf(tmp,"Version %d.%d", cmMakefile::GetMajorVersion(),
          cmMakefile::GetMinorVersion());
Bill Hoffman's avatar
Bill Hoffman committed
165 166
  SetDlgItemText(IDC_CMAKE_VERSION, tmp);
  this->UpdateData(FALSE);
167 168 169
  return TRUE;  // return TRUE  unless you set the focus to a control
}

Bill Hoffman's avatar
Bill Hoffman committed
170 171

// About dialog invoke
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
void CMakeSetupDialog::OnSysCommand(UINT nID, LPARAM lParam)
{
  if ((nID & 0xFFF0) == IDM_ABOUTBOX)
    {
    CAboutDlg dlgAbout;
    dlgAbout.DoModal();
    }
  else
    {
    CDialog::OnSysCommand(nID, lParam);
    }
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CMakeSetupDialog::OnPaint() 
{
  if (IsIconic())
    {
    CPaintDC dc(this); // device context for painting

    SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

    // Center icon in client rectangle
    int cxIcon = GetSystemMetrics(SM_CXICON);
    int cyIcon = GetSystemMetrics(SM_CYICON);
    CRect rect;
    GetClientRect(&rect);
    int x = (rect.Width() - cxIcon + 1) / 2;
    int y = (rect.Height() - cyIcon + 1) / 2;

    // Draw the icon
    dc.DrawIcon(x, y, m_hIcon);
    }
  else
    {
    CDialog::OnPaint();
    }
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMakeSetupDialog::OnQueryDragIcon()
{
  return (HCURSOR) m_hIcon;
}


Bill Hoffman's avatar
Bill Hoffman committed
222 223

// Browse button
224 225
bool CMakeSetupDialog::Browse(CString &result, const char *title)
{
226 227 228 229 230 231 232
  CPathDialog dlg("Select Path", title, result); 
  if(dlg.DoModal()==IDOK)
    {
    result =  dlg.GetPathName();
    return true;
    }
  else
233
    {
234
    return false;
235 236 237 238
    }
}


Bill Hoffman's avatar
Bill Hoffman committed
239

240 241 242 243 244 245 246

void CMakeSetupDialog::SaveToRegistry()
{ 
  HKEY hKey;
  DWORD dwDummy;

  if(RegCreateKeyEx(HKEY_CURRENT_USER, 
247
		    m_RegistryKey,
248 249 250 251 252 253 254
		    0, "", REG_OPTION_NON_VOLATILE, KEY_READ|KEY_WRITE, 
		    NULL, &hKey, &dwDummy) != ERROR_SUCCESS) 
    {
    return;
    }
  else
    {
Bill Hoffman's avatar
Bill Hoffman committed
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
    // load some values
    CString regvalue;
    this->ReadRegistryValue(hKey, &(regvalue),"WhereSource","C:\\");
    if(m_WhereSource != regvalue)
      {
      regvalue = "";
      this->ReadRegistryValue(hKey, &(regvalue),"WhereSource3","");
      RegSetValueEx(hKey, _T("WhereSource4"), 0, REG_SZ, 
                    (CONST BYTE *)(const char *)regvalue, 
                    regvalue.GetLength());
      regvalue = "";
      this->ReadRegistryValue(hKey, &(regvalue),"WhereSource2","");
      RegSetValueEx(hKey, _T("WhereSource3"), 0, REG_SZ, 
                    (CONST BYTE *)(const char *)regvalue, 
                    regvalue.GetLength());
      regvalue = "";
      this->ReadRegistryValue(hKey, &(regvalue),"WhereSource","");
      RegSetValueEx(hKey, _T("WhereSource2"), 0, REG_SZ, 
                    (CONST BYTE *)(const char *)regvalue, 
                    regvalue.GetLength());
      RegSetValueEx(hKey, _T("WhereSource"), 0, REG_SZ, 
                    (CONST BYTE *)(const char *)m_WhereSource, 
                    m_WhereSource.GetLength());
      }
    this->ReadRegistryValue(hKey, &(regvalue),"WhereBuild","C:\\");
    if(m_WhereBuild != regvalue)
      {
      regvalue = "";
      this->ReadRegistryValue(hKey, &(regvalue),"WhereBuild3","");
      RegSetValueEx(hKey, _T("WhereBuild4"), 0, REG_SZ, 
                    (CONST BYTE *)(const char *)regvalue, 
                    regvalue.GetLength());
      regvalue = "";
      this->ReadRegistryValue(hKey, &(regvalue),"WhereBuild2","");
      RegSetValueEx(hKey, _T("WhereBuild3"), 0, REG_SZ, 
                    (CONST BYTE *)(const char *)regvalue, 
                    regvalue.GetLength());
      regvalue = "";
      this->ReadRegistryValue(hKey, &(regvalue),"WhereBuild","");
      RegSetValueEx(hKey, _T("WhereBuild2"), 0, REG_SZ, 
                    (CONST BYTE *)(const char *)regvalue, 
                    regvalue.GetLength());
      RegSetValueEx(hKey, _T("WhereBuild"), 0, REG_SZ, 
                    (CONST BYTE *)(const char *)m_WhereBuild, 
                    m_WhereBuild.GetLength());
      }
301 302 303 304 305 306
    }
  RegCloseKey(hKey);
}


void CMakeSetupDialog::ReadRegistryValue(HKEY hKey,
307 308 309
                                         CString *val,
                                         const char *key,
                                         const char *adefault)
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
{
  DWORD dwType, dwSize;
  char *pb;

  dwType = REG_SZ;
  pb = val->GetBuffer(MAX_PATH);
  dwSize = MAX_PATH;
  if(RegQueryValueEx(hKey,_T(key), NULL, &dwType, 
		     (BYTE *)pb, &dwSize) != ERROR_SUCCESS)
    {
    val->ReleaseBuffer();
    *val = _T(adefault);
    }
  else
    {
    val->ReleaseBuffer();
    }
}


void CMakeSetupDialog::LoadFromRegistry()
{ 
  HKEY hKey;
  if(RegOpenKeyEx(HKEY_CURRENT_USER, 
334
		  m_RegistryKey, 
335 336 337 338 339 340
		  0, KEY_READ, &hKey) != ERROR_SUCCESS)
    {
    return;
    }
  else
    {
Bill Hoffman's avatar
Bill Hoffman committed
341
    // load some values
342 343
    this->ReadRegistryValue(hKey, &(m_WhereSource),"WhereSource","C:\\");
    this->ReadRegistryValue(hKey, &(m_WhereBuild),"WhereBuild","C:\\");
Bill Hoffman's avatar
Bill Hoffman committed
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
    m_WhereSourceControl.AddString(m_WhereSource);
    m_WhereBuildControl.AddString(m_WhereBuild);

    CString regvalue;
    this->ReadRegistryValue(hKey, &(regvalue),"WhereSource2","C:\\");
    m_WhereSourceControl.AddString(regvalue);
    regvalue = "";
    this->ReadRegistryValue(hKey, &(regvalue),"WhereBuild2","C:\\");
    m_WhereBuildControl.AddString(regvalue);

    regvalue = "";
    this->ReadRegistryValue(hKey, &(regvalue),"WhereSource3","C:\\");
    m_WhereSourceControl.AddString(regvalue);
    regvalue = "";
    this->ReadRegistryValue(hKey, &(regvalue),"WhereBuild3","C:\\");
    m_WhereBuildControl.AddString(regvalue);

    regvalue = "";
    this->ReadRegistryValue(hKey, &(regvalue),"WhereSource4","C:\\");
    m_WhereSourceControl.AddString(regvalue);
    regvalue = "";
    this->ReadRegistryValue(hKey, &(regvalue),"WhereBuild4","C:\\");
    m_WhereBuildControl.AddString(regvalue);
367 368 369
    }
  RegCloseKey(hKey);
}
370

Bill Hoffman's avatar
Bill Hoffman committed
371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390


// Callback for browse source button
void CMakeSetupDialog::OnBrowseWhereSource() 
{
  this->UpdateData();
  Browse(m_WhereSource, "Enter Path to Source");
  this->UpdateData(false);
  this->OnChangeWhereSource();
}

// Callback for browser build button
void CMakeSetupDialog::OnBrowseWhereBuild() 
{
  this->UpdateData();
  Browse(m_WhereBuild, "Enter Path to Build");
  this->UpdateData(false);
  this->OnChangeWhereBuild();
}

391
void CMakeSetupDialog::RunCMake(bool generateProjectFiles)
392
{
393
    if(!cmSystemTools::FileExists(m_WhereBuild))
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408
    {
    std::string message =
      "Build directory does not exist, should I create it?\n\n"
      "Directory: ";
    message += (const char*)m_WhereBuild;
    if(MessageBox(message.c_str(), "Create Directory", MB_OKCANCEL) == IDOK)
      {
      cmSystemTools::MakeDirectory(m_WhereBuild);
      }
    else
      {
      MessageBox("Build Project aborted, nothing done.");
      return;
      }
    }
409
  // set the wait cursor
Bill Hoffman's avatar
Bill Hoffman committed
410 411
  ::SetCursor(LoadCursor(NULL, IDC_WAIT));  

412
  // get all the info from the dialog
413
  this->UpdateData();
414 415 416 417 418 419
  if(!m_BuildPathChanged)
    {
    // if the build path has not changed save the 
    // current GUI values to the cache
    this->SaveCacheFromGUI();
    }
Ken Martin's avatar
Ken Martin committed
420 421
  // Make sure we are working from the cache on disk
  this->LoadCacheFromDiskToGUI();
422 423 424 425 426 427 428 429 430 431 432 433 434
  // create a cmake object
  cmake make;
  // create the arguments for the cmake object
  std::vector<std::string> args;
  args.push_back((const char*)m_PathToExecutable);
  std::string arg;
  arg = "-H";
  arg += m_WhereSource;
  args.push_back(arg);
  arg = "-B";
  arg += m_WhereBuild;
  args.push_back(arg);
  // run the generate process
435
  if(make.Generate(args, generateProjectFiles) != 0)
436 437 438
    {
    cmSystemTools::Error(
      "Error in generation process, project files may be invalid");
Ken Martin's avatar
Ken Martin committed
439
    cmSystemTools::ResetErrorOccuredFlag();
440
    }
441 442
  // update the GUI with any new values in the caused by the
  // generation process
443 444
  this->LoadCacheFromDiskToGUI();
  // save source and build paths to registry
445
  this->SaveToRegistry();
446
  // path is up-to-date now
447
  m_BuildPathChanged = false;
448
  // put the cursor back
449
  ::SetCursor(LoadCursor(NULL, IDC_ARROW));
450 451 452 453 454 455 456
}


// Callback for build projects button
void CMakeSetupDialog::OnConfigure() 
{
  this->RunCMake(false);
457 458 459
}


Bill Hoffman's avatar
Bill Hoffman committed
460 461 462 463 464


// callback for combo box menu where build selection
void CMakeSetupDialog::OnSelendokWhereBuild() 
{
465 466
  m_WhereBuildControl.GetLBText(m_WhereBuildControl.GetCurSel(), 
                                m_WhereBuild);
467
  m_WhereBuildControl.SetWindowText( m_WhereBuild);
Bill Hoffman's avatar
Bill Hoffman committed
468 469 470 471 472 473 474
  this->UpdateData(FALSE);
  this->OnChangeWhereBuild();
}

// callback for combo box menu where source selection
void CMakeSetupDialog::OnSelendokWhereSource() 
{
475 476
  m_WhereSourceControl.GetLBText(m_WhereSourceControl.GetCurSel(), 
                                 m_WhereSource);
Bill Hoffman's avatar
Bill Hoffman committed
477 478 479 480 481 482 483 484 485 486 487 488 489 490
  this->UpdateData(FALSE);
  this->OnChangeWhereSource();
}

// callback for chaing source directory
void CMakeSetupDialog::OnChangeWhereSource() 
{
}

// callback for changing the build directory
void CMakeSetupDialog::OnChangeWhereBuild() 
{
  this->UpdateData();
  m_CacheEntriesList.RemoveAll();
Bill Hoffman's avatar
Bill Hoffman committed
491 492 493
  m_CacheEntriesList.ShowWindow(SW_SHOW);
  this->LoadCacheFromDiskToGUI();
  m_BuildPathChanged = true;
Bill Hoffman's avatar
Bill Hoffman committed
494 495 496 497
}


// copy from the cache manager to the cache edit list box
498
void CMakeSetupDialog::FillCacheGUIFromCacheManager()
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516
{ 
  int size = m_CacheEntriesList.GetItems().size();
  bool reverseOrder = false;
  // if there are already entries in the cache, then
  // put the new ones in the top, so they show up first
  if(size)
    {
    reverseOrder = true;
    }
  
  // all the current values are not new any more
  std::set<CPropertyItem*> items = m_CacheEntriesList.GetItems();
  for(std::set<CPropertyItem*>::iterator i = items.begin();
      i != items.end(); ++i)
    {
    CPropertyItem* item = *i;
    item->m_NewValue = false;
    }
517
  const cmCacheManager::CacheEntryMap &cache =
518
    cmCacheManager::GetInstance()->GetCacheMap();
519 520 521 522 523 524 525 526 527
  if(cache.size() == 0)
    {
    m_OKButton.EnableWindow(false);
    }
  else
    {
    m_OKButton.EnableWindow(true);
    }

528
  for(cmCacheManager::CacheEntryMap::const_iterator i = cache.begin();
529 530 531
      i != cache.end(); ++i)
    {
    const char* key = i->first.c_str();
532
    const cmCacheManager::CacheEntry& value = i->second;
533 534 535
    switch(value.m_Type )
      {
      case cmCacheManager::BOOL:
536
        if(cmSystemTools::IsOn(value.m_Value.c_str()))
537 538 539
          {
          m_CacheEntriesList.AddProperty(key,
                                         "ON",
Bill Hoffman's avatar
Bill Hoffman committed
540
                                         value.m_HelpString.c_str(),
541 542 543
                                         CPropertyList::CHECKBOX,"",
                                         reverseOrder 
            );
544 545 546 547 548
          }
        else
          {
          m_CacheEntriesList.AddProperty(key,
                                         "OFF",
Bill Hoffman's avatar
Bill Hoffman committed
549
                                         value.m_HelpString.c_str(),
550 551 552
                                         CPropertyList::CHECKBOX,"",
                                         reverseOrder
            );
553
          }
554 555
        break;
      case cmCacheManager::PATH:
Bill Hoffman's avatar
Bill Hoffman committed
556 557 558
        m_CacheEntriesList.AddProperty(key, 
                                       value.m_Value.c_str(),
                                       value.m_HelpString.c_str(),
559 560 561
                                       CPropertyList::PATH,"",
                                       reverseOrder
          );
562 563
        break;
      case cmCacheManager::FILEPATH:
Bill Hoffman's avatar
Bill Hoffman committed
564 565 566
        m_CacheEntriesList.AddProperty(key, 
                                       value.m_Value.c_str(),
                                       value.m_HelpString.c_str(),
567 568 569
                                       CPropertyList::FILE,"",
                                       reverseOrder
          );
570 571
        break;
      case cmCacheManager::STRING:
Bill Hoffman's avatar
Bill Hoffman committed
572 573 574
        m_CacheEntriesList.AddProperty(key,
                                       value.m_Value.c_str(),
                                       value.m_HelpString.c_str(),
575 576 577
                                       CPropertyList::EDIT,"",
                                       reverseOrder
          );
578 579 580 581 582
        break;
      case cmCacheManager::INTERNAL:
        break;
      }
    }
583 584 585
  // redraw the list
  m_CacheEntriesList.SetTopIndex(0);
  m_CacheEntriesList.Invalidate();
586 587
}

Bill Hoffman's avatar
Bill Hoffman committed
588
// copy from the list box to the cache manager
589
void CMakeSetupDialog::FillCacheManagerFromCacheGUI()
590
{ 
Bill Hoffman's avatar
Bill Hoffman committed
591
  cmCacheManager::GetInstance()->GetCacheMap();
592 593
  std::set<CPropertyItem*> items = m_CacheEntriesList.GetItems();
  for(std::set<CPropertyItem*>::iterator i = items.begin();
594 595
      i != items.end(); ++i)
    {
Bill Hoffman's avatar
Bill Hoffman committed
596
    CPropertyItem* item = *i; 
597
    cmCacheManager::CacheEntry *entry = 
598 599
      cmCacheManager::GetInstance()->GetCacheEntry(
        (const char*)item->m_propName);
600 601 602
    if (entry)
      {
      entry->m_Value = item->m_curValue;
603 604 605 606 607
      }
    }
}

  
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627

//! Load cache file from m_WhereBuild and display in GUI editor
void CMakeSetupDialog::LoadCacheFromDiskToGUI()
{
  if(m_WhereBuild != "")
    {
    cmCacheManager::GetInstance()->LoadCache(m_WhereBuild);
    this->FillCacheGUIFromCacheManager();
    }
}

//! Save GUI values to cmCacheManager and then save to disk.
void CMakeSetupDialog::SaveCacheFromGUI()
{
  this->FillCacheManagerFromCacheGUI();
  if(m_WhereBuild != "")
    {
    cmCacheManager::GetInstance()->SaveCache(m_WhereBuild);
    }
}
Bill Hoffman's avatar
Bill Hoffman committed
628 629


630 631 632

void CMakeSetupDialog::OnSize(UINT nType, int cx, int cy) 
{
Ken Martin's avatar
Ken Martin committed
633 634 635 636 637
  if (nType == SIZE_MINIMIZED)
    {
    CDialog::OnSize(nType, cx, cy);
    return;
    }  
638 639 640 641 642 643 644 645 646 647 648
  if (m_oldCX == -1)
    {
    m_oldCX = cx;
    m_oldCY = cy;
    }
  int deltax = cx - m_oldCX;
  int deltay = cy - m_oldCY;

  m_oldCX = cx;
  m_oldCY = cy;

649
  CDialog::OnSize(nType, cx, cy);
650 651 652 653 654

  if (deltax == 0 && deltay == 0)
    {
    return;
    }
655
  
656 657
  if(m_CacheEntriesList.m_hWnd)
    {
658 659 660 661 662 663
    // get the original sizes/positions
    CRect cRect;
    m_ListFrame.GetWindowRect(&cRect);
    m_ListFrame.SetWindowPos(&wndTop, cRect.left, cRect.top, 
                             cRect.Width() + deltax, 
                             cRect.Height() + deltay, 
664
                             SWP_NOMOVE | SWP_NOZORDER);
665 666 667 668 669 670 671 672 673 674 675 676 677 678
    m_CacheEntriesList.GetWindowRect(&cRect);
    m_CacheEntriesList.SetWindowPos(&wndTop, cRect.left, cRect.top, 
                             cRect.Width() + deltax, 
                             cRect.Height() + deltay, 
                             SWP_NOMOVE | SWP_NOZORDER);
    m_VersionDisplay.SetWindowPos(&wndTop, 5, cy-23, 0, 0,
                                  SWP_NOSIZE | SWP_NOZORDER);

    deltax = deltax + m_deltaXRemainder;
    m_deltaXRemainder = deltax%2;
    m_MouseHelp.GetWindowRect(&cRect);
    this->ScreenToClient(&cRect);
    m_MouseHelp.SetWindowPos(&wndTop, cRect.left + deltax/2, 
                             cRect.top + deltay, 
679 680
                             0, 0,
                             SWP_NOSIZE | SWP_NOZORDER);
681

682
    m_Configure.GetWindowRect(&cRect);
683
    this->ScreenToClient(&cRect);
684
    m_Configure.SetWindowPos(&wndTop, cRect.left + deltax/2, 
685 686
                                 cRect.top + deltay, 
                                 0, 0,
687
                                 SWP_NOSIZE | SWP_NOZORDER);
688 689 690 691 692 693
    m_CancelButton.GetWindowRect(&cRect);
    this->ScreenToClient(&cRect);
    m_CancelButton.SetWindowPos(&wndTop, cRect.left + deltax/2, 
                                cRect.top + deltay, 
                                0, 0,
                                SWP_NOSIZE | SWP_NOZORDER);
694 695 696 697 698 699
    m_OKButton.GetWindowRect(&cRect);
    this->ScreenToClient(&cRect);
    m_OKButton.SetWindowPos(&wndTop, cRect.left + deltax/2, 
                            cRect.top + deltay, 
                            0, 0,
                            SWP_NOSIZE | SWP_NOZORDER);
700 701 702 703 704 705 706 707 708 709 710
    }
  
}


void CMakeSetupDialog::OnGetMinMaxInfo( MINMAXINFO FAR* lpMMI )
{
  lpMMI->ptMinTrackSize.x = 550;
  lpMMI->ptMinTrackSize.y = 272;
}

711
void CMakeSetupDialog::OnCancel()
712
{
713
  if(m_CacheEntriesList.IsDirty())
714 715 716 717 718 719 720 721 722 723 724 725 726
    {
    if(MessageBox("You have changed options but not rebuilt, "
		  "are you sure you want to exit?", "Confirm Exit",
		  MB_YESNO) == IDYES)
      {
      CDialog::OnOK();
      }
    }
  else
    {
    CDialog::OnOK();
    }
}
727 728 729 730 731 732 733

void CMakeSetupDialog::OnOk() 
{
  m_CacheEntriesList.ClearDirty();
  this->RunCMake(true);
  CDialog::OnOK();
}