forked from yvt/xtbook
-
Notifications
You must be signed in to change notification settings - Fork 1
/
TWViewer.h
140 lines (108 loc) · 3.83 KB
/
TWViewer.h
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
/*
* TWViewer.h
* XTBook
*
* Created by Nexhawks on 2/23/11.
* Copyright 2011 Nexhawks. All rights reserved.
*
*/
/*
* This file is part of XTBook.
*
* XTBook 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 3 of the License, or
* (at your option) any later version.
*
* XTBook 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 XTBook. If not, see <http://www.gnu.org/licenses/>.
*/
#include <vector>
#include "XTBViewer.h"
#include "TWiki/TWTypes.h"
#include "TWViewerImageManager.h"
#include <tcw/twTimer.h>
class twSDLSemaphore;
class TWHTMLElement;
class TWRenderObject;
class TWHTMLBodyElement;
class TWRenderView;
class TWRenderDC;
class TWRenderManager;
class TWRenderBoxModelObject;
class TWNode;
struct TWViewerTouchStartRenderObjectCallbackArgs;
enum TWViewerEventType{
TWViewerEventTypeLinkTouched=0,
TWViewerEventTypeLinkHolded,
TWViewerEventTypeTextSelected
};
void touchStartRenderObjectCallbackDriver(void *data, TWNode *node);
class TWViewer : public XTBViewer{
friend void touchStartRenderObjectCallbackDriver(void *data, TWNode *node);
private:
TWHTMLBodyElement *m_htmlDocument;
TWRenderView *m_renderView;
TWRenderManager *m_fontManager;
TWViewerImageManager m_imageManager;
volatile bool m_layouted;
bool m_needsLayout;
int m_contentWidth;
bool m_drag;
TWHTMLElement *m_dragElement;
twRect m_dragRect;
bool m_selecting;
unsigned int m_selectionStart;
unsigned int m_selectionEnd;
bool m_holded;
twTimer *m_holdTimer;
twPoint m_holdPos;
twTicks m_lastInvalidTouch;
std::map<std::wstring, TWRenderObject *> m_ids;
std::map<std::wstring, TWHTMLElement *> m_domIds;
twSDLSemaphore *m_renderViewSemaphore;
void doLayout();
void startLayout();
virtual void paintContents(twDC *, twRect);
bool isElementActive(TWHTMLElement *) const;
TWHTMLElement *elementForRenderer(TWRenderObject *) const;
TWRenderObject *activeRenderObjectAtPoint(const twPoint&) const;
bool shouldLayoutAync() const;
void dragEnded();
void holded();
void searchNodeForIds(TWRenderObject *);
void searchNodeForDomIds(TWHTMLElement *);
TWViewerEventType m_lastEventType;
protected:
void touchStartRenderObjectCallback(TWViewerTouchStartRenderObjectCallbackArgs *,
TWRenderBoxModelObject *) const;
virtual void fillTopMargin(twDC *, twRect) const;
virtual void fillBottomMargin(twDC *, twRect) const;
public:
TWViewer();
virtual ~TWViewer();
// will be deleted in the destructor
void setHTMLDocument(TWHTMLBodyElement *);
TWHTMLBodyElement *htmlDocument() const;
virtual void setRect(const twRect&);
virtual void clientTouchStarted(const twPoint&, twMouseButton);
virtual void clientTouchEnded(const twPoint&, twMouseButton);
virtual void clientTouchCancelled(const twPoint&, twMouseButton);
virtual void clientDragStarted(const twPoint&, twMouseButton);
virtual void clientDragMoved(const twPoint&, twMouseButton);
virtual void clientDragEnded(const twPoint&, twMouseButton);
virtual void clientPaint(const twPaintStruct&);
TWHTMLElement *getLastTouchedElement() const{return m_dragElement;}
twRect getLastTouchedRect() const;
bool getHolded() const{return m_holded;}
TWViewerEventType getLastEventType() const{return m_lastEventType;}
std::wstring getLastSelectedText() const;
twRect rectForId(const std::wstring&) const;
TWRenderObject *renderObjectForId(const std::wstring&) const;
TWHTMLElement *htmlElementForId(const std::wstring&) const;
};