Subversion Repositories Kolibri OS

Rev

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

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