Skip to content

Commit c362d00

Browse files
committed
Add demo showcasing styling the titlebar in your dialogs
1 parent 6cd2326 commit c362d00

8 files changed

+1383
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package OTAPISDK.Sample.UseIDETitleBarStyling;
2+
3+
{$R *.res}
4+
{$IFDEF IMPLICITBUILDING This IFDEF should not be used by users}
5+
{$ALIGN 8}
6+
{$ASSERTIONS ON}
7+
{$BOOLEVAL OFF}
8+
{$DEBUGINFO OFF}
9+
{$EXTENDEDSYNTAX ON}
10+
{$IMPORTEDDATA ON}
11+
{$IOCHECKS ON}
12+
{$LOCALSYMBOLS ON}
13+
{$LONGSTRINGS ON}
14+
{$OPENSTRINGS ON}
15+
{$OPTIMIZATION OFF}
16+
{$OVERFLOWCHECKS ON}
17+
{$RANGECHECKS ON}
18+
{$REFERENCEINFO ON}
19+
{$SAFEDIVIDE OFF}
20+
{$STACKFRAMES ON}
21+
{$TYPEDADDRESS OFF}
22+
{$VARSTRINGCHECKS ON}
23+
{$WRITEABLECONST OFF}
24+
{$MINENUMSIZE 1}
25+
{$IMAGEBASE $400000}
26+
{$DEFINE DEBUG}
27+
{$ENDIF IMPLICITBUILDING}
28+
{$DESCRIPTION 'OpenToolsAPI SDK Samples - Using IDE Styling'}
29+
{$LIBSUFFIX AUTO}
30+
{$IMPLICITBUILD ON}
31+
32+
requires
33+
rtl,
34+
designide,
35+
vcl;
36+
37+
contains
38+
OTAPISample.UseThemeBarStyling.Forms.Main in 'src\OTAPISample.UseThemeBarStyling.Forms.Main.pas' {frmMainForm},
39+
OTAPISample.UseThemeBarStyling.Expert in 'src\OTAPISample.UseThemeBarStyling.Expert.pas',
40+
OTAPISample.UseThemeBarStyling.ThemeNotifier in 'src\OTAPISample.UseThemeBarStyling.ThemeNotifier.pas';
41+
42+
end.

Demos/Using_IDE_TitleBar_Theming/OTAPISDK.Sample.UseIDETitleBarStyling.dproj

