shineworld 73 Posted September 20, 2021 Hi all, I've already used Themes, with satisfaction, on some little applications. In a big application, I haven't used the TStyleManager.Engine because too hard to re-design the entire application, but I would like to have a way to style only the scrollbars colors of a TSynEdit component. It is, in some way, possible to add ONLY the TScrollingStyleHook behavior in a program without the Style engine running? Thank you for your suggenstions! Share this post Link to post
Lajos Juhász 292 Posted September 20, 2021 I doubt anyone took the time to add Delphi styles to Synedit. Share this post Link to post
shineworld 73 Posted September 20, 2021 I've already added Style in TSynEdit and it is very simple to do. For example, to add the Scrollbar style is only necessary to add this line: uses Vcl.Themes; {$R *.dfm} procedure TForm8.FormCreate(Sender: TObject); begin TStyleManager.Engine.RegisterStyleHook(TCustomSynEdit, TScrollingStyleHook); end; But I don't would to enable styling in all my project BUT only to SynEdit scrollbar so this is not a way to follow. Perhaps I need to study a way to "extract" what Vcl.Theme manager does for TScrollingStyleHook and to apply only to my version of TCustomSynEdit... Unfortunately, the entire project already living with an old theme system (Light/Dark), and now I can't change it. Share this post Link to post
shineworld 73 Posted September 23, 2021 Any idea on how to "force" the scrollbar colors? With dark mode are very very ugly: I've googled a lot searching for a way to use TThemeManager forcing it only to a component without results... Share this post Link to post
bravesofts 6 Posted September 24, 2021 (edited) 15 hours ago, shineworld said: Any idea on how to "force" the scrollbar colors? With dark mode are very very ugly: I've googled a lot searching for a way to use TThemeManager forcing it only to a component without results... try to add TScrollbar and make it related with that SynEdit and finally you will have a completely separated scrollbar with StyleElement property don't forget to make Scrollbars property to ssNone for your SynEdit Edited September 24, 2021 by bravesofts Share this post Link to post
dwrbudr 8 Posted September 24, 2021 Checking Vcl.Forms.pas, it registers both TCustomForm and TForm to the style engine. Does it help if you call TStyleManager.Engine.RegisterStyleHook(TSynEdit, TScrollingStyleHook); Share this post Link to post
shineworld 73 Posted October 18, 2021 (edited) In the end, I've solved placing two external TScrollbars (TAdvSmoothScroolbars from TMS), they permit a deep control of colors and removing Windows SCROLLBAR created by TSynEdit. - The SynEdit.ScrollBars := ssNone; - The SynEdit.UpdateScrollbars from private to protected and of dynamic type. - A helper class in my editor frame class: unit osGCodeEditorFrame; interface uses ... type TGCodeEditor = class(SynEdit.TSynEdit) private procedure EditorVBarPositionChanged(Sender: TObject; Position: Integer); procedure EditorHBarPositionChanged(Sender: TObject; Position: Integer); protected procedure UpdateScrollBars; override; private FInUpdateScrollBars: Boolean; public EditorHBar: TAdvSmoothScrollBar; EditorVBar: TAdvSmoothScrollBar; end; ... ... // creates and sets gcode editor FGCodeEditor := TSynEdit.Create(Self); FGCodeEditor.Parent := Self; FGCodeEditor.Align := alClient; FGCodeEditor.Visible := True; FGCodeEditor.ScrollBars := ssNone; // creates and sets gcode editor horizontal scroll bar FGCodeEditor.EditorHBar := TAdvSmoothScrollBar.Create(Self); FGCodeEditor.EditorHBar.Parent := Self; FGCodeEditor.EditorHBar.Align := alBottom; FGCodeEditor.EditorHBar.Kind := sbHorizontal; FGCodeEditor.EditorHBar.OnPositionChanged := FGCodeEditor.EditorHBarPositionChanged; // creates and sets gcode editor vertical scroll bar FGCodeEditor.EditorVBar := TAdvSmoothScrollBar.Create(Self); FGCodeEditor.EditorVBar.Parent := Self; FGCodeEditor.EditorVBar.Align := alRight; FGCodeEditor.EditorVBar.Kind := sbVertical; FGCodeEditor.EditorVBar.OnPositionChanged := FGCodeEditor.EditorVBarPositionChanged; ... { TGCodeEditor } procedure TGCodeEditor.EditorHBarPositionChanged(Sender: TObject; Position: Integer); begin if FInUpdateScrollBars then Exit; LeftChar := EditorHBar.Position; end; procedure TGCodeEditor.EditorVBarPositionChanged(Sender: TObject; Position: Integer); begin if FInUpdateScrollBars then Exit; TopLine := EditorVBar.Position; end; procedure TGCodeEditor.UpdateScrollBars; var MaxScroll: Integer; ScrollInfo: TScrollInfo; begin inherited; // checks if standard scroll bars enabled if ScrollBars <> ssNone then Exit; // check if custom scroll bars enabled if (EditorVBar = nil) or (EditorHBar = nil) then Exit; FInUpdateScrollBars := True; try // evaluates for custom horizontal scrollbar if EditorHBar <> nil then begin MaxScroll := Max(TSynEditStringList(Lines).LengthOfLongestLine, 1); ScrollInfo.nMin := 1; ScrollInfo.nMax := MaxScroll; ScrollInfo.nPage := CharsInWindow; ScrollInfo.nPos := LeftChar; EditorHBar.Min := ScrollInfo.nMin; EditorHBar.Max := ScrollInfo.nMax; EditorHBar.PageSize := ScrollInfo.nPage; EditorHBar.Position := ScrollInfo.nPos; EditorHBar.Visible := ScrollInfo.nMax > CharsInWindow; end else EditorHBar.Visible := False; // evaluates for custom vertical scrollbar if EditorVBar <> nil then begin MaxScroll := DisplayLineCount; ScrollInfo.nMin := 1; ScrollInfo.nMax := Max(1, MaxScroll); ScrollInfo.nPage := LinesInWindow; ScrollInfo.nPos := TopLine; EditorVBar.Min := ScrollInfo.nMin; EditorVBar.Max := ScrollInfo.nMax; EditorVBar.PageSize := ScrollInfo.nPage; EditorVBar.Position := ScrollInfo.nPos; EditorVBar.Visible := ScrollInfo.nMax > LinesInWindow; end else EditorVBar.Visible := False; finally FInUpdateScrollBars := False; end; end; In this way is possible to use standard scrollbars or custom and use the already available and called in TSynEdit.UpdateScrollbars, which does nothing is ScrollBars = ssNone to manage update of external custom scrollbars. Works perfectly: Edited October 18, 2021 by shineworld Share this post Link to post