| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- // SPDX-License-Identifier: LGPL-3.0-linking-exception
- {******************************* CONTRIBUTOR(S) ******************************
- - Edivando S. Santos Brasil | [email protected]
- (Compatibility with delphi VCL 11/2018)
- ***************************** END CONTRIBUTOR(S) *****************************}
- unit BCDefaultThemeManager;
- {$I bgracontrols.inc}
- interface
- uses
- Classes, SysUtils, {$IFDEF FPC}LResources, CustomDrawnDrawers,{$ENDIF}
- Forms, Controls, Graphics, Dialogs,
- {$IFNDEF FPC}BGRAGraphics, GraphType, FPImage, {$ENDIF}
- BCButton, BCButtonFocus, BCNumericKeyboard, BCThemeManager,
- BCSamples, {$IFDEF FPC}BGRACustomDrawn,{$ENDIF} BCKeyboard;
- type
- { TBCDefaultThemeManager }
- TBCDefaultThemeManager = class(TBCThemeManager)
- private
- FBCStyle: TBCSampleStyle;
- FButton: TBCButton;
- FButtonFocus: TBCButtonFocus;
- FCDStyle: TCDDrawStyle;
- procedure SetFBCStyle(AValue: TBCSampleStyle);
- procedure SetFButton(AValue: TBCButton);
- procedure SetFButtonFocus(AValue: TBCButtonFocus);
- procedure SetFCDStyle(AValue: TCDDrawStyle);
- protected
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- public
- procedure Apply(AControl: TWinControl); override;
- procedure Apply(); override;
- published
- property Button: TBCButton read FButton write SetFButton;
- property ButtonFocus: TBCButtonFocus read FButtonFocus write SetFButtonFocus;
- property BCStyle: TBCSampleStyle read FBCStyle write SetFBCStyle;
- property CDStyle: TCDDrawStyle read FCDStyle write SetFCDStyle;
- end;
- {$IFDEF FPC}procedure Register;{$ENDIF}
- implementation
- {$IFDEF FPC}procedure Register;
- begin
- RegisterComponents('BGRA Controls', [TBCDefaultThemeManager]);
- end;
- {$ENDIF}
- { TBCDefaultThemeManager }
- procedure TBCDefaultThemeManager.SetFButton(AValue: TBCButton);
- begin
- if FButton = AValue then
- Exit;
- FButton := AValue;
- end;
- procedure TBCDefaultThemeManager.SetFBCStyle(AValue: TBCSampleStyle);
- begin
- if FBCStyle = AValue then
- Exit;
- FBCStyle := AValue;
- end;
- procedure TBCDefaultThemeManager.SetFButtonFocus(AValue: TBCButtonFocus);
- begin
- if FButtonFocus = AValue then
- Exit;
- FButtonFocus := AValue;
- end;
- procedure TBCDefaultThemeManager.SetFCDStyle(AValue: TCDDrawStyle);
- begin
- if FCDStyle = AValue then
- Exit;
- FCDStyle := AValue;
- end;
- constructor TBCDefaultThemeManager.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- FBCStyle := ssDefault;
- FCDStyle := dsDefault;
- end;
- destructor TBCDefaultThemeManager.Destroy;
- begin
- inherited Destroy;
- end;
- procedure TBCDefaultThemeManager.Apply(AControl: TWinControl);
- var
- i: integer;
- removeTempButton: boolean;
- removeTempButtonFocus: boolean;
- tempButton: TBCButton;
- tempButtonFocus: TBCButtonFocus;
- begin
- removeTempButton := False;
- removeTempButtonFocus := False;
- if (Assigned(FButton)) and (FBCStyle = ssDefault) then
- tempButton := FButton
- else
- begin
- tempButton := TBCButton.Create(Self);
- tempButton.Name := 'BCDefaultThemeManager_tempButton';
- removeTempButton := True;
- StyleButtonsSample(tempButton, FBCStyle);
- end;
- if (Assigned(FButton)) and (FBCStyle = ssDefault) then
- tempButtonFocus := FButtonFocus
- else
- begin
- tempButtonFocus := TBCButtonFocus.Create(Self);
- tempButtonFocus.Name := 'BCDefaultThemeManager_tempButtonFocus';
- removeTempButtonFocus := True;
- StyleButtonsFocusSample(tempButtonFocus, FBCStyle);
- end;
- { Controls }
- for i := 0 to AControl.ControlCount - 1 do
- begin
- { BCButton }
- if (AControl.Controls[i] is TBCButton) then
- with TBCButton(AControl.Controls[i]) do
- if (Assigned(ThemeManager)) and
- (TBCDefaultThemeManager(ThemeManager).Name = Self.Name) and
- (tempButton.Name <> AControl.Controls[i].Name) then
- begin
- Assign(tempButton);
- end;
- { BCButtonFocus }
- if (AControl.Controls[i] is TBCButtonFocus) then
- with TBCButtonFocus(AControl.Controls[i]) do
- if (Assigned(ThemeManager)) and
- (TBCDefaultThemeManager(ThemeManager).Name = Self.Name) then
- begin
- Assign(tempButtonFocus);
- end;
- { Custom Drawn }
- if (AControl.Controls[i] is TBCDButton) then
- with TBCDButton(AControl.Controls[i]) do
- if (Assigned(ThemeManager)) and
- (TBCDefaultThemeManager(ThemeManager).Name = Self.Name) and
- (tempButtonFocus.Name <> AControl.Controls[i].Name) then
- begin
- DrawStyle := CDStyle;
- end;
- if (AControl.Controls[i] is TBCDEdit) then
- with TBCDEdit(AControl.Controls[i]) do
- if (Assigned(ThemeManager)) and
- (TBCDefaultThemeManager(ThemeManager).Name = Self.Name) and
- (tempButtonFocus.Name <> AControl.Controls[i].Name) then
- begin
- DrawStyle := CDStyle;
- end;
- if (AControl.Controls[i] is TBCDStaticText) then
- with TBCDStaticText(AControl.Controls[i]) do
- if (Assigned(ThemeManager)) and
- (TBCDefaultThemeManager(ThemeManager).Name = Self.Name) and
- (tempButtonFocus.Name <> AControl.Controls[i].Name) then
- begin
- DrawStyle := CDStyle;
- end;
- if (AControl.Controls[i] is TBCDProgressBar) then
- with TBCDProgressBar(AControl.Controls[i]) do
- if (Assigned(ThemeManager)) and
- (TBCDefaultThemeManager(ThemeManager).Name = Self.Name) and
- (tempButtonFocus.Name <> AControl.Controls[i].Name) then
- begin
- DrawStyle := CDStyle;
- end;
- if (AControl.Controls[i] is TBCDSpinEdit) then
- with TBCDSpinEdit(AControl.Controls[i]) do
- if (Assigned(ThemeManager)) and
- (TBCDefaultThemeManager(ThemeManager).Name = Self.Name) and
- (tempButtonFocus.Name <> AControl.Controls[i].Name) then
- begin
- DrawStyle := CDStyle;
- end;
- if (AControl.Controls[i] is TBCDCheckBox) then
- with TBCDCheckBox(AControl.Controls[i]) do
- if (Assigned(ThemeManager)) and
- (TBCDefaultThemeManager(ThemeManager).Name = Self.Name) and
- (tempButtonFocus.Name <> AControl.Controls[i].Name) then
- begin
- DrawStyle := CDStyle;
- end;
- if (AControl.Controls[i] is TBCDRadioButton) then
- with TBCDRadioButton(AControl.Controls[i]) do
- if (Assigned(ThemeManager)) and
- (TBCDefaultThemeManager(ThemeManager).Name = Self.Name) and
- (tempButtonFocus.Name <> AControl.Controls[i].Name) then
- begin
- DrawStyle := CDStyle;
- end;
- end;
- { Components }
- for i := 0 to AControl.ComponentCount - 1 do
- begin
- { BCNumericKeyboard }
- if (AControl.Components[i] is TBCNumericKeyboard) then
- with TBCNumericKeyboard(AControl.Components[i]) do
- if (Assigned(ThemeManager)) and
- (TBCDefaultThemeManager(ThemeManager).Name = Self.Name) and
- (tempButton.Name <> TBCNumericKeyboard(AControl.Components[i]).ButtonStyle.Name) then
- begin
- ButtonStyle.Assign(tempButton);
- UpdateButtonStyle;
- end;
- { BCRealNumericKeyboard }
- if (AControl.Components[i] is TBCRealNumericKeyboard) then
- with TBCRealNumericKeyboard(AControl.Components[i]) do
- if (Assigned(ThemeManager)) and
- (TBCDefaultThemeManager(ThemeManager).Name = Self.Name) and
- (tempButton.Name <> TBCRealNumericKeyboard(AControl.Components[i]).ButtonStyle.Name) then
- begin
- ButtonStyle.Assign(tempButton);
- UpdateButtonStyle;
- end;
- { BCKeyboard }
- if (AControl.Components[i] is TBCKeyboard) then
- with TBCKeyboard(AControl.Components[i]) do
- if (Assigned(ThemeManager)) and
- (TBCDefaultThemeManager(ThemeManager).Name = Self.Name) and
- (tempButton.Name <> TBCKeyboard(AControl.Components[i]).ButtonStyle.Name) then
- begin
- ButtonStyle.Assign(tempButton);
- UpdateButtonStyle;
- end;
- end;
- if removeTempButton then
- tempButton.Free;
- if removeTempButtonFocus then
- tempButtonFocus.Free;
- end;
- procedure TBCDefaultThemeManager.Apply;
- begin
- if Self.Owner is TWinControl then
- Apply(Self.Owner as TWinControl)
- else
- raise Exception.Create('The parent is not TWinControl descendant.');
- end;
- end.
|