forked from dail8859/LuaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI.h
More file actions
208 lines (179 loc) · 4.77 KB
/
Copy pathGUI.h
File metadata and controls
208 lines (179 loc) · 4.77 KB
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
// SciTE - Scintilla based Text Editor
/** @file GUI.h
** Interface to platform GUI facilities.
** Split off from Scintilla's Platform.h to avoid SciTE depending on implementation of Scintilla.
** Implementation in win32/GUIWin.cxx for Windows and gtk/GUIGTK.cxx for GTK+.
**/
// Copyright 1998-2010 by Neil Hodgson <neilh@scintilla.org>
// The License.txt file describes the conditions under which this software may be distributed.
#ifndef GUI_H
#define GUI_H
#define ELEMENTS(a) (sizeof(a) / sizeof(a[0]))
namespace GUI {
class Point {
public:
int x;
int y;
explicit Point(int x_=0, int y_=0) : x(x_), y(y_) {
}
};
class Rectangle {
public:
int left;
int top;
int right;
int bottom;
Rectangle(int left_=0, int top_=0, int right_=0, int bottom_ = 0) :
left(left_), top(top_), right(right_), bottom(bottom_) {
}
bool Contains(Point pt) const {
return (pt.x >= left) && (pt.x <= right) &&
(pt.y >= top) && (pt.y <= bottom);
}
int Width() const { return right - left; }
int Height() const { return bottom - top; }
bool operator==(const Rectangle &other) const {
return (left == other.left) &&
(top == other.top) &&
(right == other.right) &&
(bottom == other.bottom);
}
};
#if defined(GTK) || defined(__APPLE__)
// On GTK+ and OS X use UTF-8 char strings
typedef char gui_char;
typedef std::string gui_string;
#define GUI_TEXT(q) q
#else
// On Win32 use UTF-16 wide char strings
typedef wchar_t gui_char;
typedef std::wstring gui_string;
#define GUI_TEXT(q) L##q
#endif
gui_string StringFromUTF8(const char *s);
gui_string StringFromUTF8(const std::string &s);
std::string UTF8FromString(const gui_string &s);
gui_string StringFromInteger(long i);
gui_string HexStringFromInteger(long i);
typedef void *WindowID;
class Window {
protected:
WindowID wid;
public:
Window() : wid(0) {
}
Window &operator=(WindowID wid_) {
wid = wid_;
return *this;
}
WindowID GetID() const {
return wid;
}
void SetID(WindowID wid_) {
wid = wid_;
}
bool Created() const {
return wid != 0;
}
void Destroy();
bool HasFocus();
Rectangle GetPosition();
void SetPosition(Rectangle rc);
Rectangle GetClientPosition();
void Show(bool show=true);
void InvalidateAll();
void SetTitle(const gui_char *s);
};
typedef void *MenuID;
class Menu {
MenuID mid;
public:
Menu() : mid(0) {
}
MenuID GetID() const {
return mid;
}
void CreatePopUp();
void Destroy();
void Show(Point pt, Window &w);
};
class ElapsedTime {
long bigBit;
long littleBit;
public:
ElapsedTime();
double Duration(bool reset=false);
};
struct ScintillaFailure {
sptr_t status;
explicit ScintillaFailure(sptr_t status_) : status(status_) {
}
};
class ScintillaWindow : public Window {
// Deleted so ScintillaWindow objects can not be copied
ScintillaWindow(const ScintillaWindow &source) = delete;
ScintillaWindow &operator=(const ScintillaWindow &) = delete;
SciFnDirect fn;
sptr_t ptr;
public:
sptr_t status;
ScintillaWindow() : fn(0), ptr(0), status() {
}
void SetID(WindowID wid_) {
wid = wid_;
fn = 0;
ptr = 0;
if (wid) {
fn = reinterpret_cast<SciFnDirect>(Send(SCI_GETDIRECTFUNCTION, 0, 0));
ptr = Send(SCI_GETDIRECTPOINTER, 0, 0);
}
}
bool CanCall() const {
return wid && fn && ptr;
}
intptr_t Call(unsigned int msg, uptr_t wParam=0, sptr_t lParam=0) {
switch (msg) {
case SCI_CREATEDOCUMENT:
case SCI_CREATELOADER:
case SCI_PRIVATELEXERCALL:
case SCI_GETDIRECTFUNCTION:
case SCI_GETDIRECTPOINTER:
case SCI_GETDOCPOINTER:
case SCI_GETCHARACTERPOINTER:
throw ScintillaFailure(SC_STATUS_FAILURE);
}
if (!fn)
throw ScintillaFailure(SC_STATUS_FAILURE);
sptr_t retVal = fn(ptr, msg, wParam, lParam);
status = fn(ptr, SCI_GETSTATUS, 0, 0);
if (status > 0 && status < SC_STATUS_WARN_START)
throw ScintillaFailure(status);
return retVal;
}
sptr_t CallReturnPointer(unsigned int msg, uptr_t wParam=0, sptr_t lParam=0) {
sptr_t retVal = fn(ptr, msg, wParam, lParam);
status = fn(ptr, SCI_GETSTATUS, 0, 0);
if (status > 0 && status < SC_STATUS_WARN_START)
throw ScintillaFailure(status);
return retVal;
}
intptr_t CallPointer(unsigned int msg, uptr_t wParam, void *s) {
return Call(msg, wParam, reinterpret_cast<sptr_t>(s));
}
intptr_t CallString(unsigned int msg, uptr_t wParam, const char *s) {
return Call(msg, wParam, reinterpret_cast<sptr_t>(s));
}
sptr_t Send(unsigned int msg, uptr_t wParam=0, sptr_t lParam=0);
sptr_t SendPointer(unsigned int msg, uptr_t wParam=0, void *lParam=0);
};
bool IsDBCSLeadByte(int codePage, char ch);
}
#if defined(SCI_NAMESPACE)
// Scintilla namespace may or may not be turned on.
// If it is turned on, then make the structures usable without the Scintilla:: prefix
using Scintilla::Sci_CharacterRange;
using Scintilla::Sci_TextRange;
using Scintilla::Sci_TextToFind;
using Scintilla::SCNotification;
#endif
#endif