Jens Ansorg wrote:
Hi all,
Using m92
I have set up a database that connects to a table in mysql.
I have created a form in that database that allows me to edit records.
I'd like to extend this form a little:
I'd like to add a button that executes a function/macro that
- gets the currently selected text in a multi-line textbox
- asks me (input dialog) for a string, i.e "foo.jpg"
- adds some generated text around the selected text in the textbox, i.e. [img=foo.jpg]selected_text[/img]
is this possible with scripting in OOo?
Which language would I need?
I played around with Basic and I got so far that I get some information about the form (like what database, what query etc) but found no way to access the form fields and modify the content
any ideas?
thanks Jens Ansorg
A "Form" in a database document is really a Write document.
Forms and controls are contained in the draw page. Your first step, therefore, is to obtain the draw page.
Sub Main Dim oForms
oForms = ThisComponent.getDrawPage().getForms() MsgBox FormsHeirarchy(oForms, "") End Sub
Function FormsHeirarchy(oForms, sLead$) As String Dim s$ Dim i% Dim oForm Dim x
GlobalScope.BasicLibraries.LoadLibrary("Tools")
For i = 0 to oForms.getCount()-1
oForm = oForms.getByIndex(i)
s = s & sLead & FormHeirarchy(oForm, sLead)
Next
FormsHeirarchy = s
End Function
Function FormHeirarchy(oForm, sLead$) As String Dim s$ Dim i% Dim x
s = s & sLead & "+" & _
GetFileNameExtension(oForm.getImplementationName()) & _
":" & oForm.getName() & CHR$(10)
For i = 0 to oForm.getCount()-1
x = oForm.getByIndex(i)
If x.supportsService("com.sun.star.form.component.Form") Then
s = s & FormHeirarchy(x, sLead & "+")
Else
s = s & sLead & "++" & _
GetFileNameExtension(x.getImplementationName()) & _
":" & x.getName() & CHR$(10)
End If
Next
FormHeirarchy = s
End FunctionNow, you can see how things are embedded. Each form and forms object should support getByName(), so if you know the name and the name of each parent item, you should be able to get what you want. For example.
Function getFromForm(oDoc, sNames())
Dim x
Dim i%
x = oDoc.getDrawPage().getForms()
For i = LBound(sNames()) To UBound(sNames())
If x.hasByName(sNames(i)) Then
x = x.getByName(sNames(i))
Else
Print "Warning, object named " & sNames(i) & " does not exist"
Exit Function
End If
Next
getFromForm = x
End FunctionThe following code works for me... I have a form called Standard, which contains a form called Catalog, which contains a form called Country, which contains a control called "TextBox_Country". The second example, returns the Dealer form, which is contained in the Standard form.
Sub Main
Dim x
x = getFromForm(ThisComponent, _
Array("Standard", "Catalog", "Country", "TextBox_Country"))
x = getFromForm(ThisComponent, Array("Standard", "Dealer"))
End SubFinally, I noticed that you cross posted to the users, dev, and dba mailing lists. Wow, that is a lot of mailing lists. Of course, I might not see your answer if you do not reply to the correct one. Hmmmm....
-- Andrew Pitonyak My Macro Document: http://www.pitonyak.org/AndrewMacro.sxw My Macro Book: http://www.hentzenwerke.com/catalog/oome.htm Free Info: http://www.pitonyak.org/oo.php
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
