Bug 35890 - [Fonts] Font dialog should not show colour field
Summary: [Fonts] Font dialog should not show colour field
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 2.1   Edit
Hardware: PC Windows 2000
: P3 normal with 1 vote (vote)
Target Milestone: 4.2 M3   Edit
Assignee: Carolyn MacLeod CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on: 4786
Blocks: 19485
  Show dependency tree
 
Reported: 2003-03-31 16:11 EST by Nick Edgar CLA
Modified: 2011-09-22 16:16 EDT (History)
13 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nick Edgar CLA 2003-03-31 16:11:56 EST
build I200303

The font dialog used in the Fonts preference page should not show the colour 
field (or any other attributes that we do not capture in a font preference).

It should be possible to hide the colour field.  See bug 4786.
Comment 1 Nick Edgar CLA 2003-03-31 16:12:58 EST
Should also fix up any other refs to FontDialog in the SDK.
Comment 2 Tod Creasey CLA 2006-06-26 09:48:41 EDT
This was changed some time ago
Comment 3 adrian CLA 2006-06-26 09:55:55 EDT
How does one suppress now the display of the "Color" field in the FontDialog?
Comment 4 Kim Horne CLA 2008-03-26 11:33:24 EDT
I believe this was closed in error - this dialog still contains the color controls.  
Comment 5 Kim Horne CLA 2008-03-26 11:33:50 EDT
Punting to SWT for comment.
Comment 6 Carolyn MacLeod CLA 2008-03-26 15:11:25 EDT
Just FYI, the native call on win32 to do this is to not set the CF_EFFECTS bit in the CHOOSEFONT.Flags field.

Also note that if an API is added to turn off the color chooser in the dialog, then the FontDialog's setRGB and getRGB API will be ignored.

Currently, the SWT FontDialog supports color selection on both Windows and Mac OS X. GtkFontSelectionDialog does not seem to have this capability as yet.

I don't have time at the moment to determine whether the Mac Font Panel will allow turning the color selection control off.

