Issue 123516 - Undocumented and cumbersome css.ui.dialogs.ColorPicker
Summary: Undocumented and cumbersome css.ui.dialogs.ColorPicker
Status: ACCEPTED
Alias: None
Product: App Dev
Classification: Unclassified
Component: api (show other issues)
Version: 3.4.0
Hardware: All All
: P3 Normal
Target Milestone: ---
Assignee: AOO issues mailing list
QA Contact:
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-10-22 11:06 UTC by Ariel Constenla-Haile
Modified: 2017-05-20 10:44 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Latest Confirmation in: 4.0.1
Developer Difficulty: ---


Attachments
ColorPicker service draft (2.01 KB, text/x-idl)
2013-10-24 05:06 UTC, Ariel Constenla-Haile
no flags Details
XColorPicker interface draft (1.66 KB, text/x-idl)
2013-10-24 05:06 UTC, Ariel Constenla-Haile
no flags Details
Sample AOO Basic code (1.18 KB, text/plain)
2013-10-24 05:09 UTC, Ariel Constenla-Haile
no flags Details
ColorPicker service, second draft (1.95 KB, text/x-idl)
2013-12-10 14:43 UTC, Ariel Constenla-Haile
no flags Details
XColorPicker interface, second draft (2.94 KB, text/x-idl)
2013-12-10 14:43 UTC, Ariel Constenla-Haile
no flags Details

Note You need to log in before you can comment on or make changes to this issue.
Description Ariel Constenla-Haile 2013-10-22 11:06:02 UTC
Since 3.4.0 there is a color picker that can be "used" from the API, but it is undocumented and cumbersome, as the following OO Basic code shows:

REM  *****  BASIC  *****

Option Explicit

Sub Main
Dim oParent as Object
Dim oDialog as Object

oParent = ThisComponent.getCurrentController().getFrame().getContainerWindow()
oDialog = CreateUnoService("com.sun.star.ui.dialogs.ColorPicker")

'the dialog must be initialized with the Parent window
oDialog.initialize(Array(oParent))

'the dialog implements css.beans.XPropertyAccess
Dim aProps(1) as new com.sun.star.beans.PropertyValue

' the original selected color
aProps(0).Name = "Color"
aProps(0).Value = RGB(255,0,0)

' the "mode" is an implementation detail!
' 2 = show control with previous color
aProps(1).Name = "Mode"
aProps(1).Value = 2

oDialog.setPropertyValues(aProps)

'this is broken
oDialog.setTitle("Color Picker API Demo")

If oDialog.execute() = com.sun.star.ui.dialogs.ExecutableDialogResults.OK Then
	' retrieving the selected color is cumbersome
	Dim nSelectedColor as Long
	Dim aPropVals()
	aPropVals = oDialog.getPropertyValues()
	Dim n as Long
	For n = 0 To UBound(aPropVals)
		If aPropVals(n).Name = "Color" Then
			nSelectedColor = aPropVals(n).Value
			Exit For
		End If
	Next
	MsgBox "Selected color:  RGB( " & _
		CStr(Red(nSelectedColor)) & ", " & _
		CStr(Green(nSelectedColor)) & ", " & _
		CStr(Blue(nSelectedColor)) & " )"
End If
End Sub
Comment 1 Ariel Constenla-Haile 2013-10-24 05:06:14 UTC
Created attachment 81806 [details]
ColorPicker service draft
Comment 2 Ariel Constenla-Haile 2013-10-24 05:06:48 UTC
Created attachment 81807 [details]
XColorPicker interface draft
Comment 3 Ariel Constenla-Haile 2013-10-24 05:09:11 UTC
Created attachment 81808 [details]
Sample AOO Basic code
Comment 4 oooforum (fr) 2013-12-09 08:48:17 UTC
Maybe it would be nice to add this in API documentation:
http://www.openoffice.org/api/docs/common/ref/com/sun/star/ui/dialogs/module-ix.html
Comment 5 Ariel Constenla-Haile 2013-12-10 14:40:55 UTC
(In reply to oooforum from comment #4)
> Maybe it would be nice to add this in API documentation:
> http://www.openoffice.org/api/docs/common/ref/com/sun/star/ui/dialogs/module-
> ix.html

I've changed a bit the IDL, because it was exposing some internal implementation details (namely, the preview control displaying the original color).
Comment 6 Ariel Constenla-Haile 2013-12-10 14:43:10 UTC
Created attachment 82073 [details]
ColorPicker service, second draft
Comment 7 Ariel Constenla-Haile 2013-12-10 14:43:52 UTC
Created attachment 82074 [details]
XColorPicker interface, second draft
Comment 8 Ariel Constenla-Haile 2013-12-10 14:54:11 UTC
The second draft hides the dialog's implementation details by using two interfaces:

css::ui::dialogs::XControlInformation;
css::ui::dialogs::XControlAccess;

Showing a color picker, displaying the original color, can be done with the following Basic code:

Sub ColorPicker_PreviousColor
Dim oWin as Object
oWin = ThisComponent.getCurrentController().getFrame().getContainerWindow()

Dim oDlg
oDlg = com.sun.star.ui.dialogs.ColorPicker.create(oWin, RGB(255,0,0))

oDlg.setTitle("Color Picker Demo")
oDlg.setControlProperty("PreviousColor","Visible",True)
	
Dim nResult%
nResult = oDlg.execute()
If nResult = com.sun.star.ui.dialogs.ExecutableDialogResults.OK Then
	Dim nColor as Long
	nColor = oDlg.SelectedColor
	MsgBox "Selected color:  RGB(" & _
		CStr(Red(nColor)) & "," & _
		CStr(Green(nColor)) & "," & _
		CStr(Blue(nColor)) & ")"
End If
End Sub

Instead of using strings ("PreviousColor","Visible"), it would be better to use constants, like the FilePicker does (XFilePickerControlAccess with CommonFilePickerElementIds, ExtendedFilePickerElementIds). But for now the color picker only exposes one control (original color preview) with one property (visible).
Comment 9 Marcus 2017-05-20 10:44:53 UTC
Reset the assignee to the default "issues@openoffice.apache.org".