Best JavaScript code snippet using playwright-internal
neoOffice.js
Source:neoOffice.js
...41 return xModel;42};43Office.prototype.executeDispatch = function(unoSlotName,PropertyValueArray){44 var dis = this.GetServiceManager().createInstance("com.sun.star.frame.DispatchHelper");45 return dis.executeDispatch(this.getPluginFrame(),unoSlotName,"",0,PropertyValueArray);46};47Office.prototype.MakePropertyValue =function(cName, uValue){48 var oPropertyValue = this.NEOSHINE_Office.Bridge_GetStruct("com.sun.star.beans.PropertyValue");49 oPropertyValue.Name = cName;50 oPropertyValue.Value = uValue;51 return oPropertyValue;52};53//private:factory/swriter54Office.prototype.CreateNew = function(doctype){55 var arr= this.NEOSHINE_Office.CreateSequence(28,1);56 arr.setProperty(0,"ViewOnly",0,3);57 this.getPluginFrame().loadComponentFromURL(doctype,"_self",55,arr);58};59Office.prototype.CreatePrivate = function(doctype){60 var arr= this.NEOSHINE_Office.CreateSequence(28,0);61 this.getPluginFrame().loadComponentFromURL(doctype,"_self",55,arr);62};63Office.prototype.OpenDocument = function(FileName,nFlag){64 var ret = this.NEOSHINE_Office.DeleteTemplateFile(FileName);65 var arr= this.NEOSHINE_Office.CreateSequence(28,1);66 if(nFlag)67 arr.setProperty(0,"ReadOnly",1,3);68 else69 arr.setProperty(0,"ReadOnly",0,3);70 this.getPluginFrame().loadComponentFromURL(FileName,"_self",55,arr);71};72Office.prototype.OpenDocumentPreview = function(FileName){73 var ret = this.NEOSHINE_Office.DeleteTemplateFile(FileName);74 var arr= this.NEOSHINE_Office.CreateSequence(28,2);75 arr.setProperty(0,"Preview",1,3);76 arr.setProperty(1,"ReadOnly",1,3);77 this.getPluginFrame().loadComponentFromURL(FileName,"_self",55,arr);78};79Office.prototype.Taohong = function(templatePath){80 var ret = this.NEOSHINE_Office.DeleteTemplateFile(templatePath);81 var arr= this.NEOSHINE_Office.CreateSequence(28,1);82 arr.setProperty(0,"AsTemplate",1,3);83 this.getPluginFrame().loadComponentFromURL(templatePath,"_self",55,arr);84};85Office.prototype.ShowRecension = function(Flag){86 this.getModel().setPropertyValue("RedlineDisplayType",Flag);87};88Office.prototype.SwitchRecension = function(bFlag){89try90{91 this.getModel().setPropertyValue("RecordChanges",bFlag);92}93catch(e)94{95}96};97Office.prototype.getRecensionStatus = function(){98 return this.getModel().getPropertyValue("RecordChanges");99};100Office.prototype.ShowRecensionDialog = function(){101 var arr= this.NEOSHINE_Office.CreateSequence(28,1);102 this.executeDispatch(".uno:AcceptTrackedChanges",arr);103};104Office.prototype.AcceptAllChanges = function(){105 var arr= this.NEOSHINE_Office.CreateSequence(28,1);106 this.executeDispatch(".uno:AcceptAllTracedChange",arr);107};108Office.prototype.RejectAllChanges = function(){109 var arr= this.NEOSHINE_Office.CreateSequence(28,1);110 this.executeDispatch(".uno:RejectAllTracedChange",arr);111};112Office.prototype.PrintRevisionWithCertainAuthor = function(Author,bAcceptOther){113 var arr= this.NEOSHINE_Office.CreateSequence(28,1);114 var oViewCursor = this.getController().getViewCursor();115 var oRedLines = this.getModel().getRedlines();116 var ncount = oRedLines.getCount();117 var startRange = oViewCursor.getStart();118 var nsuccessexe = 0;119 if (oRedLines.hasElements())120 {121 var aEnum = oRedLines.createEnumeration();122 while(aEnum.hasMoreElements())123 {124 var oRedLine = aEnum.nextElement();125 var redlineAuthor = oRedLine.getPropertyValue("RedlineAuthor");126 if(Author.trim() != redlineAuthor.trim())127 {128 oViewCursor.gotoRange(oRedLine.getPropertyValue("RedlineStart"), false);129 oViewCursor.gotoRange(oRedLine.getPropertyValue("RedlineEnd"), true);130 var redlineText = oViewCursor.getString();131 oViewCursor.goLeft(1,false);132 if(bAcceptOther)133 this.executeDispatch(".uno:AcceptTracedChange",arr);134 else135 this.executeDispatch(".uno:RejectTracedChange",arr);136 nsuccessexe++;137 aEnum = oRedLines.createEnumeration();138 }139 }140 }141 oViewCursor.gotoRange(startRange,false);142 // this.getModel().print(arr);//todo143 this.executeDispatch(".uno:PrintDefault",arr);144 for(var i=0;i<nsuccessexe;i++)145 {146 this.executeDispatch(".uno:Undo",arr);147 }148};149Office.prototype.FilterCertainAuthor = function(Author,bAccept){150 var arr= this.NEOSHINE_Office.CreateSequence(28,1);151 var oViewCursor = this.getController().getViewCursor();152 var oRedLines = this.getModel().getRedlines();153 var ncount = oRedLines.getCount();154 var startRange = oViewCursor.getStart();155 if (oRedLines.hasElements())156 {157 var aEnum = oRedLines.createEnumeration();158 while(aEnum.hasMoreElements())159 {160 var oRedLine = aEnum.nextElement();161 var redlineAuthor = oRedLine.getPropertyValue("RedlineAuthor");162 if(Author.trim() == redlineAuthor.trim())163 {164 oViewCursor.gotoRange(oRedLine.getPropertyValue("RedlineStart"), false);165 oViewCursor.gotoRange(oRedLine.getPropertyValue("RedlineEnd"), true);166 var redlineText = oViewCursor.getString();167 oViewCursor.goLeft(1,false);168 if(bAccept)169 this.executeDispatch(".uno:AcceptTracedChange",arr);170 else171 this.executeDispatch(".uno:RejectTracedChange",arr);172 aEnum = oRedLines.createEnumeration();173 }174 }175 }176 oViewCursor.gotoRange(startRange,false);177};178Office.prototype.GetAllRevisions = function(){179 var oViewCursor = this.getController().getViewCursor();180 var oRedLines = this.getModel().getRedlines();181 var ncount = oRedLines.getCount();182 var sDum="";183 var separator = "&";184 var bracketsLeft = "[";185 var bracketsRight = "]";186 var quotationMarks = "\\";187 // sDum += bracketsLeft;188 var startRange = oViewCursor.getStart();189 for(var i=0;i< ncount ;i++)190 {191 var oRedLine = oRedLines.getByIndex(i);192 oViewCursor.gotoRange(oRedLine.getPropertyValue("RedlineStart"), false);193 oViewCursor.gotoRange(oRedLine.getPropertyValue("RedlineEnd"), true);194 var redlineText = oViewCursor.getString();195 // var identify = oRedLine.getPropertyValue("RedlineIdentifier");196 var redlineAuthor = oRedLine.getPropertyValue("RedlineAuthor");197 var redlineDataTime = oRedLine.getPropertyValue("RedlineDateTime");198 var redlineType = oRedLine.getPropertyValue("RedlineType");199 sDum += bracketsLeft;200 // sDum += identify;201 // sDum += quotationMarks;202 // sDum += separator;203 // sDum += quotationMarks;204 sDum += redlineText;205 // sDum += quotationMarks;206 sDum += separator;207 // sDum += quotationMarks;208 sDum += redlineAuthor;209 // sDum += quotationMarks;210 sDum += separator;211 // sDum += quotationMarks;212 sDum += redlineDataTime.Year;213 sDum += "/";214 sDum += redlineDataTime.Month;215 sDum += "/";216 sDum += redlineDataTime.Day;217 sDum += " ";218 sDum += redlineDataTime.Hours;219 sDum += ":";220 sDum += redlineDataTime.Minutes;221 //sDum += ":";222 // sDum += redlineDataTime.Seconds;223 // sDum += quotationMarks;224 sDum += separator;225 // sDum += quotationMarks;226 sDum += redlineType;227 // sDum += quotationMarks;228 // sDum += separator;229 sDum += bracketsRight;230 }231 oViewCursor.gotoRange(startRange,false);232 return sDum;233};234Office.prototype.SetRecensionInfo = function(UserName){235 var sProvider = "com.sun.star.configuration.ConfigurationProvider";236 var sAccess = "com.sun.star.configuration.ConfigurationUpdateAccess";237 var oConfigProvider = this.CreateUnoService(sProvider);238 var arr = new Array(1);239 arr[0] = this.MakePropertyValue("nodepath","/org.openoffice.UserProfile/Data");240 var oSet = oConfigProvider.createInstanceWithArguments(sAccess, arr);241 oSet.setPropertyValue("givenname",UserName);242 oSet.commitChanges();243};244Office.prototype.GetRecensionInfo = function(){245 var sProvider = "com.sun.star.configuration.ConfigurationProvider";246 var sAccess = "com.sun.star.configuration.ConfigurationAccess";247 var oConfigProvider = this.CreateUnoService(sProvider);248 var arr = new Array(1);249 arr[0] = this.MakePropertyValue("nodepath","/org.openoffice.UserProfile/Data");250 var oSet = oConfigProvider.createInstanceWithArguments(sAccess, arr);251 return oSet.getByName("givenname");252};253Office.prototype.HideToolbar = function(toolbarName){254 var xLayoutManager =255 this.getPluginFrame().getPropertyValue("LayoutManager");256 var sToolbarName = "private:resource/toolbar/"+toolbarName;257 var bShow = xLayoutManager.isElementVisible(sToolbarName); 258 if(bShow)259 {260 xLayoutManager.lock();261 xLayoutManager.hideElement(sToolbarName);262 xLayoutManager.unlock();263 }264};265Office.prototype.ShowToolbar = function(toolbarName){266 var xLayoutManager = this.getPluginFrame().getPropertyValue("LayoutManager");267 var sToolbarName = "private:resource/toolbar/"+toolbarName;268 var bShow = xLayoutManager.isElementVisible(sToolbarName);269 if(!bShow)270 {271 xLayoutManager.lock();272 if(!xLayoutManager.showElement(sToolbarName))273 {274 xLayoutManager.createElement(sToolbarName);275 xLayoutManager.showElement(sToolbarName);276 }277 xLayoutManager.unlock();278 }279};280Office.prototype.ShowMenubar = function(menubarName){281 var xLayoutManager = this.getPluginFrame().getPropertyValue("LayoutManager");282 var sMenubarName = "private:resource/menubar/"+menubarName;283 var bShow = xLayoutManager.isElementVisible(sMenubarName);284 if(!bShow)285 {286 this.getModel().lockControllers();287 xLayoutManager.showElement(sMenubarName);288 this.getModel().unlockControllers();289 }290};291Office.prototype.HideMenubar = function(menubarName){292 var xLayoutManager = this.getPluginFrame().getPropertyValue("LayoutManager");293 var sMenubarName = "private:resource/menubar/"+menubarName;294 var bShow = xLayoutManager.isElementVisible(sMenubarName);295 if(bShow)296 {297 this.getModel().lockControllers();298 xLayoutManager.hideElement(sMenubarName);299 this.getModel().unlockControllers();300 }301};302Office.prototype.IsModified = function(){303 return this.getModel().isModified();304};305Office.prototype.SetModified = function(bModified){306 this.getModel().setModified(bModified);307};308Office.prototype.IsReadOnly = function(){309 return this.getModel().isReadonly();310};311Office.prototype.IsLocation = function(){312 return this.getModel().hasLocation();313};314Office.prototype.SetReadOnly = function(bReadOnly){315 if (this.IsLocation() == false) return true;316 if (bReadOnly == this.IsReadOnly()) return true;317 if (bReadOnly)318 {319 var arr= this.NEOSHINE_Office.CreateSequence(28,1);320 this.executeDispatch(".uno:EditDoc",arr);321 this.UpdateContextMenu("remove", "ç¼è¾(~E)", "");322 this.EnableUnoID(".uno:EditDoc", false, false);323 }324 else325 {326 this.UpdateContextMenu("add", "ç¼è¾(~E)", "");327 this.EnableUnoID(".uno:EditDoc", true, false);328 var arr= this.NEOSHINE_Office.CreateSequence(28,1);329 this.executeDispatch(".uno:EditDoc",arr);330 }331 return true;332};333Office.prototype.GetFileURL = function(){334 return this.getModel().getURL();335};336Office.prototype.GetFileTitle = function(){337 return this.getModel().getTitle();338};339Office.prototype.OpenFromURL = function(URL,ReadOnly){ 340 var ret = this.NEOSHINE_Office.DeleteTemplateFile(URL);341 var arr= this.NEOSHINE_Office.CreateSequence(28,1);342 if(ReadOnly)343 arr.setProperty(0,"ReadOnly",1,3);344 //else345 //arr.setProperty(0,"ReadOnly",0,3);346 this.getPluginFrame().loadComponentFromURL(URL,"_self",55,arr);347};348Office.prototype.Save = function(){349 var arr= this.NEOSHINE_Office.CreateSequence(28,0);350 this.executeDispatch(".uno:Save", arr);351};352Office.prototype.SaveAs = function(){353 var arr= this.NEOSHINE_Office.CreateSequence(28,0);354 this.executeDispatch(".uno:SaveAs", arr);355};356//doctype:writer8,writer8_template,MS Word 97,impress8,calc8,calc8_template357Office.prototype.SaveAsOtherFormatToURL = function(URL,doctype){358 var arr= this.NEOSHINE_Office.CreateSequence(28,2);359 arr.setProperty(0,"FilterName",doctype,1);360 arr.setProperty(1,"Overwrite",1,3);361 this.getModel().storeAsURL(URL,arr);362};363Office.prototype.Close = function(){364 var arr= this.NEOSHINE_Office.CreateSequence(28,1);365 this.executeDispatch(".uno:CloseWin",arr);366};367Office.prototype.FindAndReplaceText = function(URL1, URL2){368 if (this.IsReadOnly())369 return false;370 else371 {372 var xReplaceDescriptor = this.getModel().createReplaceDescriptor();373 xReplaceDescriptor.setSearchString(URL1);374 xReplaceDescriptor.setReplaceString(URL2);375 xReplaceDescriptor.setPropertyValue("SearchCaseSensitive", true);376 return this.getModel().replaceAll(xReplaceDescriptor);377 }378};379Office.prototype.ShowSearchDialog = function(){380 var arr= this.NEOSHINE_Office.CreateSequence(28,0);381 this.executeDispatch(".uno:SearchDialog", arr);382};383Office.prototype.SetFontHeight = function(Height){384 var arr= this.NEOSHINE_Office.CreateSequence(28,3);385 arr.setProperty(0,"FontHeight.Height",Height,2);386 arr.setProperty(1,"FontHeight.Prop",100,2);387 arr.setProperty(2,"FontHeight.Diff",0,2);388 this.executeDispatch(".uno:FontHeight",arr);389};390Office.prototype.SetFirstLineIndent = function(LineIndent){391 var arr= this.NEOSHINE_Office.CreateSequence(28,1);392 arr.setProperty(0,"LeftRightMargin.FirstLineIndent",LineIndent,2);393 this.executeDispatch(".uno:LeftRightMargin",arr);394};395Office.prototype.SetParagraphSpacing = function(ParagraphSpacing){396 var xStyleFamiliesSupplier = this.getModel().getStyleFamilies();397 var xParagraphStyles = xStyleFamiliesSupplier.getByName("ParagraphStyles");398 var xStyle = xParagraphStyles.getByName("Standard");399 var aSpaceing = this.NEOSHINE_Office.Bridge_GetStruct("com.sun.star.style.LineSpacing");400 aSpaceing.Mode = 0;401 aSpaceing.Height = ParagraphSpacing;402 xStyle.setPropertyValue("ParaLineSpacing",aSpaceing);403};404Office.prototype.SetFontName = function(FontName){405 var arr= this.NEOSHINE_Office.CreateSequence(28,1);406 arr.setProperty(0,"CharFontName.FamilyName",FontName,1);407 this.executeDispatch(".uno:CharFontName",arr);408};409Office.prototype.GetOfficeVersion = function(){410 var sProvider = "com.sun.star.configuration.ConfigurationProvider";411 var sAccess = "com.sun.star.configuration.ConfigurationAccess";412 var oConfigProvider = this.CreateUnoService(sProvider);413 var arr = new Array(1);414 arr[0] = this.MakePropertyValue("nodepath","/org.openoffice.Setup/Office");415 var oSet = oConfigProvider.createInstanceWithArguments(sAccess, arr);416 return oSet.getByName("LastCompatibilityCheckID");417};418Office.prototype.ShowPageSetDialog = function(){419 var arr= this.NEOSHINE_Office.CreateSequence(28,1);420 this.executeDispatch(".uno:PageDialog",arr);421};422Office.prototype.InsertPageNumber = function(){423 var arr= this.NEOSHINE_Office.CreateSequence(28,1);424 this.executeDispatch(".uno:InsertPageNumberField",arr);425};426Office.prototype.InsertPageHeader = function(){427 if( this.HeaderFooterTogether ) 428 {429 var arr= this.NEOSHINE_Office.CreateSequence(28,0);430 this.executeDispatch(".uno:InsertPageHeaderAndFooter",arr);431 }432 else433 {434 var arr= this.NEOSHINE_Office.CreateSequence(28,2);435 arr.setProperty(0,"PageStyle","é»è®¤",1);436 arr.setProperty(1,"On",1,3);437 this.executeDispatch(".uno:InsertPageHeader",arr);438 }439};440Office.prototype.InsertPageFooter = function(){441 if( this.HeaderFooterTogether )442 {443 var arr= this.NEOSHINE_Office.CreateSequence(28,0);444 this.executeDispatch(".uno:InsertPageHeaderAndFooter",arr);445 this.executeDispatch(".uno:DisplayHeaderOrFooter",arr); 446 }447 else448 {449 var arr= this.NEOSHINE_Office.CreateSequence(28,2);450 arr.setProperty(0,"PageStyle","é»è®¤",1);451 arr.setProperty(1,"On",1,3);452 this.executeDispatch(".uno:InsertPageFooter",arr);453 }454};455Office.prototype.InsertTime = function(sFormat){456 var xNumberFormats = this.getModel().getNumberFormats();457 var nLocale = this.NEOSHINE_Office.Bridge_GetStruct("com.sun.star.lang.Locale");458 var nNewLocale = this.NEOSHINE_Office.Bridge_GetStruct("com.sun.star.lang.Locale");459 nNewLocale.Language = "zh";460 nNewLocale.Country = "CN";461 nNewLocale.Variant = "POSIX";462 nLocale.Language = "zh";463 nLocale.Country = "CN";464 nLocale.Variant = "POSIX";465 var lkey = xNumberFormats.queryKey(sFormat,nLocale,true);466 if(lkey <0)467 lKey = xNumberFormats.addNewConverted(sFormat, nLocale, nNewLocale);468 var arr= this.NEOSHINE_Office.CreateSequence(28,6);469 arr.setProperty(0,"Type",0,2);470 arr.setProperty(1,"SubType",0,2);471 arr.setProperty(2,"Name"," ",1);472 arr.setProperty(3,"Content","0",1);473 arr.setProperty(4,"Format",lkey,2);474 arr.setProperty(5,"Separator"," ",1);475 this.executeDispatch(".uno:InsertField",arr);476};477Office.prototype.InsertTextAtCurrentCursor = function(Title){478 var arr= this.NEOSHINE_Office.CreateSequence(28,1);479 arr.setProperty(0,"Text",Title,1);480 this.executeDispatch(".uno:InsertText",arr);481};482//about BookMarks stt483Office.prototype.RenameBookmark = function(oldBookmark,newBookmark){484 var oBookMarks = this.getModel().getBookmarks();485 if(oBookMarks.hasByName(oldBookmark))486 {487 var xNamed = oBookMarks.getByName(oldBookmark);488 xNamed.setName(newBookmark);489 }490};491Office.prototype.CursorToBookmark = function(aBookmarkName){492 var oBookMarks = this.getModel().getBookmarks();493 if(oBookMarks.hasByName(aBookmarkName))494 {495 var xTextContent = oBookMarks.getByName(aBookmarkName);496 var oViewCursor = this.getController().getViewCursor();497 oViewCursor.gotoRange(xTextContent.getAnchor().getStart(),false);498 //oViewCursor.goRight(1,false);499 return xTextContent;500 }501};502Office.prototype.InsertDocToBookmark = function(aBookmarkName,FileDoc,doctype){503 this.getModel().lockControllers();504 this.SetBookMarks(aBookmarkName," ");505 var oViewCursor = this.getController().getViewCursor();506 this.CursorToBookmark(aBookmarkName);507 oViewCursor.goRight(1,false);508 this.InsertDocDispatch(FileDoc,doctype);509 if(doctype=="MS Word 97")510 {511 this.CursorToBookmark(aBookmarkName);512 oViewCursor.goRight(1,false);513 var arr= this.NEOSHINE_Office.CreateSequence(28,1);514 this.executeDispatch(".uno:delete",arr);515 this.Backspaces();516 var bookcursor = this.CursorToBookmark(aBookmarkName);517 518 oViewCursor.gotoRange(bookcursor.getAnchor().getEnd(),false);519 //oViewCursor.goLeft(1,false);520 this.Backspaces();521 this.Backspaces();522 523 }524 this.getModel().unlockControllers();525 /*this.SetBookMarks(aBookmarkName," ");526 var oViewCursor = this.getController().getViewCursor();527 this.CursorToBookmark(aBookmarkName);528 oViewCursor.goRight(1,false);529 this.InsertDoc(FileDoc,doctype);530 this.CursorToBookmark(aBookmarkName);531 if(bNeedBack){532 oViewCursor.goRight(1,false);533 this.Backspaces();534 }*/535 /*536 this.SetBookMarks(aBookmarkName," ");537 var oViewCursor = this.getController().getViewCursor();538 this.CursorToBookmark(aBookmarkName);539 oViewCursor.goRight(1,false);540 var arr= this.NEOSHINE_Office.CreateSequence(28,2);541 arr.setProperty(0,"Hidden",0,3);542 arr.setProperty(1,"FilterName",doctype,1);543 var ret = this.NEOSHINE_Office.DeleteTemplateFile(FileDoc);544 var doc = this.getDesktop().loadComponentFromURL(FileDoc,"_blank",0,arr);545 var dis = this.GetServiceManager().createInstance("com.sun.star.frame.DispatchHelper");546 var PropertyValueArray = this.NEOSHINE_Office.CreateSequence(28,0);547 dis.executeDispatch(doc.getCurrentController().getFrame(),".uno:SelectAll","", 0,PropertyValueArray);548 dis.executeDispatch(doc.getCurrentController().getFrame(),".uno:Copy","", 0,PropertyValueArray);549 doc.close(true);550 551 dis.executeDispatch(this.getPluginFrame(),".uno:Paste","",0,PropertyValueArray);552 this.CursorToBookmark(aBookmarkName);553 oViewCursor.goRight(1,false);554 this.Backspaces();*/555};556Office.prototype.Backspaces = function(){557 var arr= this.NEOSHINE_Office.CreateSequence(28,1);558 this.executeDispatch(".uno:SwBackspace",arr);559};560Office.prototype.SetBookMarks = function(Name, Value){561 if (this.IsReadOnly())562 return false;563 else564 {565 var xNameAccess = this.getModel().getBookmarks();566 if(!xNameAccess.hasByName(Name))567 return false;568 var xTextRange = xNameAccess.getByName(Name).getAnchor();569 var xText = xTextRange.getText();570 xText.removeTextContent(xNameAccess.getByName(Name));571 xTextRange.setString(Value);572 var Cursor = this.getModel().getCurrentController().getViewCursor();573 Cursor.gotoRange(xTextRange, false);574 var arr= this.NEOSHINE_Office.CreateSequence(28,1);575 arr.setProperty(0,"Bookmark",Name,1);576 this.executeDispatch(".uno:InsertBookmark", arr);577 return true;578 }579};580Office.prototype.CreateBookmarkAtSelection = function(Name){581 if (this.IsReadOnly())582 return false;583 else584 {585 var arr= this.NEOSHINE_Office.CreateSequence(28,1);586 arr.setProperty(0,"Bookmark",Name,1);587 this.executeDispatch(".uno:InsertBookmark", arr);588 var oViewCursor = this.getController().getViewCursor();589 oViewCursor.goRight(1,false);590 this.InsertTextAtCurrentCursor(" ");591 this.Backspaces();592 }593};594Office.prototype.DelBookmark = function(Name){595 if (this.IsReadOnly())596 return false;597 else598 {599 var arr= this.NEOSHINE_Office.CreateSequence(28,1);600 arr.setProperty(0,"Bookmark",Name,1);601 this.executeDispatch(".uno:DeleteBookmark", arr);602 }603};604Office.prototype.GetBookmarkText = function(Name){605 var xNameAccess = this.getModel().getBookmarks();606 if(!xNameAccess.hasByName(Name))607 return false;608 var xTextRange = xNameAccess.getByName(Name).getAnchor();609 return xTextRange.getString();610};611Office.prototype.GetAllBookmarks = function(){612 var xNameAccess = this.getModel().getBookmarks();613 var names = xNameAccess.getElementNames();614 var iArrayLen = names.getLength();615 var arrRet=new Array(iArrayLen);616 for (i=0;i<iArrayLen;i++)617 {618 arrRet[i] = names.getElement(i);619 }620 return arrRet;621};622Office.prototype.ReplaceBookmarkWithPicture = function(Name, PicURL,width, height){623 if (this.IsReadOnly())624 return false;625 else626 {627 if(this.SetBookMarks(Name," "))628 {629 var oViewCursor = this.getController().getViewCursor();630 this.CursorToBookmark(Name);631 oViewCursor.goRight(1,false);632 this.InsertImageAtSelection(PicURL,width,height);633 }634 else635 {636 return false;637 }638 }639};640Office.prototype.HasBookMark = function(Name){641 var xNameAccess = this.getModel().getBookmarks();642 if(!xNameAccess.hasByName(Name))643 return false;644 else645 return true;646}647//about BookMarks end648Office.prototype.getDocumentText = function(){649 return this.getModel().getText().getString();650};651Office.prototype.PutRemoteContent = function(URL1, URL2){652var OfficeContent = this.GetNEOSHINE_Office();653OfficeContent.PutRemoteContent(URL1,URL2);654};655Office.prototype.GetRemoteContent = function(URL1, URL2){656 var OfficeContent = this.GetNEOSHINE_Office();657 OfficeContent.GetRemoteContent(URL1,URL2);658};659Office.prototype.GetRemoteContentNoOpen = function(URL1, URL2){660var OfficeContent = this.GetNEOSHINE_Office();661OfficeContent.GetRemoteContentNoOpen(URL1,URL2);662};663Office.prototype.OpenRemoteDocument = function(URL1, ReadOnly){664var OfficeContent = this.GetNEOSHINE_Office();665OfficeContent.OpenRemoteDocument(URL1,ReadOnly);666};667Office.prototype.HttpInit = function(){668var OfficeContent = this.GetNEOSHINE_Office();669OfficeContent.HttpInit();670};671Office.prototype.HttpAddPostFile = function(Name,URL){672var OfficeContent = this.GetNEOSHINE_Office();673OfficeContent.HttpAddPostFile(Name,URL);674};675Office.prototype.HttpAddPostString = function(Name,Value){676var OfficeContent = this.GetNEOSHINE_Office();677OfficeContent.HttpAddPostString(Name,Value);678};679Office.prototype.HttpPost = function(URL){680var OfficeContent = this.GetNEOSHINE_Office();681OfficeContent.HttpPost(URL);682};683Office.prototype.SavePDF = function(){684 var arr= this.NEOSHINE_Office.CreateSequence(28,0);685 this.executeDispatch(".uno:ExportDirectToPDF", arr);686};687Office.prototype.exportPDF = function(URL){//URL example:688 "file:///home/liuy/workspace/pdfexporttest.pdf"689 var arr= this.NEOSHINE_Office.CreateSequence(28,2);690 arr.setProperty(0,"URL",URL,1);691 arr.setProperty(1,"FilterName","writer_pdf_Export",1);692 this.executeDispatch(".uno:ExportDirectToPDF", arr);693};694Office.prototype.Print = function(){695 var arr= this.NEOSHINE_Office.CreateSequence(28,0);696 this.executeDispatch(".uno:PrintDefault", arr);697};698Office.prototype.ShowPrintDialog = function(){699 var arr= this.NEOSHINE_Office.CreateSequence(28,0);700 this.executeDispatch(".uno:Print", arr);701};702Office.prototype.PrintPreview = function(){703 var arr= this.NEOSHINE_Office.CreateSequence(28,0);704 this.executeDispatch(".uno:PrintPreview", arr);705};706/*707* @param sPage é¡µæ° =0(å
¨é¨)ï¼=æ°å(页æ°),=x-x(èå´) (excelåªè½ä¸ºæ°å)708* @param nCount 份æ°709* @param nPaperOrientation è¿çº¸æ¹å =0(纵å) =1(横å)710* @param nPaperFormat 纸å =0(A3) =1(A4) =2(A5) =3(B4) =4(B5) =5(LETTER) =6(LEGAL) =7(TABLOID) =8(USER)711* @param nPagerWidth 纸宽 åä½1/1000åç±³712* @param nPagerHeight çº¸é« åä½1/1000åç±³713*/714Office.prototype.OpenPrint = function(nCount,sPage,nPaperOrientation,nPaperFormat,nPagerWidth,nPagerHeight)715{716 var PrinterDescriptor = this.NEOSHINE_Office.CreateSequence(28,3);717 var size = this.NEOSHINE_Office.Bridge_GetStruct("com.sun.star.awt.Size");718 size.Width = nPagerWidth;719 size.Height = nPagerHeight;720 PrinterDescriptor.setProperty(0,"PaperOrientation",nPaperOrientation,2);721 PrinterDescriptor.setProperty(1,"PaperFormat",nPaperFormat,2);722 PrinterDescriptor.setProperty(2,"PaperSize",size,4);723 this.getModel().setPrinter(PrinterDescriptor);724 if(sPage == "0")725 {726 var arr= this.NEOSHINE_Office.CreateSequence(28,1);727 arr.setProperty(0,"CopyCount",nCount,2); 728 this.getModel().print(arr);729 }730 else731 {732 var arr= this.NEOSHINE_Office.CreateSequence(28,2);733 arr.setProperty(0,"Pages",sPage,1);734 arr.setProperty(1,"CopyCount",nCount,2); 735 this.getModel().print(arr);736 }737};738Office.prototype.InsertTableAtSelection = function(TableName,ColumnCount,RowCount){739 if (this.IsReadOnly())740 return false;741 else742 {743 var arr= this.NEOSHINE_Office.CreateSequence(28,4);744 arr.setProperty(0,"TableName",TableName,1);745 arr.setProperty(1,"Columns",ColumnCount,2);746 arr.setProperty(2,"Rows",RowCount,2);747 arr.setProperty(3,"Flags",11,2);748 this.executeDispatch(".uno:InsertTable", arr);749 }750};751Office.prototype.RemoveTable = function(TableName){752 if (this.IsReadOnly())753 return false;754 else755 {756 if(this.CursorToCell(TableName,1,1))757 {758 var arr= this.NEOSHINE_Office.CreateSequence(28,1);759 arr.setProperty(0,"TableName",TableName,1);760 this.executeDispatch(".uno:DeleteTable", arr);761 return true;762 }763 else764 return false;765 }766};767Office.prototype.SetCellContent = function(TableName,ColumnCount,RowCount,Context){768 var xNameAccess = this.getModel().getTextTables();769 if(xNameAccess.hasByName(TableName))770 {771 var xTextTable = xNameAccess.getByName(TableName);772 if(RowCount < 1 || RowCount > xTextTable.getRows().getCount() || ColumnCount < 1 || ColumnCount > xTextTable.getColumns().getCount())773 {774 return false;775 }776 var xCell = xTextTable.getCellByPosition((ColumnCount-1),(RowCount-1));777 var xViewCursor = this.getController().getViewCursor();778 xViewCursor.gotoRange(xCell,false);779 var cellProperties = xViewCursor.getPropertyValue("Cell");780 var ProtectedProperties = cellProperties.getPropertyValue("IsProtected");781 if(ProtectedProperties)782 return false;783 else784 {785 xCell.setString(Context);786 return true;787 }788 }789 else790 return false;791};792Office.prototype.GetCellContent = function(TableName,ColumnCount,RowCount){793 var xNameAccess = this.getModel().getTextTables();794 if(xNameAccess.hasByName(TableName))795 {796 var xTextTable = xNameAccess.getByName(TableName);797 if(RowCount < 1 || RowCount > xTextTable.getRows().getCount() || ColumnCount < 1 || ColumnCount > xTextTable.getColumns().getCount())798 {799 return false;800 }801 var xCell = xTextTable.getCellByPosition((ColumnCount-1),(RowCount-1));802 return xCell.getString();803 }804 else805 return false;806};807Office.prototype.SetCellProtected = function(TableName,ColumnCount,RowCount,IsProtected){808 if (this.IsReadOnly())809 return false;810 else811 {812 if(this.CursorToCell(TableName,ColumnCount,RowCount))813 {814 var arr= this.NEOSHINE_Office.CreateSequence(28,0);815 if(IsProtected)816 this.executeDispatch(".uno:Protect", arr);817 else818 this.executeDispatch(".uno:UnsetCellsReadOnly", arr);819 }820 }821};822Office.prototype.SetTableBorderVisible = function(TableName,IsVisible){823 if (this.IsReadOnly())824 return false;825 else826 {827 var xNameAccess = this.getModel().getTextTables();828 if(xNameAccess.hasByName(TableName))829 {830 var xTextTable = xNameAccess.getByName(TableName);831 var borderLine = this.NEOSHINE_Office.Bridge_GetStruct("com.sun.star.table.BorderLine");832 borderLine.Color = 0x000000;833 if(!IsVisible)834 borderLine.OuterLineWidth = 0 ;835 else836 borderLine.OuterLineWidth = 1 ;837 var tableBorder = this.NEOSHINE_Office.Bridge_GetStruct("com.sun.star.table.TableBorder");838 tableBorder.BottomLine = tableBorder.HorizontalLine =839 tableBorder.LeftLine = tableBorder.RightLine = tableBorder.TopLine =840 tableBorder.VerticalLine = borderLine;841 tableBorder.IsVerticalLineValid = tableBorder.IsHorizontalLineValid =842 tableBorder.IsLeftLineValid = tableBorder.IsRightLineValid =843 tableBorder.IsTopLineValid = tableBorder.IsBottomLineValid = true;844 xTextTable.setPropertyValue("TableBorder",tableBorder);845 return true;846 }847 else848 return false;849 }850};851/*Office.prototype.InsertImageAtSelectionTail = function(URL){852 if (this.IsReadOnly())853 return false;854 else855 {856 var arr= this.NEOSHINE_Office.CreateSequence(28,4);857 arr.setProperty(0,"FileName",URL,1);858 arr.setProperty(1,"FilterNames","<ææçæ ¼å¼>",1);859 arr.setProperty(2,"AsLink",0,3);860 arr.setProperty(3,"Style","å¾å½¢",1);861 this.executeDispatch(".uno:InsertGraphic", arr);862 }863};*/864Office.prototype.InsertImageAtSelection = function(URL,width,height){865 if (this.IsReadOnly())866 return false;867 else868 {869 var xTextRange = this.getModel().getCurrentController().getViewCursor();870 var xTextPicture = xTextRange.getText();871 var xShape = this.getModel().createInstance("com.sun.star.drawing.GraphicObjectShape");872 var size = this.NEOSHINE_Office.Bridge_GetStruct("com.sun.star.awt.Size");873 size.Width = width;874 size.Height = height;875 xShape.setSize(size);876 var xGraphicProvider = this.CreateUnoService("com.sun.star.graphic.GraphicProvider");877 var propertyValue = this.NEOSHINE_Office.CreateSequence(28,1);878 propertyValue.setProperty(0,"URL",URL,1);879 var xGraphic = xGraphicProvider.queryGraphic(propertyValue);880 xShape.setPropertyValue("Graphic", xGraphic);881 xTextPicture.insertTextContent(xTextRange,xShape,true);882 }883};884Office.prototype.SearchText = function(SText, bForward){885 var desktop = this.getDesktop();886 var component = desktop.getCurrentComponent();887 var searcher = component.createSearchDescriptor();888 if(!bForward)889 searcher.setPropertyValue("SearchBackwards", true);890 searcher.setSearchString(SText);891 var range = this.getModel().getCurrentController().getViewCursor();892 try893 {894 if(bForward)895 range = component.findNext(range.getEnd(),searcher);896 else897 range = component.findNext(range.getStart(),searcher);898 var xText = range.getText();899 var xTextCursor = xText.createTextCursorByRange(range);900 var controller = component.getCurrentController();901 controller.select(xTextCursor);902 }903 catch(e)904 {905 if(bForward)906 range = component.findFirst(searcher);907 else908 {909 range = component.findNext(this.getModel().getText().getEnd(),searcher);910 }911 var xText = range.getText();912 var xTextCursor = xText.createTextCursorByRange(range);913 var controller = component.getCurrentController();914 controller.select(xTextCursor);915 }916};917Office.prototype.CursorToCell = function(TableName,ColumnCount,RowCount){918 var xNameAccess = this.getModel().getTextTables();919 if(xNameAccess.hasByName(TableName))920 {921 var xTextTable = xNameAccess.getByName(TableName);922 if(RowCount < 1 || RowCount > xTextTable.getRows().getCount() || ColumnCount < 1 || ColumnCount > xTextTable.getColumns().getCount())923 {924 return false;925 }926 var xCell = xTextTable.getCellByPosition((ColumnCount-1),(RowCount-1));927 var xViewCursor = this.getController().getViewCursor();928 xViewCursor.gotoRange(xCell,false);929 return true;930 }931 else932 return false;933};934Office.prototype.InsertImageDialog = function(){935 if (this.IsReadOnly())936 return false;937 else938 {939 var arr= this.NEOSHINE_Office.CreateSequence(28,0);940 this.executeDispatch(".uno:InsertGraphic", arr);941 }942};943Office.prototype.InsertTableDialog = function(){944 if (this.IsReadOnly())945 return false;946 else947 {948 var arr= this.NEOSHINE_Office.CreateSequence(28,0);949 this.executeDispatch(".uno:InsertTable", arr);950 }951};952Office.prototype.RenameTable = function(oldTableName, newTableName){953 if (this.IsReadOnly())954 return false;955 else956 {957 var xNameAccess = this.getModel().getTextTables();958 if(xNameAccess.hasByName(oldTableName))959 {960 var xTextTable = xNameAccess.getByName(oldTableName);961 xTextTable.setName(newTableName);962 return true;963 }964 else965 return false;966 }967};968Office.prototype.GetAllTables = function(){969 var xNameAccess = this.getModel().getTextTables();970 var names = xNameAccess.getElementNames();971 var iArrayLen = names.getLength();972 var arrRet=new Array(iArrayLen);973 for (i=0;i<iArrayLen;i++)974 {975 arrRet[i] = names.getElement(i);976 }977 return arrRet;978};979Office.prototype.AddColums = function(TableName,Index,Count){980 if (this.IsReadOnly())981 return false;982 else983 {984 var xNameAccess = this.getModel().getTextTables();985 if(xNameAccess.hasByName(TableName))986 {987 var xTextTable = xNameAccess.getByName(TableName);988 if(Index > xTextTable.getColumns().getCount() || 70 - xTextTable.getColumns().getCount() < Count)989 {990 return sal_False;991 }992 xTextTable.getColumns().insertByIndex(Index, Count);993 return true;994 }995 else996 return false;997 }998};999Office.prototype.AddRows = function(TableName,Index,Count){1000 if (this.IsReadOnly())1001 return false;1002 else1003 {1004 var xNameAccess = this.getModel().getTextTables();1005 if(xNameAccess.hasByName(TableName))1006 {1007 var xTextTable = xNameAccess.getByName(TableName);1008 if(Index > xTextTable.getRows().getCount())1009 {1010 return sal_False;1011 }1012 xTextTable.getRows().insertByIndex(Index, Count);1013 return true;1014 }1015 else1016 return false;1017 }1018};1019Office.prototype.InsertTextFrame = function(){1020};1021Office.prototype.GetType = function(){1022};1023Office.prototype.SaveAsPic = function(){1024};1025Office.prototype.BrowsePDFInFirefox = function(PDFSaveURL){1026 //var winchild=window.open(PDFSaveURL,"_bland");1027 var url=encodeURI(PDFSaveURL);1028 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");1029 var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);1030 file.initWithPath('/usr/bin/firefox');1031 var process=Components.classes['@mozilla.org/process/util;1'].createInstance(Components.interfaces.nsIProcess);1032 process.init(file);1033 var arguments = [url];1034 process.run(false,arguments,arguments.length);1035};1036//doctype:writer8,writer8_template,MS Word 97,impress8,calc8,calc8_template ...1037Office.prototype.InsertDocDispatch = function(FileURL,doctype){1038 var arr= this.NEOSHINE_Office.CreateSequence(28,2);1039 arr.setProperty(0,"Name",FileURL,1);1040 arr.setProperty(1,"Filter",doctype,1);1041 this.executeDispatch(".uno:InsertDoc",arr);1042};1043Office.prototype.InsertDoc = function(FileURL,doctype){1044 if(doctype=="MS Word 97")1045 { 1046 this.getModel().lockControllers();1047 var oViewCursor = this.getController().getViewCursor();1048 this.InsertTextAtCurrentCursor(" ");1049 oViewCursor.goLeft(2,false);1050 //this.InsertTextAtCurrentCursor(" ");1051 this.CreateBookmarkAtSelection("PosSttInsertDoc");1052 this.InsertDocDispatch(FileURL,doctype);1053 this.CreateBookmarkAtSelection("PosEndInsertDoc");1054 1055 1056 this.CursorToBookmark("PosSttInsertDoc");1057 oViewCursor.goRight(1,false); 1058 var arr= this.NEOSHINE_Office.CreateSequence(28,1);1059 this.executeDispatch(".uno:delete",arr);1060 this.DelBookmark("PosSttInsertDoc");1061 //this.InsertTextAtCurrentCursor(" ");1062 this.Backspaces();1063 1064 this.CursorToBookmark("PosEndInsertDoc");1065 this.Backspaces();1066 this.DelBookmark("PosEndInsertDoc");1067 this.InsertTextAtCurrentCursor(" ");1068 this.Backspaces();1069 this.executeDispatch(".uno:delete",arr);1070 this.getModel().unlockControllers(); 1071 }1072 else1073 this.InsertDocDispatch(FileURL,doctype); 1074};1075Office.prototype.RegistPluginListener = function(strListenerName, strFunctionName, bRegist){1076 var ret = this.NEOSHINE_Office.RegistPluginListener(strListenerName, strFunctionName, bRegist);1077 return ret;1078};1079Office.prototype.SetListenerPresetData = function(strListenerName, strFunctionName, pData){1080 this.NEOSHINE_Office.SetListenerPresetData(strListenerName, strFunctionName, pData);1081};1082Office.prototype.UpdateListener = function(){1083 this.NEOSHINE_Office.UpdateListener();1084};1085Office.prototype.UnRegistListener = function(strListenerName){1086 var ret = this.NEOSHINE_Office.RegistPluginListener(strListenerName, "myfunc_", false);1087 return ret;1088};1089Office.prototype.NotifyEvent = function(eventName, bNotify){1090 var lisn = this.NEOSHINE_Office.RegistPluginListener("eventListener", "myfunc_", true);1091 if (lisn)1092 {1093 var prpt = this.NEOSHINE_Office.Bridge_GetStruct("com.sun.star.beans.PropertyValue");1094 prpt.Name = eventName;1095 prpt.Value = bNotify;1096 this.NEOSHINE_Office.SetListenerPresetData("eventListener", "notifyEvent", prpt);1097 }1098};1099Office.prototype.EnableKeyboard = function(ctrl_alt_shift, keyCode, bEnable){1100 var lisn = this.NEOSHINE_Office.RegistPluginListener("keyboardListener", "myfunc_", true);1101 if (lisn)1102 {1103 var e = this.NEOSHINE_Office.Bridge_GetStruct("com.sun.star.awt.KeyEvent");1104 e.Modifiers = ctrl_alt_shift;1105 e.KeyCode = keyCode;1106 var prpt = this.NEOSHINE_Office.Bridge_GetStruct("com.sun.star.beans.PropertyValue");1107 prpt.Name = bEnable ? "false" : "true";1108 prpt.Value = e;1109 this.NEOSHINE_Office.SetListenerPresetData("keyboardListener", "keyPressed", prpt);1110 }1111};1112Office.prototype.EnableUnoID = function(unoid, bEnable, bDispatchByMyself){1113 var lisn = this.NEOSHINE_Office.RegistPluginListener("dispatchListener", "myfunc_", true);1114 if (lisn)1115 {1116 var url = this.NEOSHINE_Office.Bridge_GetStruct("com.sun.star.util.URL");1117 url.Complete = unoid;1118 var prt = this.NEOSHINE_Office.Bridge_GetStruct("com.sun.star.beans.PropertyValue");1119 prt.Value = url;1120 prt.Name = bEnable ? "false" : "true";1121 if (bEnable)1122 {1123 prt.Name = bDispatchByMyself ? "true" : "false";1124 }1125 this.NEOSHINE_Office.SetListenerPresetData("dispatchListener", "queryDispatch", prt);1126 prt = this.NEOSHINE_Office.Bridge_GetStruct("com.sun.star.beans.PropertyValue");1127 prt.Name = bEnable ? "true" : "false";1128 prt.Value = url;1129 this.NEOSHINE_Office.SetListenerPresetData("dispatchListener", "addStatusListener", prt);1130 }1131};1132Office.prototype.UpdateContextMenu = function(operate, commandURL, commandText){1133 var lisn = this.NEOSHINE_Office.RegistPluginListener("contextmenuListener", "myfunc_", true);1134 if (lisn)1135 {1136 prt = this.NEOSHINE_Office.Bridge_GetStruct("com.sun.star.beans.PropertyValue");1137 prt.Value = commandURL;1138 prt.Name = operate;1139 this.NEOSHINE_Office.SetListenerPresetData("contextmenuListener", "notifyContextMenuExecute", prt);1140 }1141};1142Office.prototype.EnableMouseHandle = function(buttonType, enable){1143 var lisn = this.NEOSHINE_Office.RegistPluginListener("mouseListener", "myfunc_", true);1144 if (lisn)1145 {1146 var event = this.NEOSHINE_Office.Bridge_GetStruct("com.sun.star.awt.MouseEvent");1147 event.Buttons = buttonType; //1:LBUTTON, 2: RBUTTON, 4: MBUTTON1148 prt = this.NEOSHINE_Office.Bridge_GetStruct("com.sun.star.beans.PropertyValue");1149 prt.Value = event;1150 prt.Name = enable ? "false" : "true";1151 this.NEOSHINE_Office.SetListenerPresetData("mouseListener", "mousePressed", prt);1152 }1153};1154Office.prototype.EnableCopy = function(enable){1155 this.EnableUnoID(".uno:Copy", enable, false);1156 if (enable)1157 {1158 this.UpdateContextMenu("add", "slot:5711", "");1159 this.UpdateContextMenu("add", "å¤å¶(~C)", "");1160 }1161 else1162 {1163 this.UpdateContextMenu("remove", "slot:5711", "");1164 this.UpdateContextMenu("remove", "å¤å¶(~C)", "");1165 }1166};1167Office.prototype.EnablePaste = function(enable){1168 this.EnableUnoID(".uno:Paste", enable, false);1169 if (enable)1170 {1171 this.UpdateContextMenu("add", "slot:5712", "");1172 this.UpdateContextMenu("add", "ç²è´´(~P)", "");1173 }1174 else1175 {1176 this.UpdateContextMenu("remove", "slot:5712", "");1177 this.UpdateContextMenu("remove", "ç²è´´(~P)", "");1178 }1179};1180//------------------- Functions of operating menubar and toolbar -- Begin -------------------------------------1181Office.prototype.FindObject = function(key,resourceSettings){1182 for (var i = 0; i < resourceSettings.getCount(); i++)1183 {1184 var oItemSetting = resourceSettings.getByIndex(i);1185 for (var j = 0; j < oItemSetting.length; j++)1186 {1187 if (oItemSetting[j].Name == "CommandURL")1188 {1189 if (oItemSetting[j].Value == key)1190 {1191 var objRet = new Array(2);1192 objRet[0] = i;1193 objRet[1] = oItemSetting;1194 return objRet;1195 }1196 }1197 }1198 }1199 return 0;1200};1201Office.prototype.CreateMenu = function(menuType,menuID,menuLable,menuBarSettings){1202 var propertyValue = 0;1203 if (menuType == 2)1204 {1205 var factory = menuBarSettings.createInstanceWithContext(this.GetServiceManager().DefaultContext);1206 propertyValue = this.NEOSHINE_Office.CreateSequence(28,4);1207 propertyValue.setProperty(0,"CommandURL",menuID,1);1208 propertyValue.setProperty(1,"Label",menuLable,1);1209 propertyValue.setProperty(2,"Type",0,2);1210 propertyValue.setProperty(3,"ItemDescriptorContainer",factory,5);1211 }1212 else1213 {1214 propertyValue = this.NEOSHINE_Office.CreateSequence(28,3);1215 propertyValue.setProperty(0,"CommandURL",menuID,1);1216 propertyValue.setProperty(1,"Label",menuLable,1);1217 propertyValue.setProperty(2,"Type",menuType == 0 ? 1:0,6);1218 }1219 return propertyValue;1220};1221Office.prototype.CreateToolbarItem = function(cmdType,cmdID,cmdLabel){1222 var propertyValue = this.NEOSHINE_Office.CreateSequence(28,4);1223 propertyValue.setProperty(0,"CommandURL",cmdID,1);1224 propertyValue.setProperty(1,"Label",cmdLabel,1);1225 propertyValue.setProperty(2,"Type",cmdType == 0 ? 1:0,6);1226 propertyValue.setProperty(3,"Visible",true,3);1227 return propertyValue;1228};1229Office.prototype.GetResource = function(resourceURL){1230 var oFrame = this.getPluginFrame();1231 oLayoutManager = oFrame.LayoutManager;1232 oElement = oLayoutManager.getElement(resourceURL);1233 oElement.setPropertyValue("Persistent",false);1234 return oElement;1235}1236Office.prototype.CreateResource = function(resourceURL){1237 var oFrame = this.getPluginFrame();1238 oLayoutManager = oFrame.LayoutManager;1239 oLayoutManager.createElement(resourceURL);1240 oElement = oLayoutManager.getElement(resourceURL);1241 oElement.setPropertyValue("Persistent",false);1242 return oElement;1243}1244Office.prototype.GetImageFromURL = function(imageURL){1245 var oGraphicProvider = this.CreateUnoService("com.sun.star.graphic.GraphicProvider");1246 if (oGraphicProvider && imageURL.length > 7) // >"file://"1247 {1248 var propertyValue = this.NEOSHINE_Office.CreateSequence(28,1);1249 propertyValue.setProperty(0,"URL",imageURL,1);1250 var obj = oGraphicProvider.queryGraphic(propertyValue);1251 return obj;1252 }1253 return null;1254}1255Office.prototype.SetImageInfo = function(resourceList){1256 var oModuleCfgMgr = this.getModel().getUIConfigurationManager();1257 var oImageMgr = oModuleCfgMgr.getImageManager();1258 var cmdURL = new Array();1259 var cmdImg = new Array();1260 var nIndex = 0;1261 for (var i = 0; i < resourceList.length; i++)1262 {1263 var Iteminfo = resourceList[i];1264 var Image = this.GetImageFromURL(Iteminfo[3]);1265 if (Image && Iteminfo[1].length > 0 && !oImageMgr.hasImage(0, Iteminfo[1]))1266 {1267 cmdURL[nIndex] = Iteminfo[1];1268 cmdImg[nIndex] = Image;1269 nIndex++;1270 }1271 }1272 if (nIndex)1273 {1274 var seqString = this.NEOSHINE_Office.CreateSequence(12,nIndex);1275 var seqObj = this.NEOSHINE_Office.CreateSequence(22,nIndex);1276 for (var j = 0; j < nIndex; j++)1277 {1278 seqObj.setValue(j,cmdImg[j]);1279 seqString.setValue(j,cmdURL[j]);1280 }1281 oImageMgr.insertImages(0,seqString, seqObj);1282 }1283}1284Office.prototype.UpdateMenuItemToBar = function(optType,sPopupMenuPath,menuInfoList){1285 var keys = new Array();1286 var strTopMenuTemp = sPopupMenuPath;1287 var nIdx = strTopMenuTemp.indexOf("/");1288 for (var i = 0; nIdx > 0; i++)1289 {1290 var sSub = strTopMenuTemp.substring(0, nIdx);1291 keys[i] = sSub;1292 strTopMenuTemp = strTopMenuTemp.substring(nIdx + 1, strTopMenuTemp.length);1293 nIdx = strTopMenuTemp.indexOf("/");1294 }1295 if (nIdx < 0 && strTopMenuTemp.length > 0) 1296 {1297 keys[i] = strTopMenuTemp;1298 }1299 var oMenuBar = this.GetResource("private:resource/menubar/menubar");1300 var oMenuBarSettings = oMenuBar.getSettings(true);1301 1302 var settings = oMenuBarSettings;1303 for (var i = 0; i < keys.length; i++)1304 {1305 var oPopupObj = this.FindObject(keys[i],settings);1306 if (!oPopupObj)1307 {1308 return false;1309 }1310 1311 var oPopup = oPopupObj[1];1312 var bGet = false;1313 var m = oPopup.length;1314 for (var j = 0; j < m; j++)1315 {1316 if (oPopup[j].Name == "ItemDescriptorContainer")1317 {1318 settings = oPopup[j].Value;1319 bGet = true;1320 break;1321 } 1322 }1323 if (bGet == false)1324 {1325 return false;1326 }1327 }1328 for (var i = 0; i < menuInfoList.length; i++)1329 {1330 var menuinfo = menuInfoList[i];1331 var oPopupObj = this.FindObject(menuinfo[1],settings);1332 if (optType == 1)1333 {1334 if (oPopupObj)1335 {1336 continue;1337 }1338 var menu = this.CreateMenu(menuinfo[0],menuinfo[1],menuinfo[2],oMenuBarSettings);1339 var nIdx = settings.getCount();1340 settings.insertByIndex(nIdx, menu);1341 }1342 else if (optType == 2)1343 {1344 var pos = oPopupObj[0];1345 settings.removeByIndex(pos);1346 }1347 }1348 1349 this.SetImageInfo(menuInfoList);1350 oMenuBar.setSettings(oMenuBarSettings);1351 return true;1352};1353Office.prototype.UpdateToolBar = function(optType,toolbarCaption,toolbarURL,toolbarInfoList,InsIndex){1354 var oModuleCfgMgr = this.getModel().getUIConfigurationManager();1355 var oToolBar = 0;1356 if (optType ==1)1357 {1358 if (oModuleCfgMgr.hasSettings(toolbarURL))1359 {1360 return false;1361 }1362 oToolBar = this.CreateResource(toolbarURL);1363 var oToolBarSettings = oToolBar.getSettings(true);1364 oToolBarSettings.setPropertyValue("UIName",toolbarCaption);1365 }1366 else1367 {1368 oToolBar = this.GetResource(toolbarURL);1369 var oToolBarSettings = oToolBar.getSettings(true);1370 }1371 1372 for (var i = 0; i < toolbarInfoList.length; i++)1373 {1374 var iteminfo = toolbarInfoList[i];1375 var oItemObj = this.FindObject(iteminfo[1],oToolBarSettings);1376 if (optType == 1)1377 {1378 if (oItemObj)1379 {1380 continue;1381 }1382 var oItem = this.CreateToolbarItem(iteminfo[0],iteminfo[1],iteminfo[2]);1383 var nIdx = oToolBarSettings.getCount();1384 oToolBarSettings.insertByIndex(nIdx, oItem);1385 }1386 else if (optType == 2)1387 {1388 if (oItemObj)1389 {1390 return false;1391 }1392 var oItem = this.CreateToolbarItem(iteminfo[0],iteminfo[1],iteminfo[2]);1393 oToolBarSettings.insertByIndex(InsIndex, oItem);1394 }1395 else if (optType == 3)1396 {1397 if (!oItemObj)1398 {1399 return false;1400 }1401 var pos = oItemObj[0];1402 oToolBarSettings.removeByIndex(pos);1403 }1404 }1405 1406 this.SetImageInfo(toolbarInfoList);1407 oToolBar.setSettings(oToolBarSettings); 1408 if (oModuleCfgMgr.hasSettings(toolbarURL))1409 {1410 oModuleCfgMgr.replaceSettings(toolbarURL, oToolBarSettings);1411 }1412 else1413 {1414 oModuleCfgMgr.insertSettings(toolbarURL, oToolBarSettings);1415 }1416 oModuleCfgMgr.store();1417 return true;1418};1419//------------------- Functions of operating menubar and toolbar -- End -------------------------------------1420Office.prototype.AddMenuItemToBar = function(sPopupMenuPath,menuInfoList){1421 return this.UpdateMenuItemToBar(1,sPopupMenuPath,menuInfoList);1422}1423Office.prototype.RemoveMenuItemFromBar = function(sPopupMenuPath,menuInfoList){1424 return this.UpdateMenuItemToBar(2,sPopupMenuPath,menuInfoList);1425}1426Office.prototype.CreateToolBar = function(toolbarCaption,toolbarURL,itemInfoList){1427 return this.UpdateToolBar(1,toolbarCaption,toolbarURL,itemInfoList,0);1428}1429Office.prototype.InsertItemToToolBar = function(toolbarURL,itemInfoList,insIndex){1430 return this.UpdateToolBar(2,"",toolbarURL,itemInfoList,insIndex);1431}1432Office.prototype.RemoveItemFromToolBar = function(toolbarURL,itemInfoList){1433 return this.UpdateToolBar(3,"",toolbarURL,itemInfoList,0);1434}1435Office.prototype.OpenDocumentBuffer = function(buffer,IsReadOnly){1436 var xTempAccess = this.CreateUnoService("com.sun.star.ucb.SimpleFileAccess");1437 var xData = xTempAccess.openFileRead(buffer);1438 var arr= this.NEOSHINE_Office.CreateSequence(28,2);1439 arr.setProperty(0,"InputStream",buffer,1);1440 if(IsReadOnly)1441 arr.setProperty(1,"ReadOnly",1,3);1442 else1443 arr.setProperty(1,"ReadOnly",0,3);1444 var ret = this.getPluginFrame().loadComponentFromURL("private:stream","_self",55,arr);1445};1446Office.prototype.OpenFileDialog = function(){1447 var arr= this.NEOSHINE_Office.CreateSequence(28,0);1448 this.executeDispatch(".uno:Open", arr);1449};1450Office.prototype.ExportPDFDialog = function(){1451 var arr= this.NEOSHINE_Office.CreateSequence(28,0);1452 this.executeDispatch(".uno:ExportToPDF", arr);1453};1454Office.prototype.SetPageWidth = function(width){1455 var xStyleFamiliesSupplier = this.getModel().getStyleFamilies();1456 var xParagraphStyles = xStyleFamiliesSupplier.getByName("PageStyles");1457 var xStyle = xParagraphStyles.getByName("Standard");1458 xStyle.setPropertyValue("Width",width*1000);1459};1460Office.prototype.GetPageWidth = function(){1461 var PageStyle = this.getModel().createInstance("com.sun.star.style.PageStyle");1462 return (PageStyle.Width/1000).toFixed(2);1463};1464Office.prototype.SetPageHeight = function(Height){1465 var xStyleFamiliesSupplier = this.getModel().getStyleFamilies();1466 var xParagraphStyles = xStyleFamiliesSupplier.getByName("PageStyles");1467 var xStyle = xParagraphStyles.getByName("Standard");1468 xStyle.setPropertyValue("Height",Height*1000);1469};1470Office.prototype.GetPageHeight = function(){1471 var PageStyle = this.getModel().createInstance("com.sun.star.style.PageStyle");1472 return (PageStyle.Height/1000).toFixed(2);1473};1474Office.prototype.SetPageVertical = function(bVert){1475 var xStyleFamiliesSupplier = this.getModel().getStyleFamilies();1476 var xParagraphStyles = xStyleFamiliesSupplier.getByName("PageStyles");1477 var xStyle = xParagraphStyles.getByName("Standard");1478 xStyle.setPropertyValue("IsLandscape",bVert);1479 var width = this.GetPageWidth();1480 this.SetPageWidth(this.GetPageHeight());1481 this.SetPageHeight(width);1482};1483Office.prototype.GetPageVertical = function(){1484 var PageStyle = this.getModel().createInstance("com.sun.star.style.PageStyle");1485 return PageStyle.IsLandscape;1486};1487Office.prototype.SetLeftMargin = function(Margin){1488 var xStyleFamiliesSupplier = this.getModel().getStyleFamilies();1489 var xParagraphStyles = xStyleFamiliesSupplier.getByName("PageStyles");1490 var xStyle = xParagraphStyles.getByName("Standard");1491 xStyle.setPropertyValue("LeftMargin",Margin*1000);1492};1493Office.prototype.GetLeftMargin = function(){1494 var PageStyle = this.getModel().createInstance("com.sun.star.style.PageStyle");1495 return (PageStyle.LeftMargin/1000).toFixed(2);1496};1497Office.prototype.SetRightMargin = function(Margin){1498 var xStyleFamiliesSupplier = this.getModel().getStyleFamilies();1499 var xParagraphStyles = xStyleFamiliesSupplier.getByName("PageStyles");1500 var xStyle = xParagraphStyles.getByName("Standard");1501 xStyle.setPropertyValue("RightMargin",Margin*1000);1502};1503Office.prototype.GetRightMargin = function(){1504 var PageStyle = this.getModel().createInstance("com.sun.star.style.PageStyle");1505 return (PageStyle.RightMargin/1000).toFixed(2);1506};1507Office.prototype.SetTopMargin = function(Margin){1508 var xStyleFamiliesSupplier = this.getModel().getStyleFamilies();1509 var xParagraphStyles = xStyleFamiliesSupplier.getByName("PageStyles");1510 var xStyle = xParagraphStyles.getByName("Standard");1511 xStyle.setPropertyValue("TopMargin",Margin*1000);1512};1513Office.prototype.GetTopMargin = function(){1514 var PageStyle = this.getModel().createInstance("com.sun.star.style.PageStyle");1515 return (PageStyle.TopMargin/1000).toFixed(2);1516};1517Office.prototype.SetBottomMargin = function(Margin){1518 var xStyleFamiliesSupplier = this.getModel().getStyleFamilies();1519 var xParagraphStyles = xStyleFamiliesSupplier.getByName("PageStyles");1520 var xStyle = xParagraphStyles.getByName("Standard");1521 xStyle.setPropertyValue("BottomMargin",Margin*1000);1522};1523Office.prototype.GetBottomMargin = function(){1524 var PageStyle = this.getModel().createInstance("com.sun.star.style.PageStyle");1525 return (PageStyle.BottomMargin/1000).toFixed(2);1526};1527Office.prototype.Zoom = function(zoomValue){1528 var controller = this.getController();1529 var views = controller.getViewSettings();1530 views.setPropertyValue("ZoomValue",zoomValue);1531};1532Office.prototype.GetZoomValue = function(){1533 var controller = this.getController();1534 var views = controller.getViewSettings();1535 var zoomV = views.getPropertyValue("ZoomValue");1536 return zoomV;1537};1538Office.prototype.DisableExecuteByName = function(URL,bDisable){ 1539 this.NEOSHINE_Office.DisableExecuteByName(URL,bDisable);1540};1541Office.prototype.InsertTextFrame = function(AnchorType,PosX,PosY,Width,Height){1542 var arr= this.NEOSHINE_Office.CreateSequence(28,5);1543 arr.setProperty(0,"AnchorType",AnchorType,2);1544 arr.setProperty(1,"Pos.X",PosX,2);1545 arr.setProperty(2,"Pos.Y",PosY,2);1546 arr.setProperty(3,"Size.Width",Width,2);1547 arr.setProperty(4,"Size.Height",Height,2);1548 this.executeDispatch(".uno:InsertFrame",arr);1549};1550Office.prototype.InsertImageWholePage = function(URL){1551 if (this.IsReadOnly())1552 return false;1553 else1554 {1555 var xTextRange = this.getModel().getCurrentController().getViewCursor();1556 var xTextPicture = xTextRange.getText();1557 var xShape =1558 this.getModel().createInstance("com.sun.star.drawing.GraphicObjectShape");1559 var position = this.NEOSHINE_Office.Bridge_GetStruct("com.sun.star.awt.Point");1560 position.X = 0;1561 position.Y = 0;1562 xShape.setPosition(position);1563 var size = this.NEOSHINE_Office.Bridge_GetStruct("com.sun.star.awt.Size");1564 size.Width = this.GetPageWidth();1565 size.Height = this.GetPageHeight();1566 xShape.setSize(size);1567 var xGraphicProvider = this.CreateUnoService("com.sun.star.graphic.GraphicProvider");1568 var propertyValue = this.NEOSHINE_Office.CreateSequence(28,1);1569 propertyValue.setProperty(0,"URL",URL,1);1570 var xGraphic = xGraphicProvider.queryGraphic(propertyValue);1571 xShape.setPropertyValue("Graphic", xGraphic);1572 xShape.setPropertyValue("AnchorType", 2);1573 xShape.setPropertyValue("Opaque", true);1574 xShape.setPropertyValue("Transparency", 0);1575 xTextPicture.insertTextContent(xTextRange,xShape,true);1576 xShape.setPropertyValue("Surround", 1);1577 xShape.setPropertyValue("LayerName", "Hell");1578 return xShape;1579 }1580};1581Office.prototype.SetGraphicTransparency = function(xShape,Transparency){1582 xShape.setPropertyValue("Transparency", Transparency);1583};1584Office.prototype.GetGraphicTransparency = function(xShape){1585 return xShape.getPropertyValue("Transparency");1586};1587Office.prototype.GetAllTextFrames = function(){1588 var xNameAccess = this.getModel().getTextFrames();1589 var names = xNameAccess.getElementNames();1590 var iArrayLen = names.getLength();1591 var arrRet=new Array(iArrayLen);1592 for (i=0;i<iArrayLen;i++)1593 {1594 arrRet[i] = names.getElement(i);1595 }1596 return arrRet;1597};1598Office.prototype.RenameTextFrame = function(oldTextName, newTextName){1599 if (this.IsReadOnly())1600 return false;1601 else1602 {1603 var xNameAccess = this.getModel().getTextFrames();1604 if(xNameAccess.hasByName(oldTextName))1605 {1606 var xTextTable = xNameAccess.getByName(oldTextName);1607 xTextTable.setName(newTextName);1608 return true;1609 }1610 else1611 return false;1612 }1613};1614Office.prototype.CursorToTextFrame = function(FrameName){1615 var xNameAccess = this.getModel().getTextFrames();1616 if(xNameAccess.hasByName(FrameName))1617 {1618 var xTextFrame = xNameAccess.getByName(FrameName);1619 var xText = xTextFrame.getText();1620 var xViewCursor = this.getController().getViewCursor();1621 xViewCursor.gotoRange(xText,false);1622 xViewCursor.gotoStart(false);1623 return true;1624 }1625 else1626 return false;1627};1628Office.prototype.InsertSheet = function(Name,Index){1629 var arr= this.NEOSHINE_Office.CreateSequence(28,2);1630 arr.setProperty(0,"Name",Name,1);1631 arr.setProperty(1,"Index",Index,2);1632 this.executeDispatch(".uno:Insert",arr);1633};1634Office.prototype.StandardContext = function(FontHeight,FontName,Indent,ParagraphSpacing){1635 var oViewCursor = this.getController().getViewCursor();1636 var xText = this.getModel().getText();1637 var currentcursor = xText.createTextCursorByRange(oViewCursor);1638 this.getModel().lockControllers();1639 oViewCursor.gotoStart(false);1640 oViewCursor.gotoEnd(true);1641 this.SetFontHeight(FontHeight);1642 this.SetFontName(FontName);1643 this.SetFirstLineIndent(Indent);1644 this.SetParagraphSpacing(ParagraphSpacing);1645 oViewCursor.gotoRange(currentcursor.getStart(),false);1646 this.getModel().unlockControllers();...
EventPluginHub.js
Source:EventPluginHub.js
1/**2 * Copyright 2013 Facebook, Inc.3 *4 * Licensed under the Apache License, Version 2.0 (the "License");5 * you may not use this file except in compliance with the License.6 * You may obtain a copy of the License at7 *8 * http://www.apache.org/licenses/LICENSE-2.09 *10 * Unless required by applicable law or agreed to in writing, software11 * distributed under the License is distributed on an "AS IS" BASIS,12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13 * See the License for the specific language governing permissions and14 * limitations under the License.15 *16 * @providesModule EventPluginHub17 */18"use strict";19var CallbackRegistry = require('CallbackRegistry');20var EventPluginRegistry = require('EventPluginRegistry');21var EventPluginUtils = require('EventPluginUtils');22var EventPropagators = require('EventPropagators');23var ExecutionEnvironment = require('ExecutionEnvironment');24var accumulate = require('accumulate');25var forEachAccumulated = require('forEachAccumulated');26var invariant = require('invariant');27/**28 * Internal queue of events that have accumulated their dispatches and are29 * waiting to have their dispatches executed.30 */31var eventQueue = null;32/**33 * Dispatches an event and releases it back into the pool, unless persistent.34 *35 * @param {?object} event Synthetic event to be dispatched.36 * @private37 */38var executeDispatchesAndRelease = function(event) {39 if (event) {40 var executeDispatch = EventPluginUtils.executeDispatch;41 // Plugins can provide custom behavior when dispatching events.42 var PluginModule = EventPluginRegistry.getPluginModuleForEvent(event);43 if (PluginModule && PluginModule.executeDispatch) {44 executeDispatch = PluginModule.executeDispatch;45 }46 EventPluginUtils.executeDispatchesInOrder(event, executeDispatch);47 if (!event.isPersistent()) {48 event.constructor.release(event);49 }50 }51};52/**53 * This is a unified interface for event plugins to be installed and configured.54 *55 * Event plugins can implement the following properties:56 *57 * `extractEvents` {function(string, DOMEventTarget, string, object): *}58 * Required. When a top-level event is fired, this method is expected to59 * extract synthetic events that will in turn be queued and dispatched.60 *61 * `eventTypes` {object}62 * Optional, plugins that fire events must publish a mapping of registration63 * names that are used to register listeners. Values of this mapping must64 * be objects that contain `registrationName` or `phasedRegistrationNames`.65 *66 * `executeDispatch` {function(object, function, string)}67 * Optional, allows plugins to override how an event gets dispatched. By68 * default, the listener is simply invoked.69 *70 * Each plugin that is injected into `EventsPluginHub` is immediately operable.71 *72 * @public73 */74var EventPluginHub = {75 /**76 * Methods for injecting dependencies.77 */78 injection: {79 /**80 * @param {object} InjectedInstanceHandle81 * @public82 */83 injectInstanceHandle: EventPropagators.injection.injectInstanceHandle,84 /**85 * @param {array} InjectedEventPluginOrder86 * @public87 */88 injectEventPluginOrder: EventPluginRegistry.injectEventPluginOrder,89 /**90 * @param {object} injectedNamesToPlugins Map from names to plugin modules.91 */92 injectEventPluginsByName: EventPluginRegistry.injectEventPluginsByName93 },94 registrationNames: EventPluginRegistry.registrationNames,95 putListener: CallbackRegistry.putListener,96 getListener: CallbackRegistry.getListener,97 deleteListener: CallbackRegistry.deleteListener,98 deleteAllListeners: CallbackRegistry.deleteAllListeners,99 /**100 * Allows registered plugins an opportunity to extract events from top-level101 * native browser events.102 *103 * @param {string} topLevelType Record from `EventConstants`.104 * @param {DOMEventTarget} topLevelTarget The listening component root node.105 * @param {string} topLevelTargetID ID of `topLevelTarget`.106 * @param {object} nativeEvent Native browser event.107 * @return {*} An accumulation of synthetic events.108 * @internal109 */110 extractEvents: function(111 topLevelType,112 topLevelTarget,113 topLevelTargetID,114 nativeEvent) {115 var events;116 var plugins = EventPluginRegistry.plugins;117 for (var i = 0, l = plugins.length; i < l; i++) {118 // Not every plugin in the ordering may be loaded at runtime.119 var possiblePlugin = plugins[i];120 if (possiblePlugin) {121 var extractedEvents = possiblePlugin.extractEvents(122 topLevelType,123 topLevelTarget,124 topLevelTargetID,125 nativeEvent126 );127 if (extractedEvents) {128 events = accumulate(events, extractedEvents);129 }130 }131 }132 return events;133 },134 /**135 * Enqueues a synthetic event that should be dispatched when136 * `processEventQueue` is invoked.137 *138 * @param {*} events An accumulation of synthetic events.139 * @internal140 */141 enqueueEvents: function(events) {142 if (events) {143 eventQueue = accumulate(eventQueue, events);144 }145 },146 /**147 * Dispatches all synthetic events on the event queue.148 *149 * @internal150 */151 processEventQueue: function() {152 // Set `eventQueue` to null before processing it so that we can tell if more153 // events get enqueued while processing.154 var processingEventQueue = eventQueue;155 eventQueue = null;156 forEachAccumulated(processingEventQueue, executeDispatchesAndRelease);157 invariant(158 !eventQueue,159 'processEventQueue(): Additional events were enqueued while processing ' +160 'an event queue. Support for this has not yet been implemented.'161 );162 }163};164if (ExecutionEnvironment.canUseDOM) {165 window.EventPluginHub = EventPluginHub;166}...
EventPluginUtils.js
Source:EventPluginUtils.js
...72 cb(event, dispatchListeners, dispatchIDs);73 }74}75/**76 * Default implementation of PluginModule.executeDispatch().77 * @param {SyntheticEvent} SyntheticEvent to handle78 * @param {function} Application-level callback79 * @param {string} domID DOM id to pass to the callback.80 */81function executeDispatch(event, listener, domID) {82 listener(event, domID);83}84/**85 * Standard/simple iteration through an event's collected dispatches.86 */87function executeDispatchesInOrder(event, executeDispatch) {88 forEachEventDispatch(event, executeDispatch);89 event._dispatchListeners = null;90 event._dispatchIDs = null;91}92/**93 * Standard/simple iteration through an event's collected dispatches, but stops94 * at the first dispatch execution returning true, and returns that id.95 *...
7193daEventPluginUtils.js
Source:7193daEventPluginUtils.js
...31 var instancesLen = instancesIsArr ? dispatchInstances.length : dispatchInstances ? 1 : 0;32 warning(instancesIsArr === listenersIsArr && instancesLen === listenersLen, 'EventPluginUtils: Invalid `event`.');33 };34}35function executeDispatch(event, simulated, listener, inst) {36 var type = event.type || 'unknown-event';37 event.currentTarget = EventPluginUtils.getNodeFromInstance(inst);38 if (simulated) {39 ReactErrorUtils.invokeGuardedCallbackWithCatch(type, listener, event);40 } else {41 ReactErrorUtils.invokeGuardedCallback(type, listener, event);42 }43 event.currentTarget = null;44}45function executeDispatchesInOrder(event, simulated) {46 var dispatchListeners = event._dispatchListeners;47 var dispatchInstances = event._dispatchInstances;48 if (__DEV__) {49 validateEventDispatches(event);50 }51 if (Array.isArray(dispatchListeners)) {52 for (var i = 0; i < dispatchListeners.length; i++) {53 if (event.isPropagationStopped()) {54 break;55 }56 executeDispatch(event, simulated, dispatchListeners[i], dispatchInstances[i]);57 }58 } else if (dispatchListeners) {59 executeDispatch(event, simulated, dispatchListeners, dispatchInstances);60 }61 event._dispatchListeners = null;62 event._dispatchInstances = null;63}64function executeDispatchesInOrderStopAtTrueImpl(event) {65 var dispatchListeners = event._dispatchListeners;66 var dispatchInstances = event._dispatchInstances;67 if (__DEV__) {68 validateEventDispatches(event);69 }70 if (Array.isArray(dispatchListeners)) {71 for (var i = 0; i < dispatchListeners.length; i++) {72 if (event.isPropagationStopped()) {73 break;...
module$EventPluginHub.js
Source:module$EventPluginHub.js
1goog.provide("module$EventPluginHub");2var module$EventPluginHub = {};3goog.require("module$invariant");4goog.require("module$forEachAccumulated");5goog.require("module$accumulate");6goog.require("module$ExecutionEnvironment");7goog.require("module$EventPropagators");8goog.require("module$EventPluginUtils");9goog.require("module$EventPluginRegistry");10goog.require("module$CallbackRegistry");11var CallbackRegistry$$module$EventPluginHub = module$CallbackRegistry;12var EventPluginRegistry$$module$EventPluginHub = module$EventPluginRegistry;13var EventPluginUtils$$module$EventPluginHub = module$EventPluginUtils;14var EventPropagators$$module$EventPluginHub = module$EventPropagators;15var ExecutionEnvironment$$module$EventPluginHub = module$ExecutionEnvironment;16var accumulate$$module$EventPluginHub = module$accumulate;17var forEachAccumulated$$module$EventPluginHub = module$forEachAccumulated;18var invariant$$module$EventPluginHub = module$invariant;19var eventQueue$$module$EventPluginHub = null;20var executeDispatchesAndRelease$$module$EventPluginHub = function(event) {21 if(event) {22 var executeDispatch = EventPluginUtils$$module$EventPluginHub.executeDispatch;23 var PluginModule = EventPluginRegistry$$module$EventPluginHub.getPluginModuleForEvent(event);24 if(PluginModule && PluginModule.executeDispatch) {25 executeDispatch = PluginModule.executeDispatch26 }27 EventPluginUtils$$module$EventPluginHub.executeDispatchesInOrder(event, executeDispatch);28 if(!event.isPersistent()) {29 event.constructor.release(event)30 }31 }32};33var EventPluginHub$$module$EventPluginHub = {injection:{injectInstanceHandle:EventPropagators$$module$EventPluginHub.injection.injectInstanceHandle, injectEventPluginOrder:EventPluginRegistry$$module$EventPluginHub.injectEventPluginOrder, injectEventPluginsByName:EventPluginRegistry$$module$EventPluginHub.injectEventPluginsByName}, registrationNames:EventPluginRegistry$$module$EventPluginHub.registrationNames, putListener:CallbackRegistry$$module$EventPluginHub.putListener, getListener:CallbackRegistry$$module$EventPluginHub.getListener, 34deleteListener:CallbackRegistry$$module$EventPluginHub.deleteListener, deleteAllListeners:CallbackRegistry$$module$EventPluginHub.deleteAllListeners, extractEvents:function(topLevelType, topLevelTarget, topLevelTargetID, nativeEvent) {35 var events;36 var plugins = EventPluginRegistry$$module$EventPluginHub.plugins;37 for(var i = 0, l = plugins.length;i < l;i++) {38 var possiblePlugin = plugins[i];39 if(possiblePlugin) {40 var extractedEvents = possiblePlugin.extractEvents(topLevelType, topLevelTarget, topLevelTargetID, nativeEvent);41 if(extractedEvents) {42 events = accumulate$$module$EventPluginHub(events, extractedEvents)43 }44 }45 }46 return events47}, enqueueEvents:function(events) {48 if(events) {49 eventQueue$$module$EventPluginHub = accumulate$$module$EventPluginHub(eventQueue$$module$EventPluginHub, events)50 }51}, processEventQueue:function() {52 var processingEventQueue = eventQueue$$module$EventPluginHub;53 eventQueue$$module$EventPluginHub = null;54 forEachAccumulated$$module$EventPluginHub(processingEventQueue, executeDispatchesAndRelease$$module$EventPluginHub);55 invariant$$module$EventPluginHub(!eventQueue$$module$EventPluginHub)56}};57if(ExecutionEnvironment$$module$EventPluginHub.canUseDOM) {58 window.EventPluginHub = EventPluginHub$$module$EventPluginHub59}60module$EventPluginHub.module$exports = EventPluginHub$$module$EventPluginHub;61if(module$EventPluginHub.module$exports) {62 module$EventPluginHub = module$EventPluginHub.module$exports63}...
MapEvent.js
Source:MapEvent.js
...78 return function listener(event) {79 if (!MapEvent.isEnabled) {80 return;81 }82 return executeDispatch(event, eventName, instance);83 }84 },85 isEnabled: true,86 setEnabled: function(enabled) {87 MapEvent.isEnabled = enabled;88 },89 injection: MapEventInjection90};...
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 await page.evaluate(() => {6 const event = new KeyboardEvent('keydown', {7 });8 document.dispatchEvent(event);9 });10 await browser.close();11})();12const { chromium } = require('playwright');13(async () => {14 const browser = await chromium.launch();15 const page = await browser.newPage();16 await page.evaluate(() => {17 const event = new KeyboardEvent('keydown', {18 });19 document.dispatchEvent(event);20 });21 await browser.close();22})();23const { chromium } = require('playwright');24(async () => {25 const browser = await chromium.launch();26 const page = await browser.newPage();27 await page.evaluate(() => {28 const event = new KeyboardEvent('keydown', {29 });30 document.dispatchEvent(event);31 });32 await browser.close();33})();34const { chromium } = require('playwright');35(async () => {36 const browser = await chromium.launch();37 const page = await browser.newPage();38 await page.evaluate(() => {39 const event = new KeyboardEvent('keydown', {40 });41 document.dispatchEvent(event);42 });
Using AI Code Generation
1const {chromium} = require('playwright');2(async () => {3 const browser = await chromium.launch({headless: false});4 const page = await browser.newPage();5 await page.type('input[name="q"]', 'Playwright');6 await page.keyboard.press('Enter');7 await page.waitForSelector('text=Playwright');8 const results = await page.$$('text=Playwright');9 await results[0].evaluate((node) => {10 const event = new Event('click');11 node.dispatchEvent(event);12 });13 await page.waitForSelector('text=Playwright is a Node library to automate');14 await browser.close();15})();16const {chromium} = require('playwright');17(async () => {18 const browser = await chromium.launch({headless: false});19 const page = await browser.newPage();20 await page.type('input[name="q"]', 'Playwright');21 await page.keyboard.press('Enter');22 await page.waitForSelector('text=Playwright');23 const results = await page.$$('text=Playwright');24 await results[1].evaluate((node) => {25 const event = new Event('click');26 node.dispatchEvent(event);27 });28 await page.waitForSelector('text=Playwright is a Node library to automate');29 await browser.close();30})();
Using AI Code Generation
1const {chromium} = require('playwright');2(async () => {3 const browser = await chromium.launch({headless: false});4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.waitForSelector('text=I\'m Feeling Lucky');7 await page.click('text=I\'m Feeling Lucky');8 await page.waitForSelector('text=Google');9 await page.click('text=Google');10 await page.waitForSelector('text=I\'m Feeling Lucky');11 await page.click('text=I\'m Feeling Lucky');12 await page.waitForSelector('text=Google');13 await page.click('text=Google');14 await page.waitForSelector('text=I\'m Feeling Lucky');15 await page.click('text=I\'m Feeling Lucky');16 await page.waitForSelector('text=Google');17 await page.click('text=Google');18 await page.waitForSelector('text=I\'m Feeling Lucky');19 await page.click('text=I\'m Feeling Lucky');20 await page.waitForSelector('text=Google');21 await page.click('text=Google');22 await page.waitForSelector('text=I\'m Feeling Lucky');23 await page.click('text=I\'m Feeling Lucky');24 await page.waitForSelector('text=Google');25 await page.click('text=Google');26 await page.waitForSelector('text=I\'m Feeling Lucky');27 await page.click('text=I\'m Feeling Lucky');28 await page.waitForSelector('text=Google');29 await page.click('text=Google');30 await page.waitForSelector('text=I\'m Feeling Lucky');31 await page.click('text=I\'m Feeling Lucky');32 await page.waitForSelector('text=Google');33 await page.click('text=Google');34 await page.waitForSelector('text=I\'m Feeling Lucky');35 await page.click('text=I\'m Feeling Lucky');36 await page.waitForSelector('text=Google');37 await page.click('text=Google');38 await page.waitForSelector('text=I\'m Feeling Lucky');39 await page.click('text=I\'m Feeling Lucky');40 await page.waitForSelector('text=Google');41 await page.click('text=Google');42 await page.waitForSelector('text=I\'m Feeling Lucky
Using AI Code Generation
1const { DispatcherConnection } = require('playwright/lib/server/dispatcher');2const { ConnectionTransport } = require('playwright/lib/server/transport');3const { PageDispatcher } = require('playwright/lib/server/pageDispatcher');4const { PageChannel } = require('playwright/lib/channels');5const { Page } = require('playwright/lib/page');6const transport = new ConnectionTransport();7const connection = new DispatcherConnection(transport);8const page = new Page(connection, null, 'page1', {});9const pageDispatcher = new PageDispatcher(connection.rootDispatcher(), page, 'page1');10const pageChannel = new PageChannel(transport);11pageChannel.executeAction('evaluate', { expression: 'document.title' })12pageChannel.executeAction('evaluate', { expression: 'document.title' })13 at DispatcherConnection.dispatch (C:\Users\manas\playwright\playwright\lib\server\dispatcher.js:134:15)14 at DispatcherConnection.onMessage (C:\Users\manas\playwright\playwright\lib\server\dispatcher.js:108:14)15 at ConnectionTransport.onmessage (C:\Users\manas\playwright\playwright\lib\server\transport.js:34:24)16 at WebSocketTransport.ws.onmessage (C:\Users\manas\playwright\playwright\lib\server\transport.js:68:31)17 at WebSocket.onMessage (C:\Users\manas\playwright\playwright\lib\server\webSocketTransport.js:20:22)18 at WebSocket.emit (events.js:315:20)19 at Receiver.receiverOnMessage (C:\Users\manas\playwright\playwright\node_modules\ws\lib\websocket.js:800:20)20 at Receiver.emit (events.js:315:20)21 at Receiver.dataMessage (C:\Users\manas\playwright\playwright\node_modules\ws\lib\receiver.js:422:14)22 at Receiver.getData (C:\Users\manas\playwright\playwright\node_modules\ws\lib\receiver.js:352:17)
Using AI Code Generation
1const playwright = require('playwright');2const { InternalDispatcher } = require('playwright/lib/internal/dispatcher');3const { PageDispatcher } = require('playwright/lib/server/pageDispatcher');4const { FrameDispatcher } = require('playwright/lib/server/frameDispatcher');5(async () => {6 const browser = await playwright.chromium.launch();7 const context = await browser.newContext();8 const page = await context.newPage();9 const frame = page.mainFrame();10 const internalDispatcher = new InternalDispatcher(page);11 const pageDispatcher = new PageDispatcher(page, internalDispatcher);12 const frameDispatcher = new FrameDispatcher(frame, pageDispatcher, internalDispatcher);
Using AI Code Generation
1const { dispatcherSymbol } = require('@playwright/test/lib/server/dispatcher');2const { DispatcherConnection } = require('@playwright/test/lib/server/dispatcher/dispatcherConnection');3const { PageDispatcher } = require('@playwright/test/lib/server/dispatcher/pageDispatcher');4const { PlaywrightDispatcher } = require('@playwright/test/lib/server/dispatcher/playwrightDispatcher');5const { BrowserContextDispatcher } = require('@playwright/test/lib/server/dispatcher/browserContextDispatcher');6const { BrowserTypeDispatcher } = require('@playwright/test/lib/server/dispatcher/browserTypeDispatcher');7const { BrowserDispatcher } = require('@playwright/test/lib/server/dispatcher/browserDispatcher');8const playwright = require('playwright');9(async () => {10 const browser = await playwright.chromium.launch();11 const context = await browser.newContext();12 const page = await context.newPage();13 const pageDispatcher = page[dispatcherSymbol];14 const browserContextDispatcher = pageDispatcher._context[dispatcherSymbol];15 const browserTypeDispatcher = browserContextDispatcher._browserType[dispatcherSymbol];16 const browserDispatcher = browserContextDispatcher._browser[dispatcherSymbol];17 const playwrightDispatcher = browserTypeDispatcher._playwright[dispatcherSymbol];18 const dispatcherConnection = playwrightDispatcher._connection;
Using AI Code Generation
1const {chromium} = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.evaluate(() => {7 const event = new PointerEvent('pointerdown', {8 });9 document.dispatchEvent(event);10 });11 await browser.close();12})();13const {chromium} = require('playwright');14(async () => {15 const browser = await chromium.launch();16 const context = await browser.newContext();17 const page = await context.newPage();18 await page.evaluate(() => {19 const event = new PointerEvent('pointerdown', {20 });21 document.dispatchEvent(event);22 });23 await browser.close();24})();25const { chromium } = require('playwright');26(async () => {27 const browser = await chromium.launch();28 const context = await browser.newContext();29 const page = await context.newPage();30 await page.evaluate(() => {31 const event = new PointerEvent('pointerdown', {32 });33 document.dispatchEvent(event);34 });35 await browser.close();36})();
Using AI Code Generation
1const { executeDispatch } = require('playwright/lib/server/frames');2const { Page } = require('playwright/lib/server/page');3const { elementHandleDispatcher } = require('playwright/lib/server/elementHandlerDispatcher');4const { JSHandleDispatcher } = require('playwright/lib/server/JSHandleDispatcher');5const page = new Page(null, null, null, null, null);6const elementHandle = page.mainFrame().querySelector('input');7const elementHandleDispatcher = new elementHandleDispatcher(elementHandle);8const jsHandleDispatcher = new JSHandleDispatcher(elementHandleDispatcher);9executeDispatch(page, 'click', [jsHandleDispatcher]);10[MIT](LICENSE)
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch({ headless: false });4 const page = await browser.newPage();5 const element = await page.$('#gbqfbb');6 await page.evaluate(element => {7 element.dispatchEvent(new Event('click', { bubbles: true }));8 }, element);9 await page.waitForTimeout(3000);10 await browser.close();11})();12const { chromium } = require('playwright');13(async () => {14 const browser = await chromium.launch({ headless: false });15 const page = await browser.newPage();16 const element = await page.$('#gbqfbb');17 await element.dispatchEvent('click');18 await page.waitForTimeout(3000);19 await browser.close();20})();
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!