Subversion Repositories Kolibri OS

Rev

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

  1. //11.03.12 - start!
  2.  
  3. #ifndef AUTOBUILD
  4.         ?include "lang.h--"
  5. #endif
  6.  
  7. #define MEMSIZE 0xFE800
  8. #include "..\lib\kolibri.h"
  9. #include "..\lib\mem.h"
  10. #include "..\lib\strings.h"
  11. #include "..\lib\dll.h"
  12. #include "..\lib\io.h"
  13. #include "..\lib\list_box.h"
  14. #include "..\lib\gui.h"
  15. #include "..\lib\obj\box_lib.h"
  16.  
  17. #ifdef LANG_RUS
  18.         ?define WINDOW_HEADER "“á¯à ¢«¥­¨¥ ⥬®©"
  19.         ?define T_SKINS       "   ’¥¬  ®ª®­"
  20.         ?define T_WALLPAPERS  "   Ž¡®¨ à ¡®ç¥£® á⮫ "
  21. #else
  22.         ?define WINDOW_HEADER "Appearance"
  23.         ?define T_SKINS       "   Skins"
  24.         ?define T_WALLPAPERS  "   Wallpappers"
  25. #endif
  26.  
  27. unsigned char icons[]= FROM "icons.raw";
  28.  
  29. #define PANEL_H 30
  30. #define SKINS_STANDART_PATH "/sys/skins" //"/kolibrios/res/skins"
  31. #define WALP_STANDART_PATH "/kolibrios/res/wallpapers"
  32.  
  33. llist list[2];
  34. int active;
  35. enum { WALLPAPERS, SKINS };
  36.  
  37. char folder_path[4096];
  38. char cur_file_path[4096];
  39. char temp_filename[4096];
  40. int files_mas[100];
  41.  
  42. int cur;
  43.  
  44. system_colors sc;
  45. proc_info Form;
  46.  
  47. 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};
  48.  
  49. void Open_Dir()
  50. {
  51.         int j;
  52.         list[active].count = 0;
  53.         io.dir.load(#folder_path,DIR_ONLYREAL);
  54.         for (j=0; j<io.dir.count; j++)
  55.         {
  56.                 strcpy(#temp_filename, io.dir.position(j));
  57.                 strlwr(#temp_filename);
  58.                 if (active==SKINS) if (strcmpi(#temp_filename+strlen(#temp_filename)-4,".skn")!=0) continue;
  59.                 if (active==WALLPAPERS) if (strcmpi(#temp_filename+strlen(#temp_filename)-4,".txt")==0) continue;
  60.                 cur = list[active].count;
  61.                 files_mas[cur]=j;
  62.                 if (!strcmpi("default.skn",#temp_filename)) files_mas[0]><files_mas[list[active].count];
  63.                 list[active].count++;
  64.         }
  65. }
  66.  
  67. void Draw_List()
  68. {
  69.         int i;
  70.         int yyy;
  71.         int list_last;
  72.         list[SKINS].SetSizes(0, PANEL_H, Form.cwidth-scroll1.size_x-1, Form.cheight-PANEL_H, 40, 20);
  73.         list[WALLPAPERS].SetSizes(0, PANEL_H, Form.cwidth-scroll1.size_x-1, Form.cheight-PANEL_H, 40, 20);
  74.         if (list[active].count > list[active].visible) list_last = list[active].visible; else list_last = list[active].count;
  75.  
  76.         for (i=0; i<list_last; i++;)
  77.         {
  78.                 cur = list[active].first;
  79.                 strcpy(#temp_filename, io.dir.position(files_mas[i+cur]));
  80.                 temp_filename[strlen(#temp_filename)-4] = 0;
  81.                 yyy = i*list[active].line_h+list[active].y;
  82.                
  83.                 if (list[active].current-list[active].first==i)
  84.                 {
  85.                         if (sc.work_button<>sc.work)
  86.                         {
  87.                                 DrawBar(0, yyy, list[active].w, list[active].line_h, sc.work_button);
  88.                                 if (i<list[active].count) WriteText(12,yyy+list[active].text_y,0x80,sc.work_button_text, #temp_filename);
  89.                         }
  90.                         else
  91.                         {
  92.                                 DrawBar(0, yyy, list[active].w, list[active].line_h, sc.grab_button);
  93.                                 if (i<list[active].count) WriteText(12,yyy+list[active].text_y,0x80,sc.grab_button_text, #temp_filename);
  94.                         }
  95.                 }
  96.                 else
  97.                 {
  98.                         DrawBar(0,yyy,list[active].w, list[active].line_h, 0xFFFfff);
  99.                         WriteText(12,yyy+list[active].text_y,0x80,0, #temp_filename);
  100.                 }
  101.         }
  102.         DrawBar(0,list_last*list[active].line_h+list[active].y, list[active].w, -list_last*list[active].line_h+ list[active].h, 0xFFFfff);
  103.         DrawScroller();
  104. }
  105.  
  106. void GetFiles()
  107. {
  108.         if (list[SKINS].active)
  109.         {
  110.                 strcpy(#folder_path, SKINS_STANDART_PATH);
  111.                 Open_Dir();
  112.                 if (!list[active].count) notify("'No skins were found' -E");
  113.         }
  114.         if (list[WALLPAPERS].active)
  115.         {
  116.                 strcpy(#folder_path, WALP_STANDART_PATH);
  117.                 Open_Dir();
  118.                 if (!list[active].count) notify("'No wallpapers were found' -E");
  119.         }
  120. }
  121.  
  122. void Apply()
  123. {
  124.         if (list[SKINS].active)
  125.         {
  126.                 strcpy(#cur_file_path, #folder_path);
  127.                 cur = list[SKINS].current;
  128.                 chrcat(#cur_file_path, '/');
  129.                 strcat(#cur_file_path, io.dir.position(files_mas[cur]));
  130.                 SetSystemSkin(#cur_file_path);
  131.         }
  132.         if (list[WALLPAPERS].active)
  133.         {
  134.                 strcpy(#cur_file_path, "\\S__");
  135.                 strcat(#cur_file_path, #folder_path);
  136.                 cur = list[WALLPAPERS].current;
  137.                 chrcat(#cur_file_path, '/');
  138.                 strcat(#cur_file_path, io.dir.position(files_mas[cur]));
  139.                 RunProgram("/sys/media/kiv", #cur_file_path);
  140.                 Draw_List();
  141.         }
  142. }
  143.  
  144. OpenFile()
  145. {
  146.         if (list[SKINS].active) RunProgram("/sys/desktop", #cur_file_path);
  147.         if (list[WALLPAPERS].active) RunProgram("/sys/media/kiv", #cur_file_path);
  148. }
  149.  
  150.  
  151. void main()
  152. {  
  153.         int id, key, mouse_clicked;
  154.  
  155.         SetEventMask(0x27);
  156.         load_dll(boxlib, #box_lib_init,0);
  157.         list[SKINS].current = list[WALLPAPERS].current = -1;
  158.         list[SKINS].first = list[WALLPAPERS].first = 0;
  159.         TabClick(WALLPAPERS);
  160.         list[WALLPAPERS].SetSizes(0, 230, 350, 400-PANEL_H, 40, 18);
  161.         list[SKINS].SetSizes(0, 230, 350, 400-PANEL_H, 40, 18);
  162.         loop()
  163.         {
  164.           switch(WaitEvent())
  165.           {
  166.                 case evMouse:
  167.                         if (!CheckActiveProcess(Form.ID)) break;
  168.                         scrollbar_v_mouse (#scroll1);
  169.                         if (list[active].first <> scroll1.position)
  170.                         {
  171.                                 list[active].first = scroll1.position;
  172.                                 Draw_List();
  173.                                 break;
  174.                         }
  175.                
  176.                         mouse.get();
  177.  
  178.                         if (mouse.vert)
  179.                         {
  180.                                 if (list[SKINS].active) && (list[SKINS].MouseScroll(mouse.vert)) Draw_List();
  181.                                 if (list[WALLPAPERS].active) && (list[WALLPAPERS].MouseScroll(mouse.vert)) Draw_List();
  182.                         }
  183.  
  184.                         if (mouse_clicked)
  185.                         {
  186.                                 if (!mouse.lkm) && (list[SKINS].active) && (list[SKINS].ProcessMouse(mouse.x, mouse.y)) Apply();
  187.                                 if (!mouse.lkm) && (list[WALLPAPERS].active) && (list[WALLPAPERS].ProcessMouse(mouse.x, mouse.y)) Apply();
  188.                                 mouse_clicked=0;
  189.                         }
  190.                         if (mouse.lkm) && (list[SKINS].MouseOver(mouse.x, mouse.y)) mouse_clicked=1;
  191.                         break;
  192.  
  193.  
  194.                 case evButton:
  195.                         id=GetButtonID();
  196.                         if (id==1) ExitProcess();
  197.                         if (id==2) TabClick(WALLPAPERS);
  198.                         if (id==3) TabClick(SKINS);
  199.                         break;
  200.          
  201.                 case evKey:
  202.                         key = GetKey();
  203.                         if (list[SKINS].active) && (list[SKINS].ProcessKey(key)) Apply();
  204.                         if (list[WALLPAPERS].active) && (list[WALLPAPERS].ProcessKey(key)) Apply();
  205.                         IF (key==013) OpenFile();
  206.                         if (key==9) if (list[SKINS].active) TabClick(WALLPAPERS); else TabClick(SKINS);
  207.                         IF (key==182) //Del
  208.                         {
  209.                                 DeleteFile(#cur_file_path);
  210.                                 Open_Dir();
  211.                                 Apply();
  212.                         }
  213.                         break;
  214.                  
  215.                  case evReDraw:
  216.                         sc.get();                      
  217.                         DefineAndDrawWindow(30,80,list[active].w+9,list[active].h+4+GetSkinHeight(),0x73,0xE4DFE1,WINDOW_HEADER,0);
  218.                         GetProcessInfo(#Form, SelfInfo);
  219.                         IF (Form.status_window>=2) break;
  220.                         DrawTabs();
  221.                         Draw_List();
  222.           }
  223.    }
  224. }
  225.  
  226. #define BT_PADDING 16
  227.  
  228. void DrawTab(dword x,y, but_id, is_active, text)
  229. {
  230.         dword col_bg, col_text;
  231.         dword w=strlen(text)*6+BT_PADDING, h=21;
  232.  
  233.         if (is_active)
  234.         {
  235.                 col_bg=sc.work_button;
  236.                 col_text=sc.work_button_text;
  237.         }
  238.         else
  239.         {
  240.                 col_bg=sc.work;
  241.                 col_text=sc.work_text;
  242.         }
  243.         DrawRectangle(x,y, w,h, sc.work_graph);
  244.         DrawCaptButton(x+1,y+1, w-2,h-1, but_id, col_bg, col_text, text);
  245.         _PutImage(x+6,y+4,  16,15,   but_id-2*16*15*3+#icons);
  246. }
  247.  
  248.  
  249. void DrawTabs()
  250. {
  251.         DrawBar(0,0, Form.cwidth, PANEL_H-1, sc.work);
  252.         DrawTab(10,7, 2, list[WALLPAPERS].active, T_WALLPAPERS);
  253.         DrawTab(strlen(T_WALLPAPERS)*6+BT_PADDING+21,7, 3, list[SKINS].active, T_SKINS);
  254.         DrawBar(0,PANEL_H-2, Form.cwidth, 1, sc.work_graph);
  255.         DrawBar(0,PANEL_H-1, Form.cwidth, 1, 0xEEEeee);
  256. }
  257.  
  258. void TabClick(int N)
  259. {
  260.         if (N==SKINS)
  261.         {
  262.                 list[SKINS].active = 1;
  263.                 list[WALLPAPERS].active = 0;   
  264.         }
  265.         if (N==WALLPAPERS)
  266.         {
  267.                 list[SKINS].active = 0;
  268.                 list[WALLPAPERS].active = 1;   
  269.         }
  270.         active = N;
  271.         GetFiles();
  272.         DrawTabs();
  273.         Draw_List();
  274. }
  275.  
  276.  
  277. void DrawScroller()
  278. {
  279.         scroll1.bckg_col = 0xBBBbbb;
  280.         scroll1.frnt_col = sc.work;
  281.         scroll1.line_col = sc.work_graph;
  282.  
  283.         scroll1.max_area = list[active].count;
  284.         scroll1.cur_area = list[active].visible;
  285.         scroll1.position = list[active].first;
  286.  
  287.         scroll1.all_redraw=1;
  288.         scroll1.start_x = list[active].x + list[active].w;
  289.         scroll1.start_y = list[active].y-2;
  290.         scroll1.size_y = list[active].h+2;
  291.  
  292.         scrollbar_v_draw(#scroll1);
  293. }
  294.  
  295.  
  296. stop:
  297.