OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [host/] [tools/] [configtool/] [common/] [win32/] [ControlView.cpp] - Blame information for rev 790

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
// ####ECOSHOSTGPLCOPYRIGHTBEGIN####                                        
2
// -------------------------------------------                              
3
// This file is part of the eCos host tools.                                
4
// Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.            
5
//
6
// This program is free software; you can redistribute it and/or modify     
7
// it under the terms of the GNU General Public License as published by     
8
// the Free Software Foundation; either version 2 or (at your option) any   
9
// later version.                                                           
10
//
11
// This program is distributed in the hope that it will be useful, but      
12
// WITHOUT ANY WARRANTY; without even the implied warranty of               
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        
14
// General Public License for more details.                                 
15
//
16
// You should have received a copy of the GNU General Public License        
17
// along with this program; if not, write to the                            
18
// Free Software Foundation, Inc., 51 Franklin Street,                      
19
// Fifth Floor, Boston, MA  02110-1301, USA.                                
20
// -------------------------------------------                              
21
// ####ECOSHOSTGPLCOPYRIGHTEND####                                          
22
// ControlView.cpp : implementation file
23
//
24
//
25
//===========================================================================
26
//===========================================================================
27
//#####DESCRIPTIONBEGIN####
28
//
29
// Author(s):   sdf
30
// Contact(s):  sdf
31
// Date:                1998/08/11
32
// Version:             0.01
33
// Purpose:     
34
// Description: This is the implementation of the tree (control) view
35
// Requires:    
36
// Provides:    
37
// See also:    
38
// Known bugs:  
39
// Usage:       
40
//
41
//####DESCRIPTIONEND####
42
//
43
//===========================================================================
44
 
45
#include "stdafx.h"
46
#ifndef PLUGIN
47
#include "BCMenu.h"
48
#endif
49
#include "ControlView.h"
50
#include "ConfigTool.h"
51
#include "ConfigItem.h"
52
#include "ConfigToolDoc.h"
53
#include <stdlib.h>
54
#include "CTUtils.h"
55
#include "CellView.h"
56
#include "MessageBox.h"
57
#include "FindDialog.h"
58
#include "CTPropertiesDialog.h"
59
#include "ConfigViewOptionsDialog.h"
60
#ifdef PLUGIN
61
  //#include "ide.common.h"
62
  #define INCLUDEFILE "ide.guicommon.h"  // for ID_EDIT_FINDAGAIN
63
  #include "IncludeSTL.h"
64
  #include "CTMain.h"
65
#else
66
  #include "MainFrm.h"
67
#endif
68
 
69
#include <afxpriv.h> // for WM_COMMANDHELP, WM_HITTEST
70
#include <htmlhelp.h>
71
 
72
#include "DescView.h" // for testing
73
#ifdef _DEBUG
74
#define new DEBUG_NEW
75
#undef THIS_FILE
76
static char THIS_FILE[] = __FILE__;
77
#endif
78
 
79
/////////////////////////////////////////////////////////////////////////////
80
// CControlView
81
 
82
IMPLEMENT_DYNCREATE(CControlView, CTreeView)
83
 
84
CControlView::CControlView()
85
{
86
  m_bHasVScroll=-1;
87
  m_nWorkspace=0;
88
  m_dwDefaultStyle&=(~WS_VSCROLL);
89
  m_hContext=NULL;
90
  m_hExpandedForFind=NULL;
91
  m_GrayPen.CreatePen(PS_SOLID,1,RGB(192,192,192));
92
  CConfigTool::SetControlView(this);
93
}
94
 
95
CControlView::~CControlView()
96
{
97
  CConfigTool::SetControlView(0);
98
}
99
 
100
static UINT WM_FINDREPLACE = ::RegisterWindowMessage(FINDMSGSTRING);
101
 
102
BEGIN_MESSAGE_MAP(CControlView, CTreeView)
103
//{{AFX_MSG_MAP(CControlView)
104
ON_WM_PAINT()
105
ON_NOTIFY_REFLECT(TVN_ITEMEXPANDED, OnItemexpanded)
106
ON_NOTIFY_REFLECT(TVN_SELCHANGED, OnSelchanged)
107
ON_WM_LBUTTONDOWN()
108
ON_WM_VSCROLL()
109
ON_WM_SIZE()
110
ON_COMMAND(ID_RESTORE_DEFAULTS, OnRestoreDefaults)
111
ON_COMMAND(ID_POPUP_PROPERTIES, OnPopupProperties)
112
ON_COMMAND(ID_UNLOAD_PACKAGE, OnUnload)
113
ON_WM_KEYDOWN()
114
ON_COMMAND(ID_VIEW_URL, OnViewUrl)
115
ON_WM_CREATE()
116
ON_WM_HSCROLL()
117
ON_WM_MOUSEMOVE()
118
ON_NOTIFY_REFLECT(TVN_ITEMEXPANDING, OnItemexpanding)
119
ON_WM_MOUSEWHEEL()
120
ON_WM_RBUTTONDOWN()
121
ON_WM_SYSKEYDOWN()
122
ON_WM_SYSCHAR()
123
ON_COMMAND(ID_VIEW_HEADER, OnViewHeader)
124
ON_REGISTERED_MESSAGE( WM_FINDREPLACE, OnFind)
125
ON_COMMAND(ID_EDIT_FIND,OnEditFind)
126
ON_COMMAND(ID_EDIT_FINDAGAIN,OnEditFindAgain)
127
ON_UPDATE_COMMAND_UI(ID_EDIT_FINDAGAIN, OnUpdateEditFindAgain)
128
ON_UPDATE_COMMAND_UI(ID_EDIT_FIND, OnUpdateEditFind)
129
ON_WM_CHAR()
130
        ON_NOTIFY_REFLECT(TVN_DELETEITEM, OnDeleteitem)
131
        ON_COMMAND(ID_CV_WHATS_THIS, OnWhatsThis)
132
ON_MESSAGE(WM_SETFONT,OnSetFont)
133
        ON_WM_HELPINFO()
134
        ON_WM_MENUCHAR()
135
        //}}AFX_MSG_MAP
136
END_MESSAGE_MAP()
137
 
138
 
139
/////////////////////////////////////////////////////////////////////////////
140
// CControlView drawing
141
 
142
void CControlView::OnDraw(CDC* pDC)
143
{
144
  UNUSED_ALWAYS(pDC);
145
}
146
 
147
/////////////////////////////////////////////////////////////////////////////
148
// CControlView diagnostics
149
 
150
#ifdef _DEBUG
151
void CControlView::AssertValid() const
152
{
153
  CTreeView::AssertValid();
154
}
155
 
156
void CControlView::Dump(CDumpContext& dc) const
157
{
158
  CTreeView::Dump(dc);
159
}
160
#endif //_DEBUG
161
 
162
 
163
/////////////////////////////////////////////////////////////////////////////
164
// CControlView message handlers
165
 
