Code Viewer

./interface.js File Size: 46.99 KB

  1. /*
  2. * -----
  3. * Screenshot Sender - interface.js
  4. * -----
  5. * Functions for loading interface windows.
  6. * -----
  7. */
  8.  
  9. var objWindows = {};
  10. var objChildWindows = {};
  11. var objControls = {};
  12. var objPrefTemp = {};
  13.  
  14. var InterfacePath = MsgPlus.ScriptFilesPath + '\\Languages\\';
  15.  
  16. /*
  17.         Name:    FileExists
  18.         Purpose:        Check whether a file exists or not.
  19.         Parameters: sFilePath - The path to the file that we want to check the existence of.
  20.         Return:  Boolean, whether the file exists.
  21. */
  22. function FileExists(sFilePath) {
  23.         _debug.getfuncname(arguments);
  24.         var nFilePtr = _win32.CreateFileW(sFilePath, 0x80000000, 1, 0, 3, 0, 0)
  25.         _win32.CloseHandle(nFilePtr);
  26.         return nFilePtr !== -1;
  27. }
  28.  
  29. /*
  30.         Name:    OpenWindow
  31.         Purpose:        Open an interface window in the current language.
  32.         Parameters: Name - The name of the window.
  33.         Return:  pPlusWnd object.
  34. */
  35. function OpenWindow(Name, ShowCode, SetIcon) {
  36.         _debug.getfuncname(arguments);
  37.         if (typeof objWindows[Name] === TYPE_OBJECT &&
  38.                 typeof objWindows[Name].Handle === TYPE_NUMBER &&
  39.                 _win32.IsWindow(objWindows[Name].Handle)) {
  40.                
  41.                 _win32.SetForegroundWindow(objWindows[Name].Handle);
  42.                 return false;
  43.         }
  44.         if (typeof ShowCode === TYPE_UNDEFINED) ShowCode = 0;
  45.         if (typeof SetIcon === TYPE_UNDEFINED) SetIcon = 0;
  46.         if (_lang.IsRtl == true) ShowCode |= WNDOPT_RTL;
  47.         if (IsWinVista() == true) ShowCode |= 0x100;
  48.         // If the file exists in the current translation, load it
  49.         var FilePath = InterfacePath + (typeof objPreferences['cLanguage'] === TYPE_UNDEFINED ? MsgPlus.UILangCode : objPreferences['cLanguage']) + '\\' + Name + '.xml';
  50.         if (FileExists(FilePath) == false) {
  51.                 // Otherwise, load the default translation(en)
  52.                 FilePath = InterfacePath + 'en\\' + Name + '.xml';
  53.         }
  54.         objWindows[Name] = MsgPlus.CreateWnd('\\' + FilePath, Name, ShowCode);
  55.         if (SetIcon !== false && hScriptIcon !== 0) SetWndIcon(objWindows[Name].Handle);
  56.         if (IsWinVista() === false) _win32.SetWindowLongW(objWindows[Name].Handle, _win32._const._GWL_STYLE, _win32.GetWindowLongW(objWindows[Name].Handle, _win32._const._GWL_STYLE) &~ _win32._const._WS_CAPTION &~ _win32._const._WS_BOARDER);
  57.         return objWindows[Name];
  58. }
  59.  
  60. function RegisterWindowHooks(pPlusWnd, nHooks, bHook) {
  61.         _debug.getfuncname(arguments);
  62.         if (typeof pPlusWnd === TYPE_STRING) {
  63.                 if (typeof objWindows[pPlusWnd] !== TYPE_UNDEFINED) pPlusWnd = objWindows[pPlusWnd];
  64.                 else if (typeof objChildWindows[pPlusWnd] !== TYPE_UNDEFINED) pPlusWnd = objChildWindows[pPlusWnd];
  65.                 else return false;
  66.         }
  67.  
  68.         if (typeof bHook === TYPE_UNDEFINED) bHook = true;
  69.         if (typeof nHooks === TYPE_OBJECT && nHooks.length) {
  70.                 var i = nHooks.length, val;
  71.                 while (i--) {
  72.                         val = 1*nHooks[i];
  73.                         if (!isNaN(val) && val > 0) pPlusWnd.RegisterMessageNotification(val, bHook);
  74.                 }
  75.         }
  76.         else if (typeof nHooks === TYPE_NUMBER) {
  77.                 pPlusWnd.RegisterMessageNotification(nHooks, bHook);
  78.         }
  79. }
  80.  
  81. /*
  82.         Name:    OpenChildWindow
  83.         Purpose:        Open an child interface window in the current language.
  84.         Parameters: Name - The name of the child window.
  85.                                 Parent - The pPlusWnd object of the parent window
  86.                                 X + Y - the position of the child window on the parent.
  87.                                 Visible - Boolean : if the child window should be shown by default or not
  88.                                 FileName - String : file name of the XML file(without file extension)
  89.         Return:  pPlusWnd object.
  90. */
  91. function OpenChildWindow(Name, Parent, X, Y, Visible, FileName) {
  92.         _debug.getfuncname(arguments);
  93.         if (typeof Visible === TYPE_UNDEFINED) Visible = true;
  94.         if (typeof FileName === TYPE_UNDEFINED) FileName = Parent.WindowId + '-' + Name;
  95.         // If the file exists in the current translation, load it
  96.         var FilePath = InterfacePath + (typeof objPreferences['cLanguage'] === TYPE_UNDEFINED ? MsgPlus.UILangCode : objPreferences['cLanguage']) + '\\' + FileName + '.xml';
  97.         if (FileExists(FilePath) == false) {
  98.                 // Otherwise, load the default translation(en)
  99.                 FilePath = InterfacePath + 'en\\' + FileName + '.xml'
  100.         }
  101.         objChildWindows[Name] = MsgPlus.CreateChildWnd(Parent, '\\' + FilePath, Name, X, Y, Visible);
  102.         return objChildWindows[Name];
  103. }
  104.  
  105. /*
  106.         Name:    CloseWindow
  107.         Purpose:        Closes the specified window and removes its reference from the object
  108.         Parameters: Name - The name of the window.
  109.         Return:  True suceeded / False failed
  110. */
  111. function CloseWindow(Name) {
  112.         _debug.getfuncname(arguments);
  113.         if (typeof objWindows[Name] !== TYPE_OBJECT) return false;
  114.                 objWindows[Name].Close(6);
  115.                 delete objWindows[Name];
  116.                 return true;
  117. }
  118.  
  119. /*
  120.         Name:    EnumControls
  121.         Purpose:        Enum the controls from a specified window
  122.         Parameters: File - The name of the file
  123.                          pPlusWnd - The Plus! window object
  124.         Return:  None
  125. */
  126. function EnumControls(File, pPlusWnd) {
  127.         _debug.getfuncname(arguments);
  128.         // Load the XML from the specified file
  129.         var XML = new ActiveXObject('MSXML.DOMDocument');
  130.         XML.load(File);
  131.         // Loop through all of the controls
  132.         var Controls = XML.selectNodes('/Interfaces/Window[@Id=\'' + pPlusWnd.WindowId + '\']/Controls/Control');
  133.         for (i=0; i<Controls.length; i ++) {
  134.                 var Id = Controls[i].getAttribute('Id');
  135.                 var Type = Controls[i].getAttribute('xsi:type');
  136.                 // Controls starting with _ are options but not stired in the registry (ie Debug info is in the ScriptInfo.xml)
  137.                 if (Id.charAt(0) !== '_') {
  138.                         // Get the value depending on the control's type
  139.                         objControls[Id] = {};
  140.                         objControls[Id].XsiType = Type;
  141.                         objControls[Id].Value = pPlusWnd_GetControlvalue(pPlusWnd, Id, Type);
  142.                 }
  143.         }
  144. }
  145.  
  146. /*
  147.         Name:    pPlusWnd_GetControlvalue
  148.         Purpose:        Get the values for each control on the window
  149.         Parameters: pPlusWnd - The Plus! window object
  150.                         Id - The id of the control
  151.                         XsiType - The type of the control
  152.         Return:  The controls value
  153. */
  154. function pPlusWnd_GetControlvalue(pPlusWnd, Id, XsiType) {
  155.         _debug.getfuncname(arguments);
  156.         switch (XsiType) {
  157.                 case 'RichEditControl':
  158.                 case 'EditControl':
  159.                         return pPlusWnd.GetControlText(Id);
  160.                 case 'CheckBoxControl':
  161.                 case 'RadioControl':
  162.                         return pPlusWnd.Button_IsChecked(Id);
  163.                 case 'SliderControl':
  164.                         return pPlusWnd.SendControlMessage(Id, _win32._const._TBM_GETPOS, 0, 0);
  165.                 case 'ComboBoxControl':
  166.                         return pPlusWnd.Combo_GetCurSel(Id);
  167.                 default :
  168.                         delete objControls[Id]; // We don't use all of the controls therefore lets remove any from the object so they dont present errors
  169.         }
  170. }
  171.  
  172. /*
  173.         Name:    pPlusWnd_SetControlvalue
  174.         Purpose:        Set the values for each control on the window
  175.         Parameters: pPlusWnd - The Plus! window object
  176.                         Id - The id of the control
  177.                         XsiType - The type of the control
  178.                         Value - The value to set for the control
  179.         Return:  The controls value
  180. */
  181. function pPlusWnd_SetControlvalue(pPlusWnd, Id, XsiType, Value) {
  182.         _debug.getfuncname(arguments);
  183.         switch (XsiType) {
  184.                 case 'RichEditControl':
  185.                 case 'EditControl':
  186.                         return pPlusWnd.SetControlText(Id, Value);
  187.                 case 'CheckBoxControl':
  188.                 case 'RadioControl':
  189.                         return pPlusWnd.Button_SetCheckState(Id, Value);
  190.                 case 'SliderControl':
  191.                         return pPlusWnd.SendControlMessage(Id, _win32._const._TBM_SETPOS, true, Value);
  192.                 case 'ComboBoxControl':
  193.                         return pPlusWnd.Combo_SetCurSel(Id, Value);
  194.         }
  195. }
  196.  
  197. /*
  198.         Name:   OpenPreferences
  199.         Purpose:        Opens the preferences window
  200.         Parameters:     None
  201.         Return: The preferences window
  202. */
  203. function OpenPreferences() {
  204.         _debug.getfuncname(arguments);
  205.         var pPlusWnd = OpenWindow('Preferences', 1, true);
  206.         if (!pPlusWnd) return;
  207.  
  208.         LoadChildWindows();
  209.  
  210.         var PrefSize = GetWindowSize(pPlusWnd.Handle);
  211.         if (PrefSize !== false) {
  212.                 var PrefWidthSmall = PrefSize.Width;
  213.                 var ChildSize = GetWindowSize(objChildWindows['PrefGeneral'].Handle);
  214.                 var DashSize = GetWindowSize(objChildWindows['PrefDashboard'].Handle);
  215.                 objPrefTemp['WidthLarge'] = PrefWidthSmall + ChildSize.Width - DashSize.Width;
  216.                 objPrefTemp['WidthSmall'] = PrefWidthSmall;
  217.         } else {
  218.                 objPrefTemp['WidthLarge'] = 618;
  219.                 objPrefTemp['WidthSmall'] = 317;
  220.         }
  221.        
  222.         objPrefTemp['ChildOpen'] = 'PrefDashboard';
  223.         Preferences_ShowChild('PrefDashboard');
  224.         _win32.ShowWindow(pPlusWnd.Handle, _win32._const._SW_SHOW);
  225.         return pPlusWnd;
  226. }
  227.  
  228. /*
  229.         Name:   LoadChildWindows
  230.         Purpose:        Load our child windows to the main container Preferences
  231.         Parameters:     None
  232.         Return: None
  233. */
  234. function LoadChildWindows() {
  235.         _debug.getfuncname(arguments);
  236.         var Pos = {
  237.                 x:      objWindows['Preferences'].GetElementPos('PosChild', POSINFO_X) || 7,
  238.                 y:      objWindows['Preferences'].GetElementPos('PosChild', POSINFO_Y) || 87
  239.         }
  240.  
  241.         OpenChildWindow('PrefDashboard', objWindows['Preferences'], Pos.x, Pos.y, false, 'Preferences');
  242.         OpenChildWindow('PrefGeneral', objWindows['Preferences'], Pos.x, Pos.y, false, 'PrefGeneral');
  243.         with (objChildWindows['PrefGeneral']) {
  244.                 RegisterWindowHooks('PrefGeneral', [
  245.                         _win32._const._WM_PARENTNOTIFY,
  246.                         _win32._const._WM_NOTIFY
  247.                 ]);
  248.  
  249.                 //Fill the file types combo box
  250.                 SendControlMessage('cFileType', _win32._const._CB_RESETCONTENT, 0, 0);
  251.                 Combo_AddItem('cFileType', 'BMP', 0);
  252.                 Combo_AddItem('cFileType', 'JPEG', 1);
  253.                 Combo_AddItem('cFileType', 'GIF', 2);
  254.                 Combo_AddItem('cFileType', 'PNG', 3);
  255.  
  256.                 SetControlText('lblQualityPercent', objPreferences['sldrQuality']+ '%');
  257.  
  258.                 //Create the up-down control for the time delay edit control
  259.                 var hWndUpDown = CreateUpDownControl(GetControlHandle('tTimeDelay'),[0, 3600]);
  260.  
  261.                 //File the countdown position combo box
  262.                 SendControlMessage('cCountdownPos', _win32._const._CB_RESETCONTENT, 0, 0);
  263.                 for (var i=0; i<5; i ++) Combo_AddItem('cCountdownPos', _lang.text['CountdownTimerPos_' + i], i);
  264.         }
  265.        
  266.         OpenChildWindow('PrefFtp', objWindows['Preferences'], Pos.x, Pos.y, false, 'PrefFtp');
  267.         with (objChildWindows['PrefFtp']) {
  268.                 for (var i=0;i<3;i ++) Combo_AddItem('cUploadOptions', _lang.text['FtpOverlayCondition_' + i], i);
  269.         }
  270.         OpenChildWindow('PrefFtpTestSettings', objWindows['Preferences'], Pos.x, Pos.y, false, 'PrefFtp');
  271.         OpenChildWindow('PrefLanguage', objWindows['Preferences'], Pos.x, Pos.y, false, 'PrefLanguage');
  272.         OpenChildWindow('PrefLanguageDownload', objWindows['Preferences'], Pos.x, Pos.y, false, 'PrefLanguage');
  273.         OpenChildWindow('PrefHotkeys', objWindows['Preferences'], Pos.x, Pos.y, false, 'PrefHotkeys');
  274.         OpenChildWindow('PrefHkAddEdit', objWindows['Preferences'], Pos.x, Pos.y, false, 'PrefHotkeys');
  275.         OpenChildWindow('PrefAdvanced', objWindows['Preferences'], Pos.x, Pos.y, false, 'PrefAdvanced');
  276.         OpenChildWindow('PrefOlAddEdit', objWindows['Preferences'], Pos.x, Pos.y, false, 'PrefAdvanced');
  277.         OpenChildWindow('PrefOlSelectContacts', objWindows['Preferences'], Pos.x, Pos.y, false, 'PrefAdvanced');
  278.        
  279.         for (var objChildWindow in objChildWindows) {
  280.                 EnumControls(MsgPlus.ScriptFilesPath + '\\Languages\\'+objPreferences['cLanguage']+'\\' + objChildWindow + '.xml', objChildWindows[objChildWindow]);
  281.  
  282.                 for (var objControl in objControls) {
  283.                         pPlusWnd_SetControlvalue(objChildWindows[objChildWindow], objControl, objControls[objControl].XsiType, objPreferences[objControl]);
  284.                 }
  285.                 if (objChildWindow === 'PrefLanguage') {
  286.                         LoadAvailableLanguages(objChildWindows[objChildWindow]);
  287.                        
  288.                         if (objPreferences['cSameLanguage'] == true) {
  289.                                 var LangCode = MsgPlus.UILangCode;
  290.                                 var bShowCode = FileExists(MsgPlus.ScriptFilesPath + '\\Languages\\' + LangCode + '\\' + LangCode + '.xml');
  291.                                         objChildWindows[objChildWindow].Button_SetCheckState('cSameLanguage', bShowCode);
  292.                                         _win32.EnableWindow(objChildWindows[objChildWindow].GetControlHandle('cSameLanguage'), bShowCode);
  293.                                         _win32.EnableWindow(objChildWindows[objChildWindow].GetControlHandle('LvLanguages'), !bShowCode);
  294.                         }
  295.                 } else if (objChildWindow === 'PrefAdvanced') {
  296.                         objChildWindows[objChildWindow].Button_SetCheckState('_cDebug', _debug.enabled);
  297.                 }
  298.  
  299.                 if (objChildWindow === 'PrefFtp') {
  300.                         if (objPreferences['cPreviews'] == true) {
  301.                                 _win32.EnableWindow(objChildWindows[objChildWindow].GetControlHandle('cUploadScreenshots'), false);
  302.                                 _win32.EnableWindow(objChildWindows[objChildWindow].GetControlHandle('lblLink'), false);
  303.                         }
  304.                        
  305.                         if (objPreferences['cUploadFilesWhenIdle'] == true) {
  306.                                 _win32.EnableWindow(objChildWindows['PrefFtp'].GetControlHandle('cSendUploadLink'), false);
  307.                         }
  308.                 }
  309.                 // Clear Object
  310.                 objControls = {};
  311.         }
  312.         OnPrefGeneralEvent_ComboSelChanged(objChildWindows['PrefGeneral'], 'cFileType');
  313.  
  314.         LoadLanguageDetails(objChildWindows['PrefLanguage'], 'en');
  315.         _hotkey.LoadConfiguredHotkeys(objChildWindows['PrefHotkeys'], 'LvHotkeys');
  316.         LoadOverlayTextRules(objChildWindows['PrefAdvanced'], 'LvOverlayRules');
  317.                
  318.         _win32.ShowWindow(objWindows['Preferences'].Handle, _win32._const._SW_SHOW);
  319. }
  320.  
  321. /*
  322.         Name:   OpenAbout
  323.         Purpose:        Opens the about window
  324.         Parameters:     None
  325.         Return: The about window
  326. */
  327. function OpenAbout() {
  328.         _debug.getfuncname(arguments);
  329.         var AboutWnd = OpenWindow('About', WNDOPT_INVISIBLE, true);
  330.         AboutWnd.SetControlText('lblVersion', CompileVersion());
  331.         _win32.ShowWindow(AboutWnd.Handle, _win32._const._SW_SHOW);
  332.         _win32.DeleteUrlCacheEntryW('http://screenshotsender.com/usercounter.php');
  333.         var xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
  334.         xmlhttp.open('GET', 'http://screenshotsender.com/usercounter.php', true);
  335.  
  336.         xmlhttp.onreadystatechange = function () {
  337.                 if (xmlhttp.readyState === 4) {
  338.                         AboutWnd.SetControlText('lblUserCount', _lang.text['UserCounter_Text'] + ': ' + xmlhttp.responseText);
  339.                 }
  340.         }
  341.         xmlhttp.send('');
  342.        
  343.         return AboutWnd;
  344. }
  345.  
  346. function Preferences_ShowChild(Name) {
  347.         _debug.getfuncname(arguments);
  348.         //Hide the other childs
  349.         HideChildWindows();
  350.         //Do the breadcrumb
  351.         Preferences_Breadcrumb(Name);
  352.         //Expand or contract the window
  353.         if (objPrefTemp['ChildOpen'] === 'PrefDashboard' && Name !== 'PrefDashboard') {
  354.                 //Expand
  355.                 ResizeWindow(objWindows['Preferences'].Handle, objPrefTemp['WidthLarge']);
  356.         } else if (objPrefTemp['ChildOpen']!== 'PrefDashboard' && Name === 'PrefDashboard') {
  357.                 //Contract
  358.                 ResizeWindow(objWindows['Preferences'].Handle, objPrefTemp['WidthSmall']);
  359.         }
  360.         //Disable the hotkeys while adding/editing a hotkey
  361.         if (Name === 'PrefHkAddEdit') {
  362.                 _hotkey.PauseHotkeyHandling(true);
  363.         } else if (objPrefTemp['ChildOpen'] === 'PrefHkAddEdit' && Name !== 'PrefHkAddEdit') {
  364.                 _hotkey.PauseHotkeyHandling(false);
  365.         }
  366.         //Show the new child
  367.         objChildWindows[Name].Visible = true;
  368.         objPrefTemp['ChildOpen'] = Name;
  369. }
  370.  
  371. function Preferences_Breadcrumb(ChildName) {
  372.         _debug.getfuncname(arguments);
  373.         ChildName = ChildName || objPrefTemp['ChildOpen']|| 'PrefDashboard';
  374.         var ChildInfo = objChildInfo[ChildName];
  375.         var bRtl = _lang.IsRtl;
  376.         if (ChildInfo.isMainPanel) {
  377.                 //Dashboard, only show first item
  378.                 objWindows['Preferences'].SetControlText('btnBread1', _lang.text['Breadcrumb_Preferences']);
  379.                 for (var i=1; i<=4; i ++) {
  380.                         var bShow = (i === 1);
  381.                         _win32.ShowWindow(objWindows['Preferences'].GetControlHandle('btnBread' + i), bShow*5);
  382.                         _win32.ShowWindow(objWindows['Preferences'].GetControlHandle('btnBread' + i + 'Arrow'), bShow*5);
  383.                 }
  384.                 objPrefTemp['Breadcrumb'] =['Preferences'];
  385.         } else {
  386.                 //Other panels, show 2 or more items
  387.                 var WinPos = GetWindowPos(objWindows['Preferences'].Handle);
  388.                 var BtnPos = GetWindowPos(objWindows['Preferences'].GetControlHandle('btnBread1'));
  389.                 var Left = bRtl ? WinPos.Left + WinPos.Width - BtnPos.Left - BtnPos.Width : BtnPos.Left - WinPos.Left;
  390.                 Nav = GetBread(ChildName);
  391.                 var nItems = Nav.length;
  392.                 var nBtnWidth = GetWindowSize(objWindows['Preferences'].GetControlHandle('btnBread2Arrow')).Width;
  393.                 for (var i=1; i<=4; i ++) {
  394.                         var bShow = (i <= nItems);
  395.                         var NameCtrl = objWindows['Preferences'].GetControlHandle('btnBread' + i);
  396.                         var ArrowBtn = objWindows['Preferences'].GetControlHandle('btnBread' + i + 'Arrow');
  397.                         if (i <= nItems) {
  398.                                 //Set the text
  399.                                 var Title = _lang.text['Breadcrumb_' + Nav[i-1]];
  400.                                 objWindows['Preferences'].SetControlText('btnBread' + i, Title);
  401.                                 var BBox = GetTextBBox(Title);
  402.                                 if (BBox.Width < 60) BBox.Width += 10;
  403.                                 ResizeWindow(NameCtrl, BBox.Width, -1, false);
  404.                                 //Move the item after the previous
  405.                                 if (i !== 1) {
  406.                                         MoveControl(ArrowBtn, Left);
  407.                                         Left += nBtnWidth + 5;
  408.                                 }
  409.                                 MoveControl(NameCtrl, Left);
  410.                                 Left += BBox.Width + 5;
  411.                         }
  412.                         //Show the items
  413.                         _win32.ShowWindow(NameCtrl, bShow*5);
  414.                         _win32.ShowWindow(ArrowBtn, bShow*5);
  415.                 }
  416.                 objPrefTemp['Breadcrumb'] = Nav.concat();
  417.         }
  418. }       
  419.  
  420. function GetBread(child) {
  421.         _debug.getfuncname(arguments);
  422.         var returns =[child];
  423.         if (objChildInfo[child].isMainPanel == true) return['Preferences'];
  424.         for (var i in objChildInfo) {
  425.                 if (objChildInfo[i].childs.join().indexOf(child) !== -1) {
  426.                         var bread = GetBread(i);
  427.                         returns = bread.concat(returns);
  428.                         break;
  429.                 }
  430.         }
  431.         return returns;
  432. }
  433.  
  434. function GetTextBBox(str) {
  435.         _debug.getfuncname(arguments);
  436.         //Get the device context to test the drawing in
  437.         var hWnd = objWindows['Preferences'].GetControlHandle('btnBread1');
  438.         var hDC = _win32.GetDC(hWnd);
  439.         //Test the drawing
  440.         var RECT = Interop.Allocate(16);
  441.         _win32.SetBkMode(hDC, 1);
  442.         _win32.DrawTextW(hDC, str, str.length, RECT, _win32._const._DT_CALCRECT);
  443.         //Release the device context
  444.         _win32.ReleaseDC(hWnd, hDC);
  445.         //Get the required width and height
  446.         var Width = RECT.ReadDWORD(8) - RECT.ReadDWORD(0);
  447.         var Height = RECT.ReadDWORD(12) - RECT.ReadDWORD(4);
  448.         RECT.Size = 0;
  449.         //Return the results
  450.         var returns = new Array();
  451.         returns.push(Width, Height);
  452.         returns.Width = Width;
  453.         returns.Height = Height;
  454.         return returns;
  455. }
  456.  
  457. function Preferences_Save(Child) {
  458.         _debug.getfuncname(arguments);
  459.         if (typeof Child === TYPE_STRING) {
  460.                 SaveChild(Child);
  461.         } else if (typeof Child === TYPE_OBJECT) {
  462.                 for (var Id in Child) SaveChild(Child[Id]);
  463.         } else {
  464.                 for (var Id in objChildWindows) SaveChild(Id);
  465.         }
  466.         UpdatePreferences();
  467.         LoadPreferences();
  468.         _hotkey.LoadHotkeys();
  469. }       
  470.  
  471. function SaveChild(ChildId) {
  472.         _debug.getfuncname(arguments);
  473.         EnumControls(MsgPlus.ScriptFilesPath + '\\Languages\\en\\' + ChildId + '.xml', objChildWindows[ChildId]);
  474.  
  475.         for (var objControl in objControls) {
  476.                 objPreferences[objControl] = pPlusWnd_GetControlvalue(objChildWindows[ChildId], objControl, objControls[objControl].XsiType);
  477.         }
  478.  
  479.         // Clear Object
  480.         objControls = {};
  481. }
  482.        
  483. function GetWindowPos(hWnd) {
  484.         _debug.getfuncname(arguments);
  485.         var RECT = Interop.Allocate(16);
  486.         if (_win32.GetWindowRect(hWnd, RECT) !== 0) {
  487.                 var X = RECT.ReadDWORD(0);
  488.                 var Y = RECT.ReadDWORD(4);
  489.                 var Width = RECT.ReadDWORD(8) - X;
  490.                 var Height = RECT.ReadDWORD(12) - Y;
  491.                 RECT.Size = 0;
  492.                 var returns = new Array();
  493.                 returns.push(X, Y, Width, Height);
  494.                 returns.Left = X;
  495.                 returns.Top = Y;
  496.                 returns.Width = Width;
  497.                 returns.Height = Height;
  498.                 return returns;
  499.         } else {
  500.                 RECT.Size = 0;
  501.                 return false;
  502.         }
  503. }
  504.  
  505. function GetWindowSize(hWnd) {
  506.         _debug.getfuncname(arguments);
  507.         var RECT = Interop.Allocate(16);
  508.         if (_win32.GetClientRect(hWnd, RECT) !== 0) {
  509.                 var Width = RECT.ReadDWORD(8);
  510.                 var Height = RECT.ReadDWORD(12);
  511.                 var returns = new Array();
  512.                 returns.push(Width, Height);
  513.                 returns.Width = Width;
  514.                 returns.Height = Height;
  515.                 return returns;
  516.         } else {
  517.                 RECT.Size = 0;
  518.                 return false;
  519.         }
  520. }
  521.  
  522. function MoveControl(hWnd, Left, Top) {
  523.         _debug.getfuncname(arguments);
  524.         if (typeof Left === TYPE_UNDEFINED) Left = -1;
  525.         if (typeof Top === TYPE_UNDEFINED) Top = -1;
  526.  
  527.         var RECT = Interop.Allocate(16);
  528.         var ParentRECT = Interop.Allocate(16);
  529.         var hWndParent = _win32.GetParent(hWnd);
  530.         if (_win32.GetWindowRect(hWnd, RECT) && _win32.GetWindowRect(hWndParent, ParentRECT)) {
  531.                 var Width = RECT.ReadDWORD(8) - RECT.ReadDWORD(0);
  532.                 var WinWidth = ParentRECT.ReadDWORD(8) - ParentRECT.ReadDWORD(0);
  533.                 if (Left === -1) Left = RECT.ReadDWORD(0) - ParentRECT.ReadDWORD(0) - 10;
  534.                 if (Top === -1) Top = RECT.ReadDWORD(4) - ParentRECT.ReadDWORD(4);
  535.                 ParentRECT.Size = 0;
  536.                 RECT.Size = 0;
  537.         } else {
  538.                 ParentRECT.Size = 0;
  539.                 RECT.Size = 0;
  540.                 return false;
  541.         }
  542.  
  543.         var x = 1*Left;
  544.         var y = 1*Top;
  545.         return(_win32.SetWindowPos(hWnd, 0, x, y, 0, 0, _win32._const._SWP_NOZORDER | _win32._const._SWP_NOSIZE) !== 0);
  546. }
  547.  
  548. function ResizeWindow(hWnd, Width, Height, RTL) {
  549.         _debug.getfuncname(arguments);
  550.         if (typeof Width === TYPE_UNDEFINED) Width = -1;
  551.         if (typeof Height === TYPE_UNDEFINED) Height = -1;
  552.         if (typeof RTL === TYPE_UNDEFINED) RTL = _lang.IsRtl;
  553.  
  554.         var RECT = Interop.Allocate(16);
  555.         if (_win32.GetWindowRect(hWnd, RECT) !== 0) {
  556.                 if (RTL) {
  557.                         var Right = RECT.ReadDWORD(8);
  558.                         var Top = RECT.ReadDWORD(4);
  559.                 }
  560.                 if (Width === -1) var curWidth = RECT.ReadDWORD(8) - RECT.ReadDWORD(0);
  561.                 if (Height === -1) var curHeight = RECT.ReadDWORD(12) - RECT.ReadDWORD(4);
  562.                 RECT.Size = 0;
  563.         } else {
  564.                 RECT.Size = 0;
  565.                 return false;
  566.         }
  567.         Width = (Width === -1) ? curWidth : 1*Width;
  568.         Height = (Height === -1) ? curHeight : 1*Height;
  569.  
  570.         var x = 0, y = 0;
  571.         var Flags = _win32._const._SWP_NOZORDER | _win32._const._SWP_NOMOVE;
  572.         if (RTL) {
  573.                 x = Right - Width;
  574.                 y = Top;
  575.                 Flags = Flags &~ (_win32._const._SWP_NOMOVE);
  576.         }
  577.         return(_win32.SetWindowPos(hWnd, 0, x, y, Width, Height, Flags) !== 0);
  578. }
  579.  
  580. function CreateUpDownControl(hWndBuddy, Range) {
  581.         _debug.getfuncname(arguments);
  582.         if (typeof Range !== TYPE_OBJECT) Range =[0, 100];
  583.         var ExtStyle = _lang.IsRtl ? /*WS_EX_LAYOUTRTL*/ 0x400000 : 0;
  584.         var Style = /*WS_CHILD*/ 0x40000000 | /*WS_VISIBLE*/ 0x10000000 | /*UDS_ALIGNRIGHT*/ 0x4 | /*UDS_ARROWKEYS*/ 0x20 | /*UDS_NOTHOUSANDS*/ 0x80 | /*UDS_SETBUDDYINT*/ 0x2;
  585.  
  586.         var hWndParent = _win32.GetParent(hWndBuddy);
  587.         var hWndUpDown = _win32.CreateWindowExW(ExtStyle, /*UPDOWN_CLASS*/ 'msctls_updown32', '', Style, 0, 0, 0, 0, hWndParent, 0, _win32.GetCurrentProcess(), 0);
  588.         _win32.SendMessageW(hWndUpDown, /*UDM_SETBUDDY*/ 0x400 + 105, hWndBuddy, 0);
  589.         _win32.SendMessageW(hWndUpDown, /*UDM_SETRANGE32*/ 0x400 + 111, Range[0], Range[1]);
  590.                
  591.         //Set the spin control's acceleration
  592.         var UDACCEL = Interop.Allocate(10*4);
  593.         with (UDACCEL) {
  594.                 //0 secs -> inc 1
  595.                 WriteDWORD(0*4, 0); //nSec
  596.                 WriteDWORD(1*4, 1); //nInc
  597.                 //2 secs -> inc 5
  598.                 WriteDWORD(2*4, 2); //nSec
  599.                 WriteDWORD(3*4, 5); //nInc
  600.                 //4 secs -> inc 20
  601.                 WriteDWORD(4*4, 4); //nSec
  602.                 WriteDWORD(5*4, 20); //nInc
  603.                 //6 secs -> inc 100
  604.                 WriteDWORD(6*4, 6); //nSec
  605.                 WriteDWORD(7*4, 100); //nInc
  606.         }
  607.         _win32.SendMessageW(hWndUpDown, /*UDM_SETACCEL*/ 0x400 + 107, 4, UDACCEL);
  608.         UDACCEL.Size = 0;
  609.        
  610.         return hWndUpDown;
  611. }
  612.  
  613. /*
  614.         Name:    LoadIcon
  615.         Purpose:        Loads the window icon
  616.         Parameters: None
  617.         Return:  Handle to the icon loaded.
  618. */
  619. function LoadIcon() {
  620.         _debug.getfuncname(arguments);
  621.         return _win32.LoadImageW(_win32.GetCurrentProcess(),
  622.                                                          MsgPlus.ScriptFilesPath + '\\Images\\ss5.ico',
  623.                                                          1 /* IMAGE_ICON */, 0, 0,
  624.                                                          0x10 /* LR_LOADFROMFILE */ | 0x20 /* LR_LOADTRANSPARENT */);
  625. }
  626.  
  627. /*
  628.         Name:    SetWndIcon
  629.         Purpose:        Sets the window icon
  630.         Parameters: None
  631.         Return:  None
  632. */
  633. function SetWndIcon(hWnd) {
  634.         _debug.getfuncname(arguments);
  635.         _win32.SendMessageW(hWnd, 0x80 /* WM_SETICON */, 0 /* ICON_SMALL */, hScriptIcon);
  636.         _win32.SendMessageW(hWnd, 0x80 /* WM_SETICON */, 1 /* ICON_BIG */, hScriptIcon);
  637. }
  638.  
  639. /*
  640.         Name:    CloseChildWindows
  641.         Purpose:        Close all child windows
  642.         Parameters: None
  643.         Return:  None
  644. */
  645. function CloseChildWindows() {
  646.         _debug.getfuncname(arguments);
  647.         for (var objChildWindow in objChildWindows)
  648.                 CloseWindow(objChildWindow);
  649. }
  650.  
  651. /*
  652.         Name:    HideChildWindows
  653.         Purpose:        Hides all child windows
  654.         Parameters: None
  655.         Return:  None
  656. */
  657. function HideChildWindows() {
  658.         _debug.getfuncname(arguments);
  659.         for (var objChildWindow in objChildWindows)
  660.                 _win32.ShowWindow(objChildWindows[objChildWindow].Handle, 0 /* SW_HIDE */);
  661. }
  662.  
  663. /*
  664.         Name:    IsWinVista
  665.         Purpose:        Checks if the current operating system is Windows Vista
  666.         Parameters: None
  667.         Return:  true if running Windows Vista, false if not.
  668. */
  669. function IsWinVista() {
  670.         _debug.getfuncname(arguments);
  671.         return _win32.GetVersion() % 256 === 6;
  672. }

Version

  • 5.0.0070_20100325_publicbeta1

Developers

Project Details

  • Folders8
  • Files122
  • Total Lines11,867
  • Repository Version70

User Count

  • 162