Jump to content
Mark-

TStyleManager.ActiveStyle...

Recommended Posts

Hello,

 

I provide the user a menu to select a desired style for the application. I have tested most styles and have trouble with only one, named “Windows”.

 

As an example:

 

Ruby Graphite

image.thumb.png.d06519827deadeaf8a7aee721bd0bbd3.png

 

Windows

image.thumb.png.108fc17785c73f028ab219fb3ad47138.png

 

The window color for the text is wrong.

 

Here is the code to fetch the background color and font color:

procedure TDrawingSurface2.GetStyleColors(out bgColor, fColor: TColor);
var
 actStyle:TCustomStyleServices;
begin
 actStyle:=TStyleManager.ActiveStyle;
 if Assigned(actStyle) and actStyle.Enabled then
  begin
   bgColor:=actStyle.GetStyleColor(scWindow);
   fColor:=actStyle.GetStyleFontColor(sfWindowTextNormal);
  end
 else
  begin
   bgColor:=clWindow;
   fColor:=clWindowText;
  end;
end;

The else is never triggered.

I can check for the style name “Windows” and return:

bgColor:=clWindow;
fColor:=clWindowText;

and the dialog is correct.

image.thumb.png.78c9818bb43194f00c90e30835c30151.png

 

Any ideas?

 

Thanks,

 

Mark

 

Edited by Mark-

Share this post


Link to post

TStyleManager.ActiveStyle will never return nil.  If there is no style assigned then it returns the TStyleManager.SystemStyle (the Vcl.Themes.TUxThemeStyle class).

 

TUxThemeStyle.Enabled returns True if the Win32 uxtheme.dll is successfully loaded and your app is manifested for ComCtrl32 v6.  So, this is likely why your 'else' is never triggered.

 

TUxThemeStyle.DoGetStyleColor(scWindow) returns clBtnFace, not clWindow as you are expecting.  The style colors which return clWindow are:

  • scComboBox
  • scComboBoxDisabled
  • scEdit
  • scEditDisabled
  • scGrid
  • scListBox
  • scListBoxDisabled
  • scListView
  • scTreeView

 

TUxThemeStyle.DoGetStyleFontColor(sfWindowTextNormal) does return clWindowText, as expected. 

 

In any case, is your Label not simply set to Transparent=True or ParentColor=True?

Edited by Remy Lebeau
  • Like 1

Share this post


Link to post

Thanks for the response Remy.

 

OK I can trim down the code.

The text is drawn on a TCustomPanel. I am creating the dialog to replace MessageDlg. Styling is the last test.

 

What confuses me is TUxThemeStyle.DoGetStyleColor(scWindow) works for all styles I tested, 10 or so, except one, "Windows".

So, I will test with using another selector.

 

I tested all the selectors, above, with Ruby Graphite and all returned the wrong color:

image.png.e4b1260d0ffddd6beeda1bf5b01b7825.png

 

Interesting...

Edited by Mark-

Share this post


Link to post

I may be misunderstanding the issue, but I use (Style).IsSystemStyle to check for the "Windows" style.

Share this post


Link to post
7 minutes ago, MarkShark said:

I may be misunderstanding the issue, but I use (Style).IsSystemStyle to check for the "Windows" style.

Thanks for the response.

 

The issue is:

bgColor:=actStyle.GetStyleColor(scWindow);

returns the correct color for all  styles I tested, 10 or so, except one, "Windows".

Edited by Mark-

Share this post


Link to post
36 minutes ago, Mark- said:

returns the correct color for all  styles I tested, 10 or so, except one, "Windows".

That depends on the definition of correct.

  • Like 1

Share this post


Link to post
7 minutes ago, Uwe Raabe said:

That depends on the definition of correct.

See the examples above.

Correct as in the color returned is the same, or not, as the color of the window.

Share this post


Link to post
45 minutes ago, Mark- said:

Correct as in the color returned is the same, or not, as the color of the window.

See here: 

13 hours ago, Remy Lebeau said:

TUxThemeStyle.DoGetStyleColor(scWindow) returns clBtnFace, not clWindow as you are expecting.

Update: You can see what colors are returned here:

