-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathaeditory.h
More file actions
177 lines (145 loc) · 6.62 KB
/
aeditory.h
File metadata and controls
177 lines (145 loc) · 6.62 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
/*****************************************************************************
This is part of Alterlib - the free code collection under the MIT License
------------------------------------------------------------------------------
Copyright (C) 2006-2023 Maxim L. Grishin (altmer@arts-union.ru)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*****************************************************************************/
#ifndef AEDITORY_H
#define AEDITORY_H
#include "atypes.h"
#include "at_array.h"
#include "avariant.h"
#include "adelegate.h"
namespace alt {
typedef pair<variant,variant> dualVar;
typedef trio<variant,variant,variant> tribleVar;
class hexEditObject
{
public:
hexEditObject(){object=NULL;}
hexEditObject(const hexEditObject &val){object=val.object;method=val.method;user_val=val.user_val;}
hexEditObject& operator=(const hexEditObject &val)
{
object=val.object;
method=val.method;
user_val=val.user_val;
return *this;
}
template<typename OT>
hexEditObject(OT *obj,intx (OT::*proc)(void*,int,uintx,intx), void *user)
{
object=static_cast<alt::delegateBase*>(obj);
method=static_cast<intx (alt::delegateBase::*)(void*,int,uintx,intx)>(proc);
user_val=user;
}
~hexEditObject(){}
enum Commands
{
SIZE, GET, SET,
COLOR, BASE,
EXIT
};
intx operator()(int code, uintx addr, intx val)
{
if(!object)return 0;
return (object->*method)(user_val,code,addr,val);
}
private:
alt::delegateBase *object;
intx (alt::delegateBase::*method)(void*,int,uintx,intx);
void *user_val;
};
class editory
{
public:
editory();
virtual ~editory();
//размер документа в символах
virtual intx ed_width(){return -1;}
virtual intx ed_height(){return 0;}
virtual uint32 ed_defaultFill(){return 0;}
virtual uint32 ed_defaultColor(){return 0;}
//структура строки
struct edLineData
{
uintx index; //реальный индекс строки, поскольку строки могут быть разной высоты!
uintx count; //высота строки в символах
uint32 background; //подсветка строки
//левый: указатель или данные => изображение,
// строка => строка,
// целое или с запятой => пробелы
// (для отридцательных позиция: с запятой - абсолютная, целое - относительно последнего слова)
//средний: [Если пусто - переход по Ctrl+Click запрещен]
// целое - номер строки для реализации перехода
// прочее - пользовательский идентификатор
//правый: [Если пусто - DblClick-выделение запрещено]
// цвет в случае строки (color, fill - подложка),
// цвет в случае пробелов, (целое - цвет подложки)
// параметры в случае изображения (w,h,count - символов строки)
array<tribleVar> words;
//todo: рассчет позиции здесь! И вообще все отрефакторить!
};
//запрос содержимого строки
virtual edLineData* ed_line(uintx index){return NULL;}
enum Markers
{
BRANCH,
BOOKMARK,
BREAKPOINT,
READTRAP,
WRITETRAP
};
//графические маркеры
struct edMarkers
{
uintx type;
uintx up,down,left,right;
variant inf;
};
virtual array<edMarkers>* ed_markers(uintx start, uintx size){return NULL;}
virtual void setCommentary(intx line, string comment)
{
string key = getLineCommentKey(line);
if(key.isEmpty()) return;
if(comment.isEmpty())
commentary_map.remove(key);
else
commentary_map[key] = comment;
}
virtual string defaultCommentary(intx line)
{
return string();
}
string commentary(intx line)
{
string key = getLineCommentKey(line);
if(key.isEmpty()) return string();
if(!commentary_map.contains(key))
return defaultCommentary(line);
return commentary_map[key];
}
void setCommentaryMap(alt::hash<string,string> map) {commentary_map = map;}
alt::hash<string,string> commentaryMap() {return commentary_map;}
virtual bool onDoubleClick(variant middle) { return false; }
virtual bool onControlClick(variant middle) { return false; }
protected:
//комментарии
alt::hash<string,string> commentary_map;
virtual string getLineCommentKey(intx line);
};
} // namespace alt
#endif // AEDITORY_H