166
void CControlView::OnPaint()
167
{
168
  CPaintDC dc(this); // device context for painting
169
 
170
  // First let the control do its default drawing.
171
  CWnd::DefWindowProc( WM_PAINT, (WPARAM)dc.m_hDC, 0 );
172
 
173
  CConfigToolDoc* pDoc = CConfigTool::GetConfigToolDoc();
174
  if(pDoc->ItemCount()>0)
175
  {
176
    // Redraw the disabled labels
177
    CFont *pOldFont=dc.SelectObject(GetFont());
178
    dc.SetTextColor(GetSysColor(COLOR_GRAYTEXT));
179
 
180
    for(HTREEITEM h=GetFirstVisibleItem();h;h=GetNextVisibleItem(h))
181
    {
182
      const UINT selflag = TVIS_DROPHILITED | TVIS_SELECTED;
183
      if(!IsActive(h)&&!(GetItemState( h, selflag ) & selflag )){
184
        // Do not meddle with selected items or drop highlighted items
185
        CRect rect;
186
        GetItemRect( h, &rect, TRUE );
187
        dc.TextOut(m_TreeXOffsetAdjustment+rect.left+2, rect.top+1, GetItemText(h));
188
      }
189
    }
190
    dc.SelectObject(pOldFont);
191
 
192
    // Now draw grid lines
193
 
194
    CRect rcClient;
195
    GetClientRect(rcClient);
196
    CPen *pOldPen=dc.SelectObject(&m_GrayPen);
197
    int cy=0;
198
    for(h=GetFirstVisibleItem();h;h=GetNextVisibleItem(h))
199
    {
200
      dc.MoveTo(rcClient.left,cy);
201
      dc.LineTo(rcClient.right,cy);
202
      cy+=m_nItemHeight;
203
    }
204
    dc.MoveTo(rcClient.left,cy);
205
    dc.LineTo(rcClient.right,cy);
206
    dc.SelectObject(pOldPen);
207
 
208
  }
209
}
210
 
211
void CControlView::OnItemexpanded(NMHDR* pNMHDR, LRESULT* pResult)
212
{
213
  //NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
214
  SetScrollRangePos();
215
  //SetHScrollRangePos();
216
  if(CConfigTool::GetCellView()){
217
    CConfigTool::GetCellView()->Invalidate();
218
//sdf1    CConfigTool::GetCellView()->UpdateWindow();
219
  }
220
 
221
  *pResult = 0;
222
  UNUSED_ALWAYS(pNMHDR);
223
}
224
 
225
void CControlView::OnItemexpanding(NMHDR* pNMHDR, LRESULT* pResult)
226
{
227
  //NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
228
 
229
  *pResult = 0;
230
  UNUSED_ALWAYS(pNMHDR);
231
}
232
 
233
void CControlView::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult)
234
{
235
  CConfigToolDoc* pDoc = CConfigTool::GetConfigToolDoc();
236
  if(pDoc->ItemCount()>0){
237
    // Do nothing if in process of destroying configitems
238
    NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
239
    pDoc->UpdateAllViews (this, CConfigToolDoc::SelChanged, (CObject *)&TI(pNMTreeView->itemNew.hItem));
240
    CConfigItem &ti=TI(pNMTreeView->itemNew.hItem);
241
 
242
    CString strDesc(ti.Desc());
243
    if(strDesc.IsEmpty()){
244
      strDesc=_T("No context help is available for this item");
245
    }
246
    //pMain->m_wndHelp.SetWindowText(strDesc);
247
    //pMain->m_wndHelp.SetTitle(ti.ItemNameOrMacro());
248
    SetScrollPos();
249
    if(CConfigTool::GetCellView()){
250
      CConfigTool::GetCellView()->Sync();
251
    }
252
  }
253
  *pResult = 0;
254
}
255
 
256
 
257
 
258
 
259
void CControlView::OnLButtonDown(UINT nFlags, CPoint point)
260
{
261
  CConfigTool::GetCellView()->CancelCellEdit();
262
  {
263
    UINT nFlags;
264
    HTREEITEM h=HitTest(point,&nFlags);
265
    if(h && IsActive(h) && (nFlags&TVHT_ONITEMICON))
266
    {
267
      SelectItem(h);
268
      BumpItem (h, TI (h).HasBool () ? 0 : 1); // toggle boolean or increment data
269
    }
270
    else
271
    {
272
      CTreeView::OnLButtonDown(nFlags,point);
273
    }
274
  }
275
 
276
  // Relay to the splitter
277
  ClientToScreen(&point);
278
  GetParent()->ScreenToClient(&point);
279
  GetParent()->SendMessage(WM_LBUTTONDOWN,(WPARAM)nFlags,MAKELPARAM(point.x,point.y));
280
}
281
 
282
 
283
void CControlView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
284
{
285
  // Round to nearest item and express in units of items for the benefit of CTreeView
286
  nPos=(nPos+m_nItemHeight/2)/m_nItemHeight;
287
  DefWindowProc(WM_VSCROLL,MAKELONG(nSBCode, nPos), (LPARAM)pScrollBar->m_hWnd);
288
  SetScrollPos();
289
}
290
 
291
/////////////////////////////////////////////////////////////////////////////
292
// CControlView message handlers
293
 
294
void CControlView::OnInitialUpdate()
295
{
296
  CTreeView::OnInitialUpdate();
297
#ifdef IE4
298
  SetItemHeight(20);
299
#endif
300
  /*
301
  #ifndef PLUGIN
302
  // Do this here, because the framework resets the title after calling OnOpenDocument()
303
  CConfigToolDoc* pDoc = CConfigTool::GetConfigToolDoc();
304
  CString strTitle(pDoc->BuildTree());
305
  if(strTitle.IsEmpty())
306
  {
307
                strTitle+=_T("Repository ");
308
    strTitle+=pDoc->Repository();
309
    }
310
    pDoc->SetTitle(strTitle);
311
    #endif
312
  */
313
}
314
 
315
void CControlView::OnSize(UINT nType, int cx, int cy)
316
{
317
  //m_nInOnSize++;
318
  CScrollBar *cv=GetScrollBarCtrl(SB_VERT);
319
  //int dx=cx-m_Size.cx;
320
  //int dy=cy-m_Size.cy;
321
  /*
322
  TRACE("WM_SIZE[%d] dx=%d dy=%d depth=%d ch=%08x cv=%08x",
323
                0,
324
    dx,dy,
325
    m_nInOnSize,
326
    ch,cv);
327
                */
328
  int bIsHScrollBarDelta=(cv==NULL);
329
  //int bIsVScrollBarDelta=(ch==NULL);
330
  if(bIsHScrollBarDelta/*dx==-16*/){
331
    cx=m_Size.cx;
332
  }
333
  //    if(bIsVScrollBarDelta/*dy==-16*/){
334
  //            cy=m_Size.cy;
335
  //    }
336
  if(cx!=m_Size.cx || cy!=m_Size.cy){
337
    m_Size=CSize(cx,cy);
338
    DefWindowProc(WM_SIZE,(WPARAM)nType,MAKELPARAM(cx,cy));
339
  }
340
  KillScrollBars();
341
  SetScrollRangePos();
342
  //SetHScrollRangePos();
343
  //m_nInOnSize--;
344
}
345
 
346
BOOL CControlView::PreCreateWindow(CREATESTRUCT& cs)
347
{
348
  cs.style=TVS_HASBUTTONS | TVS_LINESATROOT | TVS_SHOWSELALWAYS |
349
    WS_CHILD | WS_VISIBLE /*| WS_BORDER*/ | WS_TABSTOP;
350
  cs.style&=(~WS_VSCROLL);
351
  m_dwDefaultStyle&=(~WS_VSCROLL);
352
  return CTreeView::PreCreateWindow(cs);
353
}
354
 
