kolibrios-fun/programs/cmm/notes/notes.c
Kirill Lipatov (Leency) 2ec87d22f7 C-- app updates
WebView 1.8b: 
- key scroll by up and down lists 12 pixels instead of 1
- open app with param when href="" contains '|' symbol, example: href="/sys/tmpdisk|a0"
Eolite 3.96b: 
- fix sorting
- an option to highlight odd lines
- copy path to clipboard by clicking on path bar
- rewrite the code related to device an folder update: so this change removed unnecessary refreshes
- add refresh when /kolibrios mounted
IconEdit 0.57b:
- improve color gradient block
- press Delete key when smth selected fill selection by color2 and resents selection
- impove window appearance when the dark skin is set
- fix a stupid but issue which made impossible to open non-square images
- fix an issue that wrong zoom number displayed
Notes 0.8: 
- reworking, work in progress
- delete binary
Sysmon 0.87:
- minor visible improvement in progress bars
TmpDisk 0.67a:
- deny users to shoot in the foot: show forbid message on /tmp0 deletion

git-svn-id: svn://kolibrios.org@7422 a494cfbc-eb01-0410-851d-a64ba20cac60
2018-10-01 16:41:14 +00:00

227 lines
5.8 KiB
C

// Notes v0.8 ALPHA
#define MEMSIZE 0xDAE80
#include "..\lib\kolibri.h"
#include "..\lib\mem.h"
#include "..\lib\strings.h"
#include "..\lib\fs.h"
#include "..\lib\dll.h"
#include "..\lib\obj\box_lib.h"
#include "..\lib\gui.h"
#include "..\lib\encoding.h"
#include "..\lib\list_box.h"
//===================================================//
// //
// DATA //
// //
//===================================================//
#ifndef AUTOBUILD
#include "lang.h--"
#endif
#ifdef LANG_RUS
?define WINDOW_CAPTION "‡ ¬¥âª¨"
?define DELETE_TEXT "“¤ «¨âì";
#else
?define WINDOW_CAPTION "Notes and reminders"
?define DELETE_TEXT "Delete";
#endif
#define RED_LINE_X 22
#define COL_RED_LINE 0xF3C9C9
unsigned char edge[sizeof(file "edge.raw")]= FROM "edge.raw"; //292x6
#define EDGE_H 6
#define TITLE_H 24
#define HEADER_HEIGHT TITLE_H+EDGE_H
#define LINES_COUNT 13
#define WIN_W 270
#define WIN_H RED_LINE_X*LINES_COUNT+HEADER_HEIGHT+4
#define DELETE_BTN 4;
#define DELETE_W sizeof(DELETE_TEXT)+2*6
#include "engine.h"
dword ed_mouse;
edit_box notebox = {0,999,0,COL_BG_ACTIVE,0x94AECE,COL_BG_ACTIVE,0xffffff,0,
MAX_LINE_CHARS-1,NULL,#ed_mouse,ed_always_focus+ed_focus};
dword lists[] = { 0xEAEAEA, 0xCDCDCD, 0xF0F0F0, 0xD8D8D8, 0 };
bool delete_active = false;
block delBtn;
//===================================================//
// //
// CODE //
// //
//===================================================//
void main()
{
int btn;
dword cur_line_offset;
load_dll(boxlib, #box_lib_init,0);
if (param) notes.OpenTxt(#param); else notes.OpenTxt(abspath("notes.txt"));
notes.cur_y = -1;
SetEventMask(0x27);
loop() switch(WaitEvent())
{
case evMouse:
edit_box_mouse stdcall (#notebox);
mouse.get();
if (delete_active) && (delBtn.hovered()) break;
if (mouse.lkm) && (mouse.y<TITLE_H) && (mouse.x<WIN_W-39) EventDragWindow();
if (mouse.pkm)
&& (notes.MouseOver(mouse.x, mouse.y)) {
if (notes.ProcessMouse(mouse.x, mouse.y)) EventListRedraw();
EventDrawDeleteButton();
}
if (mouse.key&MOUSE_LEFT)&&(mouse.up)
&& (notes.ProcessMouse(mouse.x, mouse.y)) {
EventListRedraw();
EventActivateLine(notes.cur_y);
}
break;
case evButton:
btn = GetButtonID();
switch(btn)
{
case CLOSE_BTN:
EventExitApp();
break;
case DELETE_BTN:
EventDeleteCurrentNode();
break;
default:
notes.lines[btn-CHECKBOX_ID].state ^= 1;
EventListRedraw();
break;
}
break;
case evKey:
GetKeys();
switch(key_scancode)
{
case SCAN_CODE_ESC:
EventExitApp();
break;
case SCAN_CODE_DOWN:
EventActivateLine(notes.cur_y+1);
break;
case SCAN_CODE_UP:
EventActivateLine(notes.cur_y-1);
break;
default:
if (notes.cur_y>=0) {
EAX = key_editbox;
edit_box_key stdcall (#notebox);
}
}
break;
case evReDraw:
draw_window();
}
}
void DrawCloseButton(dword x,y,w,h)
{
DrawRectangle(x,y,w,h,0xC96832);
DrawRectangle3D(x+1,y+1,w-2,h-2,0xE6A37F,0xDD8452);
PutPixel(x+w-1, y+1, 0xE08C5E);
DefineButton(x+1,y+1,w-1,h-1,CLOSE_BTN+BT_HIDE,0);
WriteTextB(-6+w/2+x,h/2-4+y,0x80,0xFFFfff,"x");
}
void draw_window()
{
int i;
DefineUnDragableWindow(100,100,WIN_W, WIN_H);
notes.SetSizes(RED_LINE_X+1, HEADER_HEIGHT, WIN_W-1, RED_LINE_X*LINES_COUNT, RED_LINE_X);
DrawRectangle3D(0,0,WIN_W,TITLE_H-1,0xBB6535, 0xCD6F3B);
DrawRectangle3D(1,1,WIN_W-2,TITLE_H-3,0xEFBFA4, 0xDD8452);
DrawBar(2,2,WIN_W-3,TITLE_H-4,0xE08C5E);
WriteText(9,TITLE_H/2-6,0x90,0xA9613A,WINDOW_CAPTION);
WriteTextB(7,TITLE_H/2-7,0x90,0xFFFfff,WINDOW_CAPTION);
_PutImage(1, TITLE_H, 292,EDGE_H, #edge);
PutPixel(notes.x+RED_LINE_X, notes.y-1, COL_RED_LINE);
ECX-=1; $int 0x40;
DrawCloseButton(WIN_W-23,4,16,16);
DrawRectangle(0,TITLE_H,WIN_W,WIN_H-HEADER_HEIGHT+EDGE_H,0xBBBBBB);
for (i=0; lists[i]!=0; i++) DrawBar(1,WIN_H-i-1, WIN_W-1, 1, lists[i]);
EventListRedraw();
}
void DrawEditBoxN()
{
notebox.width = notes.w-notes.x-8;
notebox.left = notes.x+5;
notebox.pos = notebox.offset = notebox.shift = notebox.shift_old = 0;
notebox.cl_curs_x = notebox.cl_curs_y = 0;
notebox.size = strlen(notebox.text);
notebox.top = notes.cur_y*notes.item_h+4+notes.y;
edit_box_draw stdcall(#notebox);
}
//===================================================//
// //
// EVENTS //
// //
//===================================================//
void EventActivateLine(int line_n)
{
if (line_n<0) || (line_n>notes.count) return;
notes.cur_y = line_n;
notebox.text = notes.DrawLine(notes.cur_y, notes.item_h);
EventListRedraw();
DrawEditBoxN();
}
void EventExitApp()
{
notes.SaveTxt();
ExitProcess();
}
void EventDrawDeleteButton()
{
notes.DrawLine(notes.cur_y, notes.item_h);
delBtn.set_size(WIN_W-DELETE_W-1, notes.cur_y*notes.item_h+notes.y, DELETE_W, notes.item_h-1);
DefineButton(delBtn.x, delBtn.y, delBtn.w, delBtn.h, DELETE_BTN, 0xFF0000);
WriteText(delBtn.x+10, delBtn.h/2-3 + delBtn.y, 0x80, 0xFFFfff, DELETE_TEXT);
notebox.top=-20;
delete_active = true;
}
void EventDeleteCurrentNode()
{
notes.lines[notes.cur_y].Delete();
EventListRedraw();
}
void EventListRedraw()
{
delete_active = false;
DeleteButton(DELETE_BTN);
notes.DrawList();
}
stop: