'Danny B 'http://www.oooforum.org/forum/viewtopic.phtml?p=73054#73054 '********************************************************************** ' UtilForm module ' ' Utility functions for working with document Forms. ' '********************************************************************** ' Copyright (c) 2003-2004 Danny Brewer ' d29583@groovegarden.com ' ' This library is free software; you can redistribute it and/or ' modify it under the terms of the GNU Lesser General Public ' License as published by the Free Software Foundation; either ' version 2.1 of the License, or (at your option) any later version. ' ' This library is distributed in the hope that it will be useful, ' but WITHOUT ANY WARRANTY; without even the implied warranty of ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ' Lesser General Public License for more details. ' ' You should have received a copy of the GNU Lesser General Public ' License along with this library; if not, write to the Free Software ' Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ' ' See: http://www.gnu.org/licenses/lgpl.html ' '********************************************************************** ' If you make changes, please append to the change log below. ' ' Change Log ' Danny Brewer Revised 2004-08-16-02 ' '********************************************************************** '---------- ' Get the Forms collection from a certian page of a document. ' Optional Parameters: ' nPage - The page number of a document that has multiple ' draw pages, such as Draw, Impress or Calc. ' Passing -1 is the same as omitting this argument. ' oDoc - The document model. If not supplied, then ThisComponent is used. ' It is okay to pass one of the document's controllers or frame instead. ' ' Once you have the collection of Forms, you can do the following things... ' from XNameContainer.... ' oForms.insertByName( "FormName", oForm ) ' oForms.removeByName( "FormName" ) ' oForms.replaceByName( "FormName", oForm ) ' aNames = oForms.getElementNames() ' oForm = oForms.getByName( "FormName ) ' If oForms.hasByName( "FormName" ) Then... ' from XIndexAccess... ' oForms.insertByIndex( 0, oForm ) ' oForms.removeByIndex( 0 ) ' oForms.replaceByIndex( 0, oForm ) ' nNumForms = oForms.getCount() ' oForm = oForms.getByIndex( 0 ) ' from XEnumerationAccess... ' oEnumeration = oForms.createEnumeration() ' ...then use hasMoreElements() and nextElement() ' ' Examples.... ' Create new form, and give it the name MyForm... ' oForm = createUnoService( "com.sun.star.form.component.Form" ) ' oForms.insertByName( "MyForm", oForm ) ' Get the form named MyForm ' oForm = oForms.getByName( "MyForm" ) ' Function FormGetForms( Optional nPage, Optional oDoc ) As Object ' If no document specified, then use this document. If IsMissing( oDoc ) Then oDoc = ThisComponent EndIf ' If no page number specified, then pass -1. If IsMissing( nPage ) Then nPage = -1 EndIf oDrawPage = GetDrawPage( nPage, oDoc ) oForms = oDrawPage.getForms() FormGetForms = oForms End Function '---------- ' Get the DrawPage of a document. ' Optional Parameters: ' nPage - The page number of a document that has multiple ' draw pages, such as Draw, Impress or Calc. ' Passing -1 is the same as omitting this argument. ' oDoc - The document model. If not supplied, then ThisComponent is used. ' It is okay to pass one of the document's controllers or frame instead. ' Function GetDrawPage( Optional nPage, Optional oDoc ) As Object ' If no document specified, then use this document. If IsMissing( oDoc ) Then oDoc = ThisComponent oDocModel = oDoc Else oDocModel = GetDocumentModel( oDoc ) EndIf ' If the document is a spreadsheet... If oDocModel.supportsService( "com.sun.star.sheet.SpreadsheetDocument" ) Then oSheet = oDocModel.getSheets().getByIndex( nPage ) oDrawPage = oSheet.getDrawPage() ElseIf oDocModel.supportsService( "com.sun.star.text.TextDocument" ) Then ' Ignore the nPage parameter for Writer documents. oDrawPage = oDocModel.getDrawPage() ' If no draw page number specified, then assume ' there is only one draw page, via. an XDrawPageSupplier interface, ' instead of multiple pages via. an XDrawPagesSupplier interface. ElseIf IsMissing( nPage ) Or (nPage = -1) Then oDrawPage = oDocModel.getDrawPage() Else oDrawPage = oDocModel.getDrawPages().getByIndex( nPage ) EndIf GetDrawPage = oDrawPage End Function '---------- ' Create a new Form, or return the existing form of the same name. ' This returns the form. ' Parameters: ' cFormName - The form's name. (Usually: "Standard") ' Optional Parameters: ' nPage - The page number of a document that has multiple ' draw pages, such as Draw, Impress or Calc. ' Passing -1 is the same as omitting this argument. ' oDoc - The document model. If not supplied, then ThisComponent is used. ' It is okay to pass one of the document's controllers or frame instead. ' Function FormCreateForm( ByVal cFormName As String, Optional nPage, Optional oDoc ) As Object ' If no document specified, then use this document. If IsMissing( oDoc ) Then oDoc = ThisComponent EndIf ' If no page number specified, then pass -1. If IsMissing( nPage ) Then nPage = -1 EndIf oForms = FormGetForms( nPage, oDoc ) If oForms.hasByName( cFormName ) Then ' Get existing form. oForm = oForms.getByname( cFormName ) Else ' Create new form. oForm = createUnoService( "com.sun.star.form.component.Form" ) oForms.insertByName( cFormName, oForm ) EndIf FormCreateForm = oForm End Function '---------- ' Create a Button control. ' This returns the control model. (Not the control.) ' Parameters: ' x, y, width, height - the control's location and size. ' cControlCaption - The name that is displayed to the user. ' cControlName - The control's name. ' cFormName - The form's name. (Usually: "Standard") ' Optional Parameters: ' nPage - The page number of a document that has multiple ' draw pages, such as Draw, Impress or Calc. ' Passing -1 is the same as omitting this argument. ' oDoc - The document model. If not supplied, then ThisComponent is used. ' It is okay to pass one of the document's controllers or frame instead. ' Function FormCreateControl_Button( _ ByVal x As Long, ByVal y As Long,_ ByVal width As Long, ByVal height As Long,_ ByVal cControlCaption As String,_ ByVal cControlName As String,_ ByVal cFormName As String,_ Optional nPage,_ Optional oDoc ) As Object ' If no document specified, then use this document. If IsMissing( oDoc ) Then oDoc = ThisComponent EndIf ' If no page number specified, then pass -1. If IsMissing( nPage ) Then nPage = -1 EndIf oControlShape = FormCreateControlShape( "com.sun.star.form.component.CommandButton",_ cControlName, cFormName, nPage, oDoc ) oControlModel = oControlShape.getControl() oControlShape.Position = MakePoint( x, y ) oControlShape.Size = MakeSize( width, height ) oControlModel.Label = cControlCaption oControlModel.Align = 0 'added by nab on 20090105 ' print oControlModel.getname ' xray oControlModel FormCreateControl_Button = oControlModel End Function '---------- ' Create a new control. ' This returns the control model. (Not the control.) ' Parameters: ' cControlServiceName ' - something like... "com.sun.star.form.component.CommandButton" ' cControlName - The control's name. ' cFormName - The form's name. (Usually: "Standard") ' Optional Parameters: ' nPage - The page number of a document that has multiple ' draw pages, such as Draw, Impress or Calc. ' Passing -1 is the same as omitting this argument. ' oDoc - The document model. If not supplied, then ThisComponent is used. ' It is okay to pass one of the document's controllers or frame instead. ' Function FormCreateControl( ByVal cControlServiceName As String,_ ByVal cControlName As String,_ ByVal cFormName As String,_ Optional nPage,_ Optional oDoc ) As Object ' If no document specified, then use this document. If IsMissing( oDoc ) Then oDoc = ThisComponent EndIf ' If no page number specified, then pass -1. If IsMissing( nPage ) Then nPage = -1 EndIf oControlShape = FormCreateControlShape( cControlServiceName,_ cControlName, cFormName, nPage, oDoc ) oControlModel = oControlShape.getControl() FormCreateControl = oControlModel End Function '---------- ' Create a new control -- return its shape. ' This is very similar to CreateControl(), but returns the control shape. ' This returns the control shape. ' Parameters: ' cControlServiceName ' - something like... "com.sun.star.form.component.CommandButton" ' cControlName - The control's name. ' cFormName - The form's name. (Usually: "Standard") ' Optional Parameters: ' nPage - The page number of a document that has multiple ' draw pages, such as Draw, Impress or Calc. ' Passing -1 is the same as omitting this argument. ' oDoc - The document model. If not supplied, then ThisComponent is used. ' It is okay to pass one of the document's controllers or frame instead. ' Function FormCreateControlShape( ByVal cControlServiceName As String,_ ByVal cControlName As String,_ ByVal cFormName As String,_ Optional nPage,_ Optional oDoc ) As Object ' If no document specified, then use this document. If IsMissing( oDoc ) Then oDoc = ThisComponent EndIf ' If no page number specified, then pass -1. If IsMissing( nPage ) Then nPage = -1 EndIf oDrawPage = GetDrawPage( nPage, oDoc ) oForms = oDrawPage.getForms() If oForms.hasByName( cFormName ) Then ' Get existing form. oForm = oForms.getByName( cFormName ) Else ' Create new form. oForm = createUnoService( "com.sun.star.form.component.Form" ) oForms.insertByName( cFormName, oForm ) EndIf ' Create the control shape for the draw page. oControlShape = MakeControlShape( oDoc, MakePoint( 1000, 2000 ), MakeSize( 4000, 1000 ) ) ' Create the control model. oControlModel = createUnoService( cControlServiceName ) ' Introduce the control model to the control shape. oControlShape.setControl( oControlModel ) ' Note that both the control model and control shape are still disembodied. ' That is, they are not contained in any hierarchy. ' Now insert the control model into the form. oForm.insertByName( cControlName, oControlModel ) ' Insert the control shape into the draw page. oDrawPage.add( oControlShape ) ' Special behavior for Writer. ' Anchor the control to a paragraph. (Default is draw page.) oDocModel = GetDocumentModel( oDoc ) If oDocModel.supportsService( "com.sun.star.text.TextDocument" ) Then oControlShape.AnchorType = com.sun.star.text.TextContentAnchorType.AT_PARAGRAPH ' oCtrlShape.AnchorType = com.sun.star.text.TextContentAnchorType.AT_PAGE EndIf FormCreateControlShape = oControlShape End Function '---------- ' Get a control model from a form of a document. ' This returns the control model. (Not the control.) ' Parameters: ' cControlName - The control's name. ' cFormName - The form's name. (Usually: "Standard") ' Optional Parameters: ' nPage - The page number of a document that has multiple ' draw pages, such as Draw, Impress or Calc. ' Passing -1 is the same as omitting this argument. ' oDoc - The document model. If not supplied, then ThisComponent is used. ' It is okay to pass one of the document's controllers or frame instead. ' Function FormGetControlModel( cControlName As String,_ ByVal cFormName As String,_ Optional nPage,_ Optional oDoc ) As Object ' If no document specified, then use this document. If IsMissing( oDoc ) Then oDoc = ThisComponent EndIf ' If no page number specified, then pass -1. If IsMissing( nPage ) Then nPage = -1 EndIf oForms = FormGetForms( nPage, oDoc ) oForm = oForms.getByName( cFormName ) oControlModel = oForm.getByName( cControlName ) FormGetControlModel = oControlModel End Function '---------- ' Get a control from a form of a document. ' This returns the control. (Not the model.) ' Parameters: ' cControlName - The control's name. ' cFormName - The form's name. (Usually: "Standard") ' Optional Parameters: ' nPage - The page number of a document that has multiple ' draw pages, such as Draw, Impress or Calc. ' Passing -1 is the same as omitting this argument. ' oDoc - The document model. If not supplied, then ThisComponent is used. ' It is okay to pass one of the document's controllers or frame instead. ' Function FormGetControl( cControlName As String,_ ByVal cFormName As String,_ Optional nPage,_ Optional oDoc ) As Object ' If no document specified, then use this document. If IsMissing( oDoc ) Then oDoc = ThisComponent EndIf ' If no page number specified, then pass -1. If IsMissing( nPage ) Then nPage = -1 EndIf oControlModel = FormGetControlModel( cControlName, cFormName, nPage, oDoc ) oDocCtrl = GetDocumentController( oDoc ) oControl = oDocCtrl.getControl( oControlModel ) FormGetControl = oControl End Function '---------- ' Search the draw page for a particular control shape. ' This returns the control shape. ' Parameters: ' cControlName - The control's name. ' cFormName - The form's name. (Usually: "Standard") ' Optional Parameters: ' nPage - The page number of a document that has multiple ' draw pages, such as Draw, Impress or Calc. ' Passing -1 is the same as omitting this argument. ' oDoc - The document model. If not supplied, then ThisComponent is used. ' It is okay to pass one of the document's controllers or frame instead. ' Function FormFindControlShape( cControlName As String,_ ByVal cFormName As String,_ Optional nPage,_ Optional oDoc ) As Object ' If no document specified, then use this document. If IsMissing( oDoc ) Then oDoc = ThisComponent EndIf ' If no page number specified, then pass -1. If IsMissing( nPage ) Then nPage = -1 EndIf oDrawPage = GetDrawPage( nPage, oDoc ) oForms = oDrawPage.getForms() oForm = oForms.getByName( cFormName ) nNumShapes = oDrawPage.getCount() For i = 0 To nNumShapes - 1 oShape = oDrawPage.getByIndex( i ) If HasUnoInterfaces( oShape, "com.sun.star.drawing.XControlShape" ) Then oControlModel = oShape.getControl() If oControlModel.getName() = cControlName Then FormFindControlShape = oShape Exit Function EndIf EndIf Next End Function Function FormGetControlValue( cControlName As String,_ ByVal cFormName As String,_ Optional nPage,_ Optional oDoc ) As Double ' If no document specified, then use this document. If IsMissing( oDoc ) Then oDoc = ThisComponent EndIf ' If no page number specified, then pass -1. If IsMissing( nPage ) Then nPage = -1 EndIf oControlModel = FormGetControlModel( cControlName, cFormName, nPage, oDoc ) nValue = oControlModel.Value FormGetControlValue = nValue End Function Sub FormSetControlValue( cControlName As String,_ ByVal nValue As Double,_ ByVal cFormName As String,_ Optional nPage,_ Optional oDoc ) ' If no document specified, then use this document. If IsMissing( oDoc ) Then oDoc = ThisComponent EndIf ' If no page number specified, then pass -1. If IsMissing( nPage ) Then nPage = -1 EndIf oControlModel = FormGetControlModel( cControlName, cFormName, nPage, oDoc ) oControlModel.Value = nValue End Sub Function FormGetControlText( cControlName As String,_ ByVal cFormName As String,_ Optional nPage,_ Optional oDoc ) As String ' If no document specified, then use this document. If IsMissing( oDoc ) Then oDoc = ThisComponent EndIf ' If no page number specified, then pass -1. If IsMissing( nPage ) Then nPage = -1 EndIf oControlModel = FormGetControlModel( cControlName, cFormName, nPage, oDoc ) cText = oControlModel.Text FormGetControlText = cText End Function Sub FormSetControlText( cControlName As String,_ ByVal cText As String,_ ByVal cFormName As String,_ Optional nPage,_ Optional oDoc ) ' If no document specified, then use this document. If IsMissing( oDoc ) Then oDoc = ThisComponent EndIf ' If no page number specified, then pass -1. If IsMissing( nPage ) Then nPage = -1 EndIf oControlModel = FormGetControlModel( cControlName, cFormName, nPage, oDoc ) oControlModel.Text = cText End Sub Function FormGetControlState( cControlName As String,_ ByVal cFormName As String,_ Optional nPage,_ Optional oDoc ) As Boolean ' If no document specified, then use this document. If IsMissing( oDoc ) Then oDoc = ThisComponent EndIf ' If no page number specified, then pass -1. If IsMissing( nPage ) Then nPage = -1 EndIf oControlModel = FormGetControlModel( cControlName, cFormName, nPage, oDoc ) bState = oControlModel.State FormGetControlState = bState End Function Sub FormSetControlState( cControlName As String,_ ByVal bState As Boolean,_ ByVal cFormName As String,_ Optional nPage,_ Optional oDoc ) ' If no document specified, then use this document. If IsMissing( oDoc ) Then oDoc = ThisComponent EndIf ' If no page number specified, then pass -1. If IsMissing( nPage ) Then nPage = -1 EndIf oControlModel = FormGetControlModel( cControlName, cFormName, nPage, oDoc ) oControlModel.State = bState End Sub Function FormGetControlEnabled( cControlName As String,_ ByVal cFormName As String,_ Optional nPage,_ Optional oDoc ) As Boolean ' If no document specified, then use this document. If IsMissing( oDoc ) Then oDoc = ThisComponent EndIf ' If no page number specified, then pass -1. If IsMissing( nPage ) Then nPage = -1 EndIf oControlModel = FormGetControlModel( cControlName, cFormName, nPage, oDoc ) bEnabled = oControlModel.Enabled FormGetControlEnabled = bEnabled End Function Sub FormSetControlEnabled( cControlName As String,_ ByVal bEnabled As Boolean,_ ByVal cFormName As String,_ Optional nPage,_ Optional oDoc ) ' If no document specified, then use this document. If IsMissing( oDoc ) Then oDoc = ThisComponent EndIf ' If no page number specified, then pass -1. If IsMissing( nPage ) Then nPage = -1 EndIf oControlModel = FormGetControlModel( cControlName, cFormName, nPage, oDoc ) oControlModel.Enabled = bEnabled End Sub ' Note that the control is visible in Form Design Mode. ' To toggle design mode do this.... ' DocumentDispatch( oDoc, ".uno:SwitchControlDesignMode" ) ' Sub FormSetControlVisible( cControlName As String,_ ByVal bVisible As Boolean,_ ByVal cFormName As String,_ Optional nPage,_ Optional oDoc ) ' If no document specified, then use this document. If IsMissing( oDoc ) Then oDoc = ThisComponent EndIf ' If no page number specified, then pass -1. If IsMissing( nPage ) Then nPage = -1 EndIf oControl = FormGetControl( cControlName, cFormName, nPage, oDoc ) oControl.setVisible( bVisible ) End Sub Sub FormGetControlPosition( cControlName As String,_ ByVal cFormName As String,_ Optional nPage,_ Optional oDoc ) As Object ' If no document specified, then use this document. If IsMissing( oDoc ) Then oDoc = ThisComponent EndIf ' If no page number specified, then pass -1. If IsMissing( nPage ) Then nPage = -1 EndIf oShape = FormFindControlShape( cControlName, cFormName, nPage, oDoc ) oPosition = oShape.Position FormGetControlPosition = oPosition End Sub Sub FormSetControlPosition( cControlName As String,_ oPosition As com.sun.star.awt.Point,_ ByVal cFormName As String,_ Optional nPage,_ Optional oDoc ) As Object ' If no document specified, then use this document. If IsMissing( oDoc ) Then oDoc = ThisComponent EndIf ' If no page number specified, then pass -1. If IsMissing( nPage ) Then nPage = -1 EndIf oShape = FormFindControlShape( cControlName, cFormName, nPage, oDoc ) oShape.Position = oPosition End Sub Sub FormGetControlSize( cControlName As String,_ ByVal cFormName As String,_ Optional nPage,_ Optional oDoc ) As Object ' If no document specified, then use this document. If IsMissing( oDoc ) Then oDoc = ThisComponent EndIf ' If no page number specified, then pass -1. If IsMissing( nPage ) Then nPage = -1 EndIf oShape = FormFindControlShape( cControlName, cFormName, nPage, oDoc ) oSize = oShape.Size FormGetControlSize = oSize End Sub Sub FormSetControlSize( cControlName As String,_ oSize As com.sun.star.awt.Size,_ ByVal cFormName As String,_ Optional nPage,_ Optional oDoc ) As Object ' If no document specified, then use this document. If IsMissing( oDoc ) Then oDoc = ThisComponent EndIf ' If no page number specified, then pass -1. If IsMissing( nPage ) Then nPage = -1 EndIf oShape = FormFindControlShape( cControlName, cFormName, nPage, oDoc ) oShape.Size = oSize End Sub '############################################################ ' API navigation convenience '############################################################ '---------- ' This will always return the document's controller. ' Pass in any one of... ' * the document's model (subclass of com.sun.star.document.OfficeDocument) ' * the document's controller ' * the document's frame Function GetDocumentController( oDoc As Object ) As Object Dim oCtrl As Object ' If the caller gave us the document model... If oDoc.supportsService( "com.sun.star.document.OfficeDocument" ) Then ' ...then get the controller from that. oCtrl = oDoc.getCurrentController() ' If the caller gave us a document controller... ElseIf HasUnoInterfaces( oDoc, "com.sun.star.frame.XController" ) Then ' ...thanks! That's just what we wanted! oCtrl = oDoc ' If the caller gave us the document frame... ElseIf HasUnoInterfaces( oDoc, "com.sun.star.frame.XFrame" ) Then oFrame = oDoc ' ...then get the controller from the frame. oCtrl = oFrame.getController() Else ' The caller did not give us what we expected! MsgBox( "GetDocController called with incorrect parameter." ) EndIf GetDocumentController() = oCtrl End Function '---------- ' This will always return the document's frame. ' Pass in any one of... ' * the document's model (subclass of com.sun.star.document.OfficeDocument) ' * the document's controller ' * the document's frame Function GetDocumentFrame( oDoc As Object ) As Object Dim oFrame As Object ' If the caller gave us the document model... If oDoc.supportsService( "com.sun.star.document.OfficeDocument" ) Then ' ...then get the controller from that. oCtrl = oDoc.getCurrentController() ' ...then get the frame from the controller. oFrame = oCtrl.getFrame() ' If the caller gave us a document controller... ElseIf HasUnoInterfaces( oDoc, "com.sun.star.frame.XController" ) Then oCtrl = oDoc ' ...then get the frame from the controller. oFrame = oCtrl.getFrame() ' If the caller gave us the document frame... ElseIf HasUnoInterfaces( oDoc, "com.sun.star.frame.XFrame" ) Then ' ...thanks! That's just what we wanted! oFrame = oDoc Else ' The caller did not give us what we expected! MsgBox( "GetDocumentFrame called with incorrect parameter." ) EndIf GetDocumentFrame() = oFrame End Function '---------- ' This will always return the document's model. ' Pass in any one of... ' * the document's model (subclass of com.sun.star.document.OfficeDocument) ' * the document's controller ' * the document's frame Function GetDocumentModel( oDoc As Object ) As Object Dim oDocModel As Object ' If the caller gave us the document model... If oDoc.supportsService( "com.sun.star.document.OfficeDocument" ) Then ' ...thanks! That's just what we wanted! oDocModel = oDoc ' If the caller gave us a document controller... ElseIf HasUnoInterfaces( oDoc, "com.sun.star.frame.XController" ) Then oCtrl = oDoc ' ...then get the model from the controller. oDocModel = oCtrl.getModel() ' If the caller gave us the document frame... ElseIf HasUnoInterfaces( oDoc, "com.sun.star.frame.XFrame" ) Then oFrame = oDoc ' ...then get the controller from the frame. oCtrl = oFrame.getController() ' ...then get the model from the controller. oDocModel = oCtrl.getModel() Else ' The caller did not give us what we expected! MsgBox( "GetDocumentModel called with incorrect parameter." ) EndIf GetDocumentModel() = oDocModel End Function 'Sub TestNavAPI() ' oDrawDoc = StarDesktop.loadComponentFromURL( "private:factory/sdraw", "_blank", 0, Array() ) ' ' oDrawPage = oDrawDoc.getDrawPages().getByIndex( 0 ) ' oShape = MakeEllipseShape( oDrawDoc, MakePoint( 10000, 10000 ), MakeSize( 5000, 5000 ) ) ' oDrawPage.add( oShape ) ' ' oDrawDocCtrl = oDrawDoc.getCurrentController() ' oDrawDocFrame = oDrawDocCtrl.getFrame() ' ' oD = oDrawDoc '' oD = oDrawDocCtrl '' oD = oDrawDocFrame ' ' DrawingSelectShapes( oD, oShape ) ' ClipboardCopy( oD ) '' ClipboardCut( oD ) ' ClipboardPaste( oD ) ' ' oShape = DrawingGetSelection( oD ).getByIndex( 0 ) ' ' oShape.Position = MakePoint( oShape.Position.X - 3000, oShape.Position.Y + 6000 ) 'End Sub '############################################################ ' Utilities to create, initialize and return common ' structs or services. '############################################################ '---------- ' Easy sugar coated way to create and initialize a new Point struct. ' Function MakePoint( ByVal x As Long, ByVal y As Long ) As com.sun.star.awt.Point oPoint = createUnoStruct( "com.sun.star.awt.Point" ) oPoint.X = x oPoint.Y = y MakePoint = oPoint End Function '---------- ' Easy sugar coated way to create and initialize a new Size struct. ' Function MakeSize( ByVal width As Long, ByVal height As Long ) As com.sun.star.awt.Size oSize = createUnoStruct( "com.sun.star.awt.Size" ) oSize.Width = width oSize.Height = height MakeSize = oSize End Function '---------- ' Create and return a new LineDash struct. ' See... ' http://api.openoffice.org/docs/common/ref/com/sun/star/drawing/LineDash.html ' Function MakeLineDash( nDashStyle As Long, nDots As Integer, nDotLen As Long,_ nDashes As Integer, nDashLen As Long, nDistance As Long ) As com.sun.star.drawing.LineDash oLineDash = createUnoStruct( "com.sun.star.drawing.LineDash" ) oLineDash.Style = nDashStyle oLineDash.Dots = nDots oLineDash.DotLen = nDotLen oLineDash.Dashes = nDashes oLineDash.DashLen = nDashLen oLineDash.Distance = nDistance MakeLineDash = oLineDash End Function '---------- ' Create and return a new GluePoint struct. ' Use a constant from com.sun.star.drawing.EscapeDirection. ' Use a constant from com.sun.star.drawing.Alignment. Function MakeGluePoint( oPosition As com.sun.star.awt.Point,_ bIsRelative As Boolean,_ nEscapeDirection As Long,_ nPositionAlignment As Long,_ bIsUserDefined As Boolean ) oGluePoint = createUnoStruct( "com.sun.star.drawing.GluePoint2" ) With oGluePoint .Position = oPosition .PositionAlignment = nPositionAlignment .IsRelative = bIsRelative .Escape = nEscapeDirection .IsUserDefined = bIsUserDefined End With MakeGluePoint = oGluePoint End Function '############################################################ ' Drawing document '############################################################ '---------- ' Pass in any GenericDrawPage object in portrait orientation, ' and this changes it to Lanscape orientation. ' Sub SetDrawPageOrientationLandscape( oDrawPage As com.sun.star.drawing.GenericDrawPage ) If oDrawPage.Orientation = com.sun.star.view.PaperOrientation.LANDSCAPE Then Exit Sub EndIf ' Save some settings nOldWidth = oDrawPage.Width nOldHeight = oDrawPage.Height nOldBorderTop = oDrawPage.BorderTop nOldBorderLeft = oDrawPage.BorderLeft nOldBorderRight = oDrawPage.BorderRight nOldBorderBottom = oDrawPage.BorderBottom ' Change so that it will PRINT in landscape oDrawPage.Orientation = com.sun.star.view.PaperOrientation.LANDSCAPE ' Now change some paper dimensions to match oDrawPage.Width = nOldHeight oDrawPage.Height = nOldWidth oDrawPage.BorderTop = nOldBorderRight oDrawPage.BorderLeft = nOldBorderTop oDrawPage.BorderRight = nOldBorderBottom oDrawPage.BorderBottom = nOldBorderLeft End Sub '---------- ' Pass in any GenericDrawPage object in portrait orientation, ' and this changes it to Lanscape orientation. ' Sub SetDrawPageOrientationPortrait( oDrawPage As com.sun.star.drawing.GenericDrawPage ) If oDrawPage.Orientation = com.sun.star.view.PaperOrientation.PORTRAIT Then Exit Sub EndIf ' Save some settings nOldWidth = oDrawPage.Width nOldHeight = oDrawPage.Height nOldBorderTop = oDrawPage.BorderTop nOldBorderLeft = oDrawPage.BorderLeft nOldBorderRight = oDrawPage.BorderRight nOldBorderBottom = oDrawPage.BorderBottom ' Change so that it will PRINT in landscape oDrawPage.Orientation = com.sun.star.view.PaperOrientation.PORTRAIT ' Now change some paper dimensions to match oDrawPage.Width = nOldHeight oDrawPage.Height = nOldWidth oDrawPage.BorderTop = nOldBorderLeft oDrawPage.BorderLeft = nOldBorderBottom oDrawPage.BorderRight = nOldBorderTop oDrawPage.BorderBottom = nOldBorderRight End Sub '############################################################ ' Misc functions '############################################################ '---------- ' Given an angle in 100's of a degree, ' adjust it to be from 0 to 360 degrees. ' Function NormalizeAngleOOo( ByVal nAngle As Long ) As Long nAngle = nAngle - (Int( Abs( nAngle ) / 36000 ) * 36000 * Sgn( nAngle )) If nAngle < 0 Then nAngle = nAngle + 36000 EndIf NormalizeAngleOOo = nAngle End Function '---------- ' Given an angle in radians, ' adjust it to be from 0 to 2*PI radians. ' Function NormalizeAngleRadians( ByVal nAngle As Double ) As Double nAngle = nAngle - (Int( Abs( nAngle ) / (2*PI) ) * (2*PI) * Sgn( nAngle )) If nAngle < 0 Then nAngle = nAngle + (2*PI) EndIf NormalizeAngleRadians = nAngle End Function '############################################################ ' Shapes '############################################################ ' The following functions are a convenient way to create Shape objects ' and initialize their size and position. ' ' An example of how you would use them would be... ' ' oShape = MakeEllipseShape( oDrawDoc, MakePoint( 1000, 1000 ), MakeSize( 5000, 3000 ) ) ' oShape.FillStyle = com.sun.star.drawing.FillStyle.SOLID ' oShape.FillColor = RGB( 255, 0, 0 ) ' oShape.LineStyle = com.sun.star.drawing.LineStyle.SOLID ' oShape.LineColor = RGB( 0, 0, 255 ) ' oShape.LineWidth = 100 '---------- ' Create and return a RectangleShape object, ' optionally with its position and size initialized. ' Function MakeRectangleShape( oDoc As Object,_ Optional oPosition As com.sun.star.awt.Point,_ Optional oSize As com.sun.star.awt.Size ) As com.sun.star.drawing.RectangleShape oShape = oDoc.createInstance( "com.sun.star.drawing.RectangleShape" ) If Not IsMissing( oPosition ) Then oShape.Position = oPosition EndIf If Not IsMissing( oSize ) Then oShape.Size = oSize EndIf MakeRectangleShape = oShape End Function '---------- ' Create and return a EllipseShape object, ' optionally with its position and size initialized. ' Function MakeEllipseShape( oDoc As Object,_ Optional position As com.sun.star.awt.Point,_ Optional size As com.sun.star.awt.Size ) As com.sun.star.drawing.EllipseShape oShape = oDoc.createInstance( "com.sun.star.drawing.EllipseShape" ) If Not IsMissing( position ) Then oShape.Position = position EndIf If Not IsMissing( size ) Then oShape.Size = size EndIf MakeEllipseShape = oShape End Function '---------- ' Create and return a TextShape object, ' optionally with its position and size initialized. ' Function MakeTextShape( oDoc As Object,_ Optional position As com.sun.star.awt.Point,_ Optional size As com.sun.star.awt.Size ) As com.sun.star.drawing.TextShape oShape = oDoc.createInstance( "com.sun.star.drawing.TextShape" ) If Not IsMissing( position ) Then oShape.Position = position EndIf If Not IsMissing( size ) Then oShape.Size = size EndIf MakeTextShape = oShape End Function '---------- ' Create and return a LineShape object, ' optionally with its position and size initialized. ' Function MakeLineShape( oDoc As Object,_ Optional position As com.sun.star.awt.Point,_ Optional size As com.sun.star.awt.Size ) As com.sun.star.drawing.LineShape oShape = oDoc.createInstance( "com.sun.star.drawing.LineShape" ) If Not IsMissing( position ) Then oShape.Position = position EndIf If Not IsMissing( size ) Then oShape.Size = size EndIf MakeLineShape = oShape End Function '---------- ' Create and return a ControlShape object, ' optionally with its position and size initialized. ' Function MakeControlShape( oDoc As Object,_ Optional position As com.sun.star.awt.Point,_ Optional size As com.sun.star.awt.Size ) As com.sun.star.drawing.ControlShape oShape = oDoc.createInstance( "com.sun.star.drawing.ControlShape" ) If Not IsMissing( position ) Then oShape.Position = position EndIf If Not IsMissing( size ) Then oShape.Size = size EndIf MakeControlShape = oShape End Function '---------- ' Create and return a GraphicObjectShape object, ' optionally with its position and size initialized. ' Function MakeGraphicObjectShape( oDoc As Object,_ Optional oPosition As com.sun.star.awt.Point,_ Optional oSize As com.sun.star.awt.Size ) As com.sun.star.drawing.GraphicObjectShape oShape = oDoc.createInstance( "com.sun.star.drawing.GraphicObjectShape" ) If Not IsMissing( oPosition ) Then oShape.Position = oPosition EndIf If Not IsMissing( oSize ) Then oShape.Size = oSize EndIf MakeGraphicObjectShape = oShape End Function '---------- ' Given an object supporting the XShapes interface, ' find and return a named shape in that collection of shapes. ' Since a drawing page supports XShapes, you can use this ' function to find a named shape within a draw page, ' or within a grouped shape, or a selection of shapes. ' Function FindShapeByName( oShapes, cShapeName As String ) nNumShapes = oShapes.getCount() For i = 0 To nNumShapes - 1 oShape = oShapes.getByIndex( i ) If oShape.getName() = cShapeName Then FindShapeByName = oShape Exit Function EndIf Next End Function '############################################################ ' Utilities to build PolyPolygons and Bezier shapes. '############################################################ ' Convenient way to build up a PolyPolygonBezierCoords structure. ' See example in test routine TestBezierShape() below. ' Call this to start a new polygon of points. Sub PolyPoly_BeginPoly( oCoords As com.sun.star.drawing.PolyPolygonBezierCoords ) aArrayOfArrayPoints = oCoords.Coordinates aArrayOfArrayFlags = oCoords.Flags Array1_AppendElement( aArrayOfArrayPoints, Array() ) Array1_AppendElement( aArrayOfArrayFlags, Array() ) oCoords.Coordinates = aArrayOfArrayPoints oCoords.Flags = aArrayOfArrayFlags End Sub ' Call this to add a point, and flag, to the currently open polygon. Sub PolyPoly_AddPoint( oCoords As com.sun.star.drawing.PolyPolygonBezierCoords,_ ByVal oNewPoint As com.sun.star.awt.Point,_ ByVal nNewFlag As Long ) aArrayOfArrayPoints = oCoords.Coordinates aArrayOfArrayFlags = oCoords.Flags nNumPolys = Array1_Size( aArrayOfArrayPoints ) aPoints = aArrayOfArrayPoints( nNumPolys - 1 ) aFlags = aArrayOfArrayFlags( nNumPolys - 1 ) Array1_AppendElement( aPoints, oNewPoint ) Array1_AppendElement( aFlags, nNewFlag ) aArrayOfArrayPoints( nNumPolys - 1 ) = aPoints aArrayOfArrayFlags( nNumPolys - 1 ) = aFlags oCoords.Coordinates = aArrayOfArrayPoints oCoords.Flags = aArrayOfArrayFlags End Sub '############################################################ ' Styles '############################################################ '---------- ' Add a new style to the style catalog if it is not already present. ' This returns the style object so that you can alter its properties. ' Function DefineGraphicsStyle( oDoc As Object, cStyleName As String, Optional cParentStyleName As String ) If IsMissing( cParentStyleName ) Then cParentStyleName = "" EndIf DefineGraphicsStyle = DefineStyle( oDoc, "graphics", cStyleName, cParentStyleName ) End Function '---------- ' Lookup and return a graphics style from the document. ' Function GetGraphicsStyle( oDoc As Object, cStyleName As String ) GetGraphicsStyle = GetStyle( oDoc, "graphics", cStyleName ) End Function '############################################################ ' Test program for DrawMod. '############################################################ Sub DrawModTest ' Make sure DannysOOoLib library of modules are loaded. BasicLibraries.LoadLibrary( "DannysOOoLib" ) ' Create a new Draw document oDoc = StarDesktop.loadComponentFromURL( "private:factory/sdraw", "_blank", 0, Array() ) ' Get the first page oDrawPage = oDoc.drawPages( 0 ) Test_ColorRectangles( oDoc, oDrawPage ) Test_ColorSpirals( oDoc, oDrawPage Test_FlowerOfArcs( oDoc, oDrawPage ) Test_DrawLines( oDoc, oDrawPage ) Test_Polygon( oDoc, oDrawPage ) TestBezierShape( oDoc, oDrawPage ) End Sub Sub Test_ColorRectangles( oDoc, oDrawPage ) ' Draw some colored rectangles oSize = MakeSize( 1000, 2000 ) For i = 0 To 15 oShape = MakeRectangleShape( oDoc, MakePoint( 1000 + (i * 1200), 1000 ), oSize ) oShape.FillColor = HSB( i / 15, 1.0, 1.0 ) oDrawPage.add( oShape ) Next End Sub Sub Test_ColorSpirals( oDoc, oDrawPage ) ' Draw some spirals nPosX = 5000 ' start position X nPosY = 7000 ' start position Y nAngle = 4500 ' 45 degrees starting angle bTurnLeft = TRUE ' first spiral turns to the left ' Draw growing spiral oSpiral1 = DrawSpiralOfArcs( oDoc, oDrawPage, nPosX, nPosY, nAngle,_ 2000, 300, bTurnLeft, 72, 1.0, 30 ) ' Draw shrinking spiral oSpiral2 = DrawSpiralOfArcs( oDoc, oDrawPage, nPosX, nPosY, nAngle,_ 2000, 2460, (Not bTurnLeft), 72, 1.0, -30 ) ' Now add some color to the first spiral. ' Each segment gets an increasing hue. nNumSegments = oSpiral1.getCount() For i = 0 To nNumSegments - 1 oShape = oSpiral1.getByIndex( i ) ' get the arc segment of the spiral oShape.LineColor = HSB( i / (nNumSegments-1), 1.0, 1.0 ) Next ' Now color the second spiral nNumSegments = oSpiral2.getCount() For i = 0 To nNumSegments - 1 oShape = oSpiral2.getByIndex( i ) ' get the arc segment of the spiral oShape.LineColor = HSB( i / (nNumSegments-1), 1.0, 1.0 ) Next End Sub Sub Test_FlowerOfArcs( oDoc, oDrawPage ) ' Draw a curvy flower nPosX = 16000 ' start position X nPosY = 8000 ' start position Y DrawFlowerOfArcs( oDoc, oDrawPage, nPosX, nPosY,_ 40, 8, 9000, 300, TRUE, 1.0, 0, 500 ) End Sub Sub Test_DrawLines(oDoc, oDrawPage ) nSegments = 16 For i = 1 to nSegments DrawLine( oDoc, oDrawPage,_ 1000, i*250+11500, 5000, (nSegments-i)*250+11500,_ RGB(255*(i/nSegments),150,255*((nSegments-i)/nSegments)), 150 ) Next nCenterX = 2500 nCenterY = 11000 nSegments = 18 For i = 1 to nSegments DrawLineAngleDegrees( oDoc, oDrawPage, nCenterX, nCenterY,_ (i / nSegments) * 360,_ 1000,_ RGB(255*(i/nSegments), 255*((nSegments-i)/nSegments), 190 ), 150 ) Next End Sub Sub Test_Polygon( oDoc, oDrawPage ) oShape = oDoc.createInstance( "com.sun.star.drawing.PolyLineShape" ) oDrawPage.add( oShape ) oCoord = Array(_ MakePoint( 1000, 1000 ),_ MakePoint( 2000, 2000 ),_ MakePoint( 3000, 1000 ),_ MakePoint( 0, 0 ),_ MakePoint( 500, 2000 ),_ MakePoint( 0, 3000 ),_ MakePoint( 1000, 2000 ),_ MakePoint( 2000, 3000 ),_ MakePoint( 3000, 2000 ) ) oShape.PolyPolygon = Array( oCoord ) oShape.LineWidth = 100 oShape.LineColor = RGB( 120, 200, 180 ) oShape.Position = MakePoint( 5500, 12000 ) End Sub Sub TestBezierShape( oDoc, oDrawPage ) ' Shorter constant names, just to make the code below easier to read. POINT_NORMAL = com.sun.star.drawing.PolygonFlags.NORMAL POINT_CONTROL = com.sun.star.drawing.PolygonFlags.CONTROL ' Create the object which holds geometry description of a poly-polygon. oCoords = createUnoStruct( "com.sun.star.drawing.PolyPolygonBezierCoords" ) ' Add one polygon (bezier polygon) PolyPoly_BeginPoly( oCoords ) PolyPoly_AddPoint( oCoords, MakePoint( 1000, 1000 ), POINT_NORMAL ) PolyPoly_AddPoint( oCoords, MakePoint( 3000, 4000 ), POINT_CONTROL ) PolyPoly_AddPoint( oCoords, MakePoint( 3000, 4000 ), POINT_CONTROL ) PolyPoly_AddPoint( oCoords, MakePoint( 5000, 1000 ), POINT_NORMAL ) ' Add another polygon (bezier polygon) PolyPoly_BeginPoly( oCoords ) PolyPoly_AddPoint( oCoords, MakePoint( 1000, 2000 ), POINT_NORMAL ) PolyPoly_AddPoint( oCoords, MakePoint( 3000, 6000 ), POINT_CONTROL ) PolyPoly_AddPoint( oCoords, MakePoint( 3000, 6000 ), POINT_CONTROL ) PolyPoly_AddPoint( oCoords, MakePoint( 5000, 2000 ), POINT_NORMAL ) ' Create the shape. oPolyPolygonBezierShape = oDoc.createInstance( "com.sun.star.drawing.ClosedBezierShape" ) ' Add it to page. oDrawPage.add( oPolyPolygonBezierShape ) ' Set its geometry. oPolyPolygonBezierShape.PolyPolygonBezier = oCoords ' Move it... oPolyPolygonBezierShape.Position = MakePoint( 11000, 12000 ) oPolyPolygonBezierShape.FillColor = HSB( 1/6, 1.0, 1.0 ) End Sub '############################################################ ' Dispatch help '############################################################ '---------- ' A super easy to use Dispatch on an office document. ' Arguments are similar to the args for the com.sun.star.frame.XDispatchHelper ' interface of com.sun.star.frame.DispatchHelper. ' What makes this so easy to use are two things: ' 1. The fact that the oDocumentFrame parameter can actually accept ' either the document model or one of its controllers. ' 2. The optional parameters. ' For an example of how simple this routine is to use, see ' routines below such as ClipboardCopy(). ' ' Parameters: ' oDocumentFrame - An office document frame. ' But wait! It could be the document controller ' or the document model. This routine will find ' the document frame from either of these. ' cURL - The dispatch URL. ' Optional: ' cTargetFrameName - Defaults to blank. ' nSearchFlags - Defaults to zero. ' aDispatchArgs - Defaults an an empty sequence. ' Sub DocumentDispatch( ByVal oDocumentFrame As Object,_ ByVal cURL As String,_ Optional cTargetFrameName,_ Optional nSearchFlags,_ Optional aDispatchArgs ) ' If they gave us the wrong parameter... If Not IsNull( oDocumentFrame ) Then If Not HasUnoInterfaces( oDocumentFrame, "com.sun.star.frame.XFrame" ) Then ' Be sure that we've got the document frame. ' Someone might have passed us the document model or one of ' its controller's. oDocumentFrame = GetDocumentFrame( oDocumentFrame ) EndIf EndIf If IsMissing( cTargetFrameName ) Then cTargetFrameName = "" EndIf If IsMissing( nSearchFlags ) Then nSearchFlags = 0 EndIf If IsMissing( aDispatchArgs ) Then aDispatchArgs = Array() EndIf oDispatchHelper = createUnoService( "com.sun.star.frame.DispatchHelper" ) oDispatchHelper.executeDispatch( oDocumentFrame, cURL, cTargetFrameName, nSearchFlags, aDispatchArgs ) End Sub '############################################################ ' Clipboard manipulation '############################################################ Sub ClipboardPaste( oDocumentFrame ) DocumentDispatch( oDocumentFrame, ".uno:Paste" ) ' DocumentDispatch( oDocumentFrame, "slot:5712" ) End Sub Sub ClipboardCopy( oDocumentFrame ) DocumentDispatch( oDocumentFrame, ".uno:Copy" ) ' DocumentDispatch( oDocumentFrame, "slot:5711" ) End Sub Sub ClipboardCut( oDocumentFrame ) DocumentDispatch( oDocumentFrame, ".uno:Cut" ) ' DocumentDispatch( oDocumentFrame, "slot:5710" ) End Sub ' Given a string of text, put that text into the clipboard. ' This works by... ' 1. Invisibly create a new Writer document ' 2. Insert text into that document. ' 3. Select All ' 4. Copy ' 5. Close the invisible writer document. ' So what ends up in the clipboard can be pasted to an external ' program as Text. But the clipboard contains additional information ' about the text, such as whatever default font and style it had in ' the temporary Writer document. ' Sub TextToClipboard( ByVal cText As String ) oDoc = StarDesktop.loadComponentFromURL( "private:factory/swriter", "_blank", 0,_ Array( MakePropertyValue( "Hidden", True ) ) ) ' Get the text of the document. oText = oDoc.getText() ' Get a cursor that can move over or to any part of the text. oCursor = oText.createTextCursor() ' Insert text and paragraph breaks into the text, at the cursor position. oText.insertString( oCursor, cText, False ) SelectAll( oDoc ) ClipboardCopy( oDoc ) oDoc.close( True ) End Sub '############################################################ ' Misc. other Dispatch utilities '############################################################ Sub SelectAll( oDocumentFrame ) DocumentDispatch( oDocumentFrame, ".uno:SelectAll" ) ' DocumentDispatch( oDocumentFrame, "slot:5723" ) End Sub Sub DrawFlipVertical( oDocumentFrame ) DocumentDispatch( oDocumentFrame, ".uno:MirrorVert" ) End Sub Sub DrawFlipHorizontal( oDocumentFrame ) DocumentDispatch( oDocumentFrame, ".uno:MirrorHorz" ) End Sub '############################################################ ' Compare operators for com.sun.star.util.DateTime '############################################################ ' Return True if oDateTime1 is equal to oDateTime2. Function DateTimeEqual( ByVal oDateTime1 As com.sun.star.util.DateTime, _ ByVal oDateTime2 As com.sun.star.util.DateTime ) As Boolean DateTimeEqual = False If oDateTime1.HundredthSeconds = oDateTime2.HundredthSeconds _ And oDateTime1.Seconds = oDateTime2.Seconds _ And oDateTime1.Minutes = oDateTime2.Minutes _ And oDateTime1.Hours = oDateTime2.Hours _ And oDateTime1.Day = oDateTime2.Day _ And oDateTime1.Month = oDateTime2.Month _ And oDateTime1.Year = oDateTime2.Year _ Then DateTimeEqual = True EndIf End Function ' Return True if oDateTime1 is greater than oDateTime2. Function DateTimeGreater( ByVal oDateTime1 As com.sun.star.util.DateTime, _ ByVal oDateTime2 As com.sun.star.util.DateTime ) As Boolean DateTimeGreater = False If oDateTime1.Year > oDateTime2.Year Then DateTimeGreater = True ElseIf oDateTime1.Year = oDateTime2.Year Then If oDateTime1.Month > oDateTime2.Month Then DateTimeGreater = True ElseIf oDateTime1.Month = oDateTime2.Month Then If oDateTime1.Day > oDateTime2.Day Then DateTimeGreater = True ElseIf oDateTime1.Day = oDateTime2.Day Then If oDateTime1.Hours > oDateTime2.Hours Then DateTimeGreater = True ElseIf oDateTime1.Hours = oDateTime2.Hours Then If oDateTime1.Minutes > oDateTime2.Minutes Then DateTimeGreater = True ElseIf oDateTime1.Minutes = oDateTime2.Minutes Then If oDateTime1.Seconds > oDateTime2.Seconds Then DateTimeGreater = True ElseIf oDateTime1.Seconds = oDateTime2.Seconds Then If oDateTime1.HundredthSeconds > oDateTime2.HundredthSeconds Then DateTimeGreater = True EndIf EndIf EndIf EndIf EndIf EndIf EndIf End Function ' Return True if oDateTime1 is less than oDateTime2. Function DateTimeLess( ByVal oDateTime1 As com.sun.star.util.DateTime, _ ByVal oDateTime2 As com.sun.star.util.DateTime ) As Boolean DateTimeLess = DateTimeGreater( oDateTime2, oDateTime1 ) End Function ' Return True if oDateTime1 is greater than or equal to oDateTime2. Function DateTimeGreaterOrEqual( ByVal oDateTime1 As com.sun.star.util.DateTime, _ ByVal oDateTime2 As com.sun.star.util.DateTime ) As Boolean DateTimeGreaterOrEqual = Not DateTimeLess( oDateTime1, oDateTime2 ) End Function ' Return True if oDateTime1 is less than or equal to oDateTime2. Function DateTimeLessOrEqual( ByVal oDateTime1 As com.sun.star.util.DateTime, _ ByVal oDateTime2 As com.sun.star.util.DateTime ) As Boolean DateTimeLessOrEqual = Not DateTimeGreater( oDateTime1, oDateTime2 ) End Function ' Return True if oDateTime1 is not equal to oDateTime2. Function DateTimeNotEqual( ByVal oDateTime1 As com.sun.star.util.DateTime, _ ByVal oDateTime2 As com.sun.star.util.DateTime ) As Boolean DateTimeNotEqual = Not DateTimeEqual( oDateTime1, oDateTime2 ) End Function