Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 7920 → Rev 7921

/programs/cmm/eolite/Eolite.c
213,7 → 213,7
else {
param[strrchr(#param, '/')-1] = '\0';
strcpy(#path, #param);
//in future we need also to select file
SelectFileByName(#param+strlen(#param)+1);
}
}
}
712,7 → 712,7
y=filenum*files.item_h+files.y,
icon_y = files.item_h-icon_size/2+1+y;
BDVK file;
char temp_path[sizeof(file_path)];
char full_path[4096];
char label_file_name[4096];
if (filenum==-1) return;
DrawBar(files.x,y,4,files.item_h,bgcol);
727,7 → 727,7
file.sizelo = ESDWORD[file_offet+32];
file.sizehi = ESDWORD[file_offet+36];
file_name_off = file_offet+40;
sprintf(#temp_path,"%s/%s",#path,file_name_off);
sprintf(#full_path,"%s/%s",#path,file_name_off);
 
if (! TestBit(attr, 4) ) //file or folder?
{
742,11 → 742,11
ext1="<DIR>";
WriteTextCenter(files.x+files.w-140, files.text_y+y+1, 72, col.list_gb_text, ext1);
}
if (chrnum(#path, '/')==1) file_size = GetDeviceSizeLabel(#temp_path);
if (chrnum(#path, '/')==1) file_size = GetDeviceSizeLabel(#full_path);
}
if (file_size) WriteText(7-strlen(file_size)*6+files.x+files.w-58,
files.text_y+y+1, files.font_type, col.list_gb_text, file_size);
DrawIconByExtension(#temp_path, ext1, files.x+4, icon_y, bgcol);
DrawIconByExtension(#full_path, ext1, files.x+4, icon_y, bgcol);
 
if (TestBit(attr, 1)) || (TestBit(attr, 2)) text_col=col.list_text_hidden; //system or hiden?
if (bgcol==col.selec)
/programs/cmm/quark/Tupfile.lua
0,0 → 1,6
if tup.getconfig("NO_CMM") ~= "" then return end
if tup.getconfig("LANG") == "ru"
then C_LANG = "LANG_RUS"
else C_LANG = "LANG_ENG" -- this includes default case without config
end
tup.rule("quark.c", "c-- /D=AUTOBUILD /D=$(C_LANG) %f" .. tup.getconfig("KPACK_CMD"), "quark.com")
/programs/cmm/quark/build.bat
0,0 → 1,15
@ECHO OFF
 
C-- "quark.c"
del "quark"
rename "quark.com" "quark"
del warning.txt
 
if exist quark (
"C:\Program Files (x86)\WinImage\winimage.exe" "D:\Kolibri\Desktop\kolibri.img" /H /Q /I quark
d:
cd "D:\Kolibri\Infrastructure\QEMU"
call "z_kos.bat"
) else (
pause
)
/programs/cmm/quark/data.h
0,0 → 1,140
//===================================================//
// //
// TRANSLATIONS //
// //
//===================================================//
 
char short_app_name[] = "Quark";
 
#ifdef LANG_RUS
 
char intro[] = "â® ¯à®á⮩ ¯à®á¬®âà騪 ⥪áâ .
®¯à®¡ã©â¥ ®âªàëâì ª ª®©-­¨¡ã¤ì ⥪áâ®¢ë© ä ©«.";
 
char copied_chars[] = "‘ª®¯¨à®¢ ­® ᨢ®«®¢: %i";
 
char about[] = "Quark Text v0.2
€¢â®à: Š¨à¨«« ‹¨¯ â®¢ aka Leency
‘ ©â: http://aspero.pro
 
ƒ®àï稥 ª« ¢¨è¨:
Ctrl+O - ®âªàëâì ä ©«
Ctrl+I - ¯®ª § âì ¨­ä®à¬ æ¨î ® ä ©«¥
Ctrl+«îá - 㢥«¨ç¨âì èà¨äâ
Ctrl+Œ¨­ãá - 㬥­ìè¨âì èà¨äâ
Ctrl+Tab - ¢ë¡à âì ª®¤¨à®¢ªã ⥪áâ 
Ctrl+E - ®âªàëâì ä ©« ¢ ¤à㣮© ¯à®£à ¬¬¥
 
®¨áª:
Ctrl+F - ®âªàëâì ¯ ­¥«ì ¯®¨áª 
F3 - ¨áª âì ¤ «¥¥
Esc - áªàëâì ¯ ­¥«ì ¯®¨áª ";
 
char color_scheme_names[] = "’¢®à®¦¥ª\nŠ®á¬®á ";
#define FILE_SAVED_WELL "'” ©« ãᯥ譮 á®åà ­¥­'O"
#define FILE_NOT_SAVED "'Žè¨¡ª  ¯à¨ á®åà ­¥­¨¨ ä ©« !'E"
 
char rmb_menu[] =
"‚ë१ âì|Ctrl+X
Š®¯¨à®¢ âì|Ctrl+C
‚áâ ¢¨âì|Ctrl+V
-
Žâªàëâì ¢ ¯ ¯ª¥
Š®¯¨à®¢ âì ¯ãâì ä ©« ";
 
#else
 
char intro[] = "Quark will be a nice Code Editor one day.
Try to open some text file.";
 
char copied_chars[] = "Copied %i chars";
 
char about[] = "Quark Text v0.2
Author: Kiril Lipatov aka Leency
Website: http://aspero.pro
 
Hotkeys:
Ctrl+O - open file
Ctrl+I - show file properties
Ctrl+Plus - bigger font
Ctrl+Down - smaller font
Ctrl+Tab - select charset
Ctrl+E - reopen current file in another app
 
Search:
Ctrl+F - open search
F3 - search next
Esc - hide search bar";
 
char color_scheme_names[] = "Dairy\nCosmos ";
#define FILE_SAVED_WELL "'File saved'O"
#define FILE_NOT_SAVED "'Error saving file!'E"
 
char rmb_menu[] =
"Cut|Ctrl+X
Copy|Ctrl+C
Paste|Ctrl+V
-
Reveal in folder
Copy file path";
 
#endif
 
//===================================================//
// //
// DATA //
// //
//===================================================//
 
dword color_schemes[] = {
//bg, text, scroll, selected, cursor
0xFCF0DA, 0x171501, 0xB2ACA0, 0xD8CAA7, 0xFF0000, //Dairy
0x282923, 0xD8D8D2, 0x555551, 0x5A574A, 0xFFFfff //Cosmos
};
 
struct THEME
{
dword bg, text, cursor;
} theme;
 
char default_dir[] = "/rd/1";
od_filter filter2 = { 33, "TXT\0ASM\0HTM\0HTML\0C\0H\0C--\0H--\0CPP\0\0" };
 
DrawBufer DrawBuf;
 
dword cursor_pos=0;
 
collection_int lines = {0};
 
//===================================================//
// //
// SETTINGS //
// //
//===================================================//
 
 
_ini ini = { "/sys/settings/app.ini", "Quark" };
 
void LoadIniSettings()
{
font_size = ini.GetInt("FontSize", 'M');
user_encoding = ini.GetInt("Encoding", CH_AUTO);
curcol_scheme = ini.GetInt("ColorScheme", 0);
Form.left = ini.GetInt("WinX", 150);
Form.top = ini.GetInt("WinY", 50);
Form.width = ini.GetInt("WinW", 640);
Form.height = ini.GetInt("WinH", 560);
}
 
void SaveIniSettings()
{
ini.SetInt("FontSize", font_size);
ini.SetInt("Encoding", user_encoding);
ini.SetInt("ColorScheme", curcol_scheme);
ini.SetInt("WinX", Form.left);
ini.SetInt("WinY", Form.top);
ini.SetInt("WinW", Form.width);
ini.SetInt("WinH", Form.height);
}
 
 
/programs/cmm/quark/prepare_page.h
0,0 → 1,86
 
void ParseAndPaint()
{
//search.clear();
list.KeyHome();
list.count=0;
 
Parse();
 
list.visible = list.h / list.item_h;
if (list.count < list.visible) {
DrawBuf.bufh = list.visible;
} else {
DrawBuf.bufh = list.count;
}
 
DrawBuf.Init(list.x, list.y, list.w, DrawBuf.bufh+1*list.item_h);
DrawPage();
}
 
void Parse()
{
dword off;
int line_end;
dword line_length=0;
dword line_start = io.buffer_data;
dword buflen = strlen(io.buffer_data) + io.buffer_data;
 
lines.drop();
lines.add(io.buffer_data);
selection.cancel();
 
for (off = io.buffer_data; off < buflen; off++)
{
line_length += list.font_w;
if (line_length + 30 >= list.w) || (ESBYTE[off] == 10)
{
//searching a 'white' for a normal word-break
for(line_end = off; line_end != line_start; line_end--)
{
if (__isWhite(ESBYTE[line_end])) { off=line_end+1; break; }
}
line_length = off - line_start * list.font_w;
list.count++;
lines.add(off);
line_start = off;
line_length = 0;
}
}
lines.add(buflen);
list.count++;
}
 
void PaintVisible()
{
int i;
dword y;
dword line_bg;
bool swapped = false;
 
list.column_max = lines.get(list.cur_y+1) - lines.get(list.cur_y);
list.CheckDoesValuesOkey();
if (selection.end_offset < selection.start_offset) {
swapped = selection.swap_start_end();
}
 
for ( i=list.first; i < list.first+list.visible+1; i++)
{
y = i * list.item_h;
line_bg = theme.bg;
 
if (selection.start_y < i) && (selection.end_y > i) line_bg = selection.color;
DrawBuf.DrawBar(0, y, list.w, list.item_h, line_bg);
 
selection.draw(i);
 
if (i<list.count) DrawBuf.WriteText(3, y+3, list.font_type, theme.text,
lines.get(i), lines.get(i+1) - lines.get(i));
}
 
PutPaletteImage(list.first * DrawBuf.bufw * list.item_h * 4 + buf_data+8,
DrawBuf.bufw, list.h, list.x, list.y, 32, 0);
 
if (swapped) selection.swap_start_end();
}
 
/programs/cmm/quark/quark.c
0,0 → 1,726
/*
Quark Code Edit v0.2
Author: Kiril Lipatov aka Leency
Licence: GPLv2
 
The core components of this app are:
1. list: text grid with keyboard and mouse proceed
2. lines: the mas of pointers for each line start
3. selection
*/
 
#define MEMSIZE 1024*100
 
//===================================================//
// //
// LIB //
// //
//===================================================//
 
#include "../lib/io.h"
#include "../lib/gui.h"
#include "../lib/list_box.h"
#include "../lib/draw_buf.h"
#include "../lib/events.h"
#include "../lib/array.h"
#include "../lib/clipboard.h"
#include "../lib/math.h"
 
#include "../lib/obj/box_lib.h"
#include "../lib/obj/libini.h"
#include "../lib/obj/libimg.h"
#include "../lib/obj/iconv.h"
#include "../lib/obj/proc_lib.h"
 
#include "../lib/patterns/simple_open_dialog.h"
#include "../lib/patterns/toolbar_button.h"
 
//===================================================//
// //
// INTERNAL INCLUDES //
// //
//===================================================//
 
proc_info Form;
llist list;
 
#define TOOLBAR_H 38
#define TOOLBAR_ICON_WIDTH 24
#define TOOLBAR_ICON_HEIGHT 22
#define STATUSBAR_H 15
#define TAB_H 20
 
int user_encoding;
int real_encoding = CH_CP866;
int curcol_scheme;
int font_size;
 
#include "data.h"
 
#include "../txtread/search.h"
#include "selection.h"
#include "prepare_page.h"
 
//===================================================//
// //
// DATA //
// //
//===================================================//
 
scroll_bar scroll = { 15,200,398,44,0,2,115,15,0,0xeeeeee,
0xBBBbbb,0xeeeeee,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
 
char title[4196];
 
bool help_opened = false;
 
int reopenin_mx,
theme_mx,
burger_mx,
search_mx;
 
enum {
CHANGE_CHARSET=12,
REOPEN_IN_APP=1,
COLOR_SCHEME=8,
RMB_MENU,
BTN_FIND_NEXT,
BTN_FIND_CLOSE
};
 
dword menu_id;
 
EVENTS button;
EVENTS key;
 
//===================================================//
// //
// CODE //
// //
//===================================================//
 
void InitDlls()
{
load_dll(boxlib, #box_lib_init, 0);
load_dll(libio, #libio_init, 1);
load_dll(libimg, #libimg_init, 1);
load_dll(libini, #lib_init, 1);
load_dll(iconv_lib, #iconv_open, 0);
load_dll(Proc_lib, #OpenDialog_init,0);
OpenDialog_init stdcall (#o_dialog);
}
 
void LoadFileFromDocPack()
{
dword bufsize = atoi(#param + 1) + 20;
dword bufpointer = malloc(bufsize);
dword filesize;
 
ESDWORD[bufpointer+0] = 0;
ESDWORD[bufpointer+4] = 8;
 
IpcSetArea(bufpointer, bufsize);
SetEventMask(EVM_IPC);
 
if (@WaitEventTimeout(200) != evIPC) {
notify("'IPC FAIL'E");
return;
}
 
io.buffer_data = malloc(ESDWORD[bufpointer+12]);
strcpy(io.buffer_data, bufpointer + 16);
}
 
void main()
{
InitDlls();
LoadIniSettings();
EventSetColorScheme(curcol_scheme);
if (param[0] == '*') {
LoadFileFromDocPack();
param[0]='\0';
sprintf(#title, "#DOCPACK - %s", #short_app_name);
} else {
if (streq(#param,"-new")) {Form.left+=40;Form.top+=40;}
LoadFile(#param);
}
SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
loop()
{
switch(@WaitEventTimeout(400))
{
case evMouse:
HandleMouseEvent();
break;
case evKey:
HandleKeyEvent();
break;
case evButton:
HandleButtonEvent();
break;
case evReDraw:
if (CheckActiveProcess(Form.ID)) EventMenuClick();
draw_window();
break;
default:
DrawStatusBar(" "); //clean DrawStatusBar text with delay
}
}
}
 
//===================================================//
// //
// EVENT HANDLERS //
// //
//===================================================//
 
void HandleButtonEvent()
{
int btn = GetButtonID();
if (btn==1) {
SaveIniSettings();
ExitProcess();
}
button.press(btn);
switch(btn-10)
{
case BTN_FIND_NEXT:
EventSearchNext();
break;
case BTN_FIND_CLOSE:
search.hide();
break;
}
}
 
void HandleKeyEvent()
{
int new_y;
if (help_opened) {
help_opened = false;
DrawPage();
return;
}
GetKeys();
 
if (key_modifier & KEY_LCTRL) || (key_modifier & KEY_RCTRL) {
if (key.press(ECTRL + key_scancode)) return;
switch (key_scancode)
{
case SCAN_CODE_KEY_X:
EventCut();
return;
case SCAN_CODE_KEY_C:
EventCopy();
return;
case SCAN_CODE_KEY_V:
EventPaste();
return;
case SCAN_CODE_UP:
EventMagnifyPlus();
return;
case SCAN_CODE_DOWN:
EventMagnifyMinus();
return;
case SCAN_CODE_TAB:
EventShowCharsetsList();
return;
case SCAN_CODE_KEY_F:
search.show();
return;
case SCAN_CODE_HOME:
list.KeyHome();
list.KeyHomeHor();
DrawPage();
return;
case SCAN_CODE_END:
list.KeyEnd();
list.column_max = strlen(lines.get(list.cur_y));
list.KeyEndHor();
DrawPage();
return;
case SCAN_CODE_KEY_A:
selection.select_all();
DrawPage();
return;
}
}
switch (key_scancode)
{
case SCAN_CODE_F1:
EventShowInfo();
return;
case SCAN_CODE_ESC:
search.hide();
return;
case SCAN_CODE_ENTER:
if (! search_box.flags & ed_focus) return;
case SCAN_CODE_F3:
EventSearchNext();
return;
}
if (search.edit_key()) {
return;
} else if (list.ProcessKey(key_scancode)) {
DrawPage();
return;
}
EventInsertCharIntoText();
}
 
void HandleMouseEvent()
{
mouse.get();
list.wheel_size = 7;
if (list.MouseScroll(mouse.vert)) {
DrawPage();
return;
}
if (!scroll.delta2) && (list.MouseOver(mouse.x, mouse.y)) {
if (mouse.key&MOUSE_LEFT) {
 
GetKeyModifier();
if (key_modifier & KEY_LSHIFT) || (key_modifier & KEY_RSHIFT) {
if (mouse.down) && (!selection.is_active()) selection.set_start();
list.ProcessMouse(mouse.x, mouse.y);
if (mouse.up) selection.set_end();
DrawPage();
return;
}
 
list.ProcessMouse(mouse.x, mouse.y);
if (mouse.down) {
selection.set_start();
}
selection.set_end();
DrawPage();
}
if (mouse.key&MOUSE_RIGHT) && (mouse.up) {
EventShowRmbMenu();
}
return;
}
scrollbar_v_mouse (#scroll);
if (list.first != scroll.position) {
list.first = scroll.position;
DrawPage();
}
search.edit_mouse();
}
 
//===================================================//
// //
// EVENTS //
// //
//===================================================//
 
bool EventSearchNext()
{
int new_y = search.find_next(list.first, theme.bg);
if (new_y) {
list.first = new_y / list.item_h;
list.CheckDoesValuesOkey();
DrawPage();
}
}
 
void EventNewFile()
{
RunProgram(#program_path, "-new");
}
 
void EventOpenDialog()
{
OpenDialog_start stdcall (#o_dialog);
if (o_dialog.status) {
LoadFile(#openfile_path);
ParseAndPaint();
}
}
 
void EventSave()
{
int res;
char backy_param[4096];
if (io.buffer_data) {
io.dir.make("/tmp0/1/quark_backups");
sprintf(#backy_param, "%s -o /tmp0/1/quark_backups", #param);
io.run("/sys/develop/backy", #backy_param);
if (! io.write(#param, io.buffer_data) ) {
notify(FILE_SAVED_WELL);
} else {
notify(FILE_NOT_SAVED);
}
}
}
 
void EventShowFileInfo()
{
char ss_param[4096];
if (!param) return;
strcpy(#ss_param, "-p ");
strcpy(#ss_param+3, #param);
RunProgram("/sys/File managers/Eolite", #ss_param);
}
 
void EventMagnifyMinus()
{
SetSizes('S');
ParseAndPaint();
}
 
void EventMagnifyPlus()
{
SetSizes('M');
ParseAndPaint();
}
 
void EventShowCharsetsList()
{
menu_id = CHANGE_CHARSET;
open_lmenu(Form.left + Form.cwidth, Form.top + skin_height
+ Form.cheight - 6, MENU_ALIGN_BOT_RIGHT, user_encoding+1,
"UTF-8\nKOI8-RU\nCP1251\nCP1252\nISO8859-5\nCP866\nAUTO");
}
 
void EventShowReopenMenu()
{
menu_id = REOPEN_IN_APP;
open_lmenu(Form.left+5 + reopenin_mx, Form.top+29+skin_height,
MENU_ALIGN_TOP_LEFT, NULL,
"Tinypad\nTextEdit\nWebView\nFB2Read\nHexView\nOther");
}
 
void EventShowThemesList()
{
menu_id = COLOR_SCHEME;
open_lmenu(Form.left+2 + theme_mx + 26,
Form.top+29+skin_height, MENU_ALIGN_TOP_RIGHT,
curcol_scheme+1, #color_scheme_names);
}
 
void EventShowRmbMenu()
{
menu_id = RMB_MENU;
open_lmenu(Form.left + mouse.x+4, Form.top + skin_height + mouse.y,
MENU_ALIGN_TOP_LEFT, NULL, #rmb_menu);
}
 
 
void EventSetColorScheme(dword _setn)
{
curcol_scheme = _setn;
theme.bg = color_schemes[curcol_scheme*5];
theme.text = color_schemes[curcol_scheme*5+1];
scroll.bckg_col = theme.bg;
scroll.frnt_col = scroll.line_col = color_schemes[curcol_scheme*5+2];
selection.color = color_schemes[curcol_scheme*5+3];
theme.cursor = color_schemes[curcol_scheme*5+4];
if (list.count) ParseAndPaint();
}
 
 
void EventShowInfo() {
static dword shared_about;
if (!shared_about) {
shared_about = memopen("QUARK_ABOUT", sizeof(about)+1, SHM_OPEN_ALWAYS + SHM_READ);
strcpy(shared_about, #about);
}
RunProgram("/sys/dialog", "-info 122 *QUARK_ABOUT");
}
 
void EventChangeCharset(dword id)
{
if (param[0]=='\0') return;
user_encoding = id;
LoadFile(#openfile_path);
ParseAndPaint();
draw_window();
}
 
void EventOpenFileInOtherApp(dword _id)
{
dword app;
byte open_param[4096];
switch(_id) {
case 0: app = "/sys/tinypad"; break;
case 1: app = "/sys/develop/t_edit"; break;
case 2: app = "/sys/network/webview"; break;
case 3: app = "/sys/fb2read"; break;
case 4: app = "/sys/develop/heed"; break;
case 5: open_param[0]='~';
strcpy(#open_param+1,#param);
RunProgram("/sys/@open", #open_param);
return;
}
RunProgram(app, #param);
}
 
void EventMenuClick()
{
dword click_id = get_menu_click();
 
if (click_id) && (menu_id) switch(menu_id)
{
case CHANGE_CHARSET: EventChangeCharset(click_id-1); break;
case REOPEN_IN_APP: EventOpenFileInOtherApp(click_id-1); break;
case COLOR_SCHEME: EventSetColorScheme(click_id-1); break;
case RMB_MENU: EventRbmMenuClick(click_id-1); break;
default: notify("'Error: wrong menu number'E");
}
menu_id = NULL;
}
 
void EventClickSearch()
{
if (search.visible) {
search.hide();
} else {
search.show();
}
}
 
void EventInsertCharIntoText()
{
dword cursor_pos = lines.get(list.cur_y) + list.cur_x;
 
switch(key_scancode)
{
case SCAN_CODE_DOWN:
case SCAN_CODE_UP:
case SCAN_CODE_HOME:
case SCAN_CODE_END:
case SCAN_CODE_PGUP:
case SCAN_CODE_PGDN:
return;
case SCAN_CODE_BS:
case SCAN_CODE_DEL:
notify("'Not supported yet'A");
return;
}
 
if (list.cur_x >= list.column_max) return;
 
ESBYTE[cursor_pos] = key_ascii;
list.KeyRight();
PaintVisible();
}
 
void EventOpenSysfuncs()
{
if (io.run("/sys/docpack", "f") <= 0) {
notify("'Can not open SysFunctions because\n/rd/1/docpack is not found!'E");
}
}
 
void EventOpenPipet()
{
io.run("/sys/develop/pipet", NULL);
}
 
void EventRbmMenuClick(dword id)
{
switch(id) {
case 0: EventCut(); break;
case 1: EventCopy(); break;
case 2: EventPaste(); break;
case 3: EventRevealInFolder(); break;
case 4: EventCopyFilePath(); break;
}
}
 
void EventCut()
{
//selection.copy();
}
 
void EventCopy()
{
char copy_status_text[32];
 
dword copy_buf;
dword copy_len;
dword copy_start;
dword copy_end;
 
if (selection.is_active()) {
copy_start = selection.start_offset;
copy_end = selection.end_offset;
if (copy_start > copy_end) copy_start >< copy_end;
} else {
copy_start = lines.get(list.cur_y);
copy_end = lines.get(list.cur_y+1);
}
copy_len = copy_end - copy_start;
copy_buf = malloc(copy_len + 2);
strncpy(copy_buf, copy_start, copy_len);
ESBYTE[copy_buf+copy_len] = '\0';
Clipboard__CopyText(copy_buf);
free(copy_buf);
 
sprintf(#copy_status_text, #copied_chars, copy_len);
DrawStatusBar(#copy_status_text);
}
 
void EventPaste()
{
//selection.copy();
}
 
void EventRevealInFolder()
{
RunProgram("/sys/File managers/Eolite", #param);
}
 
void EventCopyFilePath()
{
char copy_status_text[32];
Clipboard__CopyText(#param);
sprintf(#copy_status_text, #copied_chars, strlen(#param));
DrawStatusBar(#copy_status_text);
}
 
//===================================================//
// //
// DRAWS AND OTHER FUNCS //
// //
//===================================================//
 
void EncodeToDos()
{
real_encoding = user_encoding;
 
// Autodetecting charset
if (real_encoding == CH_AUTO) {
real_encoding = CH_CP866;
if (strstr(io.buffer_data, "\208\190")) real_encoding = CH_UTF8;
else {
if (chrnum(io.buffer_data, '\246')>5)
|| (strstr(io.buffer_data, "пр")) real_encoding = CH_CP1251;
}
}
if (real_encoding != CH_CP866)
ChangeCharset(real_encoding, "CP866", io.buffer_data);
}
 
void LoadFile(dword f_path)
{
if (io.buffer_data) free(io.buffer_data);
if (ESBYTE[f_path]) {
strcpy(#param, f_path);
if (!io.read(#param)) goto NO_DATA;
sprintf(#title, "%s - %s", #param, #short_app_name);
EncodeToDos();
}
else {
NO_DATA:
io.buffer_data = malloc(sizeof(intro));
strcpy(io.buffer_data, #intro);
strcpy(#title, #short_app_name);
}
list.ClearList();
}
 
int AddTopBarButton(dword _event, _hotkey, char image_id, int x, pressed) {
if (_hotkey) key.add_n(_hotkey, _event);
return DrawTopPanelButton(button.add(_event), x, 5, image_id, pressed);
}
 
 
void DrawToolbar()
{
#define SMALL_GAP 26+5
#define BIG_GAP 26+18
incn x;
bool thema = false;
bool reopa = false;
 
bool serha = search.draw(BTN_FIND_NEXT+10, BTN_FIND_CLOSE+10, Form.cheight - SEARCH_H - STATUSBAR_H);
if (menu_id == COLOR_SCHEME) thema = true;
if (menu_id == REOPEN_IN_APP) reopa = true;
 
DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 1, sc.work);
DrawBar(0, TOOLBAR_H - 1, Form.cwidth, 1, sc.work_graph);
//AddTopBarButton(#EventNewFile, ECTRL+SCAN_CODE_KEY_N, 2, x.set(8), false);
AddTopBarButton(#EventOpenDialog, ECTRL+SCAN_CODE_KEY_O, 0, x.set(8), false);
//AddTopBarButton(#EventSave, ECTRL+SCAN_CODE_KEY_S, 5, x.inc(SMALL_GAP), false);
AddTopBarButton(#EventShowFileInfo, ECTRL+SCAN_CODE_KEY_I, 10, x.inc(SMALL_GAP), false);
AddTopBarButton(#EventMagnifyMinus, ECTRL+SCAN_CODE_MINUS, 32, x.inc(BIG_GAP), false);
AddTopBarButton(#EventMagnifyPlus, ECTRL+SCAN_CODE_PLUS, 33, x.inc(SMALL_GAP), false);
AddTopBarButton(#EventClickSearch, ECTRL+SCAN_CODE_KEY_F, 49, x.inc(BIG_GAP), serha); search_mx = EAX;
x.set(Form.cwidth-4);
AddTopBarButton(#EventShowInfo, NULL, -1, x.inc(-SMALL_GAP), false); burger_mx = EAX;
AddTopBarButton(#EventShowThemesList, NULL, 40, x.inc(-BIG_GAP), thema); theme_mx = EAX;
AddTopBarButton(#EventShowReopenMenu, ECTRL+SCAN_CODE_KEY_E, 16, x.inc(-SMALL_GAP), reopa); reopenin_mx = EAX;
//AddTopBarButton(#EventOpenSysfuncs, NULL, 18, x.inc(-SMALL_GAP), false);
//AddTopBarButton(#EventOpenPipet, NULL, 39, x.inc(-SMALL_GAP), false);
DefineHiddenButton(Form.cwidth-70, Form.cheight - STATUSBAR_H + 1,
60, 12, button.add(#EventShowCharsetsList));
}
 
void DrawStatusBar(dword _in_text)
{
static char status_text[64];
if (Form.status_window>2) return;
if (_in_text) strncpy(#status_text, _in_text, sizeof(status_text));
DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, sc.work_graph);
DrawBar(0,Form.cheight - STATUSBAR_H+1, Form.cwidth,STATUSBAR_H-1, sc.work);
WriteTextCenter(Form.cwidth-70, Form.cheight - STATUSBAR_H + 4,
60, sc.work_text, real_encoding*10+#charsets);
WriteText(5, Form.cheight - STATUSBAR_H + 4, 0x80, sc.work_text, #status_text);
}
 
void draw_window()
{
int old_w = list.w;
DefineAndDrawWindow(Form.left,Form.top,Form.width,Form.height,0x73,0,#title,0);
GetProcessInfo(#Form, SelfInfo);
sc.get();
if (Form.status_window>2) return;
if (Form.width < 430) { MoveSize(OLD,OLD,430,OLD); return; }
if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; }
button.init(40);
key.init(40);
 
SetSizes(font_size);
 
if ((list.w == old_w) && (list.count)) {
DrawPage();
} else {
ParseAndPaint();
}
 
DrawToolbar();
DrawStatusBar(NULL);
}
 
void DrawPage()
{
scroll.max_area = list.count;
scroll.cur_area = list.visible;
scroll.position = list.first;
scroll.all_redraw = 0;
scroll.start_x = list.x + list.w;
scroll.start_y = list.y;
scroll.size_y = list.h;
scrollbar_v_draw(#scroll);
 
DrawRectangle(scroll.start_x, scroll.start_y, scroll.size_x,
scroll.size_y-1, scroll.bckg_col);
PaintVisible();
}
 
 
void SetSizes(char _size)
{
font_size = _size;
if (font_size == 'S') list.SetFont(6, 9, 00001000b);
if (font_size == 'M') list.SetFont(8, 14, 00011000b);
list.item_w = list.font_w;
list.horisontal_selelection = true;
list.SetSizes(0, TOOLBAR_H, Form.cwidth-scroll.size_x-1,
Form.cheight - TOOLBAR_H - search.height() - STATUSBAR_H /*- TAB_H*/,
math.round(list.font_h * 1.4));
}
/programs/cmm/quark/selection.h
0,0 → 1,94
struct SELECTION {
dword start_x, start_y, start_offset;
dword end_x, end_y, end_offset;
dword color;
bool is_active();
void set_start();
void set_end();
void draw();
void draw_line();
void cancel();
bool swap_start_end();
void normalize();
void select_all();
} selection;
 
bool SELECTION::is_active()
{
if (start_offset) && (end_offset) && (start_offset != end_offset) {
return true;
} else {
return false;
}
}
 
void SELECTION::draw_line(dword x,y,w)
{
DrawBuf.DrawBar(x, y, w, list.item_h, color);
}
 
void SELECTION::draw(int i)
{
if (is_active()) {
if (start_y == i) && (end_y == i) draw_line(start_x * list.font_w+2, start_y * list.item_h, end_x - start_x * list.font_w);
else if (start_y == i) draw_line(start_x * list.font_w+2, start_y * list.item_h, list.w -2- calc(start_x * list.font_w));
else if (end_y == i) draw_line(0, end_y * list.item_h, end_x * list.font_w+2);
//DrawBuf.DrawBar(start_x * list.font_w + 2, start_y * list.item_h, 2, list.item_h, 0x00FF00);
//DrawBuf.DrawBar(end_x * list.font_w + 0, end_y * list.item_h, 2, list.item_h, 0xFF00FF);
}
DrawBuf.DrawBar(list.cur_x * list.font_w + 2, list.cur_y * list.item_h, 2, list.item_h, theme.cursor); //DrawCursor
}
 
void SELECTION::cancel()
{
start_offset = end_offset = lines.get(list.cur_y) + list.cur_x;
start_x = end_x = list.cur_x;
start_y = end_y = list.cur_y;
normalize();
}
 
void SELECTION::set_start()
{
start_x = list.cur_x;
start_y = list.cur_y;
normalize();
start_offset = lines.get(start_y) + start_x;
}
 
void SELECTION::set_end()
{
end_x = list.cur_x;
end_y = list.cur_y;
normalize();
end_offset = lines.get(end_y) + end_x;
debugval("end_x", end_x);
debugval("end_y", end_y);
}
 
 
void SELECTION::normalize()
{
start_x = math.min(start_x, lines.get(start_y+1) - lines.get(start_y));
end_x = math.min(end_x, lines.get(end_y+1) - lines.get(end_y));
}
 
void SELECTION::select_all()
{
start_y = 0;
start_x = 0;
end_y = lines.count-2;
end_x = lines.get(end_y+1) - lines.get(end_y);
//normalize();
start_offset = lines.get(start_y) + start_x;
end_offset = lines.get(end_y) + end_x;
debugval("end_x__", end_x);
debugval("end_y__", end_y);
}
 
bool SELECTION::swap_start_end()
{
start_offset >< end_offset;
start_x >< end_x;
start_y >< end_y;
return true;
}