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); }
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); }