⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 controlview.cpp

📁 eCos1.31版
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//####COPYRIGHTBEGIN####//                                                                          // ----------------------------------------------------------------------------// Copyright (C) 1998, 1999, 2000 Red Hat, Inc.//// This program is part of the eCos host tools.//// This program is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by the Free // Software Foundation; either version 2 of the License, or (at your option) // any later version.// // This program is distributed in the hope that it will be useful, but WITHOUT // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for // more details.// // You should have received a copy of the GNU General Public License along with// this program; if not, write to the Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.//// ----------------------------------------------------------------------------//                                                                          //####COPYRIGHTEND####// ControlView.cpp : implementation file//////===========================================================================//===========================================================================//#####DESCRIPTIONBEGIN####//// Author(s): 	sdf// Contact(s):	sdf// Date:		1998/08/11// Version:		0.01// Purpose:	// Description:	This is the implementation of the tree (control) view// Requires:	// Provides:	// See also:    // Known bugs:	// Usage:	////####DESCRIPTIONEND####////===========================================================================#include "stdafx.h"#ifndef PLUGIN#include "BCMenu.h"#endif#include "ControlView.h"#include "ConfigTool.h"#include "ConfigItem.h"#include "ConfigToolDoc.h"#include <stdlib.h>#include "CTUtils.h"#include "CellView.h"#include "MessageBox.h"#include "FindDialog.h"#include "CTPropertiesDialog.h"#include "ConfigViewOptionsDialog.h"#ifdef PLUGIN  //#include "ide.common.h"  #define INCLUDEFILE "ide.guicommon.h"  // for ID_EDIT_FINDAGAIN  #include "IncludeSTL.h"  #include "CTMain.h"#else  #include "MainFrm.h"#endif#include <afxpriv.h> // for WM_COMMANDHELP, WM_HITTEST#include <htmlhelp.h>#include "DescView.h" // for testing#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CControlViewIMPLEMENT_DYNCREATE(CControlView, CTreeView)CControlView::CControlView(){  m_bHasVScroll=-1;  m_nWorkspace=0;  m_dwDefaultStyle&=(~WS_VSCROLL);  m_hContext=NULL;  m_hExpandedForFind=NULL;  m_GrayPen.CreatePen(PS_SOLID,1,RGB(192,192,192));	  CConfigTool::SetControlView(this);}CControlView::~CControlView(){  CConfigTool::SetControlView(0);}static UINT WM_FINDREPLACE = ::RegisterWindowMessage(FINDMSGSTRING);BEGIN_MESSAGE_MAP(CControlView, CTreeView)//{{AFX_MSG_MAP(CControlView)ON_WM_PAINT()ON_NOTIFY_REFLECT(TVN_ITEMEXPANDED, OnItemexpanded)ON_NOTIFY_REFLECT(TVN_SELCHANGED, OnSelchanged)ON_WM_LBUTTONDOWN()ON_WM_VSCROLL()ON_WM_SIZE()ON_COMMAND(ID_RESTORE_DEFAULTS, OnRestoreDefaults)ON_COMMAND(ID_POPUP_PROPERTIES, OnPopupProperties)ON_COMMAND(ID_UNLOAD_PACKAGE, OnUnload)ON_WM_KEYDOWN()ON_COMMAND(ID_VIEW_URL, OnViewUrl)ON_WM_CREATE()ON_WM_HSCROLL()ON_WM_MOUSEMOVE()ON_NOTIFY_REFLECT(TVN_ITEMEXPANDING, OnItemexpanding)ON_WM_MOUSEWHEEL()ON_WM_RBUTTONDOWN()ON_WM_SYSKEYDOWN()ON_WM_SYSCHAR()ON_COMMAND(ID_VIEW_HEADER, OnViewHeader)ON_REGISTERED_MESSAGE( WM_FINDREPLACE, OnFind)ON_COMMAND(ID_EDIT_FIND,OnEditFind)ON_COMMAND(ID_EDIT_FINDAGAIN,OnEditFindAgain)ON_UPDATE_COMMAND_UI(ID_EDIT_FINDAGAIN, OnUpdateEditFindAgain)ON_UPDATE_COMMAND_UI(ID_EDIT_FIND, OnUpdateEditFind)ON_WM_CHAR()	ON_NOTIFY_REFLECT(TVN_DELETEITEM, OnDeleteitem)	ON_COMMAND(ID_CV_WHATS_THIS, OnWhatsThis)ON_MESSAGE(WM_SETFONT,OnSetFont)	ON_WM_HELPINFO()	ON_WM_MENUCHAR()	//}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CControlView drawingvoid CControlView::OnDraw(CDC* pDC){  UNUSED_ALWAYS(pDC);}/////////////////////////////////////////////////////////////////////////////// CControlView diagnostics#ifdef _DEBUGvoid CControlView::AssertValid() const{  CTreeView::AssertValid();}void CControlView::Dump(CDumpContext& dc) const{  CTreeView::Dump(dc);}#endif //_DEBUG/////////////////////////////////////////////////////////////////////////////// CControlView message handlersvoid CControlView::OnPaint() {  CPaintDC dc(this); // device context for painting    // First let the control do its default drawing.  CWnd::DefWindowProc( WM_PAINT, (WPARAM)dc.m_hDC, 0 );    CConfigToolDoc* pDoc = CConfigTool::GetConfigToolDoc();  if(pDoc->ItemCount()>0)  {    // Redraw the disabled labels    CFont *pOldFont=dc.SelectObject(GetFont());    dc.SetTextColor(GetSysColor(COLOR_GRAYTEXT));        for(HTREEITEM h=GetFirstVisibleItem();h;h=GetNextVisibleItem(h))    {      const UINT selflag = TVIS_DROPHILITED | TVIS_SELECTED;		      if(!IsActive(h)&&!(GetItemState( h, selflag ) & selflag )){        // Do not meddle with selected items or drop highlighted items        CRect rect;		        GetItemRect( h, &rect, TRUE );        dc.TextOut(m_TreeXOffsetAdjustment+rect.left+2, rect.top+1, GetItemText(h));			      }    }    dc.SelectObject(pOldFont);        // Now draw grid lines        CRect rcClient;    GetClientRect(rcClient);    CPen *pOldPen=dc.SelectObject(&m_GrayPen);    int cy=0;    for(h=GetFirstVisibleItem();h;h=GetNextVisibleItem(h))    {      dc.MoveTo(rcClient.left,cy);      dc.LineTo(rcClient.right,cy);      cy+=m_nItemHeight;    }    dc.MoveTo(rcClient.left,cy);    dc.LineTo(rcClient.right,cy);    dc.SelectObject(pOldPen);      }}void CControlView::OnItemexpanded(NMHDR* pNMHDR, LRESULT* pResult) {  //NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;  SetScrollRangePos();  //SetHScrollRangePos();  if(CConfigTool::GetCellView()){    CConfigTool::GetCellView()->Invalidate();//sdf1    CConfigTool::GetCellView()->UpdateWindow();  }     *pResult = 0;  UNUSED_ALWAYS(pNMHDR);}void CControlView::OnItemexpanding(NMHDR* pNMHDR, LRESULT* pResult) {  //NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;    *pResult = 0;  UNUSED_ALWAYS(pNMHDR);}void CControlView::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult) {  CConfigToolDoc* pDoc = CConfigTool::GetConfigToolDoc();  if(pDoc->ItemCount()>0){    // Do nothing if in process of destroying configitems    NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;    pDoc->UpdateAllViews (this, CConfigToolDoc::SelChanged, (CObject *)&TI(pNMTreeView->itemNew.hItem));    CConfigItem &ti=TI(pNMTreeView->itemNew.hItem);        CString strDesc(ti.Desc());    if(strDesc.IsEmpty()){      strDesc=_T("No context help is available for this item");    }    //pMain->m_wndHelp.SetWindowText(strDesc);    //pMain->m_wndHelp.SetTitle(ti.ItemNameOrMacro());    SetScrollPos();    if(CConfigTool::GetCellView()){      CConfigTool::GetCellView()->Sync();    }  }  *pResult = 0;}void CControlView::OnLButtonDown(UINT nFlags, CPoint point) {  CConfigTool::GetCellView()->CancelCellEdit();  {    UINT nFlags;    HTREEITEM h=HitTest(point,&nFlags);    if(h && IsActive(h) && (nFlags&TVHT_ONITEMICON))    {      SelectItem(h);      BumpItem (h, TI (h).HasBool () ? 0 : 1); // toggle boolean or increment data    }    else    {      CTreeView::OnLButtonDown(nFlags,point);    }  }    // Relay to the splitter  ClientToScreen(&point);  GetParent()->ScreenToClient(&point);  GetParent()->SendMessage(WM_LBUTTONDOWN,(WPARAM)nFlags,MAKELPARAM(point.x,point.y));	}void CControlView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) {   // Round to nearest item and express in units of items for the benefit of CTreeView  nPos=(nPos+m_nItemHeight/2)/m_nItemHeight;  DefWindowProc(WM_VSCROLL,MAKELONG(nSBCode, nPos), (LPARAM)pScrollBar->m_hWnd);  SetScrollPos();}/////////////////////////////////////////////////////////////////////////////// CControlView message handlersvoid CControlView::OnInitialUpdate() {  CTreeView::OnInitialUpdate();#ifdef IE4  SetItemHeight(20);#endif  /*  #ifndef PLUGIN  // Do this here, because the framework resets the title after calling OnOpenDocument()  CConfigToolDoc* pDoc = CConfigTool::GetConfigToolDoc();  CString strTitle(pDoc->BuildTree());  if(strTitle.IsEmpty())  {		strTitle+=_T("Repository ");    strTitle+=pDoc->Repository();    }    pDoc->SetTitle(strTitle);    #endif  */}void CControlView::OnSize(UINT nType, int cx, int cy) {  //m_nInOnSize++;  CScrollBar *cv=GetScrollBarCtrl(SB_VERT);  //int dx=cx-m_Size.cx;  //int dy=cy-m_Size.cy;  /*  TRACE("WM_SIZE[%d] dx=%d dy=%d depth=%d ch=%08x cv=%08x",		0,    dx,dy,    m_nInOnSize,    ch,cv);		*/  int bIsHScrollBarDelta=(cv==NULL);  //int bIsVScrollBarDelta=(ch==NULL);  if(bIsHScrollBarDelta/*dx==-16*/){    cx=m_Size.cx;  }  //	if(bIsVScrollBarDelta/*dy==-16*/){  //		cy=m_Size.cy;  //	}  if(cx!=m_Size.cx || cy!=m_Size.cy){    m_Size=CSize(cx,cy);    DefWindowProc(WM_SIZE,(WPARAM)nType,MAKELPARAM(cx,cy));  }  KillScrollBars();  SetScrollRangePos();  //SetHScrollRangePos();  //m_nInOnSize--;}BOOL CControlView::PreCreateWindow(CREATESTRUCT& cs) {  cs.style=TVS_HASBUTTONS | TVS_LINESATROOT | TVS_SHOWSELALWAYS |    WS_CHILD | WS_VISIBLE /*| WS_BORDER*/ | WS_TABSTOP;  cs.style&=(~WS_VSCROLL);  m_dwDefaultStyle&=(~WS_VSCROLL);  return CTreeView::PreCreateWindow(cs);}void CControlView::OnRButtonDown(UINT nFlags, CPoint point) {  UNUSED_ALWAYS(nFlags);  UINT Flags;  HTREEITEM h=HitTest(point,&Flags);  if(h){    SelectItem(h);  }  // point is in client coords  ClientToScreen(&point);  ShowPopupMenu(h,point);}// Button functionalityvoid CControlView::Refresh (HTREEITEM h) // was Enable(){  if(h){    AdjustItemImage(h);    // Invalidate the labels of the affected items    CRect rect;		    GetItemRect(h, rect, TRUE );    rect.left+=m_TreeXOffsetAdjustment;    InvalidateRect(rect);    // Do the same for the cell view    CRect rcBuddyClient;    CConfigTool::GetCellView()->GetClientRect(rcBuddyClient);    rect.left=rcBuddyClient.left;    rect.right=rcBuddyClient.right;    CConfigTool::GetCellView()->InvalidateRect(rect);  }}BOOL CControlView::IsActive(HTREEITEM h) const{  const CdlUserVisible vitem = TI (h).GetCdlItem ();  return vitem ? vitem->is_active () : true; }void CControlView::AdjustItemImage(HTREEITEM h){  CConfigItem &ti=TI(h);  CString str(ti.ItemNameOrMacro());  if(ti.Modified()){    str+=_TCHAR('*');  }  //#ifndef PLUGIN  //	CConfigTool::GetConfigToolDoc()->SetTitle(_T("rt")); // Parameter is ignored  //#endif  SetItemText(h,str);    int nImage=0;  enum {FolderIcon=0, CheckBoxIcon=2, RadioIcon=6, IntegerIcon=10, StringIcon=12, EnumIcon=14, PackageIcon=16, DoubleIcon=20};  if (ti.HasBool ())  {    if (ti.IsPackage ())      nImage = PackageIcon;    else      nImage = ti.HasRadio () ? RadioIcon : CheckBoxIcon;        if (ti.IsEnabled ())      nImage += 2;  }  else  {    switch(ti.Type())    {    /*    case CConfigItem::Boolean:    nImage=ti.IsPackage()?PackageIcon:CheckBoxIcon;    // These images have all four states    if(ti.Value())    {				nImage+=2;        }        break;        case CConfigItem::Radio:        nImage=RadioIcon;        // Has four states        if(ti.Value())        {        nImage+=2;        }        break;      */    case CConfigItem::Double:      nImage=DoubleIcon;      break;    case CConfigItem::Integer:      nImage=IntegerIcon;      break;    case CConfigItem::Enum:      nImage=EnumIcon;      break;    case CConfigItem::None:      nImage = FolderIcon;      break;    case CConfigItem::String:      // if a package use the enabled package icon else use the string icon      nImage = ti.IsPackage () ? PackageIcon + 2 : StringIcon;      break;    default:      ASSERT(FALSE);      break;    }  }  // All items have an enabled alternative  if(!IsActive(h))  {    nImage+=1;  }  //	else if (ti.Type () == CConfigItem::Boolean)  else if ((ti.Type () != CConfigItem::None) || ti.HasBool ())  {    // grey icon if the option is not modifiable or is inactive    const CdlValuable valuable = ti.GetCdlValuable();    if (valuable && ! (valuable->is_modifiable () && valuable->is_active ()))      nImage++;  }  BOOL b=SetItemImage(h,nImage,nImage);  ASSERT(b);}ItemIntegerType CControlView::Value(HTREEITEM h) const{  ItemIntegerType rc;  CConfigItem &ti=TI(h);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -