/// <summary> /// Sets the style for the xTextViewCursor. /// </summary> /// <param name="paraStyleName">Name of the paragraph style. <see cref="tud.mci.tangram.models.documents.WriterDocument.ParaStyleName"/></param> /// <param name="charStyleName">Name of the character style. <see cref="tud.mci.tangram.models.documents.WriterDocument.CharStyleName"/></param> /// <returns><code>true</code> if all styles wa successfully set, otherwise <code>false</code></returns> public bool SetStyle(String paraStyleName = ParaStyleName.NONE, String charStyleName = CharStyleName.NONE) { bool success = false; try { // query its XPropertySet interface, we want to set character and paragraph properties XPropertySet xCursorPropertySet = (XPropertySet)TextViewCursor; // set the appropriate properties for character and paragraph style try { xCursorPropertySet.setPropertyValue("ParaStyleName", Any.Get(paraStyleName)); success = true; } catch (IllegalArgumentException ex) { System.Diagnostics.Debug.WriteLine("ParaStyleName: '" + paraStyleName + "' was not accepted.\n" + ex); } try { xCursorPropertySet.setPropertyValue("CharStyleName", Any.Get(charStyleName)); success = true; } catch (IllegalArgumentException ex) { System.Diagnostics.Debug.WriteLine("CharStyleName: '" + charStyleName + "' was not accepted.\n" + ex); } } catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } return(success); }
private Workbook(Uri uri) { if (uri.Scheme.ToLower() == "file") { if (!File.Exists(uri.LocalPath)) { throw new FileNotFoundException(uri.LocalPath); } } var aLoader = OfficeServiceManager.loader; Peer = (XSpreadsheetDocument)aLoader.loadComponentFromURL( uri.AbsoluteUri, "_blank", 0, new[] { new PropertyValue() { Name = "Hidden", Value = new uno.Any(true) }, new PropertyValue() { Name = "MacroExecutionMode", Value = new uno.Any(MacroExecMode.FROM_LIST_NO_WARN) } } ); this.storePeer = (XStorable)Peer; this.closePeer = (XCloseable)Peer; this.propSetPeer = (XPropertySet)Peer; this.FormatsSupplier = (XNumberFormatsSupplier)Peer; }
/// <summary> /// Sets a property and add the change in the uno manager. /// </summary> /// <param name="obj">The obj.</param> /// <param name="propName">Name of the property.</param> /// <param name="value">The value of the property.</param> /// <param name="doc">The undo manager.</param> internal static bool SetPropertyUndoable(XPropertySet obj, String propName, Object value, XUndoManagerSupplier doc) { bool success = false; XUndoManager undoManager = null; if (doc != null) { undoManager = ((XUndoManagerSupplier)doc).getUndoManager() as XUndoManager; if (undoManager != null) { var is_lock = undoManager.isLocked(); undoManager.enterUndoContext("Change Property : " + propName); } } var oldVal = GetProperty(obj, propName); success = SetProperty(obj, propName, value); if (doc != null) { if (undoManager != null) { undoManager.addUndoAction(new ParameterUndo("Change a Prop", obj, propName, oldVal, value)); undoManager.leaveUndoContext(); } } return(success); }
/// <summary> /// Copies the text. /// </summary> /// <param name="xDialog">The x dialog.</param> /// <param name="aEvent">A event object.</param> public void CopyText(XDialog xDialog, Object aEvent) { XControlContainer xControlContainer = (XControlContainer)xDialog; String aTextPropertyStr = "Text"; String aText = ""; XControl xTextField1Control = xControlContainer.getControl("TextField1"); XControlModel xControlModel1 = xTextField1Control.getModel(); XPropertySet xPropertySet1 = (XPropertySet)xControlModel1; try { aText = (String)xPropertySet1.getPropertyValue(aTextPropertyStr).Value; } catch (unoidl.com.sun.star.uno.Exception e) { Console.WriteLine("copyText caught exception! " + e); } XControl xTextField2Control = xControlContainer.getControl("TextField2"); XControlModel xControlModel2 = xTextField2Control.getModel(); XPropertySet xPropertySet2 = (XPropertySet)xControlModel2; try { xPropertySet2.setPropertyValue(aTextPropertyStr, new uno.Any(aText)); } catch (unoidl.com.sun.star.uno.Exception e) { Console.WriteLine("copyText caught exception! " + e); } global::System.Windows.Forms.MessageBox.Show("DialogComponent", "copyText() called"); }
public virtual void Connect() { Logger.Debug("connecting"); try { EnvUtils.InitUno(); SocketUtils.Connect(); //var sock = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP); XComponentContext localContext = Bootstrap.bootstrap(); //XComponentContext localContext = Bootstrap.defaultBootstrap_InitialComponentContext(); XMultiComponentFactory localServiceManager = localContext.getServiceManager(); XConnector connector = (XConnector)localServiceManager.createInstanceWithContext("com.sun.star.connection.Connector", localContext); XConnection connection = connector.connect(_connectionString); XBridgeFactory bridgeFactory = (XBridgeFactory)localServiceManager.createInstanceWithContext("com.sun.star.bridge.BridgeFactory", localContext); _bridge = bridgeFactory.createBridge("", "urp", connection, null); _bridgeComponent = (XComponent)_bridge; _bridgeComponent.addEventListener(this); _serviceManager = (XMultiComponentFactory)_bridge.getInstance("StarOffice.ServiceManager"); XPropertySet properties = (XPropertySet)_serviceManager; // Get the default context from the office server. var oDefaultContext = properties.getPropertyValue("DefaultContext"); _componentContext = (XComponentContext)oDefaultContext.Value; _connected = true; Logger.Info("connected"); } catch (NoConnectException connectException) { throw new OpenOfficeException("connection failed: " + _connectionString + ": " + connectException.Message); } catch (Exception exception) { throw new OpenOfficeException("connection failed: " + _connectionString, exception); } }
virtual public void Dispose() { if (this.Shape != null) { try { // register for property changes XPropertySet shapePropertySet = (XPropertySet)Shape; if (shapePropertySet != null) { shapePropertySet.removePropertyChangeListener("Size", eventForwarder); shapePropertySet.removePropertyChangeListener("Position", eventForwarder); } } catch { } } //this.Shape = null; //this.AcccessibleCounterpart = null; // remove from the pages' shape list if (Page != null && Page.shapeList != null && Page.shapeList.Contains(this)) { Page.shapeList.Remove(this); } Disposed = true; fire_DisposingEvent(); }
/// <summary> /// Gets the property of a PropertySet or a XControl. /// </summary> /// <param name="propertySet">The property set or the control.</param> /// <param name="propName">Name of the property.</param> /// <returns>the value of the Any Object returned from the PropertySet</returns> public static Object GetProperty(Object propertySet, String propName) { if (propertySet != null && !String.IsNullOrWhiteSpace(propName)) { XPropertySet ps = null; if (propertySet is XPropertySet) { ps = propertySet as XPropertySet; } else if (propertySet is XControl) { // for a XControll you have to get the model to change or get the properties XControlModel model = ((XControl)propertySet).getModel(); if (model != null && model is XPropertySet) { ps = model as XPropertySet; } } if (ps != null) { return(OoUtils.GetProperty(ps, propName)); } } return(null); }
private void registerListeners() { // register for property changes XPropertySet shapePropertySet = (XPropertySet)Shape; if (shapePropertySet != null) { // init value for bounding box Rectangle propertyBoundRect = (Rectangle)shapePropertySet.getPropertyValue("BoundRect").Value; currentBoundRect = propertyBoundRect != null ? new System.Drawing.Rectangle(propertyBoundRect.X, propertyBoundRect.Y, propertyBoundRect.Width, propertyBoundRect.Height) : new System.Drawing.Rectangle(); try { shapePropertySet.removePropertyChangeListener("Size", eventForwarder); shapePropertySet.removePropertyChangeListener("Position", eventForwarder); shapePropertySet.addPropertyChangeListener("Size", eventForwarder); shapePropertySet.addPropertyChangeListener("Position", eventForwarder); } catch { } } if (Shape is XEventBroadcaster) { try { ((XEventBroadcaster)Shape).addEventListener(eventForwarder as unoidl.com.sun.star.document.XEventListener); } catch { } } }
protected XDrawPagesSupplier UseDraw() { try { //create new draw document and insert rectangle shape XComponent xDrawComponent = NewDocComponent("sdraw"); XDrawPagesSupplier xDrawPagesSupplier = xDrawComponent as XDrawPagesSupplier; Object drawPages = xDrawPagesSupplier.getDrawPages(); XIndexAccess xIndexedDrawPages = drawPages as XIndexAccess; Object drawPage = xIndexedDrawPages.getByIndex(0).Value; System.Diagnostics.Debug.WriteLine(xIndexedDrawPages.getCount()); if (drawPage is XDrawPage) { XDrawPage xDrawPage = (XDrawPage)drawPage; if (xDrawPage is XComponent) { (xDrawPage as XComponent).addEventListener(new TestOOoEventListerner()); } // get internal service factory of the document XMultiServiceFactory xDrawFactory = xDrawComponent as XMultiServiceFactory; Object drawShape = xDrawFactory.createInstance( "com.sun.star.drawing.RectangleShape"); XShape xDrawShape = drawShape as XShape; xDrawShape.setSize(new Size(10000, 20000)); xDrawShape.setPosition(new Point(5000, 5000)); xDrawPage.add(xDrawShape); // XText xShapeText = (XText)drawShape // COMMENTED BY CODEIT.RIGHT; XPropertySet xShapeProps = (XPropertySet)drawShape; // wrap text inside shape xShapeProps.setPropertyValue("TextContourFrame", new uno.Any(true)); return(xDrawPagesSupplier); } else { //TODO: handle if no drwapage was found System.Diagnostics.Debug.WriteLine("no XDrawPage found"); System.Diagnostics.Debug.WriteLine(drawPage); } } catch (unoidl.com.sun.star.lang.DisposedException e) { //works from Patch 1 MXContext = null; throw e; } return(null); }
/// <summary> /// Gets all properties of the object. /// </summary> /// <param name="obj">The obj.</param> /// <param name="debug">if set to <c>true</c> the properties will be printed /// to the System.Diagnostics.Debug output.</param> /// <returns>A dictionary with the properties. The name is the key an the value /// is set as uno.Any. You can access the real value by using uno.Any.Value</returns> public static Dictionary <String, uno.Any> GetAllProperties(XPropertySet obj, bool debug = true) { String output = ""; if (obj != null) { try { var b = obj.getPropertySetInfo(); if (b != null) { Property[] a = b.getProperties(); if (debug) { System.Diagnostics.Debug.WriteLine("Object [" + obj + "] has " + a.Length + " Properties:"); } var properties = new Dictionary <String, uno.Any>(); foreach (var item in a) { try { if (obj != null && item != null && item.Name != null && obj.getPropertyValue(item.Name).hasValue()) { if (debug) { output += "\n" + ("\tProperty: " + item.Name + " = " + obj.getPropertyValue(item.Name)); } properties.Add(item.Name, obj.getPropertyValue(item.Name)); } else { output += "\n" + "Can't get property - " + item.Name; } } catch (Exception) { output += "\n" + "Can't get property - " + item.Name; } } System.Diagnostics.Debug.WriteLine(output); return(properties); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Can't get properties of object: " + e); } } else { System.Diagnostics.Debug.WriteLine("object is null and therefore not of type XPropertySet and no properties could be displayed! "); } return(new Dictionary <String, uno.Any>()); }
/// <summary> /// Creates a line seperator. /// </summary> /// <param name="xMenuElementFactory">The x menu element factory.</param> /// <returns></returns> protected XPropertySet CreateLineSeperator(XMultiServiceFactory xMenuElementFactory) { // create a line separator for our new help sub menu XPropertySet xSeparator = (XPropertySet)xMenuElementFactory.createInstance("com.sun.star.ui.ActionTriggerSeparator"); short aSeparatorType = ActionTriggerSeparatorType.LINE; xSeparator.setPropertyValue("SeparatorType", Any.Get(aSeparatorType)); return(xSeparator); }
/// <summary> /// Creates the entry. /// </summary> /// <param name="entry">The entry.</param> /// <param name="properties">The properties.</param> /// <returns></returns> protected XPropertySet CreateEntry(XPropertySet entry, IDictionary <String, Object> properties) { if (entry != null) { foreach (var property in properties) { entry.setPropertyValue(property.Key, Any.Get(property.Value)); } } return(entry); }
public static bool HasTitleAndDescription(XPropertySet properties) { if (properties != null && properties.getPropertyValue("Name").Value != null && properties.getPropertyValue("Title").Value != null && properties.getPropertyValue("Description").Value != null) { return(true); } return(false); }
private void searchForDocs() { while (serach) { try { if (XDesktop != null) { XEnumerationAccess xEnumerationAccess = XDesktop.getComponents(); XEnumeration enummeraration = xEnumerationAccess.createEnumeration(); var _uids = DesktopDocumentComponents.Keys; while (enummeraration.hasMoreElements()) { Any anyelemet = enummeraration.nextElement(); XComponent element = anyelemet.Value as XComponent; if (element != null) { //FIXME: for debugging //System.Diagnostics.Debug.WriteLine("Window from Desktop found _________________"); //Debug.GetAllInterfacesOfObject(element); //System.Diagnostics.Debug.WriteLine("\tProperties _________________"); //Debug.GetAllProperties(element); XPropertySet ps = element as XPropertySet; if (ps != null) { var uid = OoUtils.GetStringProperty(ps, "RuntimeUID"); if (uid != null && !uid.Equals("")) { if (!DesktopDocumentComponents.ContainsKey(uid)) { //FIXME: for fixing Console.WriteLine("Found new Desktop child with uid:" + uid); DesktopDocumentComponents.Add(uid, element); } } } } } } } catch (DisposedException dex) { this.Dispose(); throw dex; } catch (System.Exception) { } //Console.WriteLine("\t\tSearch for Docs"); Thread.Sleep(WAIT_TIME); } }
public XControl CreateHorizontalFixedLine(String _sLabel, int _nPosX, int _nPosY, int _nWidth, int _nHeight, int orientation, String sName = "") { if (MXMcf == null) { return(null); } try { // create a unique id by means of an own implementation... if (String.IsNullOrWhiteSpace(sName)) { sName = createUniqueName(MXDlgModelNameContainer, "FIXED_LINE"); } else { sName = createUniqueName(MXDlgModelNameContainer, sName); } // create a controlmodel at the multiservicefactory of the dialog model... Object oFLModel = MXMcf.createInstanceWithContext(OO.Services.AWT_CONTROL_FIXED_LINE_MODEL, MXContext); Object oFLControl = MXMcf.createInstanceWithContext(OO.Services.AWT_CONTROL_FIXED_LINE, MXContext); if (oFLModel != null && oFLControl != null && oFLControl is XControl) { ((XControl)oFLControl).setModel(oFLModel as XControlModel); } XMultiPropertySet xFLModelMPSet = (XMultiPropertySet)oFLModel; // Set the properties at the model - keep in mind to pass the property names in alphabetical order! xFLModelMPSet.setPropertyValues( new String[] { "Height", "Name", "Orientation", "PositionX", "PositionY", "Width" }, Any.Get(new Object[] { _nHeight, sName, orientation, _nPosX, _nPosY, _nWidth })); XPropertySet xFLPSet = (XPropertySet)oFLModel; xFLPSet.setPropertyValue("Label", Any.Get(_sLabel)); return(oFLControl as XControl); } catch (unoidl.com.sun.star.uno.Exception ex) { System.Diagnostics.Debug.WriteLine("uno.Exception:"); System.Diagnostics.Debug.WriteLine(ex); } catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine("System.Exception:"); System.Diagnostics.Debug.WriteLine(ex); } return(null); }
private void appendToWriterDoc(XPropertySet ps) { if (WriterDoc != null && ps != null) { var trT = AppendNonEmptyTrimedStyledParagraphToWriterDoc(ps.getPropertyValue("Title").Value.ToString(), WriterDocument.ParaStyleName.HEADING_1); var trD = AppendNonEmptyTrimedStyledParagraphToWriterDoc(ps.getPropertyValue("Description").Value.ToString()); var trN = AppendNonEmptyTrimedStyledParagraphToWriterDoc(ps.getPropertyValue("Name").Value.ToString(), WriterDocument.ParaStyleName.MARGINALIA); //add bookmarks WriterDoc.InsertBookmark(trT, ps.GetHashCode() + "_Title"); WriterDoc.InsertBookmark(trD, ps.GetHashCode() + "_Desc"); WriterDoc.InsertBookmark(trN, ps.GetHashCode() + "_Name"); } }
/// <summary> /// get current ZoomValue and view ViewOffset properties /// </summary> /// <param name="drawViewProperties">The draw view properties.</param> private void refreshDrawViewProperties(XPropertySet drawViewProperties) { if (drawViewProperties == null) { return; } // get the current zoom factor in percent, as displayed in openoffice ZoomValue = (System.Int16)drawViewProperties.getPropertyValue("ZoomValue").Value; // get the view offset: from the top left position of the displayed page to the top left position of the view area in 100th/mm unoidl.com.sun.star.awt.Point vOffset = drawViewProperties.getPropertyValue("ViewOffset").Value as unoidl.com.sun.star.awt.Point; if (vOffset != null) { ViewOffset = new System.Drawing.Point(vOffset.X, vOffset.Y); } }
/// <summary> /// Gets a property value. /// </summary> /// <param name="obj">The obj.</param> /// <param name="propName">Name of the property.</param> /// <returns> /// the property form the property set or null /// </returns> internal static Object GetProperty(XPropertySet obj, String propName) { try { if (obj != null) { XPropertySetInfo propInfo = obj.getPropertySetInfo(); if (propInfo != null && propInfo.hasPropertyByName(propName)) { return(obj.getPropertyValue(propName).Value); } } } catch { } return(null); }
public XPropertySet InsertProgressBar(int _nPosX, int _nPosY, int _nWidth, int _nHeight, int _nProgressMax, int _nProgress, String sName = "") { XPropertySet xPBModelPSet = null; try { // create a unique name by means of an own implementation... if (String.IsNullOrWhiteSpace(sName)) { sName = createUniqueName(MXDlgModelNameContainer, "PROGRESS_BAR"); } else { sName = createUniqueName(MXDlgModelNameContainer, sName); } // create a controlmodel at the multiservicefactory of the dialog model... Object oPBModel = MXMcf.createInstanceWithContext(OO.Services.AWT_CONTROL_PROGRESS_BAR_MODEL, MXContext); XMultiPropertySet xPBModelMPSet = (XMultiPropertySet)oPBModel; // Set the properties at the model - keep in mind to pass the property names in alphabetical order! xPBModelMPSet.setPropertyValues( new String[] { "Height", "Name", "PositionX", "PositionY", "Width" }, Any.Get(new Object[] { _nHeight, sName, _nPosX, _nPosY, _nWidth })); // The controlmodel is not really available until inserted to the Dialog container MXDlgModelNameContainer.insertByName(sName, Any.Get(oPBModel)); xPBModelPSet = (XPropertySet)oPBModel; // The following properties may also be set with XMultiPropertySet but we // use the XPropertySet interface merely for reasons of demonstration xPBModelPSet.setPropertyValue("ProgressValueMin", Any.Get(0)); xPBModelPSet.setPropertyValue("ProgressValueMax", Any.Get(_nProgressMax)); xPBModelPSet.setPropertyValue("ProgressValue", Any.Get(_nProgress)); } catch (unoidl.com.sun.star.uno.Exception ex) { System.Diagnostics.Debug.WriteLine("uno.Exception:"); System.Diagnostics.Debug.WriteLine(ex); } catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine("System.Exception:"); System.Diagnostics.Debug.WriteLine(ex); } return(xPBModelPSet); }
/// <summary> /// Gets the preview image bitmap data for the page. /// </summary> /// <param name="bitmapData">The bitmap data.</param> /// <remarks>This function is time limited to 100 ms.</remarks> public void GetPreview(out byte[] bitmapData) { byte[] bitmapDataResult = new byte[0]; XPropertySet pageProperties = DrawPage as XPropertySet; if (pageProperties != null) { TimeLimitExecutor.WaitForExecuteWithTimeLimit(100, () => { try { bitmapDataResult = (byte[])pageProperties.getPropertyValue("Preview").Value; } catch (ThreadAbortException) { } } , "GetPrieviewBitmap"); } bitmapData = bitmapDataResult; }
/// <summary> /// registers various property listeners /// </summary> private void registerListeners() { try { if (refreshPagePropertiesTimer != null) { refreshPagePropertiesTimer.Stop(); refreshPagePropertiesTimer.Dispose(); } refreshPagePropertiesTimer = new System.Timers.Timer(5000); XPropertySet pageProperties = DrawPage as XPropertySet; if (pageProperties != null) { //Debug.PrintAllProperties(pageProperties); onRefreshPage(this, null); pageProperties.addPropertyChangeListener("Orientation", eventForwarder); pageProperties.addVetoableChangeListener("Orientation", eventForwarder); pageProperties.addPropertyChangeListener("", eventForwarder); refreshPagePropertiesTimer.Elapsed += new System.Timers.ElapsedEventHandler(onRefreshPage); // start the refresh timer with some delay so not all pages will update their properties at the same time! Task t = new Task(new Action(() => { Thread.Sleep(rnd.Next(1000)); refreshPagePropertiesTimer.Start(); })); t.Start(); //eventForwarder.Modified += eventForwarder_Modified; //eventForwarder.NotifyEvent += eventForwarder_NotifyEvent; //eventForwarder.PropertiesChange += eventForwarder_PropertiesChange; //eventForwarder.PropertyChange += eventForwarder_PropertyChange; //eventForwarder.VetoableChange += eventForwarder_VetoableChange; } XMultiPropertySet pageMultiProperties = (XMultiPropertySet)DrawPage; if (pageMultiProperties != null) { pageMultiProperties.addPropertiesChangeListener(new string[] { }, eventForwarder); } } catch (DisposedException) { ((IDisposable)this).Dispose(); } catch (Exception) { } }
/// <summary> /// Sets a property. /// </summary> /// <param name="obj">The obj.</param> /// <param name="propName">Name of the property.</param> /// <param name="value">The value of the property.</param> /// <returns><c>true</c> if the property could been set without an error, otherwise <c>false</c></returns> internal static bool SetProperty(XPropertySet obj, String propName, Object value) { if (obj != null) { //var proInfo = obj.getPropertySetInfo(); //var properties = proInfo.getProperties(); //List<String> props = new List<String>(); //foreach (var prop in properties) //{ // props.Add(prop.Name); //} if (obj.getPropertySetInfo() != null && obj.getPropertySetInfo().hasPropertyByName(propName)) { try { obj.setPropertyValue(propName, Any.Get(value)); return(true); } catch (unoidl.com.sun.star.beans.PropertyVetoException) { System.Diagnostics.Debug.WriteLine("Property value is unacceptable"); } catch (unoidl.com.sun.star.uno.RuntimeException) { System.Diagnostics.Debug.WriteLine("Property value set cause internal error"); Logger.Instance.Log(LogPriority.IMPORTANT, "OoUtils", "[FATAL ERROR] Cannot set property '" + propName + "' to value: '" + (value != null ? value.ToString() : "NULL") + "' for the current object"); } } else { XPropertyContainer pc = obj as XPropertyContainer; if (pc != null) { try { pc.addProperty(propName, (short)2, Any.Get(value)); return(true); } catch { } } } } return(false); }
public Object InsertHorizontalFixedLine(String _sLabel, int _nPosX, int _nPosY, int _nWidth, int _nHeight, int orientation, String sName = "") { try { // create a unique name by means of an own implementation... if (String.IsNullOrWhiteSpace(sName)) { sName = createUniqueName(MXDlgModelNameContainer, "FIXED_LINE"); } else { sName = createUniqueName(MXDlgModelNameContainer, sName); } // create a controlmodel at the multiservicefactory of the dialog model... Object oFLModel = MXMcf.createInstanceWithContext(OO.Services.AWT_CONTROL_FIXED_LINE_MODEL, MXContext); XMultiPropertySet xFLModelMPSet = (XMultiPropertySet)oFLModel; // Set the properties at the model - keep in mind to pass the property names in alphabetical order! xFLModelMPSet.setPropertyValues( new String[] { "Height", "Name", "Orientation", "PositionX", "PositionY", "Width" }, Any.Get(new Object[] { _nHeight, sName, orientation, _nPosX, _nPosY, _nWidth })); // The controlmodel is not really available until inserted to the Dialog container MXDlgModelNameContainer.insertByName(sName, Any.Get(oFLModel)); // The following property may also be set with XMultiPropertySet but we // use the XPropertySet interface merely for reasons of demonstration XPropertySet xFLPSet = (XPropertySet)oFLModel; xFLPSet.setPropertyValue("Label", Any.Get(_sLabel)); return(oFLModel); } catch (unoidl.com.sun.star.uno.Exception ex) { System.Diagnostics.Debug.WriteLine("uno.Exception:"); System.Diagnostics.Debug.WriteLine(ex); } catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine("System.Exception:"); System.Diagnostics.Debug.WriteLine(ex); } return(null); }
public static XLayer getActiveLayer(XController xController) { XLayer bActiveLayer = null; if (xController != null) { try { XPropertySet xPropSet = (XPropertySet)xController; bActiveLayer = xPropSet.getPropertyValue("ActiveLayer").Value as XLayer; } catch (unoidl.com.sun.star.uno.Exception e) { System.Diagnostics.Debug.WriteLine("Error while getting active layer:\n" + e); } } return(bActiveLayer); }
protected override void propertyChange(PropertyChangeEvent evt) { //System.Diagnostics.Debug.WriteLine("property changed: " + evt.PropertyName); if (evt.Source == Shape && (evt.PropertyName.Equals("Position") || evt.PropertyName.Equals("Size")) && Shape is XPropertySet) { XPropertySet shapePropertySet = (XPropertySet)Shape; { // Rectangle propertyBoundRect = (Rectangle)shapePropertySet.getPropertyValue("BoundRect").Value; Rectangle propertyBoundRect = (Rectangle)shapePropertySet.getPropertyValue("FrameRect").Value; currentBoundRect.X = propertyBoundRect.X; currentBoundRect.Y = propertyBoundRect.Y; currentBoundRect.Width = propertyBoundRect.Width; currentBoundRect.Height = propertyBoundRect.Height; OnBoundRectChangeEvent(); } } }
private bool VerifyRedirectParameter(ref XTextGraphicObjectsSupplier comp, string imageName) { logger.Debug("VerifyRedirectParameter"); // Get old image Object xImageObject = comp.getGraphicObjects().getByName(imageName).Value; XTextContent xImage = (XTextContent)xImageObject; // Get property set object of the existing image (XContent) // We will use this property set object to set the new Graphic property of the old image // to be the new image stream XPropertySet xPropSet = (XPropertySet)xImage; // Get XMCF to create a graphic provider component XMultiComponentFactory xMCF = localContext.getServiceManager(); // Assign the new graphic image to existent page object //xPropSet.setPropertyValue("Graphic", new uno.Any(typeof(UNOIDL.graphic.XGraphic), xNewGraphic)); //var crop = (UNOIDL.container.XIndexContainer) xPropSet.getPropertyValue("ImageMap").Value; var size = (Size)xPropSet.getPropertyValue("ActualSize").Value; var url = xPropSet.getPropertyValue("GraphicURL").Value as string; bool elementFind = false; if (ConfigurationManager.AppSettings["RedirectSizeFilter"] != null && size != null) { var sizeFilter = ConfigurationManager.AppSettings["RedirectSizeFilter"].ToString().Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); var arrOfSizeFilter = sizeFilter.Select(p => new { Width = int.Parse(p.Split(',')[0]), Height = int.Parse(p.Split(',')[1]) }); if (arrOfSizeFilter.Count() > 0) { elementFind = arrOfSizeFilter.Any(x => x.Width == size.Width && x.Height == size.Height); } } if (ConfigurationManager.AppSettings["RedirectUrlFilter"] != null && size != null) { var urlFilter = ConfigurationManager.AppSettings["RedirectUrlFilter"].ToString().Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); if (urlFilter.Count() > 0) { elementFind = urlFilter.Contains(url); } } return(elementFind); }
/// <summary> /// Sets a property if possible. /// </summary> /// <param name="propertySet">The property set.</param> /// <param name="name">The name of the property.</param> /// <param name="value">The value.</param> /// <returns><c>true</c> if the property could be set otherwise <c>false</c></returns> public bool SetProperty(object propertySet, string name, object value) { if (propertySet != null) { XPropertySet ps = null; if (propertySet is XPropertySet) { ps = propertySet as XPropertySet; } else if (propertySet is XControl) { // for a XControll you have to get the model to change or get the properties XControlModel model = ((XControl)propertySet).getModel(); if (model != null && model is XPropertySet) { ps = model as XPropertySet; } } if (ps != null) { var psInfo = ps.getPropertySetInfo(); bool exist = psInfo.hasPropertyByName(name); //util.Debug.GetAllProperties(ps); if (exist) { ps.setPropertyValue(name, Any.Get(value)); return(true); } else { } } } return(false); }
/// <summary> /// Sets a property and add the change in the uno manager. /// </summary> /// <param name="obj">The obj.</param> /// <param name="propName">Name of the property.</param> /// <param name="value">The value of the property.</param> /// <param name="doc">The undo manager.</param> public static bool SetPropertyUndoable(XPropertySet obj, String propName, Object value, XUndoManagerSupplier doc) { bool success = false; XUndoManager undoManager = null; if (doc != null) { undoManager = ((XUndoManagerSupplier)doc).getUndoManager() as XUndoManager; if (undoManager != null) { var is_lock = undoManager.isLocked(); undoManager.enterUndoContext("Change Property : " + propName); } } var oldVal = GetProperty(obj, propName); success = SetProperty(obj, propName, value); if (doc != null) { if (undoManager != null) { undoManager.addUndoAction(new ParameterUndo("Change a Prop", obj, propName, oldVal, value)); undoManager.leaveUndoContext(); } } return success; }
public static XControlContainer createDialog(XMultiComponentFactory xMultiComponentFactory, XComponentContext xContext, int posX, int posY, int width, int height, string title ) { //dialog model Object oDialogModel = xMultiComponentFactory.createInstanceWithContext( "com.sun.star.awt.UnoControlDialogModel", xContext); XPropertySet xPSetDialog = (XPropertySet)oDialogModel; xPSetDialog.setPropertyValue("PositionX", Any.Get(posX)); xPSetDialog.setPropertyValue("PositionY", Any.Get(posY)); xPSetDialog.setPropertyValue("Width", Any.Get(width)); xPSetDialog.setPropertyValue("Height", Any.Get(height)); xPSetDialog.setPropertyValue("Title", Any.Get(title)); // get service manager from dialog model XMultiServiceFactory MXMsfDialogModel = (XMultiServiceFactory)oDialogModel; // dialog control model Object oUnoDialog = xMultiComponentFactory.createInstanceWithContext( "com.sun.star.awt.UnoControlDialog", xContext); XControl MXDialogControl = (XControl)oUnoDialog; XControlModel xControlModel = (XControlModel)oDialogModel; MXDialogControl.setModel(xControlModel); XToolkit xToolkit = (XToolkit)xMultiComponentFactory .createInstanceWithContext("com.sun.star.awt.Toolkit", xContext); WindowDescriptor aDescriptor = new WindowDescriptor(); aDescriptor.Type = WindowClass.TOP; aDescriptor.WindowServiceName = ""; aDescriptor.ParentIndex = -1; aDescriptor.Parent = xToolkit.getDesktopWindow(); aDescriptor.Bounds = new Rectangle(100, 200, 300, 400); aDescriptor.WindowAttributes = WindowAttribute.BORDER | WindowAttribute.MOVEABLE | WindowAttribute.SIZEABLE | WindowAttribute.CLOSEABLE; XWindowPeer xPeer = xToolkit.createWindow(aDescriptor); XWindow xWindow = (XWindow)xPeer; xWindow.setVisible(false); MXDialogControl.createPeer(xToolkit, xPeer); // execute the dialog XDialog xDialog = (XDialog)oUnoDialog; xDialog.execute(); // dispose the dialog XComponent xComponent = (XComponent)oUnoDialog; xComponent.dispose(); return(oUnoDialog as XControlContainer); }
public XTextComponent InsertEditField(String defaultText, int _nPosX, int _nPosY, int _nWidth, int _nHeight, String echoChar, XTextListener _xTextListener, XFocusListener _xFocusListener, XKeyListener _xKeyListener, String sName = "") { XTextComponent xTextComponent = null; try { // create a unique name by means of an own implementation... if (String.IsNullOrWhiteSpace(sName)) { sName = createUniqueName(MXDlgModelNameContainer, "EDIT"); } else { sName = createUniqueName(MXDlgModelNameContainer, sName); } // create a controlmodel at the multiservicefactory of the dialog model... Object oTFModel = MXMcf.createInstanceWithContext(OO.Services.AWT_CONTROL_EDIT_MODEL, MXContext); XMultiPropertySet xTFModelMPSet = (XMultiPropertySet)oTFModel; // Set the properties at the model - keep in mind to pass the property names in alphabetical order! xTFModelMPSet.setPropertyValues( new String[] { "Height", "Name", "PositionX", "PositionY", "Text", "Width" }, Any.Get(new Object[] { _nHeight, sName, _nPosX, _nPosY, defaultText, _nWidth })); // The controlmodel is not really available until inserted to the Dialog container MXDlgModelNameContainer.insertByName(sName, Any.Get(oTFModel)); if (!echoChar.Equals(String.Empty)) { XPropertySet xTFModelPSet = (XPropertySet)oTFModel; // The following property may also be set with XMultiPropertySet but we // use the XPropertySet interface merely for reasons of demonstration xTFModelPSet.setPropertyValue("EchoChar", Any.Get((short)echoChar.ToCharArray(0, 1)[0])); } if (_xFocusListener != null || _xTextListener != null || _xKeyListener != null) { XControl xTFControl = GetControlByName(sName); // add a textlistener that is notified on each change of the controlvalue... xTextComponent = (XTextComponent)xTFControl; XWindow xTFWindow = (XWindow)xTFControl; if (_xFocusListener != null) { xTFWindow.addFocusListener(_xFocusListener); } if (_xTextListener != null) { xTextComponent.addTextListener(_xTextListener); } if (_xKeyListener != null) { xTFWindow.addKeyListener(_xKeyListener); } } } catch (unoidl.com.sun.star.uno.Exception ex) { System.Diagnostics.Debug.WriteLine("uno.Exception:"); System.Diagnostics.Debug.WriteLine(ex); } catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine("System.Exception:"); System.Diagnostics.Debug.WriteLine(ex); } return(xTextComponent); }
/// <summary> /// Gets a property value. /// </summary> /// <param name="obj">The obj.</param> /// <param name="propName">Name of the property.</param> /// <returns> /// the property form the property set or null /// </returns> public static Object GetProperty(XPropertySet obj, String propName) { try { if (obj != null) { XPropertySetInfo propInfo = obj.getPropertySetInfo(); if (propInfo != null && propInfo.hasPropertyByName(propName)) { return obj.getPropertyValue(propName).Value; } } } catch { } return null; }
/// <summary> /// Sets a property. /// </summary> /// <param name="obj">The obj.</param> /// <param name="propName">Name of the property.</param> /// <param name="value">The value of the property.</param> /// <returns><c>true</c> if the property could been set without an error, otherwise <c>false</c></returns> public static bool SetProperty(XPropertySet obj, String propName, Object value) { if (obj != null) { //var proInfo = obj.getPropertySetInfo(); //var properties = proInfo.getProperties(); //List<String> props = new List<String>(); //foreach (var prop in properties) //{ // props.Add(prop.Name); //} if (obj.getPropertySetInfo() != null && obj.getPropertySetInfo().hasPropertyByName(propName)) { try { obj.setPropertyValue(propName, Any.Get(value)); return true; } catch (unoidl.com.sun.star.beans.PropertyVetoException) { System.Diagnostics.Debug.WriteLine("Property value is unacceptable"); } catch (unoidl.com.sun.star.uno.RuntimeException) { System.Diagnostics.Debug.WriteLine("Property value set cause internal error"); Logger.Instance.Log(LogPriority.IMPORTANT, "OoUtils", "[FATAL ERROR] Cannot set property '" + propName + "' to value: '" + value.ToString() + "' for the current object"); } } else { XPropertyContainer pc = obj as XPropertyContainer; if (pc != null) { try { pc.addProperty(propName, (short)2, Any.Get(value)); return true; } catch { } } } } return false; }
/// <summary> /// Creates the entry. /// </summary> /// <param name="entry">The entry.</param> /// <param name="properties">The properties.</param> /// <returns></returns> protected XPropertySet CreateEntry(XPropertySet entry, IDictionary<String, Object> properties ) { if (entry != null) { foreach (var property in properties) { entry.setPropertyValue(property.Key, Any.Get(property.Value)); } } return entry; }
public XTextComponent InsertCurrencyField(int _nPositionX, int _nPositionY, int _nWidth, int _nHeight, string curencySymbol, double defaultValue, XTextListener _xTextListener, String sName = "") { XTextComponent xTextComponent = null; try { // create a unique name by means of an own implementation... if (String.IsNullOrWhiteSpace(sName)) { sName = createUniqueName(MXDlgModelNameContainer, "CURRENCY_FIELD"); } else { sName = createUniqueName(MXDlgModelNameContainer, sName); } // create a controlmodel at the multiservicefactory of the dialog model... Object oCFModel = MXMcf.createInstanceWithContext(OO.Services.AWT_CONTROL_CURRENCY_FIELD_MODEL, MXContext); XMultiPropertySet xCFModelMPSet = (XMultiPropertySet)oCFModel; // Set the properties at the model - keep in mind to pass the property names in alphabetical order! xCFModelMPSet.setPropertyValues( new String[] { "Height", "Name", "PositionX", "PositionY", "Width" }, Any.Get(new Object[] { _nHeight, sName, _nPositionX, _nPositionY, _nWidth })); // The controlmodel is not really available until inserted to the Dialog container MXDlgModelNameContainer.insertByName(sName, Any.Get(oCFModel)); XPropertySet xCFModelPSet = (XPropertySet)oCFModel; // The following properties may also be set with XMultiPropertySet but we // use the XPropertySet interface merely for reasons of demonstration if (!curencySymbol.Equals(String.Empty)) { xCFModelPSet.setPropertyValue("PrependCurrencySymbol", Any.Get(true)); xCFModelPSet.setPropertyValue("CurrencySymbol", Any.Get(curencySymbol)); } else { xCFModelPSet.setPropertyValue("PrependCurrencySymbol", Any.Get(false)); } xCFModelPSet.setPropertyValue("Value", Any.Get(defaultValue)); if (_xTextListener != null) { // add a textlistener that is notified on each change of the controlvalue... Object oCFControl = GetControlByName(sName); xTextComponent = (XTextComponent)oCFControl; xTextComponent.addTextListener(_xTextListener); } } catch (unoidl.com.sun.star.uno.Exception ex) { System.Diagnostics.Debug.WriteLine("uno.Exception:"); System.Diagnostics.Debug.WriteLine(ex); } catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine("System.Exception:"); System.Diagnostics.Debug.WriteLine(ex); } return(xTextComponent); }
/// <summary> /// Gets all properties of the object. /// </summary> /// <param name="obj">The obj.</param> /// <param name="debug">if set to <c>true</c> the properties will be printed /// to the System.Diagnostics.Debug output.</param> /// <returns>A dictionary with the properties. The name is the key an the value /// is set as uno.Any. You can access the real value by using uno.Any.Value</returns> public static Dictionary<String, uno.Any> GetAllProperties(XPropertySet obj, bool debug = true) { String output = ""; if (obj != null) { try { var b = obj.getPropertySetInfo(); if (b != null) { Property[] a = b.getProperties(); if (debug) System.Diagnostics.Debug.WriteLine("Object [" + obj + "] has " + a.Length + " Properties:"); var properties = new Dictionary<String, uno.Any>(); foreach (var item in a) { try { if (obj != null && item != null && item.Name != null && obj.getPropertyValue(item.Name).hasValue()) { if (debug) output += "\n" + ("\tProperty: " + item.Name + " = " + obj.getPropertyValue(item.Name)); properties.Add(item.Name, obj.getPropertyValue(item.Name)); } else { output += "\n" + "Can't get property - " + item.Name; } } catch (Exception) { output += "\n" + "Can't get property - " + item.Name; } } System.Diagnostics.Debug.WriteLine(output); return properties; } } catch (Exception e) { System.Diagnostics.Debug.WriteLine("Can't get properties of object: " + e); } } else { System.Diagnostics.Debug.WriteLine("object is null and therefore not of type XPropertySet and no properties could be displayed! "); } return new Dictionary<String, uno.Any>(); }
/// <summary> /// Creates a sub menu container. /// </summary> /// <param name="xMenuElementFactory">The x menu element factory.</param> /// <param name="entries">The entries.</param> /// <returns></returns> protected XIndexContainer CreateSubMenuContainer(XMultiServiceFactory xMenuElementFactory, XPropertySet[] entries = null) { var entry = (XIndexContainer)xMenuElementFactory.createInstance("com.sun.star.ui.ActionTriggerContainer"); if (entry != null && entries != null && entries.Length > 0) { for (int i = 0; i < entries.Length; i++) { entry.insertByIndex(i,Any.Get(entries[i])); } } return entry; }
/// <summary> /// get current ZoomValue and view ViewOffset properties /// </summary> /// <param name="drawViewProperties">The draw view properties.</param> private void refreshDrawViewProperties(XPropertySet drawViewProperties) { if (drawViewProperties == null) return; // get the current zoom factor in percent, as displayed in openoffice ZoomValue = (System.Int16)drawViewProperties.getPropertyValue("ZoomValue").Value; // get the view offset: from the top left position of the displayed page to the top left position of the view area in 100th/mm unoidl.com.sun.star.awt.Point vOffset = drawViewProperties.getPropertyValue("ViewOffset").Value as unoidl.com.sun.star.awt.Point; if (vOffset != null) { ViewOffset = new System.Drawing.Point(vOffset.X, vOffset.Y); } }
public Object addRoadmap(XItemListener _xItemListener, String sName = "") { XPropertySet xDialogModelPropertySet = null; try { // create a unique name by means of an own implementation... if (String.IsNullOrWhiteSpace(sName)) sName = createUniqueName(MXDlgModelNameContainer, "ROADMAP"); else sName = createUniqueName(MXDlgModelNameContainer, sName); xDialogModelPropertySet = (XPropertySet)MXContext; // Similar to the office assistants the roadmap is adjusted to the height of the dialog // where a certain space is left at the bottom for the buttons... int nDialogHeight = (int)(xDialogModelPropertySet.getPropertyValue("Height").Value); // instantiate the roadmapmodel... Object oRoadmapModel = MXMcf.createInstanceWithContext(OO.Services.AWT_CONTROL_ROADMAP_MODEL, MXContext); // define the properties of the roadmapmodel XMultiPropertySet xRMMPSet = (XMultiPropertySet)oRoadmapModel; xRMMPSet.setPropertyValues( new String[] { "Complete", "Height", "Name", "PositionX", "PositionY", "Text", "Width" }, Any.Get(new Object[] { false, (nDialogHeight - 26), sName, 0, 0, "Steps", 85 })); m_xRMPSet = (XPropertySet)oRoadmapModel; // add the roadmapmodel to the dialog container.. MXDlgModelNameContainer.insertByName(sName, Any.Get(oRoadmapModel)); // the roadmapmodel is a SingleServiceFactory to instantiate the roadmapitems... m_xSSFRoadmap = (XSingleServiceFactory)oRoadmapModel; m_xRMIndexCont = (XIndexContainer)oRoadmapModel; //util.Debug.GetAllProperties(oRoadmapModel); //util.Debug.GetAllServicesOfObject(oRoadmapModel); // add the itemlistener to the control... XControl xRMControl = GetControlByName(sName); XItemEventBroadcaster xRMBroadcaster = (XItemEventBroadcaster)xRMControl; xRMBroadcaster.addItemListener(_xItemListener); return oRoadmapModel; } catch (System.Exception) { //jexception.printStackTrace(System.out); } return null; }
public void addTree(XSelectionChangeListener _xSelectionListener = null, String sName = "") { /*Selection * * If you are interested in knowing when the selection changes implement a * ::com::sun::star::view::XSelectionChangeListener and add the instance * with the method ::com::sun::star::view::XSelectionSupplier::addSelectionChangeListener(). * You than will be notified for any selection change. * * If you are interested in detecting either double-click events or when a user * clicks on a node, regardless of whether or not it was selected, you can get * the ::com::sun::star::awt::XWindow and add yourself as * a ::com::sun::star::awt::XMouseClickHandler. * You can use the method XTreeControl::getNodeForLocation() to retrieve the * node that was under the mouse at the time the event was fired. */ XPropertySet xDialogModelPropertySet = null; try { // create a unique name by means of an own implementation... if (String.IsNullOrWhiteSpace(sName)) sName = createUniqueName(MXDlgModelNameContainer, "TREE"); else sName = createUniqueName(MXDlgModelNameContainer, sName); xDialogModelPropertySet = (XPropertySet)MXMsfDialogModel; // Similar to the office assistants the tree is adjusted to the height of the dialog // where a certain space is left at the bottom for the buttons... int nDialogHeight = (int)(xDialogModelPropertySet.getPropertyValue("Height").Value); // instantiate the treemodel... Object oTreeModel = MXMcf.createInstanceWithContext(OO.Services.AWT_CONTROL_TREE_MODEL, MXContext); // define the properties of the treemodel m_xTreePSet = (XMultiPropertySet)oTreeModel; m_xTreePSet.setPropertyValues( new String[] { "Height", "Name", "PositionX", "PositionY", "Width" }, Any.Get(new Object[] { (nDialogHeight - 26), sName, 0, 0, 85 })); m_xRMPSet = (XPropertySet)oTreeModel; // add the treemodel to the dialog container.. MXDlgModelNameContainer.insertByName(sName, Any.Get(oTreeModel)); oMutTreeModel = OO.GetMultiServiceFactory().createInstance(OO.Services.AWT_CONTROL_MUTABLETREE_MODEL) as XMutableTreeDataModel; //set the new DdataModel XPropertySet xTItemPSet = oTreeModel as XPropertySet; if (xTItemPSet != null) xTItemPSet.setPropertyValue("DataModel", Any.Get(oMutTreeModel)); // add the itemlistener to the control... XControl xTMControl = GetControlByName(sName); XSelectionSupplier selSupp = xTMControl as XSelectionSupplier; if (selSupp != null) { selSupp.addSelectionChangeListener(_xSelectionListener); } } catch (System.Exception) { //jexception.printStackTrace(System.out); } }