DarkMode

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

DarkMode

Post by jeffp »

How can I turn on Dark Mode in code. I finally have this option in my application. I now want to turn on Dark Mode in the Editor SDK to make my program.

Thanks.
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: DarkMode

Post by zarkogajic »

Hi Jeff,

This (?):

image.png

Have you tried playing with:

image(1).png

So:

IXV_Inst.Settings['CustomUI.Theme'] := 'Dark Gray';
Inst.FireAppPrefsChanged(PXV_AppPrefsChange_CustomUI, nil);


-žarko
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: DarkMode

Post by jeffp »

Perfect. Thanks
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: DarkMode

Post by jeffp »

Also, is there a place I can get a comprehensive list of all Settings, like CustomUI.Theme.
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: DarkMode

Post by zarkogajic »

Hi Jeff,

https://github.com/tracker-software/CABNodeExplorer/releases

-žarko
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17820
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

DarkMode

Post by Tracker Supp-Stefan »

:)
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: DarkMode

Post by jeffp »

Another general Dark Mode issue has come up in my application.

As a bit of background, I am embedding your ActiveX Editor SDK into my Delphi Application or exe.

So here's the new issue.

When I open my Delphi Application, I click on a certain tab which displays your embedded Editor in my program. When the Editor initially displays I load a settings file and then what you see are the Editor Toolbars, etc. At this point I can open a file and work with the editor.

Then while the Editor is in this state, I choose an option in my Delphi application that changes the Theme of my entire program to Dark Mode. Whether or not I subsequently change your Dark Mode setting, the Editor looses all it's toolbars and seems to go into a sort of shell looking or blank state. Again, this is a result of the Delphi application changing Themes. Since your Editor is embedded in my application, the theme change seems to affect the Active X control in a negative way.

Does this make any sense? And if so, is there some call I can make within the Editor after such a theme switch that would put the Editor back in the state it was in (with the toolbars, etc.) before the switch. It's almost as if I need to reinitialize the editor in some way once this happens, but I don't know how to do that, especially if there was already a document loaded in the editor that needs to remain open.

Any help here would be greatly appreciated.

Again, to clarify, this happens independent of my changing or not the setting IXV_Inst.Settings['CustomUI.Theme'] from this origin thread request.

--Jeff
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2352
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: DarkMode

Post by Vasyl-Tracker Dev Team »

Hi Jeff.

In C#, to change theme:

Code: Select all

{
    PDFXEdit.ICabNode pr = pdfCtl.Inst.Settings["CustomUI"];
    pr["Theme"].v = "Black"; // "DarkGray", "White", "Black"
                             // "" - it inherits system's UI  style
}
pdfCtl.Inst.FireAppPrefsChanged(PDFXEdit.PXV_AppPrefsChanges.PXV_AppPrefsChange_CustomUI);
To just enable the inheritance of the system's 'Dark Mode for apps' you need to specify CustomUI.Theme="" and CustomUI.CanUseSysDarkMode=true. Do it once and then Editor will autoupdate its whole UI every time when user change that system's DarkMode option (in System/Colors/YourDefaultAppMode=Dark|Light).

We tested that code in our FullDemo and its works well, without loosing toolbars customization. Can you confirm that on your side with the latest version of our SDK?

Cheers.
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: DarkMode

Post by jeffp »

I guess I wasn't clear in my last message. The issue has nothing to do with how Dark Mode or any theme is set in your Editor.

With your Editor being embedded as an Active X control inside my Delphi application, something happens to the Editor when I change themes inside my Delphi app. This is not related to the setting you showed me in my initial post to this thread.

It seems to be the way the ActiveX is affected by a change in theme from the application that you Editor is embedded in.

Any ideas here as to what this may be?

--Jeff
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: DarkMode

Post by zarkogajic »

Hi Jeff,

How do you change the theme in your app. Let's see a few lines of code.


p.s.
What probably happens is that pxv_control's window hadle gets recreated when you do theme change.

p.s.2.
The same thing would happen for TWebBrowser.

-žarko
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: DarkMode

Post by jeffp »

In the Delphi Vcl.Themes.pas unit, I call this

TStyleManager.TrySetStyle('Windows 10 Dark', False);

You'll need to make sure that Theme is turned on in your IDE.

Yes, it does feel like a Window handle recreation issue. When I make that call, the entire application seems to disappear and reappear.

Is there a way deal with the Window handle of your embedded ActiveX control when this happens?

--Jeff
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: DarkMode

Post by zarkogajic »

Hi Jeff,

Yes, SetStyle calls RecreateWnd - and all handles are recreated - and that's causing pxv_control to "lose its state".
Is there a way deal with the Window handle of your embedded ActiveX control when this happens?
That would be super tricky (if possible at all) and I would suggest not to go that way.

How important is to allow style change for user on-the-fly?

Let them choose a style (save it somewhere) and restart the app - then apply the style (before doing anything with pxv_control).

-žarko
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: DarkMode

Post by jeffp »

I was doing it on a restart of the app before. Looks like I'll need to return to that way of doing it.

Thanks for your help here.

--Jeff
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2352
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: DarkMode

Post by Vasyl-Tracker Dev Team »

Zarko - thanks for your helpful help! :)
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: DarkMode

Post by zarkogajic »

Hi Jeff,

You got me thinking here ... so I was not settled until either I'm sure there's "no solution" or "solution found" :)

What happens here is that RecreateWnd calls CreateWnd / DestroyWnd where standard VCL controls would re-apply their "state" (check what TWinControl or TCustomTreeView does) when the handle was destroyed/created.

Since we cannot save pxv_control's state and since you will not be styling the pxv_control via VCL styling - we do not really need the handle to be destroyed / created.

In other words the handle needs to be preserved in between DestroyWnd / CreateWnd - when we are really not destroying it - meaning we need to override the implementation of those two methods.

If pxv_control is on a form, you can do the task simply by using class intercepting/interposing:

Code: Select all

//form's unit where TPXV_Control is used

type
  TPXV_Control = class(PDFXEdit_TLB.TPXV_Control)
  strict private
    TheHandle : THandle;
  protected
    procedure DestroyWnd; override;
    procedure CreateWnd; override;
  end;
and the implementation:

Code: Select all

procedure TPXV_Control.CreateWnd;
begin
  if (TheHandle <> 0) AND IsWindow(TheHandle) then
  begin
    WindowHandle := TheHandle;
    TheHandle := 0;
    WinApi.Windows.SetParent(WindowHandle, Parent.Handle);
  end
  else
    inherited CreateWnd;
end;

procedure TPXV_Control.DestroyWnd;
begin
  if csRecreating in self.ControlState then
  begin
    WinApi.Windows.SetParent(WindowHandle, Application.Handle);
    TheHandle := WindowHandle;
    WindowHandle := 0;
  end
  else
    inherited DestroyWnd;
end;
HTH :)


-žarko
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: DarkMode

Post by jeffp »

YES!

The seems to work. I'll do some more testing, but thanks so much for sticking with this one.

You guys are awesome. As always!

--Jeff
User avatar
TrackerSupp-Daniel
Site Admin
Posts: 8436
Joined: Wed Jan 03, 2018 6:52 pm

DarkMode

Post by TrackerSupp-Daniel »

:)
Dan McIntyre - Support Technician
Tracker Software Products (Canada) LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Post Reply