~ubuntu-branches/ubuntu/lucid/cmake/lucid

« back to all changes in this revision

Viewing changes to Source/MFCDialog/CMakeSetupDialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Artur Rona
  • Date: 2009-12-16 11:11:54 UTC
  • mfrom: (3.1.9 sid)
  • Revision ID: james.westby@ubuntu.com-20091216111154-6accvv6yq86h2hkc
Tags: 2.8.0-5ubuntu1
* Merge from debian testing (LP: #497349). Remaining changes:
  - Keep the Replaces: on cmake-data to cover the Kubuntu version from
    Jaunty in case someone decides to do an (unsupported) Jaunty->Lucid
    upgrade.

Show diffs side-by-side

added added

removed removed

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