Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

[f56bbc]: src / GUI.h Maximize Restore History

Download this file

GUI.h    173 lines (147 with data), 3.6 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
// 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
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) {
return (left == other.left) &&
(top == other.top) &&
(right == other.right) &&
(bottom == other.bottom);
}
};
#if defined(GTK)
// On GTK+ 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
//typedef std::basic_string<gui_char> gui_string;
gui_string StringFromUTF8(const char *s);
std::string UTF8FromString(const gui_string &s);
gui_string StringFromInteger(int 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 {
int status;
ScintillaFailure(int status_) : status(status_) {
}
};
class ScintillaWindow : public Window {
// Private so ScintillaWindow objects can not be copied
ScintillaWindow(const ScintillaWindow &source);
ScintillaWindow &operator=(const ScintillaWindow &);
SciFnDirect fn;
sptr_t ptr;
public:
ScintillaWindow() : fn(0), ptr(0) {
}
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;
}
sptr_t Call(unsigned int msg, uptr_t wParam=0, sptr_t lParam=0) {
sptr_t retVal = fn(ptr, msg, wParam, lParam);
sptr_t status = fn(ptr, SCI_GETSTATUS, 0, 0);
if (status > 0)
throw ScintillaFailure(status);
return retVal;
}
sptr_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);
}
#endif