home *** CD-ROM | disk | FTP | other *** search
/ Freelog 125 / Freelog_MarsAvril2015_No125.iso / Bureautique / OpenOffice / Apache_OpenOffice_4.1.1_Win_x86_install_fr.exe / openoffice1.cab / ButtonPressHandler.js < prev    next >
Text File  |  2014-02-25  |  5KB  |  126 lines

  1. // *************************************************************
  2. //  
  3. //  Licensed to the Apache Software Foundation (ASF) under one
  4. //  or more contributor license agreements.  See the NOTICE file
  5. //  distributed with this work for additional information
  6. //  regarding copyright ownership.  The ASF licenses this file
  7. //  to you under the Apache License, Version 2.0 (the
  8. //  "License"); you may not use this file except in compliance
  9. //  with the License.  You may obtain a copy of the License at
  10. //  
  11. //    http://www.apache.org/licenses/LICENSE-2.0
  12. //  
  13. //  Unless required by applicable law or agreed to in writing,
  14. //  software distributed under the License is distributed on an
  15. //  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. //  KIND, either express or implied.  See the License for the
  17. //  specific language governing permissions and limitations
  18. //  under the License.
  19. //  
  20. // *************************************************************
  21. //this script acts as a handler for the buttons in the Highlight dialog
  22. importClass(Packages.com.sun.star.uno.UnoRuntime);
  23. importClass(Packages.com.sun.star.uno.Type);
  24. importClass(Packages.com.sun.star.uno.AnyConverter);
  25.  
  26. importClass(Packages.com.sun.star.awt.XButton);
  27. importClass(Packages.com.sun.star.awt.XControl);
  28. importClass(Packages.com.sun.star.awt.ActionEvent);
  29. importClass(Packages.com.sun.star.awt.XControlModel);
  30. importClass(Packages.com.sun.star.awt.XControlContainer);
  31. importClass(Packages.com.sun.star.awt.XDialog);
  32. importClass(Packages.com.sun.star.awt.XTextComponent);
  33.  
  34. importClass(Packages.com.sun.star.util.XReplaceable);
  35. importClass(Packages.com.sun.star.util.XReplaceDescriptor);
  36. importClass(Packages.com.sun.star.util.XPropertyReplace);
  37.  
  38. importClass(Packages.com.sun.star.beans.XPropertySet);
  39. importClass(Packages.com.sun.star.beans.PropertyValue);
  40.  
  41. // Scripting Framework DialogFactory class
  42. importClass(Packages.com.sun.star.script.framework.browse.DialogFactory);
  43.  
  44. // Get the ActionEvent object from the ARGUMENTS list
  45. event = ARGUMENTS[0];
  46.  
  47. // Each argument is of type Any so we must use the AnyConverter class to
  48. // convert it into the interface or primitive type we expect
  49. button = AnyConverter.toObject(new Type(XButton), event.Source);
  50.  
  51. // We can now query for the model of the button and get its properties
  52. control = UnoRuntime.queryInterface(XControl, button);
  53. cmodel = control.getModel();
  54. pset = UnoRuntime.queryInterface(XPropertySet, cmodel);
  55.  
  56. if (pset.getPropertyValue("Label").equals("Exit"))
  57. {
  58.     // We can get the XDialog in which this control appears by calling
  59.     // getContext() on the XControl interface
  60.     xDialog = UnoRuntime.queryInterface(
  61.         XDialog, control.getContext());
  62.     
  63.     // Close the dialog
  64.     xDialog.endExecute();
  65. }
  66. else
  67. {
  68.     // We can get the list of controls for this dialog by calling
  69.     // getContext() on the XControl interface of the button
  70.     controls = UnoRuntime.queryInterface(
  71.         XControlContainer, control.getContext());
  72.  
  73.     // Now get the text field control from the list
  74.     textField =
  75.         UnoRuntime.queryInterface(
  76.             XTextComponent, controls.getControl("HighlightTextField"));
  77.  
  78.     searchKey = textField.getText();
  79.  
  80.     // highlight the text in red
  81.     red = java.awt.Color.red.getRGB();
  82.  
  83.     replaceable =
  84.         UnoRuntime.queryInterface(XReplaceable, XSCRIPTCONTEXT.getDocument()); 
  85.  
  86.     descriptor = replaceable.createReplaceDescriptor();
  87.  
  88.     // Gets a XPropertyReplace object for altering the properties
  89.     // of the replaced text
  90.     xPropertyReplace = UnoRuntime.queryInterface(XPropertyReplace, descriptor);
  91.  
  92.     // Sets the replaced text property fontweight value to Bold
  93.     wv = new PropertyValue("CharWeight", -1,
  94.         new java.lang.Float(Packages.com.sun.star.awt.FontWeight.BOLD),
  95.             Packages.com.sun.star.beans.PropertyState.DIRECT_VALUE);
  96.  
  97.     // Sets the replaced text property color value to RGB parameter
  98.     cv = new PropertyValue("CharColor", -1,
  99.         new java.lang.Integer(red),
  100.             Packages.com.sun.star.beans.PropertyState.DIRECT_VALUE);
  101.  
  102.     // Apply the properties
  103.     props = new Array;
  104.     props[0] = cv;
  105.     props[1] = wv;
  106.  
  107.     try {
  108.         xPropertyReplace.setReplaceAttributes(props);
  109.  
  110.         // Only matches whole words and case sensitive
  111.         descriptor.setPropertyValue(
  112.             "SearchCaseSensitive", new java.lang.Boolean(true));
  113.         descriptor.setPropertyValue("SearchWords", new java.lang.Boolean(true));
  114.  
  115.         // Replaces all instances of searchKey with new Text properties
  116.         // and gets the number of instances of the searchKey 
  117.         descriptor.setSearchString(searchKey); 
  118.         descriptor.setReplaceString(searchKey); 
  119.         replaceable.replaceAll(descriptor);
  120.     }
  121.     catch (e) {
  122.         java.lang.System.err.println("Error setting up search properties"
  123.             + e.getMessage());
  124.     }
  125. }
  126.