7 messages in org.openoffice.fr.progRe: [prog] création et suppression de...
FromSent OnAttachments
JovialJul 12, 2004 5:11 am 
BobJul 12, 2004 5:16 am 
JovialJul 12, 2004 7:33 am 
JovialJul 12, 2004 7:36 am 
Agnès SimonetJul 12, 2004 9:58 am 
Tony GALMICHEJul 12, 2004 10:23 am 
JovialJul 12, 2004 1:00 pm 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [prog] création et suppression de controleActions...
From:Jovial (luck@free.fr)
Date:Jul 12, 2004 7:33:02 am
List:org.openoffice.fr.prog

Bon j'ai trouver du code à l'adresse suivante :

http://www.oooforum.org/forum/viewtopic.php?p=32361#32361

Pour l'instant j'ai pas réussi à m'en servir mais je le met à disposition si ça peut servir à d'autre.

'********************************************************************** ' UtilForm module ' ' Utility functions for working with document Forms. ' '********************************************************************** ' Copyright (c) 2003-2004 Danny Brewer ' d29@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-05-08-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

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