Subversion Repositories Kolibri OS

Rev

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

  1. //11.03.12 - start!
  2. //ver 2.0
  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\menu.h"
  14. #include "..\lib\gui.h"
  15. #include "..\lib\obj\box_lib.h"
  16. #include "..\lib\patterns\select_list.h"
  17.  
  18.  
  19. //===================================================//
  20. //                                                   //
  21. //                       DATA                        //
  22. //                                                   //
  23. //===================================================//
  24.  
  25. #ifdef LANG_RUS
  26.         ?define WINDOW_HEADER " áâனª¨ ®ä®à¬«¥­¨ï"
  27.         ?define T_SKINS       "‘â¨«ì ®ª®­"
  28.         ?define T_WALLPAPERS  "Ž¡®¨"
  29. #else
  30.         ?define WINDOW_HEADER "Appearance"
  31.         ?define T_SKINS       "Skins"
  32.         ?define T_WALLPAPERS  "Wallpappers"
  33. #endif
  34.  
  35. #define PANEL_H 40
  36. #define LP 10 //LIST_PADDING
  37. #define SKINS_STANDART_PATH "/kolibrios/res/skins"                                                     
  38. #define WALP_STANDART_PATH "/kolibrios/res/wallpapers"
  39.  
  40. signed int active_skin=-1, active_wallpaper=-1;
  41. enum { SKINS=2, WALLPAPERS };
  42.  
  43. char folder_path[4096];
  44. char cur_file_path[4096];
  45. char temp_filename[4096];
  46. int files_mas[400];
  47.  
  48. int cur;
  49.  
  50. proc_info Form;
  51. block skp;
  52.  
  53. _tabs tabs = { LP, LP, NULL, NULL, SKINS };
  54.  
  55. checkbox checkbox1 = { "Checkbox", true };
  56. more_less_box spinbox1 = { 23, 0, 999, "SpinBox" };
  57. edit_box edit1 = {180,NULL,NULL,0xffffff,0x94AECE,0xFFFfff,0xffffff,
  58.         0x10000000,sizeof(param),#param,0, 0b};
  59.  
  60. #define MENU_LIST "Open file     Enter\nDelete          Del"
  61.  
  62. //===================================================//
  63. //                                                   //
  64. //                       CODE                        //
  65. //                                                   //
  66. //===================================================//
  67.  
  68. void main()
  69. {  
  70.         int id, mouse_clicked;
  71.  
  72.         SetEventMask(0x27);
  73.         load_dll(boxlib, #box_lib_init,0);
  74.         EventTabClick(SKINS);
  75.         loop() switch(WaitEvent())
  76.         {
  77.                 case evMouse:
  78.                         if (!CheckActiveProcess(Form.ID)) break;
  79.                         SelectList_ProcessMouse();
  80.                         edit_box_mouse stdcall (#edit1);
  81.  
  82.                         if (mouse.pkm)&&(select_list.MouseOver(mouse.x, mouse.y)) {
  83.                                 select_list.ProcessMouse(mouse.x, mouse.y);
  84.                                 SelectList_Draw();
  85.                                 menu.show(Form.left+mouse.x, Form.top+mouse.y+skin_height, 185, MENU_LIST, 10);
  86.                         }
  87.                         break;
  88.  
  89.                 case evButton:
  90.                         id=GetButtonID();
  91.                         if (id==1) ExitProcess();
  92.                         if (id==SKINS) EventTabClick(SKINS);
  93.                         if (id==WALLPAPERS) EventTabClick(WALLPAPERS);
  94.                         checkbox1.click(id);
  95.                         spinbox1.click(id);
  96.                         break;
  97.          
  98.                 case evKey:
  99.                         GetKeys();
  100.                         if (select_list.ProcessKey(key_scancode)) EventApply();
  101.                         if (key_scancode==SCAN_CODE_ENTER) EventOpenFile();
  102.                         if (key_scancode==SCAN_CODE_TAB)
  103.                                 if (tabs.active_tab==SKINS) EventTabClick(WALLPAPERS);
  104.                                 else EventTabClick(SKINS);
  105.                         if (key_scancode==SCAN_CODE_DEL) EventDeleteFile();
  106.                         for (id=select_list.cur_y+1; id<select_list.count; id++)
  107.                         {
  108.                                 strcpy(#temp_filename, io.dir.position(files_mas[id]));
  109.                                 if (temp_filename[0]==key_ascii) || (temp_filename[0]==key_ascii-32)
  110.                                 {
  111.                                         select_list.cur_y = id - 1;
  112.                                         select_list.KeyDown();
  113.                                         EventApply();
  114.                                         break;
  115.                                 }
  116.                         }
  117.                         EAX= key_ascii << 8;
  118.                         edit_box_key stdcall (#edit1);
  119.                         break;
  120.                  
  121.                  case evReDraw:
  122.                         system.color.get();                    
  123.                         DefineAndDrawWindow(screen.width-600/2,80,630,404+skin_height,0x74,0xE4DFE1,WINDOW_HEADER,0);
  124.                         GetProcessInfo(#Form, SelfInfo);
  125.                         IF (Form.status_window>=2) break;
  126.                         DrawWindowContent();
  127.                         if (menu.list.cur_y) {
  128.                                 if (menu.list.cur_y == 10) EventOpenFile();
  129.                                 if (menu.list.cur_y == 11) EventDeleteFile();
  130.                                 menu.list.cur_y = 0;
  131.                         };
  132.    }
  133. }
  134.  
  135.  
  136. void DrawWindowContent()
  137. {
  138.         int id;
  139.         incn y;
  140.  
  141.         DrawWideRectangle(0, 0, Form.cwidth, Form.cheight, LP, system.color.work);
  142.  
  143.         tabs.w = Form.cwidth-LP-LP;
  144.         tabs.h = Form.cheight-LP-LP;
  145.         tabs.draw_wrapper();
  146.        
  147.         tabs.draw_button(tabs.x+TAB_PADDING, SKINS, T_SKINS);  
  148.         tabs.draw_button(strlen(T_SKINS)*8+tabs.x+TAB_PADDING+TAB_PADDING, WALLPAPERS, T_WALLPAPERS);
  149.  
  150.         id = select_list.cur_y;
  151.         SelectList_Init(
  152.                 tabs.x+TAB_PADDING,
  153.                 tabs.y+TAB_HEIGHT+TAB_PADDING,
  154.                 250,
  155.                 tabs.h - TAB_PADDING - TAB_PADDING - TAB_HEIGHT,
  156.                 false
  157.                 );
  158.         select_list.cur_y = id;
  159.  
  160.         skp.set_size(
  161.                 select_list.x + select_list.w + TAB_PADDING + scroll1.size_x + 20,
  162.                 select_list.y + 30,
  163.                 250,
  164.                 select_list.h - 50
  165.         );
  166.  
  167.         SelectList_Draw();
  168.         SelectList_DrawBorder();
  169.  
  170.         if (tabs.active_tab == SKINS)
  171.         {
  172.                 DrawBar(skp.x-20, select_list.y, skp.w+40, select_list.h, system.color.work);
  173.                 DrawRectangle(skp.x-20, select_list.y, skp.w+40, select_list.h, system.color.work_graph);
  174.                 y.n = skp.y;
  175.                 DrawFrame(skp.x, skp.y, skp.w, skp.h, " Components Preview ");
  176.                 checkbox1.draw(skp.x+20, y.inc(30));
  177.                 spinbox1.draw(skp.x+20, y.inc(30));
  178.                 WriteText(skp.x+20, y.inc(30), 0x90, system.color.work_text, "Edit box");
  179.                 DrawEditBoxPos(skp.x+20, y.inc(20), #edit1);
  180.                 DrawStandartCaptButton(skp.x+20, skp.y+skp.h-40, GetFreeButtonId(), "Button1");
  181.                 DrawStandartCaptButton(skp.x+120, skp.y+skp.h-40, GetFreeButtonId(), "Button2");
  182.         }
  183. }
  184.  
  185.  
  186.  
  187. void Open_Dir()
  188. {
  189.         int j;
  190.         select_list.count = 0;
  191.         if(io.dir.buffer)free(io.dir.buffer);
  192.         io.dir.load(#folder_path,DIR_ONLYREAL);
  193.         for (j=0; j<io.dir.count; j++)
  194.         {
  195.                 strcpy(#temp_filename, io.dir.position(j));
  196.                 strlwr(#temp_filename);
  197.                 if (tabs.active_tab==SKINS) if (strcmpi(#temp_filename+strlen(#temp_filename)-4,".skn")!=0) continue;
  198.                 if (tabs.active_tab==WALLPAPERS) if (strcmpi(#temp_filename+strlen(#temp_filename)-4,".txt")==0) continue;
  199.                 cur = select_list.count;
  200.                 files_mas[cur]=j;
  201.                 if (!strcmpi("default.skn",#temp_filename)) files_mas[0]><files_mas[select_list.count];
  202.                 select_list.count++;
  203.         }
  204. }
  205.  
  206. void SelectList_DrawLine(dword i)
  207. {
  208.         int yyy, list_last;
  209.  
  210.         cur = select_list.first + i;
  211.         strcpy(#temp_filename, io.dir.position(files_mas[cur]));
  212.         temp_filename[strlen(#temp_filename)-4] = 0;
  213.         yyy = i*select_list.item_h+select_list.y;
  214.        
  215.         if (select_list.cur_y-select_list.first==i)
  216.         {
  217.                 DrawBar(select_list.x, yyy, select_list.w, select_list.item_h, system.color.work_button);
  218.                 WriteText(select_list.x+12,yyy+select_list.text_y,select_list.font_type,system.color.work_button_text, #temp_filename);
  219.         }
  220.         else
  221.         {
  222.                 DrawBar(select_list.x,yyy,select_list.w, select_list.item_h, 0xFFFfff);
  223.                 WriteText(select_list.x+12,yyy+select_list.text_y,select_list.font_type,0, #temp_filename);
  224.         }
  225. }
  226.  
  227. void SelectList_LineChanged()
  228. {
  229.         EventApply();
  230. }
  231.  
  232. //===================================================//
  233. //                                                   //
  234. //                     EVENTS                        //
  235. //                                                   //
  236. //===================================================//
  237.  
  238. void EventTabClick(int N)
  239. {
  240.         tabs.click(N);
  241.         if (tabs.active_tab == SKINS)
  242.         {
  243.                 active_wallpaper = select_list.cur_y;
  244.                 strcpy(#folder_path, SKINS_STANDART_PATH);
  245.                 select_list.ClearList();
  246.                 Open_Dir();
  247.                 if (!select_list.count) notify("'No skins were found' -E");
  248.                 select_list.cur_y = active_skin;
  249.         }
  250.         if (tabs.active_tab == WALLPAPERS)
  251.         {
  252.                 active_skin = select_list.cur_y;
  253.                 strcpy(#folder_path, WALP_STANDART_PATH);
  254.                 select_list.ClearList();
  255.                 Open_Dir();
  256.                 if (!select_list.count) notify("'No wallpapers were found' -E");
  257.                 select_list.cur_y = active_wallpaper;
  258.         }
  259.         if (select_list.cur_y>select_list.visible) select_list.first=select_list.cur_y; select_list.CheckDoesValuesOkey();
  260.         if (select_list.w) DrawWindowContent();
  261. }
  262.  
  263. void EventDeleteFile()
  264. {
  265.         io.del(#cur_file_path);
  266.         Open_Dir();
  267.         EventApply();
  268. }
  269.  
  270. void EventApply()
  271. {
  272.         if (tabs.active_tab==SKINS)
  273.         {
  274.                 cur = select_list.cur_y;
  275.                 sprintf(#cur_file_path,"%s/%s",#folder_path,io.dir.position(files_mas[cur]));
  276.                 SetSystemSkin(#cur_file_path);
  277.         }
  278.         if (tabs.active_tab==WALLPAPERS)
  279.         {
  280.                 cur = select_list.cur_y;
  281.                 sprintf(#cur_file_path,"\\S__%s/%s",#folder_path,io.dir.position(files_mas[cur]));
  282.                 RunProgram("/sys/media/kiv", #cur_file_path);
  283.                 SelectList_Draw();
  284.         }
  285. }
  286.  
  287. void EventOpenFile()
  288. {
  289.         if (tabs.active_tab==SKINS) RunProgram("/sys/skincfg", #cur_file_path);
  290.         if (tabs.active_tab==WALLPAPERS) RunProgram("/sys/media/kiv", #cur_file_path);
  291. }
  292.  
  293. stop:
  294.