355
void CControlView::OnRButtonDown(UINT nFlags, CPoint point)
356
{
357
  UNUSED_ALWAYS(nFlags);
358
  UINT Flags;
359
  HTREEITEM h=HitTest(point,&Flags);
360
  if(h){
361
    SelectItem(h);
362
  }
363
  // point is in client coords
364
  ClientToScreen(&point);
365
  ShowPopupMenu(h,point);
366
}
367
 
368
// Button functionality
369
 
370
void CControlView::Refresh (HTREEITEM h) // was Enable()
371
{
372
  if(h){
373
    AdjustItemImage(h);
374
    // Invalidate the labels of the affected items
375
    CRect rect;
376
    GetItemRect(h, rect, TRUE );
377
    rect.left+=m_TreeXOffsetAdjustment;
378
    InvalidateRect(rect);
379
    // Do the same for the cell view
380
    CRect rcBuddyClient;
381
    CConfigTool::GetCellView()->GetClientRect(rcBuddyClient);
382
    rect.left=rcBuddyClient.left;
383
    rect.right=rcBuddyClient.right;
384
    CConfigTool::GetCellView()->InvalidateRect(rect);
385
  }
386
}
387
 
388
BOOL CControlView::IsActive(HTREEITEM h) const
389
{
390
  const CdlUserVisible vitem = TI (h).GetCdlItem ();
391
  return vitem ? vitem->is_active () : true;
392
}
393
 
394
void CControlView::AdjustItemImage(HTREEITEM h)
395
{
396
  CConfigItem &ti=TI(h);
397
  CString str(ti.ItemNameOrMacro());
398
  if(ti.Modified()){
399
    str+=_TCHAR('*');
400
  }
401
  //#ifndef PLUGIN
402
  //    CConfigTool::GetConfigToolDoc()->SetTitle(_T("rt")); // Parameter is ignored
403
  //#endif
404
  SetItemText(h,str);
405
 
406
  int nImage=0;
407
  enum {FolderIcon=0, CheckBoxIcon=2, RadioIcon=6, IntegerIcon=10, StringIcon=12, EnumIcon=14, PackageIcon=16, DoubleIcon=20};
408
  if (ti.HasBool ())
409
  {
410
    if (ti.IsPackage ())
411
      nImage = PackageIcon;
412
    else
413
      nImage = ti.HasRadio () ? RadioIcon : CheckBoxIcon;
414
 
415
    if (ti.IsEnabled ())
416
      nImage += 2;
417
  }
418
  else
419
  {
420
    switch(ti.Type())
421
    {
422
    /*
423
    case CConfigItem::Boolean:
424
    nImage=ti.IsPackage()?PackageIcon:CheckBoxIcon;
425
    // These images have all four states
426
    if(ti.Value())
427
    {
428
                                nImage+=2;
429
        }
430
        break;
431
        case CConfigItem::Radio:
432
        nImage=RadioIcon;
433
        // Has four states
434
        if(ti.Value())
435
        {
436
        nImage+=2;
437
        }
438
        break;
439
      */
440
    case CConfigItem::Double:
441
      nImage=DoubleIcon;
442
      break;
443
    case CConfigItem::Integer:
444
      nImage=IntegerIcon;
445
      break;
446
    case CConfigItem::Enum:
447
      nImage=EnumIcon;
448
      break;
449
    case CConfigItem::None:
450
      nImage = FolderIcon;
451
      break;
452
    case CConfigItem::String:
453
      // if a package use the enabled package icon else use the string icon
454
      nImage = ti.IsPackage () ? PackageIcon + 2 : StringIcon;
455
      break;
456
    default:
457
      ASSERT(FALSE);
458
      break;
459
    }
460
  }
461
  // All items have an enabled alternative
462
  if(!IsActive(h))
463
  {
464
    nImage+=1;
465
  }
466
  //    else if (ti.Type () == CConfigItem::Boolean)
467
  else if ((ti.Type () != CConfigItem::None) || ti.HasBool ())
468
  {
469
    // grey icon if the option is not modifiable or is inactive
470
    const CdlValuable valuable = ti.GetCdlValuable();
471
    if (valuable && ! (valuable->is_modifiable () && valuable->is_active ()))
472
      nImage++;
473
  }
474
  BOOL b=SetItemImage(h,nImage,nImage);
475
  ASSERT(b);
476
}
477
 
478
ItemIntegerType CControlView::Value(HTREEITEM h) const
479
{
480
  ItemIntegerType rc;
481
  CConfigItem &ti=TI(h);
482
  if(CConfigTool::GetCellView()->ActiveCell()==h){
483
    rc=CConfigTool::GetCellView()->GetCellValue();
484
  } else
485
  {
486
    rc=ti.Value();
487
  }
488
  return rc;
489
}
490
 
