-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGlobal.h
311 lines (246 loc) · 6.92 KB
/
Global.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
// WinDjView
// Copyright (C) 2004-2015 Andrew Zhezherun
//
// 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.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
// http://www.gnu.org/copyleft/gpl.html
#pragma once
class RefCount
{
public:
RefCount() : m_nRefCount(1) {}
virtual ~RefCount() = 0;
virtual void AddRef()
{
InterlockedIncrement(&m_nRefCount);
}
virtual void Release()
{
if (InterlockedDecrement(&m_nRefCount) <= 0)
delete this;
}
protected:
long m_nRefCount;
};
struct Message
{
Message(int c) : code(c) {}
int code;
};
class Observable;
class Observer
{
public:
virtual ~Observer() {}
virtual void OnUpdate(const Observable* source, const Message* message) = 0;
};
class Observable
{
public:
void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer);
bool HasObservers() const { return !m_observers.empty(); }
bool IsObservedBy(Observer* observer) const
{ return m_observers.find(observer) != m_observers.end(); }
void UpdateObservers(const Message& message);
protected:
set<Observer*> m_observers;
};
bool IsWinVistaOrLater();
void MakeWString(const CString& strText, wstring& result);
bool MakeWString(const GUTF8String& text, wstring& result);
void MakeANSIString(const wstring& text, string& result);
void MakeANSIString(const CString& strText, string& result);
CString MakeCString(const wstring& text);
CString MakeCString(const GUTF8String& text);
GUTF8String MakeUTF8String(const CString& strText);
GUTF8String MakeUTF8String(const wstring& strText);
bool MoveToTrash(LPCTSTR lpszFileName);
void CreateSystemDialogFont(CFont& font);
void CreateSystemIconFont(CFont& font);
void CreateSystemMenuFont(CFont& font);
UINT GetMouseScrollLines();
CRect GetMonitorWorkArea(const CPoint& point);
CRect GetMonitorWorkArea(CWnd* pWnd);
CRect GetMonitorRect(CWnd* pWnd);
bool IsFromCurrentProcess(CWnd* pWnd);
int CompareVersions(const CString& strFirst, const CString& strSecond);
CString FormatDouble(double fValue);
void AFXAPI DDX_MyText(CDataExchange* pDX, int nIDC, double& value, double def = 0.0, LPCTSTR pszSuffix = NULL);
void AFXAPI DDX_MyText(CDataExchange* pDX, int nIDC, DWORD& value, DWORD def = 0, LPCTSTR pszSuffix = NULL);
void SendMessageToVisibleDescendants(HWND hWnd, UINT message, WPARAM wParam = 0, LPARAM lParam = 0);
inline CRect GetClientRect(const CWnd* pWnd)
{
ASSERT(pWnd != NULL);
CRect rect;
pWnd->GetClientRect(rect);
return rect;
}
inline CRect GetClientRect(const CWnd& wnd)
{ return GetClientRect(&wnd); }
inline CSize GetClientSize(const CWnd* pWnd)
{
ASSERT(pWnd != NULL);
CRect rect;
pWnd->GetClientRect(rect);
return rect.Size();
}
inline CSize GetClientSize(const CWnd& wnd)
{ return GetClientSize(&wnd); }
#define PAGE_RENDERED 1
#define PAGE_DECODED 2
#define LINK_CLICKED 3
#define SEARCH_RESULT_CLICKED 4
#define THUMBNAIL_RENDERED 5
#define THUMBNAIL_CLICKED 6
#define CURRENT_PAGE_CHANGED 7
#define ROTATE_CHANGED 8
#define VIEW_ACTIVATED 9
#define ZOOM_CHANGED 10
#define APP_SETTINGS_CHANGED 11
#define APP_LANGUAGE_CHANGED 12
#define BOOKMARK_ADDED 13
#define ANNOTATION_ADDED 14
#define BOOKMARK_DELETED 15
#define ANNOTATION_DELETED 16
#define BOOKMARK_CLICKED 17
#define VIEW_INITIALIZED 18
#define SOURCE_RELEASED 19
#define KEY_STATE_CHANGED 20
#define DICT_LIST_CHANGED 21
#define SIDEBAR_TAB_CHANGED 22
#define TAB_ACTIVATING 23
#define TAB_ACTIVATED 24
#define TAB_CLOSED 25
#define ANNOTATIONS_CHANGED 26
#define BOOKMARKS_CHANGED 27
#define PRINT_PAGES 28
#define EXPORT_PAGES 29
class CDIB;
struct Bookmark;
struct Annotation;
struct PageMsg : public Message
{
PageMsg(int msg, int nPage_)
: Message(msg), nPage(nPage_) {}
int nPage;
};
struct BitmapMsg : public Message
{
BitmapMsg(int msg, int nPage_, CDIB* pDIB_)
: Message(msg), nPage(nPage_), pDIB(pDIB_) {}
int nPage;
CDIB* pDIB;
};
struct LinkClicked : public Message
{
LinkClicked(const GUTF8String& url_)
: Message(LINK_CLICKED), url(url_) {}
const GUTF8String& url;
};
struct SearchResultClicked : public Message
{
SearchResultClicked(int nPage_, int nSelStart_, int nSelEnd_)
: Message(SEARCH_RESULT_CLICKED), nPage(nPage_), nSelStart(nSelStart_), nSelEnd(nSelEnd_) {}
int nPage, nSelStart, nSelEnd;
};
struct RotateChanged : public Message
{
RotateChanged(int nRotate_)
: Message(ROTATE_CHANGED), nRotate(nRotate_) {}
int nRotate;
};
struct AnnotationMsg : public Message
{
AnnotationMsg(int msg, Annotation* pAnno_, int nPage_)
: Message(msg), pAnno(pAnno_), nPage(nPage_) {}
Annotation* pAnno;
int nPage;
};
struct BookmarkMsg : public Message
{
BookmarkMsg(int msg, const Bookmark* pBookmark_)
: Message(msg), pBookmark(pBookmark_) {}
const Bookmark* pBookmark;
};
struct KeyStateChanged : public Message
{
KeyStateChanged(UINT nKey_, bool bPressed_)
: Message(KEY_STATE_CHANGED), nKey(nKey_), bPressed(bPressed_) {}
UINT nKey;
bool bPressed;
};
struct TabMsg : public Message
{
TabMsg(int msg, CWnd* pWnd_, int nTab_)
: Message(msg), pWnd(pWnd_), nTab(nTab_) {}
CWnd* pWnd;
int nTab;
};
struct PageRangeMsg : public Message
{
PageRangeMsg(int msg, const set<int>& pages_)
: Message(msg), pages(pages_) {}
const set<int>& pages;
};
struct MD5
{
MD5();
MD5(const void* data, size_t len);
MD5(const MD5& md5);
void Append(const void* data, size_t len);
void Finish();
CString ToString() const;
bool operator==(const MD5& rhs) const
{ return memcmp(md, rhs.md, sizeof(md)) == 0; }
bool operator<(const MD5& rhs) const
{ return memcmp(md, rhs.md, sizeof(md)) < 0; }
private:
void Block(const void* data);
struct State;
State* state;
unsigned char md[16];
};
string& Base64Encode(string& s);
string& Base64Decode(string& s);
inline CString LoadString(UINT nID)
{
CString strResult;
strResult.LoadString(nID);
return strResult;
}
inline CString FormatString(LPCTSTR pszFormat, ...)
{
CString strResult;
va_list argList;
va_start(argList, pszFormat);
strResult.FormatV(pszFormat, argList);
va_end(argList);
return strResult;
}
inline CString FormatString(UINT nFormatID, ...)
{
CString strResult, strFormat;
VERIFY(strFormat.LoadString(nFormatID));
va_list argList;
va_start(argList, nFormatID);
strResult.FormatV(strFormat, argList);
va_end(argList);
return strResult;
}
inline int GetTotalRotate(GP<DjVuImage> pImage, int nRotate)
{
GP<DjVuInfo> info = pImage->get_info();
return (nRotate + (info != NULL ? info->orientation : 0)) % 4;
}