But perhaps a better API to request would be one that asks the platform if the FontDialog supports color selection. Then if it does, the application would prefer to use the dialog for selecting the color of a font. Currently, Mac & windows would answer 'true' when asked for this feature. On platforms that answer 'false', you could resort to opening up a second dialog for the color selection.
Comment 7 Kim Horne CLA 2008-03-26 15:32:40 EDT
(In reply to comment #6)
rning the color selection control off.
> 
> But perhaps a better API to request would be one that asks the platform if the
> FontDialog supports color selection. Then if it does, the application would
> prefer to use the dialog for selecting the color of a font. Currently, Mac &
> windows would answer 'true' when asked for this feature. On platforms that
> answer 'false', you could resort to opening up a second dialog for the color
> selection.
> 

That doesn't really help the UI case.  Our issue is that we (in our themes code) do not tie fonts to colors - having them both in the same dialog is confusing because even if there's a logical connection between a font and a color there is no real connection for us.  There's no situation where we'd ever want to see the color chooser in the font dialog in our themes code.
Comment 8 Carolyn MacLeod CLA 2008-03-26 16:17:21 EDT
Ah, I see. I had a very quick look at the OS X Carbon Font Panel, and I can't see a way to turn off the color selector. There seems to be a way if you are using QD fonts (set hasColor to false in the FontSelectionQDStyle struct?) but we are using ATSU fonts.

SSQ, do you think it is possible to turn off the color selection control in the OS X Font Panel?
Comment 9 Silenio Quarti CLA 2008-03-28 10:42:49 EDT
I don't think it is possible to remove the color field from the carbon dialog. The field hasColor in FontSelectionQDStyle tells if the color in the struct is valid or not, it does not remove the color field.
Comment 10 kenneth westelinck CLA 2008-03-28 12:48:51 EDT
I do realize that platforms other than Linux (gtk) have a color selector in their font selector window. The real problem fro me is, how can we develop a cross platform RCP application where we want to be able to select a font and color.
Currently we would need to determine the platform we're running on and depending on that, add color selectors to the dialog, form or whatever we use as input. IMHO this is going to be a very ugly if-construct.
Eclipse itself is using this FontDialog to change fonts for view tabs or editors, and does not honor the color selection. In fact, the color is taken from, for example; "Active part foreground".
Comment 11 Carolyn MacLeod CLA 2008-03-28 16:37:27 EDT
Kenneth, I think I can help your use case.

Call fileDialog.open() to get your font, and then call getRGB().
Here's what happens:

- on Windows and Mac, getRGB() returns an RGB unless the user canceled the dialog (in which case it returns null)

- on GTK, getRGB() always returns null

So your cross-platform rcp app can do something like the following:

   FontDialog fontDialog = new FontDialog(shell);
   FontData fontData = fontDialog.open();
   if (fontData != null) {
      RGB rgb = fontDialog.getRGB();
      if (rgb == null) {
         ColorDialog colorDialog = new ColorDialog(shell);
         rgb = colorDialog.open();
      }
      if (rgb != null) {
         // do something with your fontData and rgb here...
      }
   }


The javadoc for getRGB() in FontDialog says:
 * Returns an RGB describing the color that was selected
 * in the dialog, or null if none is available.

Steve, please verify that this was intended to always return null on platforms that do not have color selection in the FontDialog. i.e. Kenneth can rely on this behavior in future - correct?

(Sorry, Kim - this doesn't help the UI case either).
Comment 12 Steve Northover CLA 2008-03-28 18:10:58 EDT
Yes, this is the intent.  We can talk more about it Monday.
Comment 13 Carolyn MacLeod CLA 2008-04-21 16:30:44 EDT
Please note that this must be deferred to 3.5 because the API freeze for 3.4 is past.

Summary of platform api for hiding color selector in FontDialog:

- Windows: don't set CF_EFFECTS bit in CHOOSEFONT.Flags field

- GTK: doesn't currently have color selection in GtkFontSelectionDialog

- Mac Carbon: no obvious way to hide the color field in FontPanel
    - this might prove tricky, but we may be able to reach in and disable it

- Mac Cocoa: NSFontPanel validModesForFontPanel: does not set  NSFontPanelTextColorEffectModeMask or NSFontPanelDocumentColorEffectModeMask
Comment 14 Cole Markham CLA 2009-04-07 12:39:37 EDT
Is there any plan to add support for disabling the color selector for the windows platform in an upcoming release?
Comment 15 Steven Darnell CLA 2010-12-03 13:35:47 EST
I am building an RCP application and I also would like to disable the color field in the font dialog.  Carolyn has indicated that there are straight-forward solutions for Windows, GTK, and Mac Cocoa.  Is it feasible to make the API changes in 3.7 and/or 4.1?
Comment 16 Carolyn MacLeod CLA 2011-09-22 12:03:32 EDT
Fixed: http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=4ce7925a86fe89375303d3ae22e64d3377f63c74

The new API is called setEffectsVisible(boolean) and there is a corresponding getter.
Here is the comment for the setter:

/**
 * Sets the effects selection controls in the dialog visible if the
 * argument is <code>true</code>, and invisible otherwise.
 * <p>
 * By default the effects selection controls are displayed if the
 * platform font dialog supports effects selection.
 * </p>
 *
 * @param visible whether or not the dialog will show the effects selection controls
 */

Note that if the effects controls are not visible, then getRGB() will always return null.

Windows and Mac Cocoa both support selection of "font effects" (underline, strikethrough, color... and on Mac there's also background color and some fancy shadow effects) in their font dialog. Gtk does not.
 
This new API will be in Eclipse 3.8 M3 and 4.2 M3.
Comment 17 Markus Keller CLA 2011-09-22 15:24:14 EDT
I get API Tools warnings for the missing @since 3.8 tags.
Maybe your workspace is missing an API Baseline?
Comment 18 Carolyn MacLeod CLA 2011-09-22 16:16:24 EDT
Thanks, Markus - I released the @since.
New workspace - I didn't have an api baseline set yet. Thanks for the reminder.  :)
Comment 19 Carolyn MacLeod CLA 2011-09-22 16:16:51 EDT
Fixed