491
void CControlView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
492
{
493
  CConfigToolDoc* pDoc = CConfigTool::GetConfigToolDoc();
494
  switch(lHint)
495
  {
496
                case CConfigToolDoc::AllSaved:
497
 
498
      {
499
        for(int nItem=0;nItem<pDoc->ItemCount();nItem++)
500
        {
501
          CConfigItem *pItem=pDoc->Item(nItem);
502
          HTREEITEM h=pItem->HItem();
503
          if(h){
504
            SetItemText(h,pItem->ItemNameOrMacro());
505
            InvalidateItem(h);
506
          }
507
        }
508
      }
509
      break;
510
    case CConfigToolDoc::NameFormatChanged:
511
      {
512
        for(int nItem=0;nItem<pDoc->ItemCount();nItem++)
513
        {
514
          CConfigItem *pItem=pDoc->Item(nItem);
515
          CString strName(pItem->ItemNameOrMacro());
516
          if(pItem->Modified()){
517
            strName+=_TCHAR('*');
518
          }
519
          SetItemText(pItem->HItem(),strName);
520
        }
521
 
522
        Invalidate();
523
      }
524
      break;
525
    case CConfigToolDoc::IntFormatChanged:
526
      break;
527
    case CConfigToolDoc::Clear:
528
      m_hExpandedForFind=NULL;
529
      m_hContext=NULL;
530
      DeleteAllItems();
531
      break;
532
    case CConfigToolDoc::ValueChanged:
533
      {
534
        CConfigItem &ti=*(CConfigItem *)pHint;
535
        HTREEITEM h=ti.HItem();
536
        AdjustItemImage(h);
537
        switch(ti.Type()){
538
        case CConfigItem::Integer:
539
          //                        case CConfigItem::Boolean:
540
          //                        case CConfigItem::Radio:
541
          {
542
            ItemIntegerType n=ti.Value();
543
            Refresh (h);
544
            for(HTREEITEM hc=GetChildItem(h);hc;hc=GetNextSiblingItem (hc)){
545
              Refresh (hc);
546
            }
547
            /*
548
            // In the case of radio buttons, do the same thing to my siblings:
549
            if(ti.Type()==CConfigItem::Radio && n==1){
550
            for(HTREEITEM hs=ti.FirstRadio()->HItem();hs;hs=GetNextSiblingItem(hs)){
551
            if(TI(hs).Type()==CConfigItem::Radio && hs!=h){
552
            AdjustItemImage(hs);
553
            // Enable or disable their children
554
            for(HTREEITEM hn=GetChildItem(hs);hn;hn=GetNextSiblingItem(hn)){
555
            Refresh (hn);
556
            }
557
            }
558
            }
559
            }
560
            */
561
            if(pDoc->m_bAutoExpand){
562
              if ( (0==(GetItemState(h,TVIS_EXPANDED) & TVIS_EXPANDED)) != (0==n) ){
563
                Expand(h,n?TVE_EXPAND:TVE_COLLAPSE);
564
                SetScrollRangePos();
565
              }
566
 
567
              //SetHScrollRangePos();
568
              if(CConfigTool::GetCellView()){
569
                CConfigTool::GetCellView()->Invalidate();
570
              }
571
            }
572
          }
573
          break;
574
        default:
575
          break;
576
        }
577
        CRect rect;
578
        GetItemRect(h,rect,FALSE);
579
        InvalidateRect(rect);
580
      }
581
      break;
582
    case CConfigToolDoc::ExternallyChanged:
583
      {
584
        for(int nItem=0;nItem<pDoc->ItemCount();nItem++){
585
          CConfigItem *pItem=pDoc->Item(nItem);
586
          AdjustItemImage(pItem->HItem());
587
        }
588
      }
589
      break;
590
    case 0:
591
      if(pDoc->ItemCount()>0)
592
      {
593
        CRect rect;
594
        GetItemRect(GetFirstVisibleItem(),rect,FALSE);
595
        m_nItemHeight=rect.Height();
596
        m_nWorkspace=m_nItemHeight;
597
        SetScrollRangePos();
598
        SetHScrollRangePos();
599
#ifdef _DEBUG
600
        int nCP=0;
601
        for(int nItem=0;nItem<pDoc->ItemCount();nItem++)
602
        {
603
          CConfigItem *pItem=pDoc->Item(nItem);
604
          ASSERT(pItem->HItem());
605
          switch(pItem->Type()){
606
          case CConfigItem::None:
607
            break;
608
          case CConfigItem::String:
609
          case CConfigItem::Enum:
610
          case CConfigItem::Integer:
611
          case CConfigItem::Double:
612
            //          case CConfigItem::Boolean:
613
            nCP++;
614
            break;
615
            //          case CConfigItem::Radio:
616
            //                  nCP+=(pItem==pItem->FirstRadio());
617
            //                  break;
618
          default:
619
            ASSERT(FALSE);
620
            break;
621
          }
622
        }
623
        TRACE(_T("### done creating - %d config items created: %d configuration points\n"),GetCount(),nCP);
624
#endif
625
 
626
        SetScrollRangePos();
627
 
628
      }
629
    default:
630
      break; // not for us, apparently
631
  }
632
  UNUSED_ALWAYS(pSender);
633
}
634
 
635
void CControlView::OnRestoreDefaults()
636
{
637
  if(TI(m_hContext).HasModifiedChildren())
638
  {
639
    switch(CUtils::MessageBoxFT(MB_YESNOCANCEL,_T("Restore defaults for nested items?")))
640
    {
641
    case IDYES:
642
      RestoreDefault(m_hContext,TRUE);
643
      break;
644
    case IDNO:
645
      RestoreDefault(m_hContext,FALSE);
646
      break;
647
    case IDCANCEL:
648
      break;
649
    default:
650
      ASSERT(FALSE);
651
      break;
652
    }
653
  } else
654
  {
655
    RestoreDefault(m_hContext,FALSE);
656
  }
657
 
658
  // current values may have changed so refresh the other views
659
  //CConfigTool::GetConfigToolDoc ()->UpdateFailingRuleCount ();
660
  if (TI (m_hContext).Type () != CConfigItem::None)
661
    CConfigTool::GetConfigToolDoc ()->UpdateAllViews (NULL, CConfigToolDoc::ValueChanged, (CObject *) GetItemData (m_hContext));
662
}
663
 
664
void CControlView::OnPopupProperties()
665
{
666
  if(NULL==m_hContext){
667
    m_hContext=GetSelectedItem();
668
  }
669
  if(NULL!=m_hContext){
670
    CCTPropertiesDialog dlg(TI(m_hContext));
671
    dlg.DoModal();
672
    m_hContext=NULL;
673
  }
674
}
675
 
676
 
677
void CControlView::RestoreDefault(HTREEITEM h, BOOL bRecurse /* = FALSE */, BOOL bTopLevel /* = TRUE */)
678
{
679
  CConfigItem &ti = TI (h);
680
  const CdlValuable valuable = ti.GetCdlValuable();
681
  if (valuable && (CdlValueFlavor_None != valuable->get_flavor ())) // skip the root node and nodes without a value
682
    valuable->set_source (CdlValueSource_Default);
683
  SetItemText (h, ti.ItemNameOrMacro ()); // remove asterisk in control view
684
 
685
  if (bTopLevel && ti.HasRadio ()) // if user-specified item is a radio button
686
  {
687
    for (CConfigItem * pItem = ti.FirstRadio (); pItem; pItem = pItem->NextRadio ())
688
    {
689
      if (&ti != pItem)
690
      {
691
        const CdlValuable valuable = pItem->GetCdlValuable();
692
        ASSERT (valuable);
693
        valuable->set_source (CdlValueSource_Default); // restore default for each sibling radio button
694
        SetItemText (pItem->HItem (), pItem->ItemNameOrMacro ()); // remove asterisk in control view
695
      }
696
 
697
    }
698
  }
699
 
700
  if (bRecurse)
701
  {
702
    for (h = GetChildItem (h); h; h = GetNextSiblingItem (h))
703
    {
704
      RestoreDefault (h, TRUE, FALSE);
705
    }
706
  }
707
}
708
 
709
BOOL CControlView::IsChanged(HTREEITEM h, BOOL bRecurse)
710
{
711
  BOOL rc = TI (h).Modified ();
712
  //    CConfigItem &ti=TI(h);
713
  //    BOOL rc=(0!=ti.StringDefaultValue().Compare(ti.StringValue()));         
714
  if(!rc && bRecurse)
715
  {
716
    for(h=GetChildItem(h);h;h=GetNextSiblingItem(h))
717
    {
718
      if(IsChanged(h,TRUE))
719
      {
720
        rc=TRUE;
721
        break;
722
      }
723
    }
724
  }
725
  return rc;
726
}
727
 
728
 
729
void CControlView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
730
{
731
  if(nChar==VK_APPS){
732
    HTREEITEM h=GetSelectedItem();
733
    ShowPopupMenu(h);
734
    return;
735
  }
736
  CTreeView::OnKeyDown(nChar, nRepCnt, nFlags);
737
}
738
 
739
void CControlView::InvalidateItem(HTREEITEM h)
740
{
741
  if(CConfigTool::GetCellView()->ActiveCell()==h)
742
  {
743
    //m_pwndCell->Invalidate();
744
  }
745
  else
746
  {
747
    CRect rect;
748
    GetItemRect(h,rect,FALSE);
749
    InvalidateRect(rect);
750
  }
751
}
752
 
