Subversion Repositories Kolibri OS

Rev

Rev 7941 | Rev 7957 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
7921 leency 1
/*
2
	Quark Code Edit v0.2
3
	Author: Kiril Lipatov aka Leency
4
	Licence: GPLv2
5
 
6
	The core components of this app are:
7924 leency 7
		1. list: text grid with keyboard and mouse events
7921 leency 8
		2. lines: the mas of pointers for each line start
9
		3. selection
10
*/
11
 
12
#define MEMSIZE 1024*100
13
 
14
//===================================================//
15
//                                                   //
16
//                       LIB                         //
17
//                                                   //
18
//===================================================//
19
 
20
#include "../lib/io.h"
21
#include "../lib/gui.h"
22
#include "../lib/list_box.h"
23
#include "../lib/draw_buf.h"
24
#include "../lib/events.h"
25
#include "../lib/array.h"
26
#include "../lib/clipboard.h"
27
#include "../lib/math.h"
28
 
29
#include "../lib/obj/box_lib.h"
30
#include "../lib/obj/libini.h"
31
#include "../lib/obj/libimg.h"
32
#include "../lib/obj/iconv.h"
33
#include "../lib/obj/proc_lib.h"
34
 
35
#include "../lib/patterns/simple_open_dialog.h"
36
#include "../lib/patterns/toolbar_button.h"
37
 
38
//===================================================//
39
//                                                   //
40
//                 INTERNAL INCLUDES                 //
41
//                                                   //
42
//===================================================//
43
 
44
proc_info Form;
45
llist list;
46
 
47
#define TOOLBAR_H 38
48
#define TOOLBAR_ICON_WIDTH  24
49
#define TOOLBAR_ICON_HEIGHT 22
50
#define STATUSBAR_H 15
51
#define TAB_H 20
52
 
53
int user_encoding;
54
int real_encoding = CH_CP866;
55
int curcol_scheme;
56
int font_size;
57
 
7945 leency 58
bool enable_edit = false;
59
 
7921 leency 60
#include "data.h"
61
 
7941 leency 62
#include "search.h"
7921 leency 63
#include "selection.h"
64
#include "prepare_page.h"
65
 
66
//===================================================//
67
//                                                   //
68
//                       DATA                        //
69
//                                                   //
70
//===================================================//
71
 
