Subversion Repositories Kolibri OS

Rev

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