753
/*
754
void CControlView::OnViewSwitches()
755
{
756
m_bSwitches ^= 1;
757
CConfigToolDoc* pDoc = CConfigTool::GetConfigToolDoc();
758
for(int nItem=0;nItem<pDoc->ItemCount();nItem++)
759
{
760
CConfigItem *pItem=pDoc->Item(nItem);
761
HTREEITEM h=pItem->HItem();
762
if(pItem->m_Icon==CConfigItem::IconCheckbox)
763
{
764
pItem->m_Icon=CConfigItem::IconSwitch;
765
} else if(pItem->m_Icon==CConfigItem::IconSwitch)
766
{
767
pItem->m_Icon=CConfigItem::IconCheckbox;
768
}
769
AdjustItemImage(h);
770
}
771
 
772
  Invalidate();
773
 
774
    }
775
 
776
      void CControlView::OnUpdateViewSwitches(CCmdUI* pCmdUI)
777
      {
778
      pCmdUI->SetCheck(m_bSwitches);
779
      }
780
 
781
        void CControlView::OnViewCheckboxes()
782
        {
783
        OnViewSwitches();
784
        }
785
        void CControlView::OnUpdateViewCheckboxes(CCmdUI* pCmdUI)
786
        {
787
        pCmdUI->SetCheck(!m_bSwitches);
788
        }
789
*/
790
void CControlView::OnViewUrl()
791
{
792
  TI(m_hContext).ViewURL();
793
}
794
 
795
bool CControlView::BumpItem(HTREEITEM h,int nInc)
796
{
797
  bool rc=false;
798
  // Take an action for clicking on the icon
799
  CConfigToolDoc* pDoc = CConfigTool::GetConfigToolDoc();
800
  CConfigItem &ti=TI(h);
801
 
802
  // do not modify the option value if it is inactive or not modifiable
803
  const CdlValuable valuable = ti.GetCdlValuable();
804
  if (!valuable || (valuable->is_modifiable () && valuable->is_active ())) {
805
    if (0 == nInc) // if a toggle request
806
    {
807
      if (ti.HasBool () && ! (ti.HasRadio () && ti.IsEnabled ())) { // only enable (not disable) a radio button
808
        rc=pDoc->SetEnabled (ti, ! ti.IsEnabled ()); // toggle enabled/disabled state
809
      }
810
    } else if (ti.IsEnabled ()) { // the item is enabled...
811
      switch(ti.Type())
812
      {
813
      case CConfigItem::None:
814
      case CConfigItem::String:
815
      case CConfigItem::Double:
816
        break;
817
      case CConfigItem::Enum:
818
        {
819
          CStringArray arEnum;
820
          ti.EvalEnumStrings (arEnum); // calculate legal values just in time
821
          if (0==arEnum.GetSize()) // if no legal values...
822
            break;           // ...do nothing
823
          int nIndex = -1;
824
          const CString strCurrent = ti.StringValue ();
825
          for (int nEnum = 0; (nEnum < arEnum.GetSize()) && (nIndex == -1); nEnum++)
826
            if (0 == arEnum[nEnum].Compare (strCurrent))
827
                                                        nIndex = nEnum; // the index of the current value
828
 
829
                                        if (nIndex != -1) // if the current value is still legal
830
                  nIndex += (nInc < 0 ? -1 : 1); // increment/decrement the index
831
                else
832
                  nIndex = 0; // otherwise select the first enum
833
 
834
                if (nIndex < 0) // if the new index is negative
835
                  nIndex = arEnum.GetSize()-1; // make it positive
836
 
837
                rc=pDoc->SetValue (ti, arEnum[nIndex % arEnum.GetSize()]);
838
        }
839
        break;
840
      case CConfigItem::Integer:
841
        {
842
          ItemIntegerType nOldValue=Value(h);
843
          if(nInc==1 && nOldValue==ItemIntegerType (-1)){
844
            nOldValue=0;
845
          } else if(nInc==-1 && nOldValue==0){
846
            nOldValue=ItemIntegerType (-1);
847
          } else {
848
            nOldValue+=nInc;
849
          }
850
          rc=pDoc->SetValue(ti,nOldValue);
851
          break;
852
        }
853
 
854
        break;
855
        /*
856
        case CConfigItem::Boolean:
857
 
858
          {
859
          ItemIntegerType nOldValue=Value(h);
860
          pDoc->SetValue(ti,nOldValue^1);
861
          }
862
          break;
863
                        case CConfigItem::Radio:
864
 
865
              if(0==Value(h)){
866
              pDoc->SetValue(ti, (ItemIntegerType) 1);
867
              }
868
              break;
869
        */
870
      default:
871
        ASSERT(FALSE);
872
        break;
873
      }
874
    }
875
  }
876
  return rc;
877
}
878
 
879
int CControlView::OnCreate(LPCREATESTRUCT lpCreateStruct)
880
{
881
  if (CTreeView::OnCreate(lpCreateStruct) == -1)
882
    return -1;
883
 
884
  BOOL b=m_il.Create(IDB_BITMAP2,16,1,RGB(0,128,128));
885
 
886
  // This code is necessary because of what appears to be an inconsistency between
887
  // different versions of the common control dll.  In some the text rectangles seem
888
  // not to take into account the offset introduced by the item image of the root item.
889
  // The offset is used in the OnPaint handler to make sure the greyed text is in the
890
  // right place.
891
 
892
  // Begin hack
893
  {
894
    HTREEITEM h=InsertItem(_T("Foo"));
895
    CRect rect1,rect2;
896
    GetItemRect(h,rect1,TRUE);
897
 
898
    SetImageList(&m_il,TVSIL_NORMAL);
899
    GetItemRect(h,rect2,TRUE);
900
    m_TreeXOffsetAdjustment=rect1.left==0?(rect2.left-rect1.left):0;
901
    DeleteItem(h);
902
  }
903
  // End hack
904
 
905
  ASSERT(b);
906
 
907
  CRect rcClient;
908
  GetClientRect(rcClient);
909
  CSplitterWnd *pSplitter=(CSplitterWnd*)GetParent();
910
  pSplitter->SetColumnInfo(1,rcClient.Width()/4,0);
911
 
912
  return 0;
913
}
914
 
915
void CControlView::KillScrollBars()
916
{
917
  CSplitterWnd *pSplit=(CSplitterWnd *)GetParent();
918
  int min,curX,curY;
919
  const int col=0;
920
  pSplit->GetColumnInfo(col,curX,min);
921
  if(-1==curX){
922
    return;
923
  }
924
  pSplit->GetRowInfo   (0,curY,min);
925
  if(-1==curY){
926
    return;
927
  }
928
  CRect rcClient;
929
  GetClientRect(rcClient);
930
  /*
931
  TRACE("splitter[%d]=(%d,%d) view=(%d,%d)",
932
                col,
933
    curX,curY,
934
    rcClient.Width(),rcClient.Height());
935
                */
936
  if(curX>rcClient.Width()&&curY>rcClient.Height()){
937
    //sdf ShowScrollBar(SB_BOTH,FALSE);
938
    ShowScrollBar(SB_VERT,FALSE);
939
  } else {
940
    if(curX>rcClient.Width()){
941
      //TRACE(" -VERT\n");
942
      ShowScrollBar(SB_VERT,FALSE);
943
    }
944
    if(curY>rcClient.Height()){
945
      //TRACE(" -HORZ\n");
946
      //sdf ShowScrollBar(SB_HORZ,FALSE);
947
    }
948
  }
949
  //TRACE("\n");
950
}
951
 