72
scroll_bar scroll = { 15,200,398,44,0,2,115,15,0,0xeeeeee,
73
	0xBBBbbb,0xeeeeee,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
74
 
75
char title[4196];
76
 
77
int reopenin_mx,
78
    theme_mx,
79
    burger_mx,
80
    search_mx;
81
 
82
enum {
83
	CHANGE_CHARSET=12,
84
	REOPEN_IN_APP=1,
85
	COLOR_SCHEME=8,
86
	RMB_MENU,
87
	BTN_FIND_NEXT,
7924 leency 88
	BTN_FIND_CLOSE,
89
	BTN_CHANGE_CHARSET
7921 leency 90
};
91
 
92
dword menu_id;
93
 
94
EVENTS button;
95
EVENTS key;
96
 
97
//===================================================//
98
//                                                   //
99
//                       CODE                        //
100
//                                                   //
101
//===================================================//
102
 
103
void InitDlls()
104
{
105
	load_dll(boxlib,    #box_lib_init,   0);
106
	load_dll(libio,     #libio_init,     1);
107
	load_dll(libimg,    #libimg_init,    1);
108
	load_dll(libini,    #lib_init,       1);
109
	load_dll(iconv_lib, #iconv_open,     0);
110
	load_dll(Proc_lib,  #OpenDialog_init,0);
111
	OpenDialog_init stdcall (#o_dialog);
112
}
113
 
114
void LoadFileFromDocPack()
115
{
116
	dword bufsize = atoi(#param + 1) + 20;
117
	dword bufpointer = malloc(bufsize);
118
 
119
	ESDWORD[bufpointer+0] = 0;
120
	ESDWORD[bufpointer+4] = 8;
7924 leency 121
	IpcSetArea(bufpointer, bufsize);
7921 leency 122
 
123
	SetEventMask(EVM_IPC);
124
	if (@WaitEventTimeout(200) != evIPC) {
125
		notify("'IPC FAIL'E");
126
		return;
127
	}
128
 
129
	io.buffer_data = malloc(ESDWORD[bufpointer+12]);
130
	strcpy(io.buffer_data, bufpointer + 16);
131
}
132
 
133
void main()
134
{
135
	InitDlls();
136
	LoadIniSettings();
137
	EventSetColorScheme(curcol_scheme);
138
	if (param[0] == '*') {
139
		LoadFileFromDocPack();
140
		param[0]='\0';
141
		sprintf(#title, "#DOCPACK - %s", #short_app_name);
142
	} else {
143
		if (streq(#param,"-new")) {Form.left+=40;Form.top+=40;}
144
		LoadFile(#param);
145
	}
146
	SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
147
	loop()
148
	{
149
		switch(@WaitEventTimeout(400))
150
		{
151
			case evMouse:
152
				HandleMouseEvent();
153
				break;
154
			case evKey:
155
				HandleKeyEvent();
156
				break;
157
			case evButton:
158
				HandleButtonEvent();
159
				break;
160
			case evReDraw:
161
				if (CheckActiveProcess(Form.ID)) EventMenuClick();
162
				draw_window();
163
				break;
164
			default:
165
				DrawStatusBar(" "); //clean DrawStatusBar text with delay
166
		}
167
	}
168
}
169
 
170
//===================================================//
171
//                                                   //
172
//                  EVENT HANDLERS                   //
173
//                                                   //
174
//===================================================//
175
 
176
void HandleButtonEvent()
177
{
178
	int btn = GetButtonID();
179
	if (btn==1) {
180
		SaveIniSettings();
181
		ExitProcess();
182
	}
183
	button.press(btn);
184
	switch(btn-10)
185
	{
186
		case BTN_FIND_NEXT:
187
			EventSearchNext();
188
			break;
189
		case BTN_FIND_CLOSE:
190
			search.hide();
191
			break;
7924 leency 192
		case BTN_CHANGE_CHARSET:
193
			EventShowCharsetsList();
194
			break;
7921 leency 195
	}
196
}
197
 
198
void HandleKeyEvent()
199
{
200
	GetKeys();
201
 
7941 leency 202
	switch (key_scancode)
203
	{
204
		case SCAN_CODE_F1:
205
			EventShowInfo();
206
			return;
207
		case SCAN_CODE_ESC:
208
			search.hide();
209
			return;
210
		case SCAN_CODE_ENTER:
211
			if (! search_box.flags & ed_focus) return;
212
		case SCAN_CODE_F3:
213
			EventSearchNext();
214
			return;
215
	}
216
 
217
	if (search.edit_key()) return;
218
 
7921 leency 219
	if (key_modifier & KEY_LCTRL) || (key_modifier & KEY_RCTRL) {
220
		if (key.press(ECTRL + key_scancode)) return;
221
		switch (key_scancode)
222
		{
7941 leency 223
			case SCAN_CODE_KEY_A:
224
				selection.select_all();
225
				DrawPage();
226
				return;
7921 leency 227
			case SCAN_CODE_KEY_X:
228
				EventCut();
229
				return;
230
			case SCAN_CODE_KEY_C:
231
				EventCopy();
232
				return;
233
			case SCAN_CODE_KEY_V:
234
				EventPaste();
235
				return;
236
			case SCAN_CODE_UP:
237
				EventMagnifyPlus();
238
				return;
239
			case SCAN_CODE_DOWN:
240
				EventMagnifyMinus();
241
				return;
242
			case SCAN_CODE_TAB:
243
				EventShowCharsetsList();
244
				return;
245
			case SCAN_CODE_KEY_F:
246
				search.show();
247
				return;
248
		}
249
	}
7941 leency 250
 
251
	if (key_modifier & KEY_LSHIFT) || (key_modifier & KEY_RSHIFT) {
252
		selection.set_start();
7924 leency 253
	} else {
7941 leency 254
		selection.cancel();
7921 leency 255
	}
7941 leency 256
 
257
	if (list.ProcessKey(key_scancode)) {
258
		if (key_modifier & KEY_LSHIFT) || (key_modifier & KEY_RSHIFT) selection.set_end();
259
		DrawPage();
7945 leency 260
		return;