Subversion Repositories Kolibri OS

Rev

Rev 6264 | Rev 6653 | 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.  
  17.  
  18. //===================================================//
  19. //                                                   //
  20. //                       DATA                        //
  21. //                                                   //
  22. //===================================================//
  23.  
  24. #ifdef LANG_RUS
  25.         ?define WINDOW_HEADER " áâனª¨ ®ä®à¬«¥­¨ï"
  26.         ?define T_SKINS       "‘â¨«ì ®ª®­"
  27.         ?define T_WALLPAPERS  "Ž¡®¨"
  28. #else
  29.         ?define WINDOW_HEADER "Appearance"
  30.         ?define T_SKINS       "Skins"
  31.         ?define T_WALLPAPERS  "Wallpappers"
  32. #endif
  33.  
  34. #define PANEL_H 40
  35. #define LIST_PADDING 20
  36. #define SKINS_STANDART_PATH "/kolibrios/res/skins"                                                     
  37. #define WALP_STANDART_PATH "/kolibrios/res/wallpapers"
  38.  
  39. llist list;
  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.  
  52. scroll_bar scroll1 = { 18,200,398, 44,18,0,115,15,0,0xeeeeee,0xD2CED0,0x555555,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
  53.  
  54.  
  55. //===================================================//
  56. //                                                   //
  57. //                       CODE                        //
  58. //                                                   //
  59. //===================================================//
  60.  
  61. void main()
  62. {  
  63.         int id, mouse_clicked;
  64.  
  65.         SetEventMask(0x27);
  66.         load_dll(boxlib, #box_lib_init,0);
  67.         EventTabClick(SKINS);
  68.         loop() switch(WaitEvent())
  69.         {
  70.                 case evMouse:
  71.                         if (!CheckActiveProcess(Form.ID)) break;
  72.                         mouse.get();
  73.                         scrollbar_v_mouse (#scroll1);
  74.                         if (list.first != scroll1.position)
  75.                         {
  76.                                 list.first = scroll1.position;
  77.                                 Draw_List();
  78.                                 break;
  79.                         }
  80.  
  81.                         if (mouse.vert) && (list.MouseScroll(mouse.vert)) Draw_List();
  82.  
  83.                         if (mouse.up)&&(mouse_clicked)
  84.                         {
  85.                                 if (mouse.lkm) && (list.ProcessMouse(mouse.x, mouse.y)) EventApply();
  86.                                 mouse_clicked=false;
  87.                         }
  88.                         else if (mouse.down)&&(mouse.lkm) && (list.MouseOver(mouse.x, mouse.y)) mouse_clicked=true;
  89.  
  90.                         if (mouse.down)&&(mouse.pkm) {
  91.                                 list.ProcessMouse(mouse.x, mouse.y);
  92.                                 Draw_List();
  93.                                 menu.show(Form.left+mouse.x, Form.top+mouse.y+skin_height, 136, "Open file     Enter\nDelete          Del", 10);
  94.                         }
  95.  
  96.                         break;
  97.  
  98.  
  99.                 case evButton:
  100.                         id=GetButtonID();
  101.                         if (id==1) ExitProcess();
  102.                         if (id==SKINS) EventTabClick(SKINS);
  103.                         if (id==WALLPAPERS) EventTabClick(WALLPAPERS);
  104.                         break;
  105.          
  106.                 case evKey:
  107.                         GetKeys();
  108.                         if (list.ProcessKey(key_scancode)) EventApply();
  109.                         if (key_scancode==SCAN_CODE_ENTER) EventOpenFile();
  110.                         if (key_scancode==SCAN_CODE_TAB) if (tabs.active_tab==SKINS) EventTabClick(WALLPAPERS); else EventTabClick(SKINS);
  111.                         if (key_scancode==SCAN_CODE_DEL) EventDeleteFile();
  112.                         for (id=list.cur_y+1; id<list.count; id++)
  113.                         {
  114.                                 strcpy(#temp_filename, io.dir.position(files_mas[id]));
  115.                                 if (temp_filename[0]==key_ascii) || (temp_filename[0]==key_ascii-32)
  116.                                 {
  117.                                         list.cur_y = id - 1;
  118.                                         list.KeyDown();
  119.                                         EventApply();
  120.                                         break;
  121.                                 }
  122.                         }
  123.                         break;
  124.                  
  125.                  case evReDraw:
  126.                         system.color.get();                    
  127.                         DefineAndDrawWindow(screen.width-400/2,80,400,404+skin_height,0x73,0xE4DFE1,WINDOW_HEADER,0);
  128.                         GetProcessInfo(#Form, SelfInfo);
  129.                         IF (Form.status_window>=2) break;
  130.                         DrawWindowContent();
  131.                         if (menu.list.cur_y) {
  132.                                 if (menu.list.cur_y == 10) EventOpenFile();
  133.                                 if (menu.list.cur_y == 11) EventDeleteFile();
  134.                                 menu.list.cur_y = 0;
  135.                         };
  136.    }
  137. }
  138.  
  139. void DrawWindowContent()
  140. {
  141.         int id;
  142.         list.SetFont(8, 14, 0x90);
  143.         id = list.cur_y;
  144.         list.SetSizes(LIST_PADDING, PANEL_H, Form.cwidth-scroll1.size_x-LIST_PADDING-LIST_PADDING, Form.cheight-PANEL_H-LIST_PADDING, 20);
  145.         list.cur_y = id;
  146.  
  147.         DrawBar(0,0, Form.cwidth, PANEL_H-LIST_PADDING, system.color.work);
  148.         DrawRectangle3D(list.x-2, list.y-2, list.w+3+scroll1.size_x, list.h+3, system.color.work_dark, system.color.work_light);
  149.         DrawWideRectangle(list.x-LIST_PADDING, list.y-LIST_PADDING, LIST_PADDING*2+list.w+scroll1.size_x, LIST_PADDING*2+list.h, LIST_PADDING-2, system.color.work);
  150.         tabs.draw(list.x+10, list.y, SKINS, T_SKINS);
  151.         if (dir_exists(WALP_STANDART_PATH)) tabs.draw(strlen(T_SKINS)*8+TAB_PADDING+list.x+21, list.y, WALLPAPERS, T_WALLPAPERS);
  152.         DrawRectangle(list.x-1, list.y-1, list.w+1+scroll1.size_x, list.h+1, system.color.work_graph);
  153.  
  154.         Draw_List();
  155. }
  156.  
  157. void DrawScroller()
  158. {
  159.         scroll1.bckg_col = MixColors(system.color.work, 0xBBBbbb, 80);
  160.         scroll1.frnt_col = MixColors(system.color.work,0xFFFfff,120);
  161.         scroll1.line_col = system.color.work_graph;
  162.  
  163.         scroll1.max_area = list.count;
  164.         scroll1.cur_area = list.visible;
  165.         scroll1.position = list.first;
  166.  
  167.         scroll1.all_redraw=1;
  168.         scroll1.start_x = list.x + list.w;
  169.         scroll1.start_y = list.y-1;
  170.         scroll1.size_y = list.h+2;
  171.  
  172.         scrollbar_v_draw(#scroll1);
  173. }
  174.  
  175. void Open_Dir()
  176. {
  177.         int j;
  178.         list.count = 0;
  179.         if(io.dir.buffer)free(io.dir.buffer);
  180.         io.dir.load(#folder_path,DIR_ONLYREAL);
  181.         for (j=0; j<io.dir.count; j++)
  182.         {
  183.                 strcpy(#temp_filename, io.dir.position(j));
  184.                 strlwr(#temp_filename);
  185.                 if (tabs.active_tab==SKINS) if (strcmpi(#temp_filename+strlen(#temp_filename)-4,".skn")!=0) continue;
  186.                 if (tabs.active_tab==WALLPAPERS) if (strcmpi(#temp_filename+strlen(#temp_filename)-4,".txt")==0) continue;
  187.                 cur = list.count;
  188.                 files_mas[cur]=j;
  189.                 if (!strcmpi("default.skn",#temp_filename)) files_mas[0]><files_mas[list.count];
  190.                 list.count++;
  191.         }
  192. }
  193.  
  194. void Draw_List()
  195. {
  196.         int i, yyy, list_last;
  197.  
  198.         if (list.count > list.visible) list_last = list.visible; else list_last = list.count;
  199.  
  200.         for (i=0; (i<list_last); i++;)
  201.         {
  202.                 cur = list.first + i;
  203.                 strcpy(#temp_filename, io.dir.position(files_mas[cur]));
  204.                 temp_filename[strlen(#temp_filename)-4] = 0;
  205.                 yyy = i*list.item_h+list.y;
  206.                
  207.                 if (list.cur_y-list.first==i)
  208.                 {
  209.                         DrawBar(list.x, yyy, list.w, list.item_h, system.color.work_button);
  210.                         WriteText(list.x+12,yyy+list.text_y,list.font_type,system.color.work_button_text, #temp_filename);
  211.                 }
  212.                 else
  213.                 {
  214.                         DrawBar(list.x,yyy,list.w, list.item_h, 0xFFFfff);
  215.                         WriteText(list.x+12,yyy+list.text_y,list.font_type,0, #temp_filename);
  216.                 }
  217.         }
  218.         DrawBar(list.x,i*list.item_h+list.y, list.w, -i*list.item_h+ list.h, 0xFFFfff);
  219.         DrawScroller();
  220. }
  221.  
  222. //===================================================//
  223. //                                                   //
  224. //                     EVENTS                        //
  225. //                                                   //
  226. //===================================================//
  227.  
  228. void EventTabClick(int N)
  229. {
  230.         tabs.click(N);
  231.         if (tabs.active_tab == SKINS)
  232.         {
  233.                 active_wallpaper = list.cur_y;
  234.                 strcpy(#folder_path, SKINS_STANDART_PATH);
  235.                 list.ClearList();
  236.                 Open_Dir();
  237.                 if (!list.count) notify("'No skins were found' -E");
  238.                 list.cur_y = active_skin;
  239.         }
  240.         if (tabs.active_tab == WALLPAPERS)
  241.         {
  242.                 active_skin = list.cur_y;
  243.                 strcpy(#folder_path, WALP_STANDART_PATH);
  244.                 list.ClearList();
  245.                 Open_Dir();
  246.                 if (!list.count) notify("'No wallpapers were found' -E");
  247.                 list.cur_y = active_wallpaper;
  248.         }
  249.         if (list.cur_y>list.visible) list.first=list.cur_y; list.CheckDoesValuesOkey();
  250.         if (list.w) DrawWindowContent();
  251. }
  252.  
  253. void EventDeleteFile()
  254. {
  255.         io.del(#cur_file_path);
  256.         Open_Dir();
  257.         EventApply();
  258. }
  259.  
  260. void EventApply()
  261. {
  262.         if (tabs.active_tab==SKINS)
  263.         {
  264.                 cur = list.cur_y;
  265.                 sprintf(#cur_file_path,"%s/%s",#folder_path,io.dir.position(files_mas[cur]));
  266.                 SetSystemSkin(#cur_file_path);
  267.         }
  268.         if (tabs.active_tab==WALLPAPERS)
  269.         {
  270.                 cur = list.cur_y;
  271.                 sprintf(#cur_file_path,"\\S__%s/%s",#folder_path,io.dir.position(files_mas[cur]));
  272.                 RunProgram("/sys/media/kiv", #cur_file_path);
  273.                 Draw_List();
  274.         }
  275. }
  276.  
  277. void EventOpenFile()
  278. {
  279.         if (tabs.active_tab==SKINS) RunProgram("/sys/skincfg", #cur_file_path);
  280.         if (tabs.active_tab==WALLPAPERS) RunProgram("/sys/media/kiv", #cur_file_path);
  281. }
  282.  
  283. stop:
  284.