Subversion Repositories Kolibri OS

Rev

Rev 7533 | Rev 7594 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. //11.03.12 - start!
  2. //ver 2.21
  3.  
  4. #ifndef AUTOBUILD
  5.         ?include "lang.h--"
  6. #endif
  7.  
  8. #define MEMSIZE 0xFE800
  9. #include "..\lib\mem.h"
  10. #include "..\lib\strings.h"
  11. #include "..\lib\io.h"
  12. #include "..\lib\list_box.h"
  13. #include "..\lib\gui.h"
  14.  
  15. #include "..\lib\obj\box_lib.h"
  16. #include "..\lib\obj\proc_lib.h"
  17.  
  18. #include "..\lib\patterns\select_list.h"
  19. #include "..\lib\patterns\simple_open_dialog.h"
  20.  
  21. #include "ini.h"
  22.  
  23. //===================================================//
  24. //                                                   //
  25. //                       DATA                        //
  26. //                                                   //
  27. //===================================================//
  28.  
  29. #ifdef LANG_RUS
  30.         ?define WINDOW_HEADER " áâனª¨ ®ä®à¬«¥­¨ï"
  31.         ?define T_SKINS       "‘â¨«ì ®ª®­"
  32.         ?define T_WALLPAPERS  "Ž¡®¨"
  33.         ?define T_SELECT_FOLDER "‚ë¡à âì ¯ ¯ªã"
  34.         ?define MENU_LIST "Žâªàëâì ä ©«   Enter\n“¤ «¨âì ä ©«     Del"
  35. #else
  36.         ?define WINDOW_HEADER "Appearance"
  37.         ?define T_SKINS       "Skins"
  38.         ?define T_WALLPAPERS  "Wallpapers"
  39.         ?define T_SELECT_FOLDER "Select wallpapers"
  40.         ?define MENU_LIST "Open file      Enter\nDelete file      Del"
  41. #endif
  42.  
  43. #define PANEL_H 40
  44. #define LP 10 //LIST_PADDING
  45. char skins_folder_path[4096] = "/kolibrios/res/skins";
  46. char wallp_folder_path[4096] = "/kolibrios/res/wallpapers";
  47.  
  48. signed int active_skin=-1, active_wallpaper=-1;
  49. enum {
  50.         SKINS=2,
  51.         WALLPAPERS,
  52.         BTN_SELECT_WALLP_FOLDER };
  53.  
  54. char folder_path[4096];
  55. char cur_file_path[4096];
  56. char cur_skin_path[4096];
  57. char temp_filename[4096];
  58. int files_mas[400];
  59.  
  60. int cur;
  61.  
  62. proc_info Form;
  63. block skp;
  64.  
  65. _tabs tabs = { LP, LP, NULL, NULL, SKINS };
  66.  
  67. checkbox checkbox1 = { "Checkbox", true };
  68. more_less_box spinbox1 = { 23, 0, 999, "SpinBox" };
  69. edit_box edit_cmm = {180,NULL,NULL,0xffffff,0x94AECE,0xFFFfff,0xffffff,
  70.         0x10000000,sizeof(param)-2,#param,0, 0b};
  71.  
  72. char st_str[16];
  73. edit_box edit_st = {180,NULL,NULL,0xffffff,0x94AECE,0xFFFfff,0xffffff,
  74.         0x10000000,sizeof(st_str)-2,#st_str,0, 0b};
  75.  
  76. char default_dir[] = "/rd/1";
  77. od_filter filter2 = { 8, "TXT\0\0" };
  78.  
  79. //===================================================//
  80. //                                                   //
  81. //                       CODE                        //
  82. //                                                   //
  83. //===================================================//
  84.  
  85. void main()
  86. {  
  87.         int id, mouse_clicked;
  88.  
  89.         load_dll(boxlib, #box_lib_init,0);
  90.         load_dll(libini, #lib_init,1);
  91.         load_dll(Proc_lib, #OpenDialog_init,0);
  92.         o_dialog.type = 2; //select folder
  93.         OpenDialog_init stdcall (#o_dialog);
  94.  
  95.         EventTabClick(SKINS);
  96.  
  97.         SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
  98.         loop() switch(WaitEvent())
  99.         {
  100.                 case evMouse:
  101.                         if (!CheckActiveProcess(Form.ID)) break;
  102.                         SelectList_ProcessMouse();
  103.  
  104.                         if (tabs.active_tab == SKINS) {
  105.                                 edit_box_mouse stdcall (#edit_cmm);
  106.                                 edit_box_mouse stdcall (#edit_st);
  107.                         }
  108.  
  109.                         if (mouse.pkm)&&(select_list.MouseOver(mouse.x, mouse.y)) {
  110.                                 select_list.ProcessMouse(mouse.x, mouse.y);
  111.                                 SelectList_Draw();
  112.                                 EventSetNewCurrent();
  113.                                 menu.show(Form.left+mouse.x, Form.top+mouse.y+skin_height, 146, MENU_LIST, 10);
  114.                         }
  115.                         break;
  116.  
  117.                 case evButton:
  118.                         id=GetButtonID();
  119.                         if (id==1) EventExit();
  120.                         if (id==SKINS) EventTabClick(SKINS);
  121.                         if (id==WALLPAPERS) EventTabClick(WALLPAPERS);
  122.                         if (id==BTN_SELECT_WALLP_FOLDER) EventSelectWallpFolder();
  123.                         checkbox1.click(id);
  124.                         spinbox1.click(id);
  125.                         break;
  126.          
  127.                 case evKey:
  128.                         GetKeys();
  129.                         if (select_list.ProcessKey(key_scancode)) EventApply();
  130.                         if (key_scancode==SCAN_CODE_ENTER) EventOpenFile();
  131.                         if (key_scancode==SCAN_CODE_TAB) {
  132.                                 if (tabs.active_tab==SKINS) EventTabClick(WALLPAPERS);
  133.                                 else EventTabClick(SKINS);                             
  134.                         }
  135.                         if (key_scancode==SCAN_CODE_DEL) EventDeleteFile();
  136.  
  137.                         if (! edit_cmm.flags & ed_focus) && (! edit_st.flags & ed_focus)
  138.                         for (id=select_list.cur_y+1; id<select_list.count; id++)
  139.                         {
  140.                                 strcpy(#temp_filename, io.dir.position(files_mas[id]));
  141.                                 if (temp_filename[0]==key_ascii) || (temp_filename[0]==key_ascii-32)
  142.                                 {
  143.                                         select_list.cur_y = id - 1;
  144.                                         select_list.KeyDown();
  145.                                         EventApply();
  146.                                         break;
  147.                                 }
  148.                         }
  149.  
  150.                         if (tabs.active_tab == SKINS) {
  151.                                 EAX = key_ascii << 8;
  152.                                 edit_box_key stdcall (#edit_cmm);
  153.                                 edit_box_key stdcall (#edit_st);                               
  154.                         }
  155.                         break;
  156.                  
  157.                  case evReDraw:        
  158.                         draw_window();
  159.                         if (menu.cur_y) {
  160.                                 if (menu.cur_y == 10) EventOpenFile();
  161.                                 if (menu.cur_y == 11) EventDeleteFile();
  162.                                 menu.cur_y = 0;
  163.                         };
  164.    }
  165. }
  166.  
  167. void draw_window()
  168. {
  169.         system.color.get();    
  170.         DefineAndDrawWindow(screen.width-600/2,80,630,404+skin_height,0x74,0xE4DFE1,WINDOW_HEADER,0);
  171.         GetProcessInfo(#Form, SelfInfo);
  172.         IF (Form.status_window>=2) return;
  173.         DrawWindowContent();
  174. }
  175.  
  176. void DrawWindowContent()
  177. {
  178.         int id;
  179.         incn y;
  180.         int list_w;
  181.  
  182.         if (tabs.active_tab == SKINS) list_w=250; else list_w=370;
  183.  
  184.         DrawWideRectangle(0, 0, Form.cwidth, Form.cheight, LP, system.color.work);
  185.  
  186.         tabs.w = Form.cwidth-LP-LP;
  187.         tabs.h = Form.cheight-LP-LP;
  188.         tabs.draw_wrapper();
  189.        
  190.         tabs.draw_button(tabs.x+TAB_PADDING, SKINS, T_SKINS);  
  191.         tabs.draw_button(strlen(T_SKINS)*8+tabs.x+TAB_PADDING+TAB_PADDING, WALLPAPERS, T_WALLPAPERS);
  192.  
  193.         id = select_list.cur_y;
  194.         SelectList_Init(
  195.                 tabs.x+TAB_PADDING,
  196.                 tabs.y+TAB_HEIGHT+TAB_PADDING,
  197.                 list_w,
  198.                 tabs.h - TAB_PADDING - TAB_PADDING - TAB_HEIGHT,
  199.                 false
  200.                 );
  201.         select_list.cur_y = id;
  202.  
  203.         skp.set_size(
  204.                 select_list.x + select_list.w + TAB_PADDING + scroll1.size_x + 20,
  205.                 select_list.y + 30,
  206.                 list_w,
  207.                 select_list.h - 50
  208.         );
  209.  
  210.         SelectList_Draw();
  211.         SelectList_DrawBorder();
  212.  
  213.         if (tabs.active_tab == SKINS)
  214.         {
  215.                 DrawBar(skp.x-20, select_list.y, skp.w+40, select_list.h, system.color.work);
  216.                 DrawRectangle(skp.x-20, select_list.y, skp.w+40, select_list.h, system.color.work_graph);
  217.                 y.n = skp.y;
  218.                 DrawFrame(skp.x, skp.y, skp.w, skp.h, " Components Preview ");
  219.                 checkbox1.draw(skp.x+20, y.inc(30));
  220.                 spinbox1.draw(skp.x+20, y.inc(30));
  221.                 WriteText(skp.x+20, y.inc(30), 0x90, system.color.work_text, "C-- Edit");
  222.                 DrawEditBoxPos(skp.x+20, y.inc(20), #edit_cmm);
  223.                 WriteText(skp.x+20, y.inc(35), 0x90, system.color.work_text, "Strandard Edit");
  224.                 DrawStEditBoxPos(skp.x+20, y.inc(20), #edit_st);
  225.                 DrawStandartCaptButton(skp.x+20, skp.y+skp.h-40, GetFreeButtonId(), "Button1");
  226.                 DrawStandartCaptButton(skp.x+120, skp.y+skp.h-40, GetFreeButtonId(), "Button2");
  227.         }
  228.         if (tabs.active_tab == WALLPAPERS)
  229.         {
  230.                 DrawStandartCaptButton(select_list.x + select_list.w + scroll1.size_x + 17,
  231.                         select_list.y, BTN_SELECT_WALLP_FOLDER, T_SELECT_FOLDER);
  232.         }
  233. }
  234.  
  235. :void DrawStEditBoxPos(dword x,y, edit_box_pointer)
  236. {
  237.         dword c_inactive = MixColors(system.color.work_graph, system.color.work, 128);
  238.         dword c_active = MixColors(system.color.work_graph, 0, 128);
  239.         ESI = edit_box_pointer;
  240.         ESI.edit_box.left = x;
  241.         ESI.edit_box.top = y;
  242.         ESI.edit_box.blur_border_color = c_inactive;
  243.         ESI.edit_box.focus_border_color = c_active;
  244.         edit_box_draw  stdcall (edit_box_pointer);
  245. }
  246.  
  247.  
  248.  
  249. void Open_Dir()
  250. {
  251.         int j;
  252.         select_list.count = 0;
  253.         if(io.dir.buffer)free(io.dir.buffer);
  254.         io.dir.load(#folder_path,DIR_ONLYREAL);
  255.         for (j=0; j<io.dir.count; j++)
  256.         {
  257.                 strcpy(#temp_filename, io.dir.position(j));
  258.                 strlwr(#temp_filename);
  259.                 if (tabs.active_tab==SKINS) {
  260.                         if (strcmpi(#temp_filename+strlen(#temp_filename)-4,".skn")!=0) continue;
  261.                 }
  262.                 if (tabs.active_tab==WALLPAPERS) {
  263.                         if (strcmpi(#temp_filename+strlen(#temp_filename)-4,".png")!=0)
  264.                         && (strcmpi(#temp_filename+strlen(#temp_filename)-4,".jpg")!=0)
  265.                         && (strcmpi(#temp_filename+strlen(#temp_filename)-5,".jpeg")!=0)
  266.                         && (strcmpi(#temp_filename+strlen(#temp_filename)-4,".gif")!=0) continue;
  267.                 }
  268.                 cur = select_list.count;
  269.                 files_mas[cur]=j;
  270.                 if (!strcmpi("default.skn",#temp_filename)) files_mas[0]><files_mas[select_list.count];
  271.                 select_list.count++;
  272.         }
  273. }
  274.  
  275. void SelectList_DrawLine(dword i)
  276. {
  277.         int yyy, list_last;
  278.  
  279.         cur = select_list.first + i;
  280.         strcpy(#temp_filename, io.dir.position(files_mas[cur]));
  281.         temp_filename[strlen(#temp_filename)-4] = 0;
  282.         yyy = i*select_list.item_h+select_list.y;
  283.        
  284.         if (select_list.cur_y-select_list.first==i)
  285.         {
  286.                 DrawBar(select_list.x, yyy, select_list.w, select_list.item_h, system.color.work_button);
  287.                 WriteText(select_list.x+12,yyy+select_list.text_y,select_list.font_type,system.color.work_button_text, #temp_filename);
  288.         }
  289.         else
  290.         {
  291.                 DrawBar(select_list.x,yyy,select_list.w, select_list.item_h, 0xFFFfff);
  292.                 WriteText(select_list.x+12,yyy+select_list.text_y,select_list.font_type,0, #temp_filename);
  293.         }
  294. }
  295.  
  296. void SelectList_LineChanged()
  297. {
  298.         EventApply();
  299. }
  300.  
  301. //===================================================//
  302. //                                                   //
  303. //                     EVENTS                        //
  304. //                                                   //
  305. //===================================================//
  306.  
  307. void EventTabClick(int N)
  308. {
  309.         tabs.click(N);
  310.         if (tabs.active_tab == SKINS)
  311.         {
  312.                 active_wallpaper = select_list.cur_y;
  313.                 strcpy(#folder_path, #skins_folder_path);
  314.                 select_list.ClearList();
  315.                 Open_Dir();
  316.                 if (!select_list.count) notify("'No skins were found' -E");
  317.                 select_list.cur_y = active_skin;
  318.         }
  319.         if (tabs.active_tab == WALLPAPERS)
  320.         {
  321.                 active_skin = select_list.cur_y;
  322.                 strcpy(#folder_path, #wallp_folder_path);
  323.                 select_list.ClearList();
  324.                 Open_Dir();
  325.                 if (!select_list.count) notify("'No wallpapers were found' -E");
  326.                 select_list.cur_y = active_wallpaper;
  327.         }
  328.         if (select_list.cur_y>select_list.visible) select_list.first=select_list.cur_y; select_list.CheckDoesValuesOkey();
  329.         if (select_list.w) DrawWindowContent();
  330. }
  331.  
  332. void EventDeleteFile()
  333. {
  334.         io.del(#cur_file_path);
  335.         Open_Dir();
  336.         EventApply();
  337. }
  338.  
  339. void EventSetNewCurrent()
  340. {
  341.         cur = select_list.cur_y;
  342.         sprintf(#cur_file_path,"%s/%s",#folder_path,io.dir.position(files_mas[cur]));
  343. }
  344.  
  345. void EventSelectWallpFolder()
  346. {
  347.         OpenDialog_start stdcall (#o_dialog);
  348.         if (o_dialog.status) {
  349.                 strcpy(#wallp_folder_path, #opendir_path);
  350.                 EventTabClick(WALLPAPERS);
  351.         }
  352. }
  353.  
  354. void EventApply()
  355. {
  356.         char kivpath[4096+10];
  357.         EventSetNewCurrent();
  358.         if (tabs.active_tab==SKINS)
  359.         {
  360.                 draw_window();
  361.                 cur = select_list.cur_y;
  362.                 SetSystemSkin(#cur_file_path);
  363.                 strcpy(#cur_skin_path, #cur_file_path);
  364.         }
  365.         if (tabs.active_tab==WALLPAPERS)
  366.         {
  367.                 SelectList_Draw();
  368.                 strcpy(#kivpath, "\\S__");
  369.                 strcat(#kivpath, #cur_file_path);
  370.                 RunProgram("/sys/media/kiv", #kivpath);
  371.         }
  372. }
  373.  
  374. void EventOpenFile()
  375. {
  376.         if (tabs.active_tab==SKINS) RunProgram("/sys/skincfg", #cur_file_path);
  377.         if (tabs.active_tab==WALLPAPERS) RunProgram("/sys/media/kiv", #cur_file_path);
  378. }
  379.  
  380. void EventExit()
  381. {
  382.         ExitProcess();
  383.         SaveSkinSettings(#cur_skin_path);
  384. }
  385.  
  386. stop:
  387.