-
Notifications
You must be signed in to change notification settings - Fork 0
/
CSSListCtrl.cpp
141 lines (114 loc) · 3 KB
/
CSSListCtrl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// CSSListCtrl.cpp : 实现文件
//
#include "stdafx.h"
#include "EBE.h"
#include "CSSListCtrl.h"
#include "EBEView.h"
#include "MainFrm.h"
#include <locale>
// CCSSListCtrl
IMPLEMENT_DYNAMIC(CCSSListCtrl, CMFCListCtrl)
CCSSListCtrl::CCSSListCtrl()
{
}
CCSSListCtrl::~CCSSListCtrl()
{
}
BEGIN_MESSAGE_MAP(CCSSListCtrl, CMFCListCtrl)
ON_NOTIFY_REFLECT(NM_CLICK, &CCSSListCtrl::OnNMClick)
END_MESSAGE_MAP()
// CCSSListCtrl 消息处理程序
BOOL CCSSListCtrl::Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID)
{
// TODO: 在此添加专用代码和/或调用基类
if(CMFCListCtrl::Create(dwStyle, rect, pParentWnd, nID)){
ModifyStyle(0,LVS_REPORT|LVS_SHOWSELALWAYS|LVS_SINGLESEL);
SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
CString strTemp;
ASSERT(strTemp.LoadString(IDS_CSSLISTCTRLCOLUM1));
InsertColumn(0,_T("CSS"),LVCFMT_LEFT,100);
InsertColumn(1,_T("Style"),LVCFMT_LEFT,500);
//载入数据
GetDataFromTxt();
return TRUE;
}
return FALSE;
}
void CCSSListCtrl::GetDataFromTxt()
{
/*
//读取数据
CStdioFile fCssList;
if(fCssList.Open(_T("CssList.txt"),CFile::modeRead)){
CString readStr;
if(fCssList.ReadString(readStr)){
int strNum;
strNum=_wtoi(readStr);
for(int i=0;i<strNum;i++){
fCssList.ReadString(readStr);
InsertItem(i,readStr);
}
}
fCssList.Close();
}*/
}
void CCSSListCtrl::ChangeDataFromModelTxt(CString ModelFilePath)
{
std::vector<CString> vecCss=GetCssFromFile(ModelFilePath);
this->DeleteAllItems();
for(int i=0;i<(int)vecCss.size();i++){
InsertItem(i-1,vecCss[i]);
SetItemText(i-1,1,m_vecCssStyle[i]);
}
UpdateData();
}
std::vector<CString> CCSSListCtrl::GetCssFromFile(CString modelFileName)
{
//区域设定
char* old_locale = _strdup( setlocale(LC_CTYPE,NULL) );
setlocale( LC_CTYPE, "chs" );//设定
m_vecCssStyle.clear();
std::vector<CString> vecCss;
CStdioFile file;
if(!file.Open(modelFileName,CFile::modeRead))
return vecCss;
CString readLine;
bool IsStyle=false;
while(file.ReadString(readLine))
{
if(readLine.Find(_T("<style"))!=-1)
IsStyle=true;
if(readLine.Find(_T("</style>"))!=-1){
IsStyle=false;
break;
}
if(IsStyle){
int pos=readLine.Find(_T("{"));
int posEnd=readLine.Find(_T("}"));
CString cssStyle=readLine.Left(posEnd);
cssStyle=readLine.Right(posEnd-pos);
m_vecCssStyle.push_back(cssStyle);
CString css=readLine.Left(pos);
css.Replace(_T("."),_T(""));
vecCss.push_back(css);
}
}
file.Close();
//恢复区域设定
setlocale( LC_CTYPE, old_locale );
free( old_locale );//还原区域设定
return vecCss;
}
void CCSSListCtrl::OnNMClick(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
// TODO: 在此添加控件通知处理程序代码
int selItem=this->GetSelectionMark();
CString selText=this->GetItemText(selItem,0);
CMainRichEditView* pview;
pview=(CMainRichEditView*)((CMainFrame*)AfxGetApp()->GetMainWnd())->GetActiveFrame()->GetActiveView();
if(NULL==pview)
return;
pview->AddStyle(SECTIONSTYLE,selText);
*pResult = 0;
}