function TUxThemeStyle.DoGetStyleColor(Color: TStyleColor): TColor;
begin
  case Color of
    scBorder: Result := clWindowFrame;
    scButtonDisabled: Result := clBtnFace;
    scButtonFocused: Result := clBtnFace;
    scButtonHot: Result := clBtnFace;
    scButtonNormal: Result := clBtnFace;
    scButtonPressed: Result := clBtnFace;
    scCategoryButtons: Result := clBtnFace;
    scCategoryButtonsGradientBase: Result := $C0C0C0;
    scCategoryButtonsGradientEnd: Result := $F0F0F0;
    scCategoryPanelGroup: Result := clMedGray;
    scComboBox: Result := clWindow;
    scComboBoxDisabled: Result := clWindow;
    scEdit: Result := clWindow;
    scEditDisabled: Result := clWindow;
    scGrid: Result := clWindow;
    scGenericBackground: Result := clBtnFace;
    scGenericGradientEnd: Result := $C0C0C0;
    scGenericGradientBase: Result := $F0F0F0;
    scHintGradientBase: Result := clInfoBk;
    scHintGradientEnd: Result := clInfoBk;
    scListBox: Result := clWindow;
    scListBoxDisabled: Result := clWindow;
    scListView: Result := clWindow;
    scPanel: Result := clBtnFace;
    scPanelDisabled: Result := clBtnFace;
    scSplitter: Result := clWhite;
    scToolBarGradientBase: Result := $C0C0C0;
    scToolBarGradientEnd: Result := $F0F0F0;
    scTreeView: Result := clWindow;
    scWindow: Result := clBtnFace;
  else
    Result := clNone;
  end;
end;

 

Edited by Uwe Raabe
add reference code
  • Confused 1

Share this post


Link to post
1 hour ago, Mark- said:

The issue is:


bgColor:=actStyle.GetStyleColor(scWindow);

returns the correct color for all  styles I tested, 10 or so, except one, "Windows".

Feel free to file a bug report.

Share this post


Link to post
42 minutes ago, Uwe Raabe said:

TUxThemeStyle.DoGetStyleColor(scWindow) returns clBtnFace, not clWindow as you are expecting.

You mean what all the other styles return, I guess I am confused.

Perhaps I am all wet, 10 are correct, one is incorrect; the 1 seems to be the issue.

 

Share this post


Link to post

What type of control is the Parent of the label (TForm, TPanel,...)?

Share this post


Link to post
6 minutes ago, Uwe Raabe said:

What type of control is the Parent of the label (TForm, TPanel,...)?

The text is drawn on a TCustomPanel.

The custom panel is on the form (TForm).

 

Share this post


Link to post
3 hours ago, Mark- said:

The text is drawn on a TCustomPanel.

The custom panel is on the form (TForm).

Did you try ParentBackground=True on the Panel? Then you would set only the Form's color and the Panel would pick up the same color.

Share this post


Link to post

A TCustomPanel is not filled with a color, but with part of the style bitmap (defined in the GroupBox.Frame object). In a lot of cases this may be similar to a solid color, but it can as well be some texture or even a transparent area for some styles like Amakrits. You might really get the best results with setting the labels Transparent property to True.

Share this post


Link to post
2 hours ago, Remy Lebeau said:

Did you try ParentBackground=True on the Panel? Then you would set only the Form's color and the Panel would pick up the same color.

Yes.  ParentBackground state made no difference.

 

image.png.91dc047dfc69d5c3b175fb0d6ec866f5.png

 

The form color is set to clWindow.

 

Edited by Mark-

Share this post


Link to post
3 hours ago, Uwe Raabe said:

A TCustomPanel is not filled with a color, but with part of the style bitmap (defined in the GroupBox.Frame object). In a lot of cases this may be similar to a solid color, but it can as well be some texture or even a transparent area for some styles like Amakrits. You might really get the best results with setting the labels Transparent property to True.

I "FillRect" the canvas of the panel, with the color returned by the style manager.

 

There is not a label. I DrawText the text on the canvas.

 

Amakrits style works.

 

image.png.da4530bbac7833a0a60215a71dda0cf6.png

Edited by Mark-

Share this post


Link to post
3 hours ago, Mark- said:

I "FillRect" the canvas of the panel, with the color returned by the style manager.

 

There is not a label. I DrawText the text on the canvas.

Why not use a transparent Label? Otherwise, maybe just get rid of the Panel altogether and draw the text directly on the Form itself using a transparent draw.

  • Like 1

Share this post


Link to post
14 minutes ago, Remy Lebeau said:

Why not use a transparent Label? Otherwise, maybe just get rid of the Panel altogether and draw the text directly on the Form itself using a transparent draw.

Like MessageDlg the dialog (MessageDlg2) resizes based buttons, button captions, based on OS language, font size, etc., and it was cleaner to use a panel. TLabel, at least, had other issues to overcome.

 

Drawing on the form, I had not thought of that solution. Good idea. I had the framework for a custom panel, from another form, so I grabbed it.

 

For now, because the only issue is the "Windows" style, window color, I check for it when fetching the window and font color,

 

Down the road I might look at drawing on the form. It is an interesting, and perhaps a cleaner, solution.

 

Thanks for your help Remy.

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×