952
void CControlView::SetScrollPos()
953
{
954
  if(m_bHasVScroll==1){
955
    CRect rect;
956
    GetTreeCtrl().GetItemRect(GetTreeCtrl().GetRootItem(),rect,FALSE);
957
    CScrollBar *cv=(CScrollBar *)(GetParent()->GetDlgItem(AFX_IDW_VSCROLL_FIRST));
958
    //BOOL cv=TRUE;
959
    if(cv && m_bHasVScroll){
960
      //TRACE("SetScrollPos %d\n",-rect.top);
961
      cv->SetScrollPos(-rect.top);
962
      //SetScrollInfo(SB_VERT,&si,SIF_POS);
963
    }
964
  }
965
}
966
 
967
void CControlView::SetScrollRangePos()
968
{
969
  RecalcWorkSpaceSize();
970
  if(m_nWorkspace>0){
971
    CScrollBar *cv=(CScrollBar *)(GetParent()->GetDlgItem(AFX_IDW_VSCROLL_FIRST));
972
    //BOOL cv=TRUE;
973
 
974
    if(cv){
975
      CRect rcClient;
976
      GetClientRect(rcClient);
977
      SCROLLINFO si;
978
      si.cbSize=sizeof SCROLLINFO;
979
      memset(&si,0,sizeof SCROLLINFO);
980
      si.nPage=rcClient.Height();
981
      si.fMask=SIF_PAGE|SIF_RANGE|SIF_POS;
982
      si.nMin=0;
983
      CRect rect;
984
      GetTreeCtrl().GetItemRect(GetTreeCtrl().GetRootItem(),rect,FALSE);
985
      si.nPos=-rect.top;
986
      BOOL bHasVScroll=(si.nPage<(unsigned)m_nWorkspace);
987
      if(bHasVScroll){
988
        si.nMax=m_nWorkspace/*-si.nPage*/;
989
        cv->SetScrollInfo(&si,SIF_PAGE|SIF_RANGE|SIF_POS);
990
        //TRACE("SetScrollInfo range=(%d,%d) pos=%d page=%d\n",si.nMin,si.nMax,si.nPos,si.nPage);
991
      }
992
      if(bHasVScroll!=m_bHasVScroll){
993
        CSplitterWnd *pSplitter=(CSplitterWnd *)GetParent();
994
        DWORD style=(pSplitter->GetScrollStyle()&(~WS_VSCROLL))
995
          |(bHasVScroll*WS_VSCROLL);
996
        pSplitter->SetScrollStyle(style);
997
        pSplitter->RecalcLayout();
998
        m_bHasVScroll=bHasVScroll;
999
      }
1000
    }
1001
  }
1002
}
1003
 
1004
void CControlView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
1005
{
1006
  CTreeView::OnHScroll(nSBCode, nPos, pScrollBar);
1007
  SetHScrollPos();
1008
}
1009
 
1010
void CControlView::SetHScrollRangePos()
1011
{
1012
  return;//sdf
1013
}
1014
 
1015
void CControlView::SetHScrollPos()
1016
{
1017
  return;//sdf
1018
  CRect rcClient;
1019
  GetClientRect(rcClient);
1020
  SCROLLINFO si;
1021
  si.cbSize=sizeof SCROLLINFO;
1022
  memset(&si,0,sizeof SCROLLINFO);
1023
  si.fMask=SIF_POS;
1024
  CRect rect;
1025
  GetTreeCtrl().GetItemRect(GetTreeCtrl().GetRootItem(),rect,FALSE);
1026
  si.nPos=-rect.left;
1027
  const int nCol=0;
1028
  CScrollBar *cv=(CScrollBar *)(GetParent()->GetDlgItem(AFX_IDW_HSCROLL_FIRST+nCol));
1029
  //BOOL cv=TRUE;
1030
  if(cv && m_bHasHScroll){
1031
    cv->SetScrollInfo(&si,SIF_POS);
1032
    //SetScrollInfo(SB_HORZ,&si,SIF_POS);
1033
  }
1034
 
1035
}
1036
 
1037
void CControlView::OnMouseMove(UINT nFlags, CPoint point)
1038
{
1039
  CTreeView::OnMouseMove(nFlags, point) ;
1040
 
1041
  // Relay the mouse event to the splitter
1042
  ClientToScreen(&point);
1043
  GetParent()->ScreenToClient(&point);
1044
  GetParent()->SendMessage(WM_MOUSEMOVE,(WPARAM)nFlags,MAKELPARAM(point.x,point.y));
1045
}
1046
 
1047
BOOL CControlView::OnMouseWheel(UINT, short zDelta, CPoint)
1048
{
1049
  UINT nScrollCode=((zDelta<0)?SB_LINEDOWN:SB_LINEUP);
1050
  LPARAM lParam=(LPARAM)GetScrollBarCtrl(SB_VERT)->GetSafeHwnd();
1051
  if(lParam){
1052
    for(int i=0;i<abs(zDelta)/WHEEL_DELTA;i++){
1053
      SendMessage(WM_VSCROLL,MAKEWPARAM(nScrollCode,0),lParam);
1054
      CConfigTool::GetCellView()->Sync();
1055
    }
1056
  }
1057
  return TRUE;
1058
}
1059
 
1060
void CControlView::RecalcWorkSpaceSize()
1061
{
1062
  //TRACE("Control view recalcworkspace\n");
1063
  CRect rcFirst,rcLast;
1064
  CConfigToolDoc* pDoc = CConfigTool::GetConfigToolDoc();
1065
  if(pDoc->ItemCount()>0){
1066
    HTREEITEM h=pDoc->FirstItem()->HItem();
1067
    if(h){
1068
      GetItemRect(h,rcFirst,FALSE);
1069
      if(pDoc->ItemCount()>0 && pDoc->Item(pDoc->ItemCount()-1)->HItem()){
1070
        for(HTREEITEM h=pDoc->Item(pDoc->ItemCount()-1)->HItem();h;h=GetPrevVisibleItem(h)){
1071
          if(GetItemRect(h,rcLast,FALSE)){
1072
            m_nWorkspace=rcLast.bottom-rcFirst.top;
1073
            break;
1074
          }
1075
        }
1076
      }
1077
    }
1078
  }
1079
}
1080
 
1081
void CControlView::OnSysKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
1082
{
1083
  switch(nChar){
1084
                case VK_F10:
1085
      if(::GetKeyState(VK_SHIFT)&0x8000){
1086
        // Shift key down
1087
        ShowPopupMenu(GetSelectedItem());
1088
      }
1089
      break;
1090
    case VK_RETURN:
1091
      if(nFlags&(1<<13)){
1092
        // Alt key down
1093
        m_hContext=GetSelectedItem();
1094
        OnPopupProperties();
1095
      }
1096
      break;
1097
  }
1098
  CTreeView::OnSysKeyDown(nChar, nRepCnt, nFlags);
1099
}
1100
 
