From: <ah...@us...> - 2012-08-11 23:20:16
|
Revision: 13392 http://jvcl.svn.sourceforge.net/jvcl/?rev=13392&view=rev Author: ahuser Date: 2012-08-11 23:20:08 +0000 (Sat, 11 Aug 2012) Log Message: ----------- * Mantis #5949: JVCL Controls issues with VCL Styles enabled * Style-Engine workarounds for TJvSpeedButton, TJvStatusBar, PerformEraseBackground * PaintEdit uses the dictated color settings fromt he Style-Engine Modified Paths: -------------- trunk/jvcl/run/JvBaseEdits.pas trunk/jvcl/run/JvLabel.pas trunk/jvcl/run/JvSpeedButton.pas trunk/jvcl/run/JvStatusBar.pas trunk/jvcl/run/JvThemes.pas trunk/jvcl/run/JvToolEdit.pas Modified: trunk/jvcl/run/JvBaseEdits.pas =================================================================== --- trunk/jvcl/run/JvBaseEdits.pas 2012-08-11 23:01:38 UTC (rev 13391) +++ trunk/jvcl/run/JvBaseEdits.pas 2012-08-11 23:20:08 UTC (rev 13392) @@ -319,7 +319,6 @@ uses SysUtils, Math, Graphics, -// JclLogic, JvJCLUtils, JvCalc, JvConsts, JvResources, JclSysUtils; {$R JvBaseEdits.Res} @@ -932,7 +931,6 @@ Invalidate; end; - procedure TJvCustomNumEdit.WMPaint(var Msg: TWMPaint); var S: string; @@ -946,9 +944,6 @@ inherited; end; - - - procedure TJvCustomNumEdit.FontChanged; begin inherited FontChanged; @@ -1029,7 +1024,6 @@ begin Bmp := TBitmap.Create; try - //Bmp.Handle := LoadBitmap(HInstance, sCalcBmp); Bmp.LoadFromResourceName(HInstance, sCalcBmp); GCalcImageIndex := DefaultImages.AddMasked(Bmp, clFuchsia); finally Modified: trunk/jvcl/run/JvLabel.pas =================================================================== --- trunk/jvcl/run/JvLabel.pas 2012-08-11 23:01:38 UTC (rev 13391) +++ trunk/jvcl/run/JvLabel.pas 2012-08-11 23:20:08 UTC (rev 13392) @@ -498,7 +498,7 @@ FChangeLink.OnChange := DoImagesChange; ControlStyle := ControlStyle + [csOpaque, csReplicatable]; {$IFDEF JVCLThemesEnabled} - if ThemeServices.{$IFDEF RTL230_UP}Enabled{$ELSE}ThemesEnabled{$ENDIF RTL230_UP} then + if ThemeServices.Enabled then ControlStyle := ControlStyle - [csOpaque]; {$ENDIF JVCLThemesEnabled} @@ -1065,7 +1065,7 @@ if Transparent <> Value then begin {$IFDEF JVCLThemesEnabled} - if ThemeServices.{$IFDEF RTL230_UP}Enabled{$ELSE}ThemesEnabled{$ENDIF RTL230_UP} then + if ThemeServices.Enabled then Value := True; // themes aware Labels are always transparent {$ENDIF JVCLThemesEnabled} if Value then @@ -1198,7 +1198,7 @@ NeedRepaint := not Transparent and ( {$IFDEF JVCLThemesEnabled} - ThemeServices.{$IFDEF RTL230_UP}Enabled{$ELSE}ThemesEnabled{$ENDIF RTL230_UP} or + ThemeServices.Enabled or {$ENDIF JVCLThemesEnabled} (FHotTrack and not (FDragging or OtherDragging))); @@ -1225,7 +1225,7 @@ NeedRepaint := not Transparent and ( {$IFDEF JVCLThemesEnabled} - ThemeServices.{$IFDEF RTL230_UP}Enabled{$ELSE}ThemesEnabled{$ENDIF RTL230_UP} or + ThemeServices.Enabled or {$ENDIF JVCLThemesEnabled} (FHotTrack and (FDragging or not OtherDragging))); Modified: trunk/jvcl/run/JvSpeedButton.pas =================================================================== --- trunk/jvcl/run/JvSpeedButton.pas 2012-08-11 23:01:38 UTC (rev 13391) +++ trunk/jvcl/run/JvSpeedButton.pas 2012-08-11 23:20:08 UTC (rev 13392) @@ -1225,7 +1225,7 @@ PaintRect := Rect(0, 0, Width, Height); {$IFDEF JVCLThemesEnabled} - if ThemeServices.{$IFDEF RTL230_UP}Enabled{$ELSE}ThemesEnabled{$ENDIF RTL230_UP} then + if ThemeServices.Enabled then begin if ControlInGlassPaint(Self) then FillRect(Canvas.Handle, ClientRect, GetStockObject(BLACK_BRUSH)) Modified: trunk/jvcl/run/JvStatusBar.pas =================================================================== --- trunk/jvcl/run/JvStatusBar.pas 2012-08-11 23:01:38 UTC (rev 13391) +++ trunk/jvcl/run/JvStatusBar.pas 2012-08-11 23:20:08 UTC (rev 13392) @@ -74,6 +74,9 @@ procedure MovePanelControls; function GetPanelClass: TStatusPanelClass; override; procedure SBSetParts(var msg: TMessage); message SB_SETPARTS; + {$IFDEF COMPILER16_UP} + procedure WndProc(var Msg: TMessage); override; + {$ENDIF COMPILER16_UP} public constructor Create(AOwner: TComponent); override; function ExecuteAction(Action: TBasicAction): Boolean; override; @@ -246,6 +249,61 @@ MovePanelControls; end; +{$IFDEF COMPILER16_UP} +procedure TJvStatusBar.WndProc(var Msg: TMessage); +var + DC, PaintDC: HDC; + Buffer: TBitmap; + PS: TPaintStruct; +begin + // TStatusBarStyleHook.Paint catches all WM_PAINT but doesn't call Control.PaintControls() + // what causes TGraphicControls to not be painted. With this code we call the PaintControls + // function in that case. + // TODO: When this bug gets fixed in a later Delphi version, the IFDEFs must be adjusted. + if (Msg.Msg = WM_PAINT) and StyleServices.Enabled and not StyleServices.IsSystemStyle then + begin + DC := HDC(Msg.WParam); + if DoubleBuffered and (DC = 0) then + begin + PaintDC := BeginPaint(Handle, PS); + try + Buffer := TBitmap.Create; + try + Buffer.SetSize(Width, Height); + Msg.WParam := WPARAM(Buffer.Canvas.Handle); + inherited WndProc(Msg); + Msg.WParam := WPARAM(DC); + PaintControls(Buffer.Canvas.Handle, nil); + BitBlt(PaintDC, 0, 0, Buffer.Width, Buffer.Height, Buffer.Canvas.Handle, 0, 0, SRCCOPY); + finally + Buffer.Free; + end; + finally + EndPaint(Handle, PS); + end; + end + else + begin + if DC <> 0 then + PaintDC := DC + else + PaintDC := BeginPaint(Handle, PS); + try + Msg.WParam := WPARAM(PaintDC); + inherited WndProc(Msg); + Msg.WParam := WPARAM(DC); + PaintControls(PaintDC, nil); + finally + if DC = 0 then + EndPaint(Handle, PS); + end; + end; + end + else + inherited WndProc(Msg); +end; +{$ENDIF COMPILER16_UP} + //=== { TJvStatusPanel } ===================================================== type Modified: trunk/jvcl/run/JvThemes.pas =================================================================== --- trunk/jvcl/run/JvThemes.pas 2012-08-11 23:01:38 UTC (rev 13391) +++ trunk/jvcl/run/JvThemes.pas 2012-08-11 23:20:08 UTC (rev 13392) @@ -91,7 +91,7 @@ PThemedElementDetails = {$IFDEF COMPILER7_UP}Themes{$ELSE}ThemeSrv{$ENDIF}.PThemedElementDetails; {$EXTERNALSYM PThemedElementDetails} TThemedElementDetails = {$IFDEF COMPILER7_UP}Themes{$ELSE}ThemeSrv{$ENDIF}.TThemedElementDetails; {$EXTERNALSYM TThemedElementDetails} {$IFDEF COMPILER16_UP} - TThemeServices = {$IFDEF COMPILER7_UP}Themes{$ELSE}ThemeSrv{$ENDIF}.TCustomStyleServices; {$EXTERNALSYM TThemeServices} + TThemeServices = Themes.TCustomStyleServices; {$EXTERNALSYM TThemeServices} {$ELSE} TThemeServices = {$IFDEF COMPILER7_UP}Themes{$ELSE}ThemeSrv{$ENDIF}.TThemeServices; {$EXTERNALSYM TThemeServices} {$ENDIF COMPILER16_UP} @@ -726,10 +726,13 @@ {$IFNDEF COMPILER16_UP} function GetElementContentRect(DC: HDC; Details: TThemedElementDetails; const BoundingRect: TRect; out AContentRect: TRect): Boolean; + function IsSystemStyle: Boolean; + function Enabled: Boolean; {$ENDIF ~COMPILER16_UP} end; function ThemeServices: TThemeServicesEx; +function StyleServices: TThemeServicesEx; { PaintControlBorder paints the themed border for WinControls only when they have the WS_EX_CLIENTEDGE. } @@ -808,7 +811,6 @@ procedure DrawGlassableImageList(ImageList: HIMAGELIST; Index: Integer; Dest: HDC; X, Y: Integer; Style: UINT; PaintOnGlass: Boolean = False); - {$IFDEF UNITVERSIONING} const UnitVersioning: TUnitVersionInfo = ( @@ -844,7 +846,7 @@ Cl: TColor; begin {$IFDEF JVCLThemesEnabled} - if ThemeServices.{$IFDEF RTL230_UP}Enabled{$ELSE}ThemesEnabled{$ENDIF RTL230_UP} and + if ThemeServices.Enabled and (Control.Parent <> nil) and ((Color = TWinControlThemeInfo(Control.Parent).Color) or (ColorToRGB(Color) = ColorToRGB(TWinControlThemeInfo(Control.Parent).Color))) and @@ -882,7 +884,7 @@ begin {$IFDEF JVCLThemesEnabled} GetObject(Brush, SizeOf(LogBrush), @LogBrush); - if ThemeServices.{$IFDEF RTL230_UP}Enabled{$ELSE}ThemesEnabled{$ENDIF RTL230_UP} and + if ThemeServices.Enabled and (Control.Parent <> nil) and (LogBrush.lbColor = Cardinal(ColorToRGB(TWinControlThemeInfo(Control.Parent).Color))) and ((not NeedsParentBackground) or @@ -917,7 +919,7 @@ begin Result := False; {$IFDEF JVCLThemesEnabled} - if ThemeServices.{$IFDEF RTL230_UP}Enabled{$ELSE}ThemesEnabled{$ENDIF RTL230_UP} then + if ThemeServices.Enabled then begin R := Rect; case uType of @@ -1141,6 +1143,13 @@ var WindowOrg: TPoint; OrgRgn, Rgn: THandle; + {$IFDEF COMPILER16_UP} + OldPen: HPEN; + OldBrush: HBRUSH; + OldFont: HFONT; + OldTextColor: TColorRef; + OldBkMode: Integer; + {$ENDIF COMPILER16_UP} begin if Control.Parent <> nil then begin @@ -1168,7 +1177,42 @@ end; try + {$IFDEF COMPILER16_UP} + // Delphi XE2's Style-Engine has a bug in the TStyleHook.WMEraseBkgnd that replaces the + // selected GDI objects with the TCanvas default objects ("System" font, ...). + // We need to repair the damage in order to have the same behavior of the native theming API. + // General rule for WM_ERASEBKGND: Return the DC in the state in that it was when the function + // was called. + OldPen := 0; + OldBrush := 0; + OldFont := 0; + OldTextColor := 0; + OldBkMode := 0; + if StyleServices.Enabled and not StyleServices.IsSystemStyle then + begin + OldPen := GetCurrentObject(DC, OBJ_PEN); + OldBrush := GetCurrentObject(DC, OBJ_BRUSH); + OldFont := GetCurrentObject(DC, OBJ_FONT); + OldTextColor := GetTextColor(DC); + OldBkMode := GetBkMode(DC); + end; + {$ENDIF COMPILER16_UP} Control.Parent.Perform(WM_ERASEBKGND, DC, DC); // force redraw + {$IFDEF COMPILER16_UP} + if StyleServices.Enabled and not StyleServices.IsSystemStyle then + begin + if GetCurrentObject(DC, OBJ_PEN) <> OldPen then + SelectObject(DC, OldPen); + if GetCurrentObject(DC, OBJ_BRUSH) <> OldBrush then + SelectObject(DC, OldBrush); + if GetCurrentObject(DC, OBJ_FONT) <> OldFont then + SelectObject(DC, OldFont); + if GetTextColor(DC) <> OldTextColor then + SetTextColor(DC, OldTextColor); + if GetBkMode(DC) <> OldBkMode then + SetBkMode(DC, OldBkMode); + end; + {$ENDIF COMPILER16_UP} finally if (Offset.X <> 0) and (Offset.Y <> 0) then SetWindowOrgEx(DC, WindowOrg.X, WindowOrg.Y, nil); @@ -1202,7 +1246,7 @@ {$ENDIF JVCLThemesEnabled} begin {$IFDEF JVCLThemesEnabled} - if (Style <> bsWin31) and ThemeServices.{$IFDEF RTL230_UP}Enabled{$ELSE}ThemesEnabled{$ENDIF RTL230_UP} then + if (Style <> bsWin31) and ThemeServices.Enabled then begin Result := Client; @@ -1305,7 +1349,7 @@ {$ENDIF COMPILER11_UP} begin {$IFDEF COMPILER11_UP} - if ThemeServices.{$IFDEF RTL230_UP}Enabled{$ELSE}ThemesEnabled{$ENDIF RTL230_UP} and CheckWin32Version(6, 0) then + if ThemeServices.Enabled and CheckWin32Version(6, 0) then begin FillChar(Options, SizeOf(Options), 0); Options.dwSize := SizeOf(Options); @@ -1316,18 +1360,31 @@ Options.dwFlags := Options.dwFlags or DTT_TEXTCOLOR; Options.crText := GetTextColor(DC); - {$IFDEF COMPILER12_UP} - with ThemeServices do - if DrawThemeTextEx(Theme[teToolBar], DC, TP_BUTTON, TS_NORMAL, PWideChar(Text), Length(Text), - TextFlags, TextRect, Options) <> E_NOTIMPL then - Exit; - {$ELSE} - S := Text; - with ThemeServices do - if DrawThemeTextEx(Theme[teToolBar], DC, TP_BUTTON, TS_NORMAL, PWideChar(S), Length(S), - TextFlags, @TextRect, Options) <> E_NOTIMPL then - Exit; - {$ENDIF COMPILER12_UP} + {$IFDEF COMPILER16_UP} + if not StyleServices.IsSystemStyle then + begin + // The Style engine doesn't have DrawThemeTextEx support + {$WARNINGS OFF} // ignore "deprecated" warning + StyleServices.DrawText(DC, StyleServices.GetElementDetails(tbPushButtonNormal), Text, TextRect, TextFlags, 0); + {$WARNINGS ON} + Exit; + end + else + {$ENDIF} + begin + {$IFDEF COMPILER12_UP} + with ThemeServices do + if DrawThemeTextEx(Theme[teToolBar], DC, TP_BUTTON, TS_NORMAL, PWideChar(Text), Length(Text), + TextFlags, TextRect, Options) <> E_NOTIMPL then + Exit; + {$ELSE} + S := Text; + with ThemeServices do + if DrawThemeTextEx(Theme[teToolBar], DC, TP_BUTTON, TS_NORMAL, PWideChar(S), Length(S), + TextFlags, @TextRect, Options) <> E_NOTIMPL then + Exit; + {$ENDIF COMPILER12_UP} + end; end; {$ENDIF COMPILER11_UP} Windows.DrawText(DC, PChar(Text), Length(Text), TextRect, TextFlags); @@ -1401,6 +1458,16 @@ AContentRect := ContentRect(DC, Details, BoundingRect); Result := True; end; + +function TThemeServicesEx.IsSystemStyle: Boolean; +begin + Result := True; +end; + +function TThemeServicesEx.Enabled: Boolean; +begin + Result := ThemesEnabled; +end; {$ENDIF ~COMPILER16_UP} function ThemeServices: TThemeServicesEx; @@ -1409,6 +1476,12 @@ {$IFDEF COMPILER7_UP}Themes{$ELSE}ThemeSrv{$ENDIF}.{$IFDEF RTL230_UP}StyleServices{$ELSE}ThemeServices{$ENDIF RTL230_UP}); end; +function StyleServices: TThemeServicesEx; +begin + Result := TThemeServicesEx( + {$IFDEF COMPILER7_UP}Themes{$ELSE}ThemeSrv{$ENDIF}.{$IFDEF RTL230_UP}StyleServices{$ELSE}ThemeServices{$ENDIF RTL230_UP}); +end; + procedure PaintControlBorder(Control: TWinControl); begin ThemeServices.PaintBorder(TWinControl(Control), False) Modified: trunk/jvcl/run/JvToolEdit.pas =================================================================== --- trunk/jvcl/run/JvToolEdit.pas 2012-08-11 23:01:38 UTC (rev 13391) +++ trunk/jvcl/run/JvToolEdit.pas 2012-08-11 23:20:08 UTC (rev 13392) @@ -1119,6 +1119,9 @@ uses RTLConsts, Math, MaskUtils, MultiMon, + {$IFDEF COMPILER16_UP} + Vcl.Themes, + {$ENDIF COMPILER16_UP} JclFileUtils, JclStrings, JvPickDate, JvJCLUtils, JvJVCLUtils, JvThemes, JvResources, JclSysUtils; @@ -1386,6 +1389,10 @@ AlignStyle: array [Boolean, TAlignment] of DWORD = ((WS_EX_LEFT, WS_EX_RIGHT, WS_EX_LEFT), (WS_EX_RIGHT, WS_EX_LEFT, WS_EX_LEFT)); + {$IFDEF COMPILER16_UP} + ColorStates: array[Boolean] of TStyleColor = (scEditDisabled, scEdit); + FontColorStates: array[Boolean] of TStyleFont = (sfEditBoxTextDisabled, sfEditBoxTextNormal); + {$ENDIF COMPILER16_UP} var LTextWidth, X: Integer; EditRect: TRect; @@ -1401,16 +1408,14 @@ ChangeBiDiModeAlignment(AAlignment); if StandardPaint and not (csPaintCopy in TEd(Editor).ControlState) then begin - if SysLocale.MiddleEast and TEd(Editor).HandleAllocated and (TEd(Editor).IsRightToLeft) then + if SysLocale.MiddleEast and TEd(Editor).HandleAllocated and TEd(Editor).IsRightToLeft then begin { This keeps the right aligned text, right aligned } - ExStyle := DWORD(GetWindowLong(TEd(Editor).Handle, GWL_EXSTYLE)) and (not WS_EX_RIGHT) and - (not WS_EX_RTLREADING) and (not WS_EX_LEFTSCROLLBAR); + ExStyle := DWORD(GetWindowLong(TEd(Editor).Handle, GWL_EXSTYLE)) and not (WS_EX_RIGHT or WS_EX_RTLREADING or WS_EX_LEFTSCROLLBAR); if TEd(Editor).UseRightToLeftReading then ExStyle := ExStyle or WS_EX_RTLREADING; if TEd(Editor).UseRightToLeftScrollBar then ExStyle := ExStyle or WS_EX_LEFTSCROLLBAR; - ExStyle := ExStyle or - AlignStyle[TEd(Editor).UseRightToLeftAlignment, AAlignment]; + ExStyle := ExStyle or AlignStyle[TEd(Editor).UseRightToLeftAlignment, AAlignment]; if DWORD(GetWindowLong(TEd(Editor).Handle, GWL_EXSTYLE)) <> ExStyle then SetWindowLong(TEd(Editor).Handle, GWL_EXSTYLE, ExStyle); end; @@ -1465,7 +1470,15 @@ SaveDC(ACanvas.Handle); try ACanvas.Brush.Style := bsClear; - ACanvas.Font.Color := DisabledTextColor; + {$IFDEF COMPILER16_UP} + if StyleServices.Enabled and not StyleServices.IsSystemStyle then + begin + ACanvas.Brush.Color := StyleServices.GetStyleColor(ColorStates[Editor.Enabled]); + ACanvas.Font.Color := StyleServices.GetStyleFontColor(FontColorStates[Editor.Enabled]); + end + else + {$ENDIF COMPILER16_UP} + ACanvas.Font.Color := DisabledTextColor; ACanvas.TextRect(EditRect, X, EditRect.Top, S); finally RestoreDC(ACanvas.Handle, -1); @@ -1473,7 +1486,15 @@ end else begin - Brush.Color := TEd(Editor).Color; + {$IFDEF COMPILER16_UP} + if StyleServices.Enabled and not StyleServices.IsSystemStyle then + begin + ACanvas.Brush.Color := StyleServices.GetStyleColor(ColorStates[Editor.Enabled]); + ACanvas.Font.Color := StyleServices.GetStyleFontColor(FontColorStates[Editor.Enabled]); + end + else + {$ENDIF COMPILER16_UP} + Brush.Color := TEd(Editor).Color; ACanvas.TextRect(EditRect, X, EditRect.Top, S); end; end; @@ -2085,9 +2106,19 @@ Result := inherited DoEraseBackground(Canvas, Param) else begin - Canvas.Brush.Color := FDisabledColor; - Canvas.Brush.Style := bsSolid; - Canvas.FillRect(ClientRect); + {$IFDEF COMPILER16_UP} + if StyleServices.Enabled and not StyleServices.IsSystemStyle then + begin + // Ignore FDisabldColor. The Style dictates the color + Result := inherited DoEraseBackground(Canvas, Param); + end + else + {$ENDIF COMPILER16_UP} + begin + Canvas.Brush.Color := FDisabledColor; + Canvas.Brush.Style := bsSolid; + Canvas.FillRect(ClientRect); + end; end; end; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |