~ubuntu-branches/ubuntu/jaunty/cmake/jaunty-security

« back to all changes in this revision

Viewing changes to Source/MFCDialog/PropertyList.cpp

  • Committer: Bazaar Package Importer
  • Author(s): A. Maitland Bottoms
  • Date: 2005-03-02 09:22:44 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050302092244-y6o9j8wr27vqcqvx
Tags: 2.0.5-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
//
3
3
 
4
4
#include "stdafx.h"
5
 
#include "PropertyList.h"
 
5
#include "shellapi.h"
 
6
#include "CMakeSetup.h"
 
7
#include "CMakeSetupDialog.h"
6
8
#include "PathDialog.h"
7
9
#include "../cmCacheManager.h"
8
10
#include "../cmSystemTools.h"
9
 
 
 
11
#include "../cmake.h"
10
12
#define IDC_PROPCMBBOX   712
11
13
#define IDC_PROPEDITBOX  713
12
14
#define IDC_PROPBTNCTRL  714
18
20
CPropertyList::CPropertyList()
19
21
{
20
22
  m_Dirty = false;
 
23
  m_ShowAdvanced = false;
21
24
  m_curSel = -1;
22
25
}
23
26
 
50
53
  ON_BN_CLICKED(IDC_PROPCHECKBOXCTRL, OnCheckBox)
51
54
  ON_COMMAND(42, OnDelete)
52
55
  ON_COMMAND(43, OnHelp)
 
56
  ON_COMMAND(44, OnIgnore)
53
57
END_MESSAGE_MAP()
54
58
 
55
59
/////////////////////////////////////////////////////////////////////////////
126
130
  int nIndex = AddString(txt);
127
131
  return nIndex;
128
132
}
129
 
 
130
 
int CPropertyList::AddPropItem(CPropertyItem* pItem, bool reverseOrder)
 
133
// order = 0 sorted
 
134
// order = 1 add to top
 
135
// order = 2 add to bottom
 
136
int CPropertyList::AddPropItem(CPropertyItem* pItem, int order)
131
137
{
 
138
  if(pItem->m_Advanced && ! m_ShowAdvanced)
 
139
    {
 
140
    m_PropertyItems.insert(pItem);
 
141
    return 0;
 
142
    }
132
143
  this->HideControls();
133
144
  int nIndex;
134
 
  if(reverseOrder)
 
145
  if(order)
135
146
    {
136
 
    nIndex = InsertString(0, _T(""));
 
147
    if(order == 1)
 
148
      {
 
149
      order = 0;
 
150
      }
 
151
    if(order == 2)
 
152
      {
 
153
      order = -1;
 
154
      }
 
155
    nIndex = InsertString(order, _T(""));
137
156
    }
138
157
  else
139
158
    {
140
 
    nIndex = AddString(_T(""));
 
159
    nIndex = AddString(pItem->m_propName);
141
160
    }
142
161
  SetItemDataPtr(nIndex,pItem);
143
162
  m_PropertyItems.insert(pItem);
144
163
  return nIndex;
145
164
}
146
165
 
147
 
int CPropertyList::AddProperty(const char* name,
148
 
                               const char* value,
149
 
                               const char* helpString,
150
 
                               int type,
151
 
                               const char* comboItems, bool reverseOrder)
 
166
void CPropertyList::AddProperty(const char* name,
 
167
                                const char* value,
 
168
                                const char* helpString,
 
169
                                int type,
 
170
                                const char* comboItems, 
 
171
                                bool reverseOrder,
 
172
                                bool advanced)
152
173
153
 
  CPropertyItem* pItem = 0;
154
 
  for(int i =0; i < this->GetCount(); ++i)
 
174
  CPropertyItem* pItem = 0; 
 
175
  for(std::set<CPropertyItem*>::iterator i = m_PropertyItems.begin();
 
176
      i != m_PropertyItems.end(); ++i)
155
177
    {
156
 
    CPropertyItem* item = this->GetItem(i);
 
178
    CPropertyItem* item = *i;
157
179
    if(item->m_propName == name)
158
180
      {
159
181
      pItem = item;
163
185
        pItem->m_HelpString = helpString;
164
186
        InvalidateList();
165
187
        }
166
 
      return i;
 
188
      pItem->m_Advanced = advanced;
 
189
      return;
167
190
      }
168
191
    }
169
192
  // if it is not found, then create a new one
172
195
    pItem = new CPropertyItem(name, value, helpString, type, comboItems);
173
196
    pItem->m_NewValue = true;
174
197
    }
175
 
  return this->AddPropItem(pItem, reverseOrder);
 
198
  pItem->m_Advanced = advanced;
 
199
  int order = 0;
 
200
  if(reverseOrder)
 
201
    {
 
202
    order = 1;
 
203
    }
 
204
  this->AddPropItem(pItem, order);
 
205
  return;
176
206
}
177
207
 
178
208
int CPropertyList::OnCreate(LPCREATESTRUCT lpCreateStruct) 
215
245
    if (m_cmbBox)
216
246
      m_cmbBox.MoveWindow(rect);
217
247
    else
218
 
      { 
 
248
      { 
219
249
      rect.bottom += 100;
220
250
      m_cmbBox.Create(CBS_DROPDOWNLIST 
221
251
                      | CBS_NOINTEGRALHEIGHT | WS_VISIBLE 
227
257
    //add the choices for this particular property
228
258
    CString cmbItems = pItem->m_cmbItems;
229
259
    lBoxSelText = pItem->m_curValue;
230
 
                
 
260
                
231
261
    m_cmbBox.ResetContent();
232
262
    int i,i2;
233
263
    i=0;
258
288
    if (m_editBox)
259
289
      m_editBox.MoveWindow(rect);
260
290
    else
261
 
      { 
 
291
      { 
262
292
      m_editBox.Create(ES_LEFT | ES_AUTOHSCROLL | WS_VISIBLE 
263
293
                       | WS_CHILD | WS_BORDER,
264
294
                       rect,this,IDC_PROPEDITBOX);
278
308
    if (m_CheckBoxControl)
279
309
      m_CheckBoxControl.MoveWindow(rect);
280
310
    else
281
 
      { 
 
311
      { 
282
312
      m_CheckBoxControl.Create("check",BS_CHECKBOX 
283
313
                               | BM_SETCHECK |BS_LEFTTEXT 
284
314
                               | WS_VISIBLE | WS_CHILD,
318
348
  if (m_btnCtrl)
319
349
    m_btnCtrl.MoveWindow(region);
320
350
  else
321
 
    {   
 
351
    {   
322
352
    m_btnCtrl.Create("...",BS_PUSHBUTTON | WS_VISIBLE | WS_CHILD,
323
353
                     region,this,IDC_PROPBTNCTRL);
324
354
    m_btnCtrl.SetFont(&m_SSerif8Font);
366
396
{
367
397
  CString newStr;
368
398
  m_editBox.GetWindowText(newStr);
369
 
        
 
399
        
370
400
  CPropertyItem* pItem = (CPropertyItem*) GetItemDataPtr(m_curSel);
371
401
  if(pItem->m_curValue != newStr)
372
402
    {
420
450
{
421
451
  CPropertyItem* pItem = (CPropertyItem*) GetItemDataPtr(m_curSel);
422
452
 
 
453
  // The dialogs might change the working directory.  Save it.
 
454
  std::string cwd = cmSystemTools::GetCurrentWorkingDirectory();
 
455
 
423
456
  //display the appropriate common dialog depending on what type
424
457
  //of chooser is associated with the property
425
458
 
427
460
    {
428
461
    CString SelectedFile; 
429
462
    CString Filter("All Files (*.*)||");
430
 
        
 
463
        
431
464
    CFileDialog FileDlg(TRUE, NULL, NULL, NULL,
432
 
                        Filter);
 
465
                        Filter);
433
466
    CString initialDir;
434
467
    CString currPath = pItem->m_curValue;
 
468
    if (currPath.Right(9) == "-NOTFOUND" || currPath == "NOTFOUND")
 
469
      {
 
470
      currPath = "";
 
471
      }
435
472
    if (currPath.GetLength() > 0)
436
473
      {
437
474
      int endSlash = currPath.ReverseFind('\\');
440
477
        endSlash = currPath.ReverseFind('/');
441
478
        }
442
479
      initialDir = currPath.Left(endSlash);
443
 
      }         
 
480
      }         
444
481
    initialDir.Replace("/", "\\");
445
482
    FileDlg.m_ofn.lpstrTitle = "Select file";
446
483
    if (currPath.GetLength() > 0)
449
486
    if(IDOK == FileDlg.DoModal())
450
487
      {
451
488
      SelectedFile = FileDlg.GetPathName();
452
 
                        
 
489
                        
453
490
      m_btnCtrl.ShowWindow(SW_HIDE);
454
491
      std::string path = SelectedFile;
455
492
      cmSystemTools::ConvertToUnixSlashes(path);
477
514
      InvalidateList();
478
515
      }
479
516
    }
 
517
 
 
518
  cmSystemTools::ChangeDirectory(cwd.c_str());
480
519
}
481
520
 
482
521
void CPropertyList::OnLButtonUp(UINT nFlags, CPoint point) 
486
525
    //if columns were being resized then this indicates
487
526
    //that mouse is up so resizing is done.  Need to redraw
488
527
    //columns to reflect their new widths.
489
 
                
 
528
                
490
529
    m_bTracking = FALSE;
491
530
    //if mouse was captured then release it
492
531
    if (GetCapture()==this)
524
563
    windowRect.left += 10; windowRect.right -= 10;
525
564
    //do not let mouse leave the list box boundary
526
565
    ::ClipCursor(windowRect);
527
 
                
 
566
                
528
567
    if (m_cmbBox)
529
568
      m_cmbBox.ShowWindow(SW_HIDE);
530
569
    if (m_editBox)
552
591
}
553
592
 
554
593
void CPropertyList::OnMouseMove(UINT nFlags, CPoint point) 
555
 
{       
 
594
{       
556
595
  if (m_bTracking)
557
596
    {
558
597
    //move divider line to the mouse pos. if columns are
568
607
    //set the cursor to a sizing cursor if the cursor is over the row divider
569
608
    ::SetCursor(m_hCursorSize);
570
609
  else
 
610
    { 
 
611
    BOOL loc;
 
612
    int curSel = ItemFromPoint(point,loc);
 
613
    if(!loc && curSel < 65535)
 
614
      {
 
615
      CPropertyItem* pItem = (CPropertyItem*) GetItemDataPtr(curSel);
 
616
      m_CMakeSetupDialog->SetDlgItemText(IDC_PROGRESS, pItem->m_HelpString);
 
617
      }
571
618
    CListBox::OnMouseMove(nFlags, point);
 
619
    }
 
620
  
572
621
}
573
622
 
574
623
void CPropertyList::InvertLine(CDC* pDC,CPoint ptFrom,CPoint ptTo)
575
624
{
576
625
  int nOldMode = pDC->SetROP2(R2_NOT);
577
 
        
 
626
        
578
627
  pDC->MoveTo(ptFrom);
579
628
  pDC->LineTo(ptTo);
580
629
 
607
656
  BOOL loc;
608
657
  m_curSel = ItemFromPoint(point,loc);
609
658
  menu.CreatePopupMenu();
 
659
  menu.AppendMenu(MF_STRING | MF_ENABLED, 44, "Ignore Cache Entry");
610
660
  menu.AppendMenu(MF_STRING | MF_ENABLED, 42, "Delete Cache Entry");
611
661
  menu.AppendMenu(MF_STRING | MF_ENABLED, 43, "Help For Cache Entry");
612
662
  menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, 
629
679
    }
630
680
}
631
681
 
 
682
void CPropertyList::OnIgnore()
 
683
{
 
684
  if(m_curSel == -1 || this->GetCount() <= 0)
 
685
    {
 
686
    return;
 
687
    }
 
688
  CPropertyItem* pItem = (CPropertyItem*) GetItemDataPtr(m_curSel);
 
689
  pItem->m_curValue = "IGNORE";
 
690
  InvalidateList();
 
691
}
 
692
 
 
693
 
 
694
 
632
695
void CPropertyList::OnDelete()
633
696
634
697
  if(m_curSel == -1 || this->GetCount() <= 0)
636
699
    return;
637
700
    }
638
701
  CPropertyItem* pItem = (CPropertyItem*) GetItemDataPtr(m_curSel);
639
 
  cmCacheManager::GetInstance()->RemoveCacheEntry(pItem->m_propName);
 
702
  m_CMakeSetupDialog->GetCMakeInstance()->GetCacheManager()->RemoveCacheEntry(pItem->m_propName);
640
703
  m_PropertyItems.erase(pItem);
641
704
  delete pItem; 
642
705
  this->DeleteString(m_curSel);
661
724
  for(int i =0; i < c; ++i)
662
725
    {
663
726
    CPropertyItem* pItem = (CPropertyItem*) GetItemDataPtr(0);
664
 
    cmCacheManager::GetInstance()->RemoveCacheEntry(pItem->m_propName);
665
 
    m_PropertyItems.erase(pItem);
666
 
    delete pItem;
667
727
    this->DeleteString(0);
668
728
    }
 
729
  for(std::set<CPropertyItem*>::iterator ii = m_PropertyItems.begin();
 
730
      ii != m_PropertyItems.end(); ++ii)
 
731
    {
 
732
    delete *ii;
 
733
    }
 
734
  m_PropertyItems.clear();
669
735
  m_Dirty = false;
670
736
  this->HideControls();
671
737
  InvalidateList();
677
743
  m_Dirty = true;
678
744
}
679
745
 
 
746
void CPropertyList::ShowAdvanced()
 
747
{
 
748
  this->SetRedraw(FALSE);
 
749
  this->ResetContent();
 
750
  m_ShowAdvanced = true; 
 
751
  std::map<std::string, CPropertyItem*> sortProps;
 
752
  for(std::set<CPropertyItem*>::iterator i = m_PropertyItems.begin();
 
753
      i != m_PropertyItems.end(); ++i)
 
754
    {
 
755
    sortProps[(const char*)(*i)->m_propName] = *i;
 
756
    }
 
757
  for(std::map<std::string, CPropertyItem*>::iterator i = sortProps.begin();
 
758
      i != sortProps.end(); ++i)
 
759
    {
 
760
    CPropertyItem* item = i->second;
 
761
    if(item->m_NewValue)
 
762
      {
 
763
      this->AddPropItem(item, 2);
 
764
      }
 
765
    }
 
766
  for(std::map<std::string, CPropertyItem*>::iterator i = sortProps.begin();
 
767
      i != sortProps.end(); ++i)
 
768
    {
 
769
    CPropertyItem* item = i->second;
 
770
    if(!item->m_NewValue)
 
771
      {
 
772
      this->AddPropItem(item, 2);
 
773
      }
 
774
    }
 
775
  this->SetRedraw(TRUE);
 
776
  this->InvalidateList();
 
777
}
 
778
 
 
779
 
 
780
void CPropertyList::HideAdvanced()
 
781
{
 
782
  this->SetRedraw(FALSE);
 
783
  this->ResetContent();
 
784
  m_ShowAdvanced = false;
 
785
  std::map<std::string, CPropertyItem*> sortProps;
 
786
  for(std::set<CPropertyItem*>::iterator i = m_PropertyItems.begin();
 
787
      i != m_PropertyItems.end(); ++i)
 
788
    {
 
789
    sortProps[(const char*)(*i)->m_propName] = *i;
 
790
    }
 
791
  for(std::map<std::string, CPropertyItem*>::iterator i = sortProps.begin();
 
792
      i != sortProps.end(); ++i)
 
793
    {
 
794
    CPropertyItem* item = i->second;
 
795
    if(item->m_NewValue && !item->m_Advanced)
 
796
      {
 
797
      this->AddPropItem(item, 2);
 
798
      }
 
799
    }
 
800
  for(std::map<std::string, CPropertyItem*>::iterator i = sortProps.begin();
 
801
      i != sortProps.end(); ++i)
 
802
    {
 
803
    CPropertyItem* item = i->second;
 
804
    if(!item->m_Advanced && !item->m_NewValue)
 
805
      {
 
806
      this->AddPropItem(item, 2);
 
807
      }
 
808
    }
 
809
  this->SetRedraw(TRUE);
 
810
  this->InvalidateList();
 
811
}
 
812