1101
void CControlView::ShowPopupMenu(HTREEITEM h,CPoint point/*=CPoint(-1,-1)*/)
1102
{
1103
  // Display a context menu
1104
  if(NULL!=h){
1105
    Menu menu;
1106
    menu.LoadMenu(IDR_CONTROLVIEW_POPUP);
1107
    Menu *pPopup=(Menu *)menu.GetSubMenu(0);
1108
 
1109
    if(point.x<0){
1110
      CRect rcItem;
1111
      GetItemRect(h,rcItem,TRUE);
1112
      point=rcItem.CenterPoint();
1113
      ClientToScreen(&point);
1114
    }
1115
    m_hContext=h;
1116
    CConfigItem &ti=TI(m_hContext);
1117
    CConfigItem::TreeItemType type=ti.Type();
1118
 
1119
    #ifndef PLUGIN
1120
    menu.LoadToolbar(IDR_MISCBAR);
1121
    #endif
1122
    if(!IsChanged(m_hContext,true)){
1123
      pPopup->EnableMenuItem(ID_RESTORE_DEFAULTS,MF_BYCOMMAND|MF_GRAYED);
1124
    }
1125
 
1126
    if((CConfigItem::None!=type) || ti.HasBool ()){
1127
                const CString strURL(ti.GetURL());
1128
        if(strURL.IsEmpty()){
1129
          pPopup->EnableMenuItem(ID_VIEW_URL,MF_BYCOMMAND|MF_GRAYED);
1130
        }
1131
    }
1132
 
1133
    const CFileName strFile(TI(h).FileName());
1134
    if(strFile.IsEmpty() || CConfigTool::GetConfigToolDoc()->BuildTree().IsEmpty()){
1135
       pPopup->EnableMenuItem(ID_VIEW_HEADER,MF_BYCOMMAND|MF_GRAYED);
1136
    }
1137
 
1138
    if(!TI(h).IsPackage()){
1139
      int n=pPopup->GetMenuItemCount();
1140
      pPopup->RemoveMenu(n-1,MF_BYPOSITION);
1141
      pPopup->RemoveMenu(n-2,MF_BYPOSITION);
1142
    }
1143
    pPopup->TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_RIGHTBUTTON, point.x,point.y,this);
1144
  }
1145
}
1146
 
1147
void CControlView::OnSysChar(UINT nChar, UINT nRepCnt, UINT nFlags)
1148
{
1149
  // TODO: Add your message handler code here and/or call default
1150
 
1151
  CTreeView::OnSysChar(nChar, nRepCnt, nFlags);
1152
}
1153
 
1154
CConfigToolDoc * CControlView::GetDocument()
1155
{
1156
  return CConfigTool::GetConfigToolDoc();
1157
}
1158
 
1159
void CControlView::OnViewHeader()
1160
{
1161
  TI(m_hContext).ViewHeader();
1162
}
1163
 
1164
void CControlView::OnEditFind()
1165
{
1166
  CConfigToolDoc *pDoc=CConfigTool::GetConfigToolDoc();
1167
  if(!CConfigTool::GetMain()->m_bFindInProgress){
1168
    (new CFindDialog())->Create(pDoc->m_strFind,pDoc->m_nFindFlags&(FR_WHOLEWORD|FR_MATCHCASE|FR_DOWN),pDoc->m_nFindWhere, this);
1169
    CConfigTool::GetMain()->m_bFindInProgress=true;
1170
  }
1171
}
1172
 
1173
void CControlView::OnEditFindAgain()
1174
{
1175
  CConfigToolDoc *pDoc=CConfigTool::GetConfigToolDoc();
1176
  DoFind(pDoc->m_strFind,pDoc->m_nFindFlags,pDoc->m_nFindWhere);
1177
}
1178
 
1179
LONG CControlView::OnFind(WPARAM wParam, LPARAM lParam)
1180
{
1181
  UNUSED_ALWAYS(wParam);
1182
  CFindDialog *pDlg=(CFindDialog *)CFindDialog::GetNotifier(lParam);
1183
  FINDREPLACE &fr=pDlg->m_fr;
1184
  CConfigToolDoc *pDoc=CConfigTool::GetConfigToolDoc();
1185
  if(0==(fr.Flags&FR_DIALOGTERM)){
1186
    pDoc->m_strFind=fr.lpstrFindWhat;
1187
    pDoc->m_nFindFlags=fr.Flags;
1188
    pDoc->m_nFindWhere=pDlg->m_nFindPos;
1189
 
1190
    CConfigItem *pItem=DoFind(pDoc->m_strFind,pDoc->m_nFindFlags,pDoc->m_nFindWhere);
1191
    if(pItem){
1192
                    // Is the find window on top of the item?
1193
                    CRect rect1,rect2;
1194
        GetItemRect(pItem->HItem(),rect1,TRUE);
1195
        ClientToScreen(rect1);
1196
        pDlg->GetWindowRect(rect2); // screen coords
1197
        rect1=rect1 & rect2;
1198
        if(rect1.Height()|rect1.Width()){
1199
          int nWidth=rect2.Width();
1200
          rect2.left=rect1.right;
1201
          rect2.right=rect2.left+nWidth;
1202
          pDlg->MoveWindow(rect2);
1203
        }
1204
    }
1205
  } else {
1206
    CConfigTool::GetMain()->m_bFindInProgress=false;
1207
  }
1208
 
1209
  return 0;
1210
}
1211
 
1212
CConfigItem * CControlView::DoFind(LPCTSTR pszWhat,DWORD dwFlags,WhereType where)
1213
{
1214
  CConfigToolDoc *pDoc=CConfigTool::GetConfigToolDoc();
1215
  int nCount=pDoc->ItemCount();
1216
  static LPCTSTR arWhereImage[]={_T("name"),_T("macro"),_T("description string"),_T("current value"),_T("default value")};
1217
 
1218
  CString strFind(pszWhat);
1219
  if(!(dwFlags&FR_MATCHCASE)){
1220
    strFind.MakeLower();
1221
  }
1222
 
1223
  HTREEITEM h=GetSelectedItem();
1224
  int nItem;
1225
  if(!h){
1226
    nItem=0;
1227
  } else {
1228
    for(nItem=nCount-1;nItem>=0;--nItem) {
1229
      if(h==pDoc->Item(nItem)->HItem()){
1230
        break;
1231
      }
1232
    }
1233
    ASSERT(nItem>=0);
1234
  }
1235
 
1236
  CConfigItem *pItem=NULL;
1237
  for(int i=0;i<nCount;i++){
1238
    if(dwFlags&FR_DOWN){
1239
      nItem=(nItem+1)%nCount;
1240
    } else {
1241
      nItem=(nCount+nItem-1)%nCount;
1242
    }
1243
    pItem=pDoc->Item(nItem);
1244
 
1245
    CString strName(pItem->StringValue(where));
1246
    if(0==(dwFlags&FR_MATCHCASE)){
1247
      strName.MakeLower();
1248
    }
1249
    int nIndex=strName.Find(strFind);
1250
    if(-1!=nIndex){
1251
      if(dwFlags&FR_WHOLEWORD){
1252
        // Enforce whole-word semantics: to left and right
1253
        if(nIndex>0 && IsWordChar(strName[nIndex-1])){
1254
          continue;
1255
        }
1256
        nIndex+=strFind.GetLength();
1257
        if(nIndex<strName.GetLength() && IsWordChar(strName[nIndex])){
1258
          continue;
1259
        }
1260
      }
1261
      break;
1262
    }
1263
  }
1264
 
1265
  if(i<nCount){
1266
    if(m_hExpandedForFind){
1267
      Expand(m_hExpandedForFind,TVE_COLLAPSE);
1268
    }
1269
    HTREEITEM h=pItem->HItem();
1270
    // Is h visible?
1271
    for(HTREEITEM hv=GetFirstVisibleItem();hv;hv=GetNextVisibleItem(hv)){
1272
      if(hv==h){
1273
        break;
1274
      }
1275
    }
1276
    if(NULL==hv){
1277
      // we want to record the highest unexpanded item
1278
      for(HTREEITEM hv=GetParentItem(h);hv;hv=GetParentItem(hv)){
1279
        const UINT selflag = TVIS_EXPANDED;
1280
        if(0==(GetItemState( hv, selflag ) & selflag )){
1281
          m_hExpandedForFind=hv;
1282
        }
1283
      }
1284
    }
1285
    EnsureVisible(h);
1286
    SelectItem(h);
1287
 
1288
  } else {
1289
    CUtils::MessageBoxF(_T("Cannot find the %s '%s'"),arWhereImage[where],pszWhat);
1290
  }
1291
  return pItem;
1292
}
1293
 
