Subversion Repositories Kolibri OS

Rev

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

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