+1,007
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Styling your forms according to the current IDE Style
2+
3+
This demo showcases how you can check if the IDE supports styling, register an notify event so you can respond to theme changes and safely handling destruction of the form.
4+
5+
When compiling and installing this package, the demo form will be registered under Help -> Help Wizards.
6+
7+
Written and tested with Delphi 11.3 Alexandria.
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
unit OTAPISample.UseThemeBarStyling.Expert;
2+
3+
interface
4+
5+
uses
6+
ToolsAPI;
7+
8+
type
9+
TOTAPISampleStyledFormExpert = class(TNotifierObject, IOTANotifier, IOTAWizard, IOTAMenuWizard)
10+
public
11+
{ IOTAMenuWizard }
12+
function GetMenuText: string;
13+
{ IOTAWizard }
14+
procedure Execute;
15+
function GetIDString: string;
16+
function GetName: string;
17+
function GetState: TWizardState;
18+
{ IOTANotifier }
19+
procedure Destroyed;
20+
end;
21+
22+
procedure Register;
23+
24+
implementation
25+
26+
uses
27+
OTAPISample.UseThemeBarStyling.Forms.Main;
28+
29+
procedure Register;
30+
begin
31+
RegisterPackageWizard(TOTAPISampleStyledFormExpert.Create as IOTAMenuWizard);
32+
end;
33+
34+
{ TOTAPISampleStyledFormExpert }
35+
36+
procedure TOTAPISampleStyledFormExpert.Destroyed;
37+
begin
38+
TfrmMainForm.DestroyForm;
39+
end;
40+
41+
procedure TOTAPISampleStyledFormExpert.Execute;
42+
begin
43+
TfrmMainForm.CreateSampleStyledForm;
44+
end;
45+
46+
function TOTAPISampleStyledFormExpert.GetIDString: string;
47+
begin
48+
Result := 'OTAPISamples.StyledFormThemeBarExpert';
49+
end;
50+
51+
function TOTAPISampleStyledFormExpert.GetMenuText: string;
52+
begin
53+
Result := 'OTAPI Sample - Show Styled ThemeBar Form';
54+
end;
55+
56+
function TOTAPISampleStyledFormExpert.GetName: string;
57+
begin
58+
Result := 'OTAPI Samples - Show Styled ThemeBar Form';
59+
end;
60+
61+
function TOTAPISampleStyledFormExpert.GetState: TWizardState;
62+
begin
63+
Result := [wsEnabled];
64+
end;
65+
66+
initialization
67+
// Do nothing
68+
69+
finalization
70+
TfrmMainForm.DestroyForm;
71+
72+
end.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
object frmMainForm: TfrmMainForm
2+
Left = 0
3+
Top = 0
4+
Caption = 'OpenToolsAPI Samples - Use IDE Styling'
5+
ClientHeight = 442
6+
ClientWidth = 532
7+
Color = clBtnFace
8+
Font.Charset = DEFAULT_CHARSET
9+
Font.Color = clWindowText
10+
Font.Height = -12
11+
Font.Name = 'Segoe UI'
12+
Font.Style = []
13+
Position = poScreenCenter
14+
OnCreate = FormCreate
15+
TextHeight = 15
16+
object CheckBox1: TCheckBox
17+
Left = 88
18+
Top = 84
19+
Width = 97
20+
Height = 17
21+
Caption = 'CheckBox1'
22+
TabOrder = 0
23+
end
24+
object Button1: TButton
25+
Left = 276
26+
Top = 112
27+
Width = 75
28+
Height = 25
29+
Caption = 'Button1'
30+
TabOrder = 1
31+
end
32+
object Panel1: TPanel
33+
Left = 60
34+
Top = 176
35+
Width = 405
36+
Height = 85
37+
Caption = 'Panel1'
38+
TabOrder = 2
39+
object RadioButton1: TRadioButton
40+
Left = 56
41+
Top = 28
42+
Width = 113
43+
Height = 17
44+
Caption = 'RadioButton1'
45+
TabOrder = 0
46+
end
47+
end
48+
object Edit1: TEdit
49+
Left = 72
50+
Top = 284
51+
Width = 221
52+
Height = 23
53+
TabOrder = 3
54+
Text = 'Edit1'
55+
end
56+
object btnClose: TButton
57+
Left = 8
58+
Top = 8
59+
Width = 75
60+
Height = 25
61+
Caption = 'Close'
62+
TabOrder = 4
63+
OnClick = btnCloseClick
64+
end
65+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
unit OTAPISample.UseThemeBarStyling.Forms.Main;
2+
3+
interface
4+
5+
uses
6+
Winapi.Windows,
7+
Winapi.Messages,
8+
System.SysUtils,
9+
System.Variants,
10+
System.Classes,
11+
Vcl.Graphics,
12+
Vcl.Controls,
13+
Vcl.Forms,
14+
Vcl.Dialogs,
15+
Vcl.StdCtrls,
16+
Vcl.ExtCtrls;
17+
18+
type
19+
TfrmMainForm = class(TForm)
20+
CheckBox1: TCheckBox;
21+
Button1: TButton;
22+
Panel1: TPanel;
23+
RadioButton1: TRadioButton;
24+
Edit1: TEdit;
25+
btnClose: TButton;
26+
procedure FormCreate(Sender: TObject);
27+
procedure btnCloseClick(Sender: TObject);
28+
private
29+
FStyleServicesNotifierID: Integer;
30+
class var FCreationID: Integer;
31+
procedure UpdateFormTheme(Sender: TObject);
32+
public
33+
class procedure CreateSampleStyledForm;
34+
class procedure DestroyForm;
35+
destructor Destroy; override;
36+
end;
37+
38+
var
39+
frmMainForm: TfrmMainForm;
40+
41+
implementation
42+
43+
{$R *.dfm}
44+
45+
uses
46+
OTAPISample.UseThemeBarStyling.ThemeNotifier,
47+
IDETheme.Utils,
48+
ToolsAPI;
49+
50+
{ TfrmMainForm }
51+
52+
class procedure TfrmMainForm.CreateSampleStyledForm;
53+
begin
54+
if not Assigned(frmMainForm) then
55+
frmMainForm := TfrmMainForm.Create(Application.MainForm)
56+
else
57+
frmMainForm.UpdateFormTheme(nil);
58+
59+
//FCreationID := frmMainForm.ShowModal;
60+
frmMainForm.Show;
61+
end;
62+
63+
destructor TfrmMainForm.Destroy;
64+
var
65+
LThemingServices: IOTAIDEThemingServices;
66+
begin
67+
if (FStyleServicesNotifierID <> -1) and (Supports(BorlandIDEServices, IOTAIDEThemingServices, LThemingServices)) then
68+
LThemingServices.RemoveNotifier(FStyleServicesNotifierID);
69+
70+
inherited;
71+
end;
72+
73+
class procedure TfrmMainForm.DestroyForm;
74+
begin
75+
if Assigned(frmMainForm) then
76+
FreeAndNil(frmMainForm);
77+
end;
78+
79+
procedure TfrmMainForm.btnCloseClick(Sender: TObject);
80+
begin
81+
//Self.ModalResult := mrOK;
82+
Self.Close;
83+
end;
84+
85+
procedure TfrmMainForm.FormCreate(Sender: TObject);
86+
var
87+
LThemingServices: IOTAIDEThemingServices;
88+
begin
89+
90+
FStyleServicesNotifierID := -1;
91+
if Supports(BorlandIDEServices, IOTAIDEThemingServices, LThemingServices) then
92+
begin
93+
if LThemingServices.IDEThemingEnabled then
94+
begin
95+
FStyleServicesNotifierID := LThemingServices.AddNotifier(TThemingServicesNotifier.Create(UpdateFormTheme));
96+
Self.UpdateFormTheme(nil);
97+
end;
98+
TIDETitleBarService.AddTitleBar(Self, nil, True);
99+
end;
100+
end;
101+
102+
procedure TfrmMainForm.UpdateFormTheme(Sender: TObject);
103+
var
104+
LThemingServices: IOTAIDEThemingServices;
105+
begin
106+
if Supports(BorlandIDEServices, IOTAIDEThemingServices250, LThemingServices) then
107+
begin
108+
if LThemingServices.IDEThemingEnabled then
109+
begin
110+
LThemingServices.RegisterFormClass(TfrmMainForm);
111+
LThemingServices.ApplyTheme(Self);
112+
end;
113+
end;
114+
end;
115+
116+
initialization
117+
// Do nothing here
118+
119+
finalization
120+
if Assigned(frmMainForm) then
121+
FreeAndNil(frmMainForm);
122+
123+
end.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
unit OTAPISample.UseThemeBarStyling.ThemeNotifier;
2+
3+
interface
4+
5+
uses
6+
System.Classes,
7+
ToolsAPI;
8+
9+
type
10+
TThemingServicesNotifier = class(TInterfacedObject, IOTANotifier, INTAIDEThemingServicesNotifier)
11+
private
12+
FNotifyEvent: TNotifyEvent;
13+
public
14+
{ IOTANotifier }
15+
procedure AfterSave;
16+
procedure BeforeSave;
17+
procedure Destroyed;
18+
procedure Modified;
19+
{ INTAIDEThemingServicesNotifier }
20+
procedure ChangedTheme;
21+
procedure ChangingTheme;
22+
{ TThemingServicesNotifier }
23+
constructor Create(const ANotifyProc: TNotifyEvent);
24+
end;
25+
26+
implementation
27+
28+
{ TThemingServicesNotifier }
29+
30+
procedure TThemingServicesNotifier.AfterSave;
31+
begin
32+
// Do Nothing
33+
end;
34+
35+
procedure TThemingServicesNotifier.BeforeSave;
36+
begin
37+
// Do Nothing
38+
end;
39+
40+
procedure TThemingServicesNotifier.ChangedTheme;
41+
begin
42+
if @FNotifyEvent <> nil then
43+
FNotifyEvent(nil);
44+
end;
45+
46+
procedure TThemingServicesNotifier.ChangingTheme;
47+
begin
48+
// Do Nothing
49+
end;
50+
51+
constructor TThemingServicesNotifier.Create(const ANotifyProc: TNotifyEvent);
52+
begin
53+
if (not Assigned(FNotifyEvent)) and (Assigned(ANotifyProc)) then
54+
FNotifyEvent := ANotifyProc;
55+
end;
56+
57+
procedure TThemingServicesNotifier.Destroyed;
58+
begin
59+
// Do Nothing
60+
end;
61+
62+
procedure TThemingServicesNotifier.Modified;
63+
begin
64+
// Do Nothing
65+
end;
66+
67+
end.

0 commit comments

Comments
 (0)