forked from yvt/xtbook
-
Notifications
You must be signed in to change notification settings - Fork 1
/
XTBContentsChooser.cpp
71 lines (53 loc) · 1.63 KB
/
XTBContentsChooser.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
//
// XTBContentsChooser.cpp
// XTBook
//
// Created by Kawada Tomoaki on 8/1/11.
// Copyright 2011 Nexhawks. All rights reserved.
//
#include "XTBContentsChooser.h"
#include <tcw/twApp.h>
#include <tcw/twTimerWithInvocation.h>
#include <tcw/twEvent.h>
#include "XTBListView.h"
#include "XTBContentsDataSource.h"
XTBContentsChooser::XTBContentsChooser(XTBArticle *article,
int currentIndex){
m_listView=new XTBListView(XTBListViewStyleValue1);
m_dataSource=new XTBContentsDataSource(article, currentIndex);
m_listView->setDataSource(m_dataSource);
m_listView->setRect(twRect(twPoint(0,0),startupSize()-getBorderSize()));
m_listView->setParent(this);
m_currentIndex=currentIndex;
if(m_currentIndex!=-1){
twPoint contLoc(0,m_currentIndex*24);
twPoint maxLoc=m_listView->getMaxContentLocation();
if(contLoc.y>maxLoc.y)
contLoc.y=maxLoc.y;
m_listView->setContentLocation(contLoc);
}
m_listView->show();
m_selectAllowed=true;
}
twSize XTBContentsChooser::startupSize() const{
twSize screenSize=tw_app->getScrSize();
return twSize(screenSize.w/2,(screenSize.h*2)/3);
}
XTBContentsChooser::~XTBContentsChooser(){
m_listView->setDataSource(NULL);
delete m_dataSource;
delete m_listView;
}
void XTBContentsChooser::backgroundTouched(){
endDialog(twDR_cancel);
}
void XTBContentsChooser::selected(){
m_lastSelectedIndex=m_listView->getLastActiveRow();
endDialog(twDR_ok);
}
void XTBContentsChooser::command(int){
if(!m_selectAllowed)
return;
m_selectAllowed=false;
tw_event->invokeDelayed(new twNoArgumentMemberFunctionInvocation<XTBContentsChooser>(this, &XTBContentsChooser::selected), 100);
}