forked from yvt/xtbook
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathXTBContentsDataSource.cpp
65 lines (55 loc) · 1.5 KB
/
XTBContentsDataSource.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
//
// XTBContentsDataSource.cpp
// XTBook
//
// Created by Kawada Tomoaki on 8/1/11.
// Copyright 2011 Nexhawks. All rights reserved.
//
#include "XTBContentsDataSource.h"
#include "XTBArticle.h"
XTBContentsDataSource::XTBContentsDataSource(XTBArticle *article, int i):
m_article(article),
m_currentIndex(i){
}
XTBContentsDataSource::~XTBContentsDataSource(){
}
int XTBContentsDataSource::rowCount(){
return m_article->indicesCount();
}
bool XTBContentsDataSource::shouldShowPageAtRow(int row) const{
if(row==0)
return true;
XTBArticleIndexItem ind1, ind2;
ind1=m_article->indexAt(row-1);
ind2=m_article->indexAt(row);
return ind1.page!=ind2.page;
}
std::wstring XTBContentsDataSource::stringAtRow(int row){
if(shouldShowPageAtRow(row)){
XTBArticleIndexItem ind=m_article->indexAt(row);
std::wstring pageStr=XTBFormatStd(L"%d", (int)ind.page);
return XTBFormat(XTBLocalizedString(L"XTBBrowserIndexPage"), pageStr.c_str(), NULL);
}else{
return std::wstring();
}
}
std::wstring XTBContentsDataSource::detailStringAtRow(int row){
std::wstring text;
XTBArticleIndexItem ind=m_article->indexAt(row);
int level=ind.level;
for(int i=0;i<level;i++){
text+=L" ";
}
const std::wstring& inText=ind.displayText;
for(size_t i=0;i<inText.size();i++){
if(inText[i]==L'[' || inText[i]==L']')
continue;
text+=inText[i];
}
return text;
}
XTBListViewItemState XTBContentsDataSource::stateAtRow(int row){
if(row==m_currentIndex)
return XTBListViewItemStateChecked;
return XTBListViewItemStateNormal;
}