Need help creating an extension for Writer

Discussions about using 3rd party extension with OpenOffice.org
Post Reply
Osgaldor
Posts: 2
Joined: Wed Jun 01, 2022 4:52 pm

Need help creating an extension for Writer

Post by Osgaldor »

I want to create an extension in OpenOffice Basic for writer. It needs a dialog box to collect a numeric value from the user (I think I'm okay with that process) and I'd like to create a little panel to output a text message either in the toolbar section at the top or in the little bar at the bottom of the window. I can't seem to find the documentation for how to create such a small panel in the window interface. Can anyone point me in the direction of the information I'm looking for? I'd kind of like to put my extension's output in the little block at the bottom left of the window where it keeps up with the page numbers. I want to be able to change to color of the text in the output panel.

I'm a fairly experienced developer in Visual Basic, Java, Python and several others. I'm building my extension in Basic.

My extension will as the user to enter a target number of words, like for a writing goal for the day and it will keep track of the word count as they write and notify the user when they have reachedtheir desired number of words.
JeJe
Volunteer
Posts: 2785
Joined: Wed Mar 09, 2016 2:40 pm

Re: Need help creating an extension for writer

Post by JeJe »

You want to add an item to the status bar?

There's the proper statusbar controller method that I don't understand and you might not be able to do it with Basic anyway

https://wiki.openoffice.org/wiki/Framew ... Controller

Or you can use the following and investigate with MRI how to add an item and set it.

Code: Select all

els = thiscomponent.currentcontroller.frame.layoutmanager.elements
for i = 0 to ubound(els)
if right(els(i).resourceurl,9)= "statusbar" then
statussettings = els(i).getsettings(true)
mri statussettings
exit for
end if
next
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Osgaldor
Posts: 2
Joined: Wed Jun 01, 2022 4:52 pm

Re: Need help creating an extension for writer

Post by Osgaldor »

I guess I should really begin by asking how to access the current word count property since my entire extension depends on it. I'd like to keep the current word count stored in a variable called currentWordCount that I can use to compare to a wordGoal variable. Is word count a property of the Document object?
openOffice 4.1.1 Windows 10
JeJe
Volunteer
Posts: 2785
Joined: Wed Mar 09, 2016 2:40 pm

Re: Need help creating an extension for writer

Post by JeJe »

Code: Select all

thiscomponent.wordcount
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
RoryOF
Moderator
Posts: 34618
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Need help creating an extension for writer

Post by RoryOF »

In some versions of Dmitri Popov's "Writers Tools" there is a Visual Word Count; the code for that may be of help to you.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
User avatar
Zizi64
Volunteer
Posts: 11362
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Need help creating an extension for writer

Post by Zizi64 »

My extension will as the user to enter a target number of words, like for a writing goal for the day and it will keep track of the word count as they write and notify the user when they have reachedtheir desired number of words.
The LibreOffice has such feature by default.
Visible Word count feature exists in the LibreOffiice.png
Visible Word count feature exists in the LibreOffiice.png (4.58 KiB) Viewed 4815 times
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Bidouille
Volunteer
Posts: 577
Joined: Mon Nov 19, 2007 10:58 am
Location: France

Re: Need help creating an extension for Writer

Post by Bidouille »

Osgaldor wrote: Wed Jun 01, 2022 5:11 pm My extension will as the user to enter a target number of words, like for a writing goal for the day and it will keep track of the word count as they write and notify the user when they have reachedtheir desired number of words.
This extension already exists: https://extensions.openoffice.org/en/pr ... controller
Don't reinvent the wheel! :)


.
User avatar
anwar4870
Banned
Posts: 3
Joined: Wed Mar 08, 2023 5:00 pm

Re: Need help creating an extension for Writer

Post by anwar4870 »

To create a small panel in the OpenOffice window interface, you will need to use the OpenOffice API (Application Programming Interface). Here are the basic steps you need to follow:

Create a new dialog box: You mentioned that you are okay with creating a dialog box to collect a numeric value from the user. You can use the OpenOffice Basic "DialogLib" library to create a dialog box. You can find more information about this library in the OpenOffice Basic Guide.

Create a panel: To create a small panel in the OpenOffice window interface, you will need to use the "

Code: Select all

com.sun.star.awt.UnoControlFixedText
" control. This control allows you to display text in a fixed area on the window interface. You can use the following code to create a panel:

Code: Select all

Dim oPanel As Object
oPanel = CreateUnoControl("com.sun.star.awt.UnoControlFixedText")
oPanel.Model.PositionX = 10 ' Set the X position of the panel
oPanel.Model.PositionY = 10 ' Set the Y position of the panel
oPanel.Model.Width = 100 ' Set the width of the panel
oPanel.Model.Height = 20 ' Set the height of the panel
oPanel.Model.MultiLine = True ' Allow the text to wrap to multiple lines
oPanel.Model.BackgroundColor = RGB(255, 255, 255) ' Set the background color of the panel
Add the panel to the window: To add the panel to the window, you will need to use the "com.sun.star.frame.XStatusListener" interface. This interface allows you to add a custom status bar item to the OpenOffice window. You can use the following code to add the panel to the window:

Code: Select all

Dim oWindow As Object
oWindow = ThisComponent.CurrentController.Frame.ContainerWindow
Dim oStatusBar As Object
oStatusBar = oWindow.StatusBar
Dim oStatusListener As Object
oStatusListener = CreateUnoListener("MyStatusListener_", "com.sun.star.frame.XStatusListener")
oStatusBar.addStatusListener(oStatusListener)
Update the panel text: To update the text displayed in the panel, you will need to use the "Text" property of the control. You can use the following code to update the panel text:

Code: Select all

oPanel.Model.Text = "Your message here"
Change the text color: To change the color of the text in the panel, you will need to use the "TextColor" property of the control. You can use the following code to change the text color:

Code: Select all

oPanel.Model.TextColor = RGB(255, 0, 0) ' Set the text color to red
I hope this helps you create the small panel you need for your OpenOffice Basic extension!

Regards
Anwar
CEO
MobilesinBD
OpenOffice 4.1.10
64-bit
JeJe
Volunteer
Posts: 2785
Joined: Wed Mar 09, 2016 2:40 pm

Re: Need help creating an extension for Writer

Post by JeJe »

anwar4870 - your code is missing the CreateUnoControl function. Its better for people if you put it all together, ideally between one set of code tags in your post, rather than several and with a test sub to run it all so it can be easily tested.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Post Reply