Subversion Repositories Kolibri OS

Rev

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