Skip to content

Commit af1176a

Browse files
committed
Added TEdit StyleHook
Fixed bug in draw of disabled TCustomLabel Fixed bug in draw of TRadioButton in wrong Vert. position Improved performance of Detour_WinApi_DrawTextEx Added support for version control forms TVersionControlSelect TCheckoutDialog TGitCheckoutDialog TUseUnitDialog TdlgRepoBrowser
1 parent 31bad61 commit af1176a

19 files changed

+1042
-125
lines changed

delphi-ide-theme-editor/IDE PlugIn/Colorizer.Hook.Forms.pas

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ function HandleColorizerStyleMessage(Self : TWinControl;var Message: TMessage; W
164164
begin
165165
HookedControls.Add(Self, TColorizerStatusBarStyleHook.Create(Self));
166166
LHook:=HookedControls[Self];
167+
end
168+
else
169+
if Self is TEdit then
170+
begin
171+
HookedControls.Add(Self, TColorizerEditStyleHook.Create(Self));
172+
LHook:=HookedControls[Self];
167173
end;
168174

169175

delphi-ide-theme-editor/IDE PlugIn/Colorizer.Hooks.IDE.pas

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,6 @@ implementation
8585
GraphUtil,
8686
SysUtils,
8787
CaptionedDockTree,
88-
89-
JclDebug,
90-
Dialogs,
91-
9288
Graphics;
9389

9490
type
@@ -749,7 +745,7 @@ function Detour_TDockCaptionDrawer_DrawDockCaption(Self : TDockCaptionDrawerClas
749745
Canvas.Pen.Color := TColorizerLocalSettings.ColorMap.FrameTopLeftInner;
750746

751747
CaptionRect.Top := CaptionRect.Top + 1;
752-
if not (TColorizerLocalSettings.Settings.UseVCLStyles and TColorizerLocalSettings.Settings.VCLStylesForms) then
748+
if TColorizerLocalSettings.Settings.DockCustomColors or not (TColorizerLocalSettings.Settings.UseVCLStyles and TColorizerLocalSettings.Settings.VCLStylesForms) then
753749
begin
754750
if State.Focused then
755751
begin
@@ -1007,49 +1003,6 @@ function Detour_TDockCaptionDrawer_DrawDockCaption(Self : TDockCaptionDrawerClas
10071003
sPopupSearchForm_PaintCategoryNode = '@Popupsrchfrm@TPopupSearchForm@PaintCategoryNode$qqrp28Idevirtualtrees@TVirtualNodep20Vcl@Graphics@TCanvasr18System@Types@TRectp33Ideinsightmgr@TIDEInsightCategoryo';
10081004
sPopupSearchForm_PaintItemNode = '@Popupsrchfrm@TPopupSearchForm@PaintItemNode$qqrp28Idevirtualtrees@TVirtualNodep20Vcl@Graphics@TCanvasr18System@Types@TRectp29Ideinsightmgr@TIDEInsightItemo';
10091005

1010-
1011-
//var
1012-
// TrampolineOpenKey : function (Self: TObject;const Key: string; CanCreate: Boolean): Boolean;
1013-
// TrampolineInternalLoadPropValues : procedure (Self: TObject);
1014-
//
1015-
//
1016-
//function DetourOpenKey(Self: TObject;const Key: string; CanCreate: Boolean): Boolean;
1017-
//var
1018-
// sCaller : string;
1019-
// i : integer;
1020-
//begin
1021-
// if pos('Hot Link', Key)>1 then
1022-
// begin
1023-
// for i:=1 to 5 do
1024-
// begin
1025-
// sCaller := ProcByLevel(i);
1026-
// AddLog2(Format('Level %d %s Key %s',[i, sCaller, Key]));
1027-
// end;
1028-
// AddLog2('');
1029-
// end;
1030-
//
1031-
// Result:= TrampolineOpenKey(Self, key, CanCreate);
1032-
//end;
1033-
1034-
//@Idereginipropset@TRegistryPropSet@InternalLoadPropValues$qqrv
1035-
1036-
//procedure DetourInternalLoadPropValues(Self: TObject);
1037-
//var
1038-
// sCaller : string;
1039-
// i : integer;
1040-
//begin
1041-
//// if pos('Hot Link', Key)>1 then
1042-
// begin
1043-
// for i:=1 to 5 do
1044-
// begin
1045-
// sCaller := ProcByLevel(i);
1046-
// AddLog2(Format('Level %d %s',[i, sCaller]));
1047-
// end;
1048-
// AddLog2('');
1049-
// end;
1050-
// TrampolineInternalLoadPropValues(Self);
1051-
//end;
1052-
10531006
procedure InstallHooksIDE;
10541007
var
10551008
{$IFDEF DELPHIXE6_UP}

delphi-ide-theme-editor/IDE PlugIn/Colorizer.Hooks.Windows.pas

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ function Detour_WinApi_DrawText(hDC: HDC; lpString: LPCWSTR; nCount: Integer; v
314314
RestoreColor:=False;
315315
sCaller:='';
316316

317-
if (uFormat=2084) and Assigned(TColorizerLocalSettings.Settings) and TColorizerLocalSettings.Settings.Enabled and Assigned(TColorizerLocalSettings.ColorMap) then
317+
if {(uFormat AND DT_CALCRECT = 0) and} (uFormat=2084) and Assigned(TColorizerLocalSettings.Settings) and TColorizerLocalSettings.Settings.Enabled and Assigned(TColorizerLocalSettings.ColorMap) then
318318
begin
319319
OrgColor:=GetTextColor(hDC);
320320
LFontColor :=ColorToRGB(TColorizerLocalSettings.ColorMap.FontColor);
@@ -405,7 +405,8 @@ function Detour_WinApi_DrawTextEx(DC: HDC; lpchText: LPCWSTR; cchText: Integer;
405405
{$IFDEF DELPHIXE6_UP}
406406
OrgColor:=0;
407407
RestoreColor:=False;
408-
if Assigned(TColorizerLocalSettings.Settings) and TColorizerLocalSettings.Settings.Enabled and Assigned(TColorizerLocalSettings.ColorMap) then
408+
409+
if (dwDTFormat AND DT_CALCRECT = 0) and Assigned(TColorizerLocalSettings.Settings) and TColorizerLocalSettings.Settings.Enabled and Assigned(TColorizerLocalSettings.ColorMap) then
409410
begin
410411
OrgColor:= GetTextColor(DC);
411412
if (TColor(OrgColor) = clWhite) or (TColor(OrgColor) = clBlack) then

delphi-ide-theme-editor/IDE PlugIn/Colorizer.Hooks.pas

Lines changed: 130 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ implementation
4848
Colorizer.uxThemeHelper,
4949
{$ENDIF}
5050
Messages,
51+
System.Diagnostics,
52+
System.TimeSpan,
5153
TypInfo,
5254
Forms,
5355
ExtCtrls,
@@ -109,6 +111,7 @@ TCustomActionPopupMenuClass = class(TCustomActionPopupMenu);
109111
TCustomControlClass = class(TCustomControl);
110112
TCustomControlBarClass = class(TCustomControlBar);
111113
TCustomButtonClass = class(TCustomButton);
114+
TCustomLabelClass = class(TCustomLabel);
112115
var
113116
{$IF CompilerVersion<27} //XE6
114117
TrampolineCustomImageList_DoDraw : procedure (Self: TObject; Index: Integer; Canvas: TCanvas; X, Y: Integer; Style: Cardinal; Enabled: Boolean) = nil;
@@ -148,7 +151,9 @@ TCustomButtonClass = class(TCustomButton);
148151
Trampoline_HintWindow_Paint : procedure (Self : THintWindow) = nil;
149152
Trampoline_MessageHintWindow_Paint : procedure (Self : THintWindow) = nil;
150153
Trampoline_Bevel_Paint : procedure (Self : TBevel) = nil;
151-
Trampoline_TCustomControlBar_PaintControlFrame : procedure (Self:TCustomControlBar; Canvas: TCanvas; AControl: TControl; var ARect: TRect)=nil;
154+
Trampoline_TCustomControlBar_PaintControlFrame : procedure (Self:TCustomControlBar; Canvas: TCanvas; AControl: TControl; var ARect: TRect) = nil;
155+
Trampoline_TCustomLabel_DoDrawText : procedure (Self : TCustomLabel;var Rect: TRect; Flags: Longint) = nil;
156+
152157

153158
//Trampoline_TCustomActionPopupMenu_CreateParams : procedure(Self: TCustomActionPopupMenu;var Params: TCreateParams) = nil;
154159

@@ -224,6 +229,122 @@ TDWordFiller = record
224229
end;
225230
{$ENDIF}
226231

232+
233+
procedure Detour_TCustomLabelClass_DoDrawText(Self : TCustomLabelClass;var Rect: TRect; Flags: Longint);
234+
const
235+
EllipsisStr = '...';
236+
Ellipsis: array[TEllipsisPosition] of Longint = (0, DT_PATH_ELLIPSIS,
237+
DT_END_ELLIPSIS, DT_WORD_ELLIPSIS);
238+
var
239+
LParentForm : TCustomForm;
240+
LRect: TRect;
241+
Height, Delim: Integer;
242+
LText, DText: string;
243+
244+
procedure DrawStyledText(DC: HDC; const Text: UnicodeString; var TextRect: TRect; TextFlags: Cardinal);
245+
const
246+
CStates: array[Boolean] of TThemedTextLabel = (ttlTextLabelDisabled, ttlTextLabelNormal);
247+
var
248+
LFormat: TTextFormat;
249+
LOptions: TStyleTextOptions;
250+
begin
251+
LFormat := TTextFormatFlags(TextFlags);
252+
if csGlassPaint in Self.ControlState then
253+
Include(LFormat, tfComposited);
254+
255+
LOptions.Flags := [stfTextColor, stfGlowSize];
256+
LOptions.TextColor := Self.Canvas.Font.Color;
257+
LOptions.GlowSize := Self.GlowSize;
258+
259+
ColorizerStyleServices.DrawText(DC,
260+
ColorizerStyleServices.GetElementDetails(CStates[Self.Enabled]), Text, TextRect, LFormat, LOptions);
261+
end;
262+
263+
procedure DrawNormalText(DC: HDC; const Text: UnicodeString; var TextRect: TRect; TextFlags: Cardinal);
264+
begin
265+
Windows.DrawTextW(DC, Text, Length(Text), TextRect, TextFlags);
266+
end;
267+
268+
begin
269+
if (Assigned(TColorizerLocalSettings.Settings) and not TColorizerLocalSettings.Settings.Enabled) or (csDesigning in Self.ComponentState) or (not Assigned(TColorizerLocalSettings.ColorMap)) then
270+
begin
271+
Trampoline_TCustomLabel_DoDrawText(Self, Rect, Flags);
272+
exit;
273+
end;
274+
275+
LParentForm:= GetParentForm(Self);
276+
if not (Assigned(LParentForm) and Assigned(TColorizerLocalSettings.HookedWindows) and (TColorizerLocalSettings.HookedWindows.IndexOf(LParentForm.ClassName)>=0)) then
277+
begin
278+
Trampoline_TCustomLabel_DoDrawText(Self, Rect, Flags);
279+
exit;
280+
end;
281+
282+
if Self.Enabled then
283+
begin
284+
Trampoline_TCustomLabel_DoDrawText(Self, Rect, Flags);
285+
exit;
286+
end
287+
else
288+
begin
289+
LText := Self.Caption;
290+
if (Flags and DT_CALCRECT <> 0) and
291+
((LText = '') or Self.ShowAccelChar and (LText[1] = '&') and (Length(LText) = 1)) then
292+
LText := LText + ' ';
293+
294+
if LText <> '' then
295+
begin
296+
if not Self.ShowAccelChar then Flags := Flags or DT_NOPREFIX;
297+
Flags := Self.DrawTextBiDiModeFlags(Flags);
298+
Self.Canvas.Font := Self.Font;
299+
if (Self.EllipsisPosition <> epNone) and not Self.AutoSize then
300+
begin
301+
DText := LText;
302+
Flags := Flags and not DT_EXPANDTABS;
303+
Flags := Flags or Ellipsis[Self.EllipsisPosition];
304+
if Self.WordWrap and (Self.EllipsisPosition in [epEndEllipsis, epWordEllipsis]) then
305+
begin
306+
repeat
307+
LRect := Rect;
308+
Dec(LRect.Right, Self.Canvas.TextWidth(EllipsisStr));
309+
310+
if TColorizerLocalSettings.Settings.UseVCLStyles and TColorizerLocalSettings.Settings.VCLStylesControls then
311+
DrawStyledText(Self.Canvas.Handle, DText, LRect, Flags or DT_CALCRECT)
312+
else
313+
DrawNormalText(Self.Canvas.Handle, DText, LRect, Flags or DT_CALCRECT);
314+
315+
Height := LRect.Bottom - LRect.Top;
316+
if (Height > Self.ClientHeight) and (Height > Self.Canvas.Font.Height) then
317+
begin
318+
Delim := LastDelimiter(' '#9, LText);
319+
if Delim = 0 then
320+
Delim := Length(LText);
321+
Dec(Delim);
322+
if ByteType(LText, Delim) = mbLeadByte then
323+
Dec(Delim);
324+
LText := Copy(LText, 1, Delim);
325+
DText := LText + EllipsisStr;
326+
if LText = '' then
327+
Break;
328+
end
329+
else
330+
Break;
331+
until False;
332+
end;
333+
if LText <> '' then
334+
LText := DText;
335+
end;
336+
337+
if TColorizerLocalSettings.Settings.UseVCLStyles and TColorizerLocalSettings.Settings.VCLStylesControls then
338+
DrawStyledText(Self.Canvas.Handle, LText, Rect, Flags)
339+
else
340+
begin
341+
Self.Canvas.Font.Color:=TColorizerLocalSettings.ColorMap.DisabledFontColor;
342+
DrawNormalText(Self.Canvas.Handle, LText, Rect, Flags);
343+
end;
344+
end;
345+
end;
346+
end;
347+
227348
procedure Detour_TCustomControlBar_PaintControlFrame(Self:TCustomControlBarClass; Canvas: TCanvas; AControl: TControl; var ARect: TRect);
228349
const
229350
Offset = 3;
@@ -2526,12 +2647,18 @@ procedure Detour_TCanvas_FillRect(Self: TCanvas;const Rect: TRect);
25262647
var
25272648
sCaller : string;
25282649
OrgBrush : Integer; //don't use SaveDC
2650+
// Stopwatch: TStopwatch;
2651+
// Elapsed: TTimeSpan;
25292652
begin
25302653
OrgBrush:=Self.Brush.Color;
25312654
try
25322655
if Assigned(TColorizerLocalSettings.Settings) and TColorizerLocalSettings.Settings.Enabled and (OrgBrush=clBtnFace) then
25332656
begin
2657+
//Stopwatch := TStopwatch.StartNew;
25342658
sCaller := ProcByLevel(1);
2659+
//Elapsed := Stopwatch.Elapsed;
2660+
//AddLog2(Format('ProcByLevel(1) Elapsed %n ms ',[elapsed.TotalMilliseconds]));
2661+
25352662
if SameText(sCaller, sEditorControlSignature) then
25362663
Self.Brush.Color:=GetGutterBkColor
25372664
else
@@ -3018,7 +3145,7 @@ procedure InstallColorizerHooks;
30183145

30193146
Trampoline_TButtonControl_WndProc := InterceptCreate(@TButtonControlClass.WndProc, @Detour_TButtonControlClass_WndProc);
30203147
// *******************************************
3021-
3148+
Trampoline_TCustomLabel_DoDrawText := InterceptCreate(@TCustomLabelClass.DoDrawText, @Detour_TCustomLabelClass_DoDrawText);
30223149
end;
30233150

30243151
procedure RemoveColorizerHooks;
@@ -3064,6 +3191,7 @@ procedure RemoveColorizerHooks;
30643191
InterceptRemove(@Trampoline_TCustomGroupBox_Paint);
30653192
InterceptRemove(@Trampoline_CustomComboBox_WMPaint);
30663193
InterceptRemove(@Trampoline_TCustomCombo_WndProc);
3194+
InterceptRemove(@Trampoline_TCustomLabel_DoDrawText);
30673195
end;
30683196

30693197
end.

0 commit comments

Comments
 (0)