📄 cellview.cpp
字号:
//####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####//===========================================================================//#####DESCRIPTIONBEGIN####//// Author(s): sdf// Contact(s): sdf// Date: 1998/08/11// Version: 0.01// Purpose: // Description: Implementation of a the cell window view class// Requires: // Provides: // See also:#include // Known bugs: // Usage: ////####DESCRIPTIONEND####////===========================================================================#include "stdafx.h"#include "ConfigTool.h"#include "CellView.h"#include "ControlView.h"#include "ConfigItem.h"#include "IntegerEdit.h"#include "DoubleEdit.h"#include "StringEdit.h"#include "ComboEdit.h"#include "CTUtils.h"#include "ConfigToolDoc.h"#include "resource.h"#ifdef PLUGIN #define INCLUDEFILE "ide.guicommon.h" // for ID_EDIT_FINDAGAIN #include "IncludeSTL.h"#endif#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CCellViewIMPLEMENT_DYNCREATE(CCellView, CView)CCellView::CCellView(): m_bComboSellPending(false){ m_hInCell=NULL; m_pwndCell=NULL; m_GrayPen.CreatePen(PS_SOLID,1,RGB(192,192,192)); CConfigTool::SetCellView(this);}CCellView::~CCellView(){ deleteZ(m_pwndCell); CConfigTool::SetCellView(0);}BEGIN_MESSAGE_MAP(CCellView, CView) //{{AFX_MSG_MAP(CCellView) ON_WM_LBUTTONDOWN() ON_WM_SIZE() ON_WM_CREATE() ON_WM_VSCROLL() ON_WM_MOUSEMOVE() ON_WM_MOUSEWHEEL() ON_COMMAND(ID_EDIT_FIND,OnEditFind) ON_COMMAND(ID_EDIT_FINDAGAIN,OnEditFindAgain) ON_UPDATE_COMMAND_UI(ID_EDIT_FINDAGAIN, OnUpdateEditFindAgain) ON_WM_RBUTTONDOWN() ON_UPDATE_COMMAND_UI(ID_EDIT_FIND, OnUpdateEditFind) ON_WM_ERASEBKGND() ON_COMMAND(ID_EDIT_COPY, OnEditCopy) ON_COMMAND(ID_EDIT_CUT, OnEditCut) ON_COMMAND(ID_EDIT_PASTE, OnEditPaste) ON_COMMAND(ID_EDIT_CLEAR, OnEditDelete) ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateEditCopy) ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, OnUpdateEditCut) ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdateEditPaste) ON_UPDATE_COMMAND_UI(ID_EDIT_CLEAR, OnUpdateEditDelete) ON_WM_HELPINFO() ON_MESSAGE(WM_CANCEL_EDIT,OnCancelEdit) //}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CCellView drawingvoid CCellView::OnInitialUpdate(){ m_nFirstVisibleItem=0; CView::OnInitialUpdate();}void CCellView::OnDraw(CDC* pDC){ CTreeCtrl &Tree=CConfigTool::GetControlView()->GetTreeCtrl(); CConfigToolDoc* pDoc=CConfigTool::GetConfigToolDoc(); if(pDoc->ItemCount()>0) { CRect rect; Tree.GetItemRect(Tree.GetRootItem(),rect,TRUE); m_nFirstVisibleItem=rect.top; CRect rcClient; GetClientRect(rcClient); CPen *pOldPen=pDC->SelectObject(&m_GrayPen); CFont *pOldFont=pDC->SelectObject(CConfigTool::GetControlView()->GetFont()); pDC->SetBkMode(TRANSPARENT); CRect rcClip; pDC->GetClipBox(rcClip); CPtrArray arItems; int dy=CConfigTool::GetControlView()->GetItemHeight(); int cy=0; for(HTREEITEM h=Tree.GetFirstVisibleItem();h;h=Tree.GetNextVisibleItem(h)) { if(cy>rcClip.bottom){ break; } CRect rcEdit(0,cy,rcClient.right,cy+dy); cy+=dy; pDC->MoveTo(rcClient.left,rcEdit.top); pDC->LineTo(rcClient.right,rcEdit.top); CConfigItem &ti=TI(h); if(h!=m_hInCell){ switch(ti.Type()){ case CConfigItem::Enum: // Using combobox rcEdit.left+=2; rcEdit.top+=2; // fall through case CConfigItem::Integer: case CConfigItem::Double: case CConfigItem::String: // Using editbox rcEdit.top+=2; rcEdit.left+=3; { CString str(ti.StringValue()); // cell contents is greyed if the option is not both active and modifiable // or if a booldata item is not enabled const CdlValuable valuable = ti.GetCdlValuable(); // check for a package explicitly because is_modifiable() returns true for a package pDC->SetTextColor (GetSysColor ((! valuable) || (valuable->is_modifiable () && valuable->is_active () && ((! ti.HasBool ()) || ti.IsEnabled ()) && ! ti.IsPackage ()) ? COLOR_WINDOWTEXT : COLOR_GRAYTEXT)); pDC->TextOut(rcEdit.left,rcEdit.top,str); } break; default: break; } } } pDC->MoveTo(rcClient.left,cy); pDC->LineTo(rcClient.right,cy); pDC->SelectObject(pOldPen); pDC->SelectObject(pOldFont); }}/////////////////////////////////////////////////////////////////////////////// CCellView diagnostics#ifdef _DEBUGvoid CCellView::AssertValid() const{ CView::AssertValid();}void CCellView::Dump(CDumpContext& dc) const{ CView::Dump(dc);}#endif //_DEBUG/////////////////////////////////////////////////////////////////////////////// CCellView message handlersvoid CCellView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) { switch(lHint) { case CConfigToolDoc::IntFormatChanged: { for(HTREEITEM h=CConfigTool::GetControlView()->GetFirstVisibleItem();h;h=CConfigTool::GetControlView()->GetNextVisibleItem(h)){ CConfigItem &ti=TI(h); if(ti.Type()==CConfigItem::Integer) { CRect rect; GetItemRect(h,rect); InvalidateRect(rect); } } if(m_pwndCell && TI(m_hInCell).Type()==CConfigItem::Integer) { CString strData; m_pwndCell->GetWindowText(strData); ItemIntegerType n; CUtils::StrToItemIntegerType(strData,n); m_pwndCell->SetWindowText(CUtils::IntToStr(n,CConfigTool::GetConfigToolDoc()->m_bHex)); } } break; case CConfigToolDoc::Clear: deleteZ(m_pwndCell); Invalidate(); UpdateWindow(); // This prevents cell view half of config pane still being displayed break; case CConfigToolDoc::ValueChanged: { CConfigItem *pti=(CConfigItem *)pHint; CRect rect; GetItemRect(pti->HItem(),rect); InvalidateRect(rect); } break; case 0: Invalidate(); break; default: break; } UNUSED_ALWAYS(pSender);}void CCellView::GetItemRect(HTREEITEM h,CRect & rect) const{ CRect rcClient; GetClientRect(rcClient); CConfigTool::GetControlView()->GetItemRect( h, &rect, FALSE ); rect.left=rcClient.left; rect.right=rcClient.right;}void CCellView::GetInCellRect(HTREEITEM h, CRect & rect, BOOL bDropped) const{ CConfigItem &ti=TI(h); GetItemRect(h,rect); switch(ti.Type()){ case CConfigItem::Enum: // Using combobox if(bDropped) { CStringArray arEnum; ti.EvalEnumStrings(arEnum); rect.bottom += (2+(int)arEnum.GetSize()-1)*rect.Height(); } break; case CConfigItem::Integer: case CConfigItem::Double: case CConfigItem::String: // Using editbox //rect.bottom++; //rect.DeflateRect(2,2); // To allow room for the border we draw ourselves //rect.InflateRect(2,2); break; default: return; }}ItemIntegerType CCellView::GetCellValue() const{ // If the item is being edited in-cell, we'll get the data from the control ItemIntegerType rc=0; switch(TI(m_hInCell).Type()){ case CConfigItem::Integer: { CString strData; m_pwndCell->GetWindowText(strData); if(!CUtils::StrToItemIntegerType(strData,rc)){ rc=0; } } break; case CConfigItem::Enum: /* case CConfigItem::Boolean: case CConfigItem::Radio: //rc=((CTreeComboBox *)m_pwndCell)->GetCurSel(); rc=((CComboEdit *)m_pwndCell)->GetCurSel(); break; */ case CConfigItem::String: default: int type=TI(m_hInCell).Type(); UNUSED_ALWAYS(type); ASSERT(FALSE); break; } return rc;}void CCellView::CancelCellEdit(bool bApplyChanges){ if(m_hInCell){ CConfigItem &ti=TI(m_hInCell); if(bApplyChanges){ CString strValue; m_pwndCell->GetWindowText(strValue);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -