Subversion Repositories Kolibri OS

Rev

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

  1. //11.03.12 - start!
  2. //ver 2.1
  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.  
  16. #include "..\lib\obj\box_lib.h"
  17. #include "..\lib\obj\proc_lib.h"
  18.  
  19. #include "..\lib\patterns\select_list.h"
  20. #include "..\lib\patterns\simple_open_dialog.h"
  21.  
  22. //===================================================//
  23. //                                                   //
  24. //                       DATA                        //
  25. //                                                   //
  26. //===================================================//
  27.  
  28. #ifdef LANG_RUS
  29.         ?define WINDOW_HEADER " áâனª¨ ®ä®à¬«¥­¨ï"
  30.         ?define T_SKINS       "‘â¨«ì ®ª®­"
  31.         ?define T_WALLPAPERS  "Ž¡®¨"
  32.         ?define T_SELECT_FOLDER "‚ë¡à âì ¯ ¯ªã"
  33. #else
  34.         ?define WINDOW_HEADER "Appearance"
  35.         ?define T_SKINS       "Skins"
  36.         ?define T_WALLPAPERS  "Wallpapers"
  37.         ?define T_SELECT_FOLDER "Select wallpapers"
  38. #endif
  39.  
  40. #define PANEL_H 40
  41. #define LP 10 //LIST_PADDING
  42. char skins_folder_path[4096] = "/kolibrios/res/skins";
  43. char wallp_folder_path[4096] = "/kolibrios/res/wallpapers";
  44.  
  45. signed int active_skin=-1, active_wallpaper=-1;
  46. enum {
  47.         SKINS=2,
  48.         WALLPAPERS,
  49.         BTN_SELECT_WALLP_FOLDER };
  50.  
  51. char folder_path[4096];
  52. char cur_file_path[4096];
  53. char temp_filename[4096];
  54. int files_mas[400];
  55.  
  56. int cur;
  57.  
  58. proc_info Form;
  59. block skp;
  60.  
  61. _tabs tabs = { LP, LP, NULL, NULL, SKINS };
  62.  
  63. checkbox checkbox1 = { "Checkbox", true };
  64. more_less_box spinbox1 = { 23, 0, 999, "SpinBox" };
  65. edit_box edit_cmm = {180,NULL,NULL,0xffffff,0x94AECE,0xFFFfff,0xffffff,
  66.         0x10000000,sizeof(param),#param,0, 0b};
  67.  
  68. char st_str[16];
  69. edit_box edit_st = {180,NULL,NULL,0xffffff,0x94AECE,0xFFFfff,0xffffff,
  70.         0x10000000,sizeof(st_str),#st_str,0, 0b};
  71.  
  72. #define MENU_LIST "Open file     Enter\nDelete          Del"
  73.  
  74. char default_dir[] = "/rd/1";
  75. od_filter filter2 = { 8, "TXT\0\0" };
  76.  
  77. //===================================================//
  78. //                                                   //
  79. //                       CODE                        //
  80. //                                                   //
  81. //===================================================//
  82.  
  83. void main()
  84. {  
  85.         int id, mouse_clicked;
  86.  
  87.         load_dll(boxlib, #box_lib_init,0);
  88.         load_dll(Proc_lib, #OpenDialog_init,0);
  89.         o_dialog.type = 2; //select folder
  90.         OpenDialog_init stdcall (#o_dialog);
  91.  
  92.         EventTabClick(SKINS);
  93.  
  94.         SetEventMask(0x27);
  95.         loop() switch(WaitEvent())
  96.         {
  97.                 case evMouse:
  98.                         if (!CheckActiveProcess(Form.ID)) break;
  99.                         SelectList_ProcessMouse();
  100.  
  101.                         if (tabs.active_tab == SKINS) {
  102.                                 edit_box_mouse stdcall (#edit_cmm);
  103.                                 edit_box_mouse stdcall (#edit_st);
  104.                         }
  105.  
  106.                         if (mouse.pkm)&&(select_list.MouseOver(mouse.x, mouse.y)) {
  107.                                 select_list.ProcessMouse(mouse.x, mouse.y);
  108.                                 SelectList_Draw();
  109.                                 EventSetNewCurrent();
  110.                                 menu.show(Form.left+mouse.x, Form.top+mouse.y+skin_height, 185, MENU_LIST, 10);
  111.                         }
  112.                         break;
  113.  
  114.                 case evButton:
  115.                         id=GetButtonID();
  116.                         if (id==1) ExitProcess();
  117.                         if (id==SKINS) EventTabClick(SKINS);
  118.                         if (id==WALLPAPERS) EventTabClick(WALLPAPERS);
  119.                         if (id==BTN_SELECT_WALLP_FOLDER) EventSelectWallpFolder();
  120.                         checkbox1.click(id);
  121.                         spinbox1.click(id);
  122.                         break;
  123.          
  124.                 case evKey:
  125.                         GetKeys();
  126.                         if (select_list.ProcessKey(key_scancode)) EventApply();
  127.                         if (key_scancode==SCAN_CODE_ENTER) EventOpenFile();
  128.                         if (key_scancode==SCAN_CODE_TAB) {
  129.                                 if (tabs.active_tab==SKINS) EventTabClick(WALLPAPERS);
  130.                                 else EventTabClick(SKINS);                             
  131.                         }
  132.                         if (key_scancode==SCAN_CODE_DEL) EventDeleteFile();
  133.  
  134.                         if (! edit_cmm.flags & 0b10) && (! edit_st.flags & 0b10)
  135.                         for (id=select_list.cur_y+1; id<select_list.count; id++)
  136.                         {
  137.                                 strcpy(#temp_filename, io.dir.position(files_mas[id]));
  138.                                 if (temp_filename[0]==key_ascii) || (temp_filename[0]==key_ascii-32)
  139.                                 {
  140.                                         select_list.cur_y = id - 1;
  141.                                         select_list.KeyDown();
  142.                                         EventApply();
  143.                                         break;
  144.                                 }
  145.                         }
  146.  
  147.                         if (tabs.active_tab == SKINS) {
  148.                                 EAX = key_ascii << 8;
  149.                                 edit_box_key stdcall (#edit_cmm);
  150.                                 edit_box_key stdcall (#edit_st);                               
  151.                         }
  152.                         break;
  153.                  
  154.                  case evReDraw:        
  155.                         draw_window();
  156.                         if (menu.list.cur_y) {
  157.                                 if (menu.list.cur_y == 10) EventOpenFile();
  158.                                 if (menu.list.cur_y == 11) EventDeleteFile();
  159.                                 menu.list.cur_y = 0;
  160.                         };
  161.    }
  162. }
  163.  
  164. void draw_window()
  165. {
  166.         system.color.get();    
  167.         DefineAndDrawWindow(screen.width-600/2,80,630,404+skin_height,0x74,0xE4DFE1,WINDOW_HEADER,0);
  168.         GetProcessInfo(#Form, SelfInfo);
  169.         IF (Form.status_window>=2) return;
  170.         DrawWindowContent();
  171. }
  172.  
  173. void DrawWindowContent()
  174. {
  175.         int id;
  176.         incn y;
  177.         int list_w;
  178.  
  179.         if (tabs.active_tab == SKINS) list_w=250; else list_w=370;
  180.  
  181.         DrawWideRectangle(0, 0, Form.cwidth, Form.cheight, LP, system.color.work);
  182.  
  183.         tabs.w = Form.cwidth-LP-LP;
  184.         tabs.h = Form.cheight-LP-LP;
  185.         tabs.draw_wrapper();
  186.        
  187.         tabs.draw_button(tabs.x+TAB_PADDING, SKINS, T_SKINS);  
  188.         tabs.draw_button(strlen(T_SKINS)*8+tabs.x+TAB_PADDING+TAB_PADDING, WALLPAPERS, T_WALLPAPERS);
  189.  
  190.         id = select_list.cur_y;
  191.         SelectList_Init(
  192.                 tabs.x+TAB_PADDING,
  193.                 tabs.y+TAB_HEIGHT+TAB_PADDING,
  194.                 list_w,
  195.                 tabs.h - TAB_PADDING - TAB_PADDING - TAB_HEIGHT,
  196.                 false
  197.                 );
  198.         select_list.cur_y = id;
  199.  
  200.         skp.set_size(
  201.                 select_list.x + select_list.w + TAB_PADDING + scroll1.size_x + 20,
  202.                 select_list.y + 30,
  203.                 list_w,
  204.                 select_list.h - 50
  205.         );
  206.  
  207.         SelectList_Draw();
  208.         SelectList_DrawBorder();
  209.  
  210.         if (tabs.active_tab == SKINS)
  211.         {
  212.                 DrawBar(skp.x-20, select_list.y, skp.w+40, select_list.h, system.color.work);
  213.                 DrawRectangle(skp.x-20, select_list.y, skp.w+40, select_list.h, system.color.work_graph);
  214.                 y.n = skp.y;
  215.                 DrawFrame(skp.x, skp.y, skp.w, skp.h, " Components Preview ");
  216.                 checkbox1.draw(skp.x+20, y.inc(30));
  217.                 spinbox1.draw(skp.x+20, y.inc(30));
  218.                 WriteText(skp.x+20, y.inc(30), 0x90, system.color.work_text, "C-- Edit");
  219.                 DrawEditBoxPos(skp.x+20, y.inc(20), #edit_cmm);
  220.                 WriteText(skp.x+20, y.inc(35), 0x90, system.color.work_text, "Strandard Edit");
  221.                 DrawStEditBoxPos(skp.x+20, y.inc(20), #edit_st);
  222.                 DrawStandartCaptButton(skp.x+20, skp.y+skp.h-40, GetFreeButtonId(), "Button1");
  223.                 DrawStandartCaptButton(skp.x+120, skp.y+skp.h-40, GetFreeButtonId(), "Button2");
  224.         }
  225.         if (tabs.active_tab == WALLPAPERS)
  226.         {
  227.                 DrawStandartCaptButton(skp.x, select_list.y, BTN_SELECT_WALLP_FOLDER, T_SELECT_FOLDER);
  228.         }
  229. }
  230.  
  231. :void DrawStEditBoxPos(dword x,y, edit_box_pointer)
  232. {
  233.         dword c_inactive = MixColors(system.color.work_graph, system.color.work, 128);
  234.         dword c_active = MixColors(system.color.work_graph, 0, 128);
  235.         ESI = edit_box_pointer;
  236.         ESI.edit_box.left = x;
  237.         ESI.edit_box.top = y;
  238.         ESI.edit_box.blur_border_color = c_inactive;
  239.         ESI.edit_box.focus_border_color = c_active;
  240.         edit_box_draw  stdcall (edit_box_pointer);
  241. }
  242.  
  243.  
  244.  
  245. void Open_Dir()
  246. {
  247.         int j;
  248.         select_list.count = 0;
  249.         if(io.dir.buffer)free(io.dir.buffer);
  250.         io.dir.load(#folder_path,DIR_ONLYREAL);
  251.         for (j=0; j<io.dir.count; j++)
  252.         {
  253.                 strcpy(#temp_filename, io.dir.position(j));
  254.                 strlwr(#temp_filename);
  255.                 if (tabs.active_tab==SKINS) {
  256.                         if (strcmpi(#temp_filename+strlen(#temp_filename)-4,".skn")!=0) continue;
  257.                 }
  258.                 if (tabs.active_tab==WALLPAPERS) {
  259.                         if (strcmpi(#temp_filename+strlen(#temp_filename)-4,".png")!=0)
  260.                         && (strcmpi(#temp_filename+strlen(#temp_filename)-4,".jpg")!=0)
  261.                         && (strcmpi(#temp_filename+strlen(#temp_filename)-5,".jpeg")!=0)
  262.                         && (strcmpi(#temp_filename+strlen(#temp_filename)-4,".gif")!=0) continue;
  263.                 }
  264.                 cur = select_list.count;
  265.                 files_mas[cur]=j;
  266.                 if (!strcmpi("default.skn",#temp_filename)) files_mas[0]><files_mas[select_list.count];
  267.                 select_list.count++;
  268.         }
  269. }
  270.  
  271. void SelectList_DrawLine(dword i)
  272. {
  273.         int yyy, list_last;
  274.  
  275.         cur = select_list.first + i;
  276.         strcpy(#temp_filename, io.dir.position(files_mas[cur]));
  277.         temp_filename[strlen(#temp_filename)-4] = 0;
  278.         yyy = i*select_list.item_h+select_list.y;
  279.        
  280.         if (select_list.cur_y-select_list.first==i)
  281.         {
  282.                 DrawBar(select_list.x, yyy, select_list.w, select_list.item_h, system.color.work_button);
  283.                 WriteText(select_list.x+12,yyy+select_list.text_y,select_list.font_type,system.color.work_button_text, #temp_filename);
  284.         }
  285.         else
  286.         {
  287.                 DrawBar(select_list.x,yyy,select_list.w, select_list.item_h, 0xFFFfff);
  288.                 WriteText(select_list.x+12,yyy+select_list.text_y,select_list.font_type,0, #temp_filename);
  289.         }
  290. }
  291.  
  292. void SelectList_LineChanged()
  293. {
  294.         EventApply();
  295. }
  296.  
  297. //===================================================//
  298. //                                                   //
  299. //                     EVENTS                        //
  300. //                                                   //
  301. //===================================================//
  302.  
  303. void EventTabClick(int N)
  304. {
  305.         tabs.click(N);
  306.         if (tabs.active_tab == SKINS)
  307.         {
  308.                 active_wallpaper = select_list.cur_y;
  309.                 strcpy(#folder_path, #skins_folder_path);
  310.                 select_list.ClearList();
  311.                 Open_Dir();
  312.                 if (!select_list.count) notify("'No skins were found' -E");
  313.                 select_list.cur_y = active_skin;
  314.         }
  315.         if (tabs.active_tab == WALLPAPERS)
  316.         {
  317.                 active_skin = select_list.cur_y;
  318.                 strcpy(#folder_path, #wallp_folder_path);
  319.                 select_list.ClearList();
  320.                 Open_Dir();
  321.                 if (!select_list.count) notify("'No wallpapers were found' -E");
  322.                 select_list.cur_y = active_wallpaper;
  323.         }
  324.         if (select_list.cur_y>select_list.visible) select_list.first=select_list.cur_y; select_list.CheckDoesValuesOkey();
  325.         if (select_list.w) DrawWindowContent();
  326. }
  327.  
  328. void EventDeleteFile()
  329. {
  330.         io.del(#cur_file_path);
  331.         Open_Dir();
  332.         EventApply();
  333. }
  334.  
  335. void EventSetNewCurrent()
  336. {
  337.         cur = select_list.cur_y;
  338.         sprintf(#cur_file_path,"%s/%s",#folder_path,io.dir.position(files_mas[cur]));
  339. }
  340.  
  341. void EventSelectWallpFolder()
  342. {
  343.         OpenDialog_start stdcall (#o_dialog);
  344.         if (o_dialog.status) {
  345.                 strcpy(#wallp_folder_path, #opendir_path);
  346.                 EventTabClick(WALLPAPERS);
  347.         }
  348. }
  349.  
  350. void EventApply()
  351. {
  352.         char kivpath[4096+10];
  353.         EventSetNewCurrent();
  354.         if (tabs.active_tab==SKINS)
  355.         {
  356.                 cur = select_list.cur_y;
  357.                 SetSystemSkin(#cur_file_path);
  358.         }
  359.         if (tabs.active_tab==WALLPAPERS)
  360.         {
  361.                 strcpy(#kivpath, "\\S__");
  362.                 strcat(#kivpath, #cur_file_path);
  363.                 RunProgram("/sys/media/kiv", #kivpath);
  364.                 SelectList_Draw();
  365.         }
  366. }
  367.  
  368. void EventOpenFile()
  369. {
  370.         if (tabs.active_tab==SKINS) RunProgram("/sys/skincfg", #cur_file_path);
  371.         if (tabs.active_tab==WALLPAPERS) RunProgram("/sys/media/kiv", #cur_file_path);
  372. }
  373.  
  374. stop:
  375.