Menu

[327ada]: / Source / VCL / vcl-styles-utils / Common / Vcl.Styles.Utils.ScreenTips.pas  Maximize  Restore  History

Download this file

162 lines (139 with data), 4.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// **************************************************************************************************
//
// Unit Vcl.Styles.Utils.ScreenTips
// unit for the VCL Styles Utils
// https://github.com/RRUZ/vcl-styles-utils/
//
// The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License");
// you may not use this file except in compliance with the License. You may obtain a copy of the
// License at http://www.mozilla.org/MPL/
//
// Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
// ANY KIND, either express or implied. See the License for the specific language governing rights
// and limitations under the License.
//
//
// Portions created by Mahdi Safsafi [SMP3] e-mail SMP@LIVE.FR
// Portions created by Rodrigo Ruz V. are Copyright (C) 2013-2020 Rodrigo Ruz V.
// All Rights Reserved.
//
// **************************************************************************************************
unit Vcl.Styles.Utils.ScreenTips;
interface
uses
System.Classes,
System.SysUtils,
Winapi.Windows,
Winapi.Messages,
Vcl.Themes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Styles.Utils.SysStyleHook,
Vcl.Forms,
Vcl.GraphUtil;
type
TSysTooltipsStyleHook = class(TSysStyleHook)
private
procedure WMPaint(var Message: TMessage); message WM_PAINT;
protected
procedure Paint(Canvas: TCanvas); override;
procedure PaintHint(Canvas: TCanvas; TextRect: TRect);
procedure WndProc(var Message: TMessage); override;
public
constructor Create(AHandle: THandle); override;
Destructor Destroy; override;
end;
implementation
uses
Winapi.CommCtrl,
{$IF CompilerVersion >= 30.0} //DX Seattle and UP.
Vcl.SysStyles,
{$IFEND}
Vcl.Styles.Utils.SysControls;
{ TSysTooltipsStyleHook }
const
TTM_ADJUSTRECT = WM_USER + 31;
procedure TSysTooltipsStyleHook.PaintHint(Canvas: TCanvas; TextRect: TRect);
var
DC: HDC;
LDetails: TThemedElementDetails;
BkColor, GradientStartColor, GradientEndColor, TextColor, LColor: TColor;
Brush: HBRUSH;
AText: PChar;
begin
DC := Canvas.Handle;
BkColor := $00767676;
GradientStartColor := clWhite;
GradientEndColor := $EFE4E3;
TextColor := $00575757;
if StyleServices.Enabled then
begin
LDetails := StyleServices.GetElementDetails(thHintBalloon);
if StyleServices.GetElementColor(LDetails, ecBorderColor, LColor) and (LColor <> clNone) then
BkColor := LColor;
if StyleServices.GetElementColor(LDetails, ecGradientColor1, LColor) and (LColor <> clNone) then
GradientStartColor := LColor;
if StyleServices.GetElementColor(LDetails, ecGradientColor2, LColor) and (LColor <> clNone) then
GradientEndColor := LColor;
if StyleServices.GetElementColor(LDetails, ecTextColor, LColor) and (LColor <> clNone) then
TextColor := LColor;
end;
{ Draw Tooltips Face }
GradientFillCanvas(Canvas, GradientStartColor, GradientEndColor, SysControl.ClientRect, gdVertical);
{ Draw Tooltips Border }
Brush := CreateSolidBrush(ColorToRGB(BkColor));
FrameRect(DC, SysControl.ClientRect, Brush);
DeleteObject(Brush);
{ Use default font for Tooltips text }
SelectObject(DC, Screen.HintFont.Handle);
{ Draw Tooltips Text }
SetBkMode(DC, TRANSPARENT);
SetTextColor(DC, ColorToRGB(TextColor));
AText := PChar(SysControl.Text);
Winapi.Windows.DrawText(DC, AText, -1, TextRect, DT_LEFT);
end;
procedure TSysTooltipsStyleHook.WMPaint(var Message: TMessage);
begin
CallDefaultProc(Message);
if (GetWindowLong(Handle, GWL_STYLE) and TTS_BALLOON) = TTS_BALLOON then
Handled := True
else
inherited;
end;
procedure TSysTooltipsStyleHook.WndProc(var Message: TMessage);
begin
inherited;
end;
constructor TSysTooltipsStyleHook.Create(AHandle: THandle);
begin
inherited;
{$IF CompilerVersion > 23.0}
StyleElements := [seClient];
{$ELSE}
OverridePaint := True;
OverridePaintNC := False;
OverrideFont := False;
{$IFEND}
end;
destructor TSysTooltipsStyleHook.Destroy;
begin
inherited;
end;
procedure TSysTooltipsStyleHook.Paint(Canvas: TCanvas);
Var
TextRect: TRect;
begin
{ Adjust text rectangle }
TextRect := SysControl.ClientRect;
SendMessage(Handle, TTM_ADJUSTRECT, 0, UINT_PTR(@TextRect));
PaintHint(Canvas, TextRect);
end;
initialization
{$IF CompilerVersion >= 30.0} //DX Seattle and UP.
TCustomStyleEngine.UnRegisterSysStyleHook('tooltips_class32', Vcl.SysStyles.TSysTooltipsStyleHook);
{$IFEND}
if StyleServices.Available then
TSysStyleManager.RegisterSysStyleHook(TOOLTIPS_CLASS, TSysTooltipsStyleHook);
finalization
TSysStyleManager.UnRegisterSysStyleHook(TOOLTIPS_CLASS, TSysTooltipsStyleHook);
end.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.