Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there any way to quickly edit a color in OpenOffice?

I know colors can be changed in Tools -> Colors -> OpenOffice.org -> Colors, but I'd like to change the colors in a more instant way. I'm trying to create a presentation in Impress and I often need to quickly test some non-standard colors (to fine-tune the font color compared to the background). At this time I need to go to the aforementioned dialog, alter the RGB values, click "Change", click OK, and manually reselect that color from the Font Color dialog. The color doesn't get refreshed automatically after committing the changes.

Anyone knows how to change colors (font colors, background colors) on the fly and/or to make the change of a particular palette color apply instantly?

share|improve this question
    
First, might want to go ahead and upgrade to OO 3.2 (if possible) in case things have changed. –  Brian Knoblauch Feb 15 '10 at 18:00
    
@Neo: I have updated the answer. In step 5 there was something missing due to a formatting error. –  Peter Mortensen Mar 1 '10 at 22:01

1 Answer 1

up vote 1 down vote accepted
+150

It is possible using macros. The following is a solution where macros are attached to a new user-defined toolbar. The items in the toolbar can be used to incrementally change the values of red, green and blue for the font colour.

It would also be possible to type in values by using InputBox in the macros instead of incrementally change the values.


Installation instructions follows. It is advisable to follow them strictly as the way to define/work with macros in OpenOffice is not very intuitive.

  1. Start Impress. Create an empty presentation or open some existing presentation.

  2. Copy the code at the end of this answer to the clipboard. Create a macro for increasing the value of Red by 20: menu Tools/Macros/Organise Macros/OpenOffice.org Basic/. Then expand to "My Macros/Standard/" so that "Standard" is selected. Press button "New".

  3. Right click on the tab in the lower left and select "Rename" and type "RedUp". Click in the edit area (to set the focus there), select all (Ctrl + A) and paste in the code. Change the line with changeValue(0, 0, 0) to changeValue(20, 0, 0). This is for increasing the value of Red by 20.

    Right click on the tab in the lower left and select: Insert/BASIC Module.

  4. Repeat step 3 five times so that there are 6 modules in all:

    Module name    changeValue line
    ----------------------------------------------
    RedUp          changeValue(  20,   0,   0)
    RedDown        changeValue( -20,   0,   0)
    GreenUp        changeValue(   0,  20,   0)
    GreenDown      changeValue(   0, -20,   0)
    BlueUp         changeValue(   0,   0,  20)
    BlueDown       changeValue(   0,   0, -20)
    
  5. Create new toolbar: menu Tools/Customise/tab Toolbars/press button New/<name it "Colour Toolbar">/OK

  6. Then Add/OpenOffice.org Macros/My Macros/Standard/RedUp/<select "Main">/Add/Close/Modify/Rename/Red Up/OK. (Note: if "Main" is not selected then a script error will happen later because "changeValue" is selected by default.)

  7. Repeat for the 5 others. Rearrange the order of the items in the toolbar so the same order is maintained as in the table above.

  8. Finally press OK to close the dialog.

Now the foreground colour of the selected text can be changed and the result be seen almost immediately! (the selection must be cleared as it inverts the colour.)

If you want to apply the current colour to some other text then add a 7th item to the toolbar where the changeValue line is: changeValue(0, 0, 0). Or alternatively press an Up and a Down for a colour (that is not too close to 0 or 255.)

The current colour is also remembered across program restarts as the RGB value is stored in a settings file. A sample path to the settings file is:

C:\Documents and Settings\peterm\Application Data\OpenOffice.org\3\user\prefs\settings.ini

If something goes wrong then settings.ini can just be deleted. It will be recreated the next time this feature is used.

I have tested it with OpenOffice 3.2.0, en-GB, but I expect it to work with OpenOffice 3.1.


The code (the line with changeValue(0, 0, 0) needs to be changed):

REM  *****  OOoBasic.    <http://en.wikipedia.org/wiki/StarOffice_Basic>  *****

Global RedDecimal as Long
Global BlueDecimal as Long
Global GreenDecimal as Long

Sub Main
    rem Default values if settings have not been stored yet.
    RedDecimal = 210
    GreenDecimal = 100
    BlueDecimal = 40

    changeValue(0, 0, 0)
End Sub


sub changeValue(aRedChange, aGreenChange, aBlueChange)
    ReadSettings

    RedDecimal = newChannelValue(RedDecimal, aRedChange)
    GreenDecimal = newChannelValue(GreenDecimal, aGreenChange)
    BlueDecimal = newChannelValue(BlueDecimal, aBlueChange)

    WriteSettings

    dim document as object
    document   = ThisComponent.CurrentController.Frame

    dim dispatcher as object
    dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

    rem Set font (foreground) colour. Note that lines for background colour
    rem are outcommented - it does not work in Impress, but it does work
    rem in Calc.
    dim args3(0) as new com.sun.star.beans.PropertyValue

    rem args3(0).Name = "BackgroundColor"
    args3(0).Name = "Color"

    args3(0).Value = RedDecimal * 256 * 256 + GreenDecimal * 256 + BlueDecimal

    rem dispatcher.executeDispatch(document, ".uno:BackgroundColor", "", 0, args3())
    dispatcher.executeDispatch(document, ".uno:Color", "", 0, args3())
End Sub


rem *************************************************************************
Function newChannelValue(aStartValue as Long, aChange as Long) as Long
    Dim toReturn as Long
    toReturn = aStartValue + aChange
    If toReturn > 255 Then
        toReturn = 255
    End If
    If toReturn < 0 Then
        toReturn = 0
    End If
    newChannelValue = toReturn
End Function


rem *************************************************************************
Sub WriteSettings
    SubstService = CreateUnoService("com.sun.star.util.PathSubstitution")
    UserPath = SubstService.substituteVariables("$(user)", true)
    PrefFile = UserPath + "/prefs/settings.ini"

    f1 = FreeFile()
    Open PrefFile for output as #f1
    Print #f1, RedDecimal
    Print #f1, GreenDecimal
    Print #f1, BlueDecimal
    Close #f1
End Sub


rem *************************************************************************
Sub ReadSettings
    SubstService = CreateUnoService("com.sun.star.util.PathSubstitution")
    UserPath = SubstService.substituteVariables("$(user)", true)
    PrefFile = UserPath + "/prefs/settings.ini"

    If FileExists(PrefFile) Then
        f1 = FreeFile()
        Open PrefFile for Input as #f1

        dim redStr as String
        dim greenStr as String
        dim blueStr as String

        Line Input #f1, redStr
        Line Input #f1, greenStr
        Line Input #f1, blueStr
        Close #f1

        RedDecimal = CInt(redStr)
        GreenDecimal = CInt(greenStr)
        BlueDecimal = CInt(blueStr)
    Else
        WriteSettings
    End If
End Sub
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.