From 3ad0875d89e59b0c31ba81ffd88c8705787d0132 Mon Sep 17 00:00:00 2001 From: "Kirill Lipatov (Leency)" Date: Sat, 11 Apr 2020 21:17:55 +0000 Subject: [PATCH] Add a new Menu component into IMG, use it in Eolite and Appearance git-svn-id: svn://kolibrios.org@7778 a494cfbc-eb01-0410-851d-a64ba20cac60 --- data/Tupfile.lua | 1 + programs/cmm/appearance/appearance.c | 28 ++- programs/cmm/browser/tabs.h | 10 +- programs/cmm/eolite/Eolite.c | 41 ++-- programs/cmm/eolite/include/menu.h | 233 ++++++++++----------- programs/cmm/eolite/include/translations.h | 4 +- programs/cmm/lib/gui/menu.h | 23 ++ programs/cmm/menu/menu.c | 28 +-- 8 files changed, 193 insertions(+), 175 deletions(-) diff --git a/data/Tupfile.lua b/data/Tupfile.lua index bc68e75e5a..9e3dde67c7 100644 --- a/data/Tupfile.lua +++ b/data/Tupfile.lua @@ -608,6 +608,7 @@ tup.append_table(img_files, { {"TXTREAD", PROGS .. "/cmm/txtread/txtread.com"}, {"TMPDISK", PROGS .. "/cmm/tmpdisk/tmpdisk.com"}, {"DEVELOP/CLIPVIEW", PROGS .. "/cmm/clipview/clipview.com"}, + {"DEVELOP/MENU", PROGS .. "/cmm/menu/menu.com"}, {"File Managers/EOLITE", PROGS .. "/cmm/eolite/Eolite.com"}, {"KF_VIEW", PROGS .. "/cmm/kf_font_viewer/font_viewer.com"}, {"GAMES/CLICKS", PROGS .. "/games/clicks/trunk/clicks.com"}, diff --git a/programs/cmm/appearance/appearance.c b/programs/cmm/appearance/appearance.c index 80d13b0391..76f7ec91b7 100644 --- a/programs/cmm/appearance/appearance.c +++ b/programs/cmm/appearance/appearance.c @@ -32,7 +32,7 @@ ?define T_SKINS "Стиль окон" ?define T_WALLPAPERS "Обои" ?define T_SELECT_FOLDER "Выбрать папку" - ?define MENU_LIST "Открыть файл Enter\nУдалить файл Del" + ?define MENU_LIST "Открыть файл |Enter\nУдалить файл |Del" ?define T_PICTURE_MODE " Положение картинки " ?define T_CHECKBOX_STRETCH "Растянуть" ?define T_CHECKBOX_TILED "Замостить" @@ -42,7 +42,7 @@ ?define T_SKINS "Skins" ?define T_WALLPAPERS "Wallpapers" ?define T_SELECT_FOLDER "Select folder" - ?define MENU_LIST "Open file Enter\nDelete file Del" + ?define MENU_LIST "Open file |Enter\nDelete file |Del" ?define T_PICTURE_MODE " Picture Mode " ?define T_CHECKBOX_STRETCH "Stretch" ?define T_CHECKBOX_TILED "Tiled" @@ -121,11 +121,12 @@ void main() edit_box_mouse stdcall (#edit_st); } - if (mouse.pkm)&&(select_list.MouseOver(mouse.x, mouse.y)) { + if (mouse.key&MOUSE_RIGHT) && (mouse.up) + &&(select_list.MouseOver(mouse.x, mouse.y)) { select_list.ProcessMouse(mouse.x, mouse.y); SelectList_Draw(); EventSetNewCurrent(); - menu.show(Form.left+mouse.x, Form.top+mouse.y+skin_height, 146, MENU_LIST, 10); + open_lmenu(Form.left+mouse.x+5, Form.top+mouse.y+skin_height, 1, 0, MENU_LIST); } break; @@ -174,11 +175,7 @@ void main() case evReDraw: draw_window(); - if (menu.cur_y) { - if (menu.cur_y == 10) EventOpenFile(); - if (menu.cur_y == 11) EventDeleteFile(); - menu.cur_y = 0; - }; + EventHandleMenuClick(); } } @@ -408,4 +405,17 @@ void EventExit() ExitProcess(); } +void EventHandleMenuClick() +{ + switch (get_menu_click()) + { + case 1: + EventOpenFile(); + break; + case 2: + EventDeleteFile(); + break; + }; +} + stop: diff --git a/programs/cmm/browser/tabs.h b/programs/cmm/browser/tabs.h index 82fb2eacd5..fe152cf546 100644 --- a/programs/cmm/browser/tabs.h +++ b/programs/cmm/browser/tabs.h @@ -111,7 +111,7 @@ void DrawActiveTab() else DrawTabsBar(); } -void DrawNewTabButton() +int DrawNewTabButton() { dword btn_light = MixColors(system.color.work_button, 0xFFFfff, 220); dword btn_dark = MixColors(system.color.work_button, 0, 180); @@ -123,7 +123,10 @@ void DrawNewTabButton() DrawRectangle3D(xxx+1, TOOLBAR_H, TAB_H, TAB_H-1, btn_light, btn_dark); PutPixel(xxx+1+TAB_H, TOOLBAR_H, btn_dark); DefineHiddenButton(xxx+1, TOOLBAR_H, TAB_H-1, TAB_H-1, NEW_TAB); - WriteText(xxx+7, TOOLBAR_H+2, 0x90, system.color.work_button_text, "+"); + WriteText(xxx+7, TOOLBAR_H+2, 0x90, system.color.work_button_text, "+"); + return xxx + TAB_H + 2; + } else { + return xxx; } } @@ -132,8 +135,7 @@ void DrawTabsBar() dword i; tab_w = GetTabWidth(); for (i=0; i200 this is only file actions, not supported by folders #ifdef LANG_RUS -char *file_captions[] = { - "Открыть", "Enter",100, - "Открыть с помощью...", "CrlEnt",201, - "Копировать", "Crl+C",104, - "Вырезать", "Crl+X",105, - "Вставить", "Crl+V",106, - "Переименовать", "F2",207, - "Удалить", "Del",108, - "Обновить папку", "F5",109, - "Свойства", "F8",110, - 0, 0, 0}; + +char file_actions[]= +"Открыть |Enter +Открыть с помощью |CrlEnt +Копировать |Crl+C +Вырезать |Crl+X +Вставить |Crl+V +Переименовать |F2 +Удалить |Del +Свойства |F8"; +char folder_actions[]= +"Открыть |Enter +Копировать |Crl+C +Вырезать |Crl+X +Вставить |Crl+V +Удалить |Del +Свойства |F8"; +char empty_folder_actions[]= +"Вставить |Crl+V"; + #elif LANG_EST -char *file_captions[] = { - "Ava", "Enter",100, - "Ava ...", "CrlEnt",201, - "Kopeeri", "Crl+C",104, - "Lїika", "Crl+X",105, - "Aseta", "Crl+V",106, - "Nimeta №mber", "F2",207, - "Kustuta", "Del",108, - "Vфrskenda", "F5",109, - "Properties", "F8",110, - 0, 0, 0}; +char file_actions[]= +"Ava |Enter +Ava ... |CrlEnt +Kopeeri |Crl+C +Lїika |Crl+X +Aseta |Crl+V +Nimeta №mber |F2 +Kustuta |Del +Properties |F8"; +char folder_actions[]= +"Ava |Enter +Kopeeri |Crl+C +Lїika |Crl+X +Aseta |Crl+V +Kustuta |Del +Properties |F8"; +char empty_folder_actions[]= +"Aseta |Crl+V"; + #else -char *file_captions[] = { - "Open", "Enter",100, - "Open with...", "CrlEnt",201, - "Copy", "Crl+C",104, - "Cut", "Crl+X",105, - "Paste", "Crl+V",106, - "Rename", "F2",207, - "Delete", "Del",108, - "Refresh", "F5",109, - "Properties", "F8",110, - 0, 0, 0}; +char file_actions[]= +"Open |Enter +Open with... |CrlEnt +Copy |Crl+C +Cut |Crl+X +Paste |Crl+V +Rename |F2 +Delete |Del +Properties |F8"; +char folder_actions[]= +"Open |Enter +Copy |Crl+C +Cut |Crl+X +Paste |Crl+V +Delete |Del +Properties |F8"; +char empty_folder_actions[]= +"Paste |Crl+V"; + #endif -llist rbmenu; -int cur_action_buf; +//Обновить папку |F5 +//Vфrskenda |F5 +//Refresh |F5 -void FileMenu() +enum { MENU_DIR=1, MENU_FILE, MENU_NO_FILE, MENU_BURGER }; + +bool active_menu = false; + +void EventMenuClick(dword _id) { - proc_info MenuForm; - int index; - - rbmenu.ClearList(); - rbmenu.SetFont(6, 9, 0x80); - rbmenu.SetSizes(0,0,10,0,18); - for (index=0; file_captions[index]!=0; index+=3) - { - if (selected_count > 0) { - //if there are files selected then show only specific menu items - if (file_captions[index+2]>=200) continue; - if (file_captions[index+2]==100) continue; - } - else if (itdir) && (file_captions[index+2]>=200) continue; - if (strlen(file_captions[index])>rbmenu.w) rbmenu.w = strlen(file_captions[index]); - rbmenu.count++; - rbmenu.visible++; + if (active_menu == MENU_NO_FILE) switch(_id) { + case 1: Paste(); break; } - rbmenu.w = rbmenu.w + 3 * rbmenu.font_w + 50; - rbmenu.h = rbmenu.count * rbmenu.item_h; - SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE); - goto _MENU_DRAW; - - loop() switch(WaitEvent()) - { - case evMouse: - mouse.get(); - if (!CheckActiveProcess(MenuForm.ID)){ cmd_free=1; ExitProcess();} - else if (mouse.move)&&(rbmenu.ProcessMouse(mouse.x, mouse.y)) MenuListRedraw(); - else if (mouse.key&MOUSE_LEFT)&&(mouse.up) {action_buf = cur_action_buf; cmd_free=1; ExitProcess(); } - break; - - case evKey: - GetKeys(); - if (key_scancode == SCAN_CODE_ESC) {cmd_free=1;ExitProcess();} - if (key_scancode == SCAN_CODE_ENTER) {action_buf = cur_action_buf; cmd_free=1; ExitProcess(); } - if (rbmenu.ProcessKey(key_scancode)) MenuListRedraw(); - break; - - case evReDraw: _MENU_DRAW: - if (menu_call_mouse) - DefineAndDrawWindow(mouse.x+Form.left+5, mouse.y+Form.top+skin_height,rbmenu.w+3,rbmenu.h+6,0x01, 0, 0, 0x01fffFFF); - else - DefineAndDrawWindow(Form.left+files.x+15, files.item_h*files.cur_y+files.y+Form.top+30,rbmenu.w+3,rbmenu.h+6,0x01, 0, 0, 0x01fffFFF); - GetProcessInfo(#MenuForm, SelfInfo); - DrawRectangle(0,0,rbmenu.w+1,rbmenu.h+2,col.graph); - DrawBar(1,1,rbmenu.w,1,0xFFFfff); - DrawPopupShadow(1,1,rbmenu.w,rbmenu.h,0); - MenuListRedraw(); + if (active_menu == MENU_FILE) switch(_id) { + case 1: Open(0); break; + case 2: ShowOpenWithDialog(); break; + case 3: Copy(#file_path, NOCUT); break; + case 4: Copy(#file_path, CUT); break; + case 5: Paste(); break; + case 6: FnProcess(2); break; + case 7: Del_Form(); break; + case 8: FnProcess(8); break; } + if (active_menu == MENU_DIR) switch(_id) { + case 1: Open(0); break; + case 2: Copy(#file_path, NOCUT); break; + case 3: Copy(#file_path, CUT); break; + case 4: Paste(); break; + case 5: Del_Form(); break; + case 6: FnProcess(8); break; + } + active_menu = NULL; } -void MenuListRedraw() +void EventShowListMenu() { - int start_y=0; - int index; + dword text; - dword m_col_bg; - dword m_col_text; - dword m_col_sh_text; + pause(3); + + if (!files.count) { + text = #empty_folder_actions; + active_menu = MENU_NO_FILE; + } else if (itdir) { + text = #folder_actions; + active_menu = MENU_DIR; + } else { + text = #file_actions; + active_menu = MENU_FILE; + } + open_lmenu(mouse.x+Form.left+5, mouse.y+Form.top+3+skin_height, 1, 0, text); +} + +bool GetMenuClick() +{ + dword chick_id; + if (active_menu) && (chick_id = get_menu_click()) { + EventMenuClick(chick_id); + return false; + } + return true; + + +} - for (index=0; file_captions[index*3]!=0; index++) - { - if (selected_count > 0) { - if (file_captions[index*3+2]==100) continue; - if (file_captions[index*3+2]>=200) continue; - } - else if ((itdir) && (file_captions[index*3+2]>=200)) continue; - DrawBar(1,start_y+2,1,rbmenu.item_h,0xFFFfff); - if (start_y/rbmenu.item_h==rbmenu.cur_y) - { - cur_action_buf = file_captions[index*3+2]; - m_col_bg = 0xFFFfff; - m_col_sh_text = 0xFAFAFA; - m_col_text = 0; - } - else - { - m_col_bg = col.work; - m_col_text = system.color.work_text; - m_col_sh_text = system.color.work_light; - } - DrawBar(2, start_y+2, rbmenu.w-1, rbmenu.item_h, m_col_bg); - WriteText(8, start_y + rbmenu.text_y + 4, rbmenu.font_type, m_col_sh_text, file_captions[index*3]); - WriteText(7, start_y + rbmenu.text_y + 3, rbmenu.font_type, m_col_text, file_captions[index*3]); - WriteText(-strlen(file_captions[index*3+1])-1*rbmenu.font_w + rbmenu.w, start_y + rbmenu.text_y + 3, rbmenu.font_type, 0x888888, file_captions[index*3+1]); - start_y+=rbmenu.item_h; - } -} \ No newline at end of file diff --git a/programs/cmm/eolite/include/translations.h b/programs/cmm/eolite/include/translations.h index 9851750ce3..f47db9fd30 100644 --- a/programs/cmm/eolite/include/translations.h +++ b/programs/cmm/eolite/include/translations.h @@ -1,5 +1,5 @@ -#define TITLE "Eolite File Manager 4.21c" -#define ABOUT_TITLE "EOLITE 4.21c" +#define TITLE "Eolite File Manager 4.22" +#define ABOUT_TITLE "EOLITE 4.22" #ifdef LANG_RUS ?define T_FILE "Файл" diff --git a/programs/cmm/lib/gui/menu.h b/programs/cmm/lib/gui/menu.h index 0c1b35226c..09be90fa42 100644 --- a/programs/cmm/lib/gui/menu.h +++ b/programs/cmm/lib/gui/menu.h @@ -79,4 +79,27 @@ KillProcess(menu_process_id); } + +:dword shared_mem = NULL; +:char shared_name[] = "LMENU"; +:void open_lmenu(dword _x, _y, _position, _selected, _text) +{ + if (!shared_mem) { + shared_mem = memopen(#shared_name, 20, SHM_CREATE); + if (EDX) shared_mem = memopen(#shared_name, 20, SHM_WRITE); + } + ESDWORD[shared_mem + 4] = _x; + ESDWORD[shared_mem + 8] = _y; + ESDWORD[shared_mem + 12] = _position; + ESDWORD[shared_mem + 16] = _selected; + RunProgram("/sys/develop/menu", _text); +} + +:dword get_menu_click() +{ + dword res = ESDWORD[shared_mem]; + ESDWORD[shared_mem] = 0; + return res; +} + #endif \ No newline at end of file diff --git a/programs/cmm/menu/menu.c b/programs/cmm/menu/menu.c index abaea6b9d5..80acfd4a8c 100644 --- a/programs/cmm/menu/menu.c +++ b/programs/cmm/menu/menu.c @@ -1,7 +1,7 @@ #define MEMSIZE 4096*40 -#include "../lib/io.h" #include "../lib/gui.h" +#include "../lib/io.h" #include "../lib/collection.h" #include "../lib/list_box.h" #include "../lib/fs.h" @@ -11,7 +11,6 @@ llist menu1; collection names; collection hotkeys; -dword shared_mem; int win_x, win_y; @@ -20,8 +19,7 @@ int max_hotkey_len; int selected = 0; -char shared_name[] = "LMENU"; - +/* dword cur_param = #param; int GetNextParam() { @@ -32,15 +30,16 @@ int GetNextParam() cur_param = next_param+1; return result; } +*/ void GetWindowPosition() { int position, rez; - shared_mem = memopen(#shared_name, 4, SHM_WRITE); - win_x = GetNextParam(); - win_y = GetNextParam(); - selected = GetNextParam(); - position = GetNextParam(); + shared_mem = memopen(#shared_name, 20, SHM_WRITE); + win_x = ESDWORD[shared_mem + 4]; + win_y = ESDWORD[shared_mem + 8]; + position = ESDWORD[shared_mem + 12]; + selected = ESDWORD[shared_mem + 16]; if (position==2) win_x -= menu1.w; if (position==3) { win_x -= menu1.w; @@ -76,7 +75,12 @@ void main() { proc_info Form; - GetMenuItems(strchr(#param, '\n') + 2); + if (!param) + die( +"'This is a menu component used in Eolite, WebView, etc... +Please forget it if you are not a developer ;)' -I"); + + GetMenuItems(#param); max_name_len = strlen(names.get(0)) * 6; max_hotkey_len = strlen(hotkeys.get(0)) * 6; @@ -170,12 +174,12 @@ void draw_list() void click() { - ESBYTE[shared_mem] = byte menu1.cur_y + 1; + ESDWORD[shared_mem] = menu1.cur_y + 1; ExitProcess(); } void exit() { - ESBYTE[shared_mem] = 0; + ESDWORD[shared_mem] = 0; ExitProcess(); }