Subversion Repositories Kolibri OS

Rev

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