1294
bool CControlView::IsWordChar(TCHAR c)
1295
{
1296
  return _istalnum(c) || _TCHAR('_')==c;
1297
}
1298
 
1299
void CControlView::OnUpdateEditFindAgain(CCmdUI* pCmdUI)
1300
{
1301
  pCmdUI->Enable(!CConfigTool::GetMain()->m_bFindInProgress && !CConfigTool::GetConfigToolDoc()->m_strFind.IsEmpty() && CWnd::GetFocus() && m_hWnd==CWnd::GetFocus()->m_hWnd);
1302
}
1303
 
1304
bool CControlView::SelectItem(const CConfigItem *pItem)
1305
{
1306
#ifdef PLUGIN
1307
  CConfigTool::GetMain()->ShoweCosBar();
1308
#else
1309
#endif
1310
  return SelectItem(pItem->HItem());
1311
}
1312
 
1313
void CControlView::OnUpdateEditFind(CCmdUI* pCmdUI)
1314
{
1315
  pCmdUI->Enable(!CConfigTool::GetMain()->m_bFindInProgress);
1316
}
1317
 
1318
BOOL CControlView::PreTranslateMessage(MSG* pMsg)
1319
{
1320
  // We handle WM_KEYDOWN here to avoid the problem of the keyboard buffer not being emptied
1321
  if(WM_KEYDOWN==pMsg->message){
1322
    HTREEITEM h=GetSelectedItem();
1323
    if(h){
1324
                    switch(pMsg->wParam){
1325
        case VK_SPACE:
1326
          if(BumpItem(h,0)){ // toggle boolean
1327
                                        return true;
1328
          }
1329
          break;
1330
        case VK_TAB:
1331
          {
1332
            bool bShift=(::GetKeyState(VK_SHIFT)&0x8000);// Shift key down
1333
            if(bShift){
1334
              h=GetPrevVisibleItem(h);
1335
            }
1336
            if(h){
1337
              SelectItem(h);
1338
              if(!CConfigTool::GetCellView()->InCell(h) && !bShift){
1339
                h=GetNextVisibleItem(h);
1340
                if(h){
1341
                  SelectItem(h);
1342
                }
1343
              }
1344
            }
1345
            if(NULL==h){
1346
              MessageBeep (0xFFFFFFFF);
1347
            }
1348
            // Always handle this message to keep focus within the tree control
1349
            return true;
1350
          }
1351
        }
1352
    }
1353
  }
1354
  return CTreeView::PreTranslateMessage(pMsg);
1355
}
1356
 
1357
void CControlView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
1358
{
1359
  HTREEITEM h=GetSelectedItem();
1360
  if(h){
1361
    switch(nChar){
1362
    case _TCHAR('>'):
1363
      if(!BumpItem(h,+1)){
1364
        MessageBeep(0xffff);
1365
      }
1366
      return;
1367
    case _TCHAR('<'):
1368
      if(!BumpItem(h,-1)){
1369
        MessageBeep(0xffff);
1370
      }
1371
      return;
1372
    }
1373
  }
1374
 
1375
  CTreeView::OnChar(nChar, nRepCnt, nFlags);
1376
}
1377
 
1378
LRESULT CControlView::OnSetFont(WPARAM, LPARAM)
1379
{
1380
  LRESULT rc=Default();
1381
  CRect rect;
1382
  GetItemRect(GetFirstVisibleItem(),rect,FALSE);
1383
  m_nItemHeight=rect.Height();
1384
  RecalcWorkSpaceSize();
1385
  return rc;
1386
}
1387
 
1388
void CControlView::OnUnload()
1389
{
1390
  if(IDYES==CUtils::MessageBoxFT(MB_YESNO|MB_DEFBUTTON2,_T("Are you sure you wish to unload this package?"))){
1391
    TI(m_hContext).Unload();
1392
    CConfigTool::GetConfigToolDoc()->RegenerateData();
1393
  }
1394
}
1395
 
1396
void CControlView::OnDeleteitem(NMHDR*, LRESULT* pResult)
1397
{
1398
  if(CConfigTool::GetCellView()){
1399
    CConfigTool::GetCellView()->Invalidate();
1400
  }
1401
        *pResult = 0;
1402
}
1403
 
1404
void CControlView::OnWhatsThis()
1405
{
1406
  DWORD dwPos=GetMessagePos();
1407
 
1408
  HH_POPUP hhp;
1409
  hhp.cbStruct=sizeof(hhp);
1410
  hhp.idString=0;
1411
  hhp.hinst=AfxGetInstanceHandle();
1412
  hhp.pszText=TI(m_hContext).Desc();
1413
  hhp.pt.x=GET_X_LPARAM(dwPos);
1414
  hhp.pt.y=GET_Y_LPARAM(dwPos);
1415
  hhp.clrForeground=(COLORREF)-1; //default 
1416
  hhp.clrBackground=GetSysColor(COLOR_INFOBK);
1417
  hhp.rcMargins=CRect(-1,-1,-1,-1);
1418
  hhp.pszFont=NULL;
1419
 
1420
  HtmlHelp(
1421
    m_hWnd,
1422
    NULL,
1423
    HH_DISPLAY_TEXT_POPUP, //HH_TP_HELP_CONTEXTMENU, 
1424
    (DWORD)&hhp
1425
    );
1426
 
1427
}
1428
 
1429
void CControlView::Refresh(LPCTSTR pszMacroName)
1430
{
1431
  const CConfigItem * pItem=CConfigTool::GetConfigToolDoc()->Find(pszMacroName);
1432
  if(pItem){ // will be NULL if item has been removed
1433
    Refresh(pItem->HItem());
1434
  }
1435
}
1436
 
1437
BOOL CControlView::OnHelpInfo(HELPINFO*)
1438
{
1439
  return CConfigTool::GetConfigToolDoc()->ShowURL(CUtils::LoadString(IDS_CONTROL_VIEW_HELP));
1440
}
1441
 
1442
LRESULT CControlView::OnMenuChar(UINT, UINT, CMenu*)
1443
{
1444
  const MSG *pMsg=GetCurrentMessage();
1445
  // punt to the mainframe to deal with shortcuts in popups
1446
  return AfxGetMainWnd()->SendMessage(pMsg->message,pMsg->wParam,pMsg->